11cb0ef41Sopenharmony_ci<!DOCTYPE html>
21cb0ef41Sopenharmony_ci<meta charset=utf-8>
31cb0ef41Sopenharmony_ci<title> Event.bubbles attribute is set to false </title>
41cb0ef41Sopenharmony_ci<link rel="help" href="https://dom.spec.whatwg.org/#dom-event-initevent">
51cb0ef41Sopenharmony_ci<link rel="help" href="https://dom.spec.whatwg.org/#concept-event-dispatch">
61cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script>
71cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script>
81cb0ef41Sopenharmony_ci<div id=log></div>
91cb0ef41Sopenharmony_ci<table id="table" border="1" style="display: none">
101cb0ef41Sopenharmony_ci    <tbody id="table-body">
111cb0ef41Sopenharmony_ci    <tr id="table-row">
121cb0ef41Sopenharmony_ci        <td id="table-cell">Shady Grove</td>
131cb0ef41Sopenharmony_ci        <td>Aeolian</td>
141cb0ef41Sopenharmony_ci    </tr>
151cb0ef41Sopenharmony_ci    <tr id="parent">
161cb0ef41Sopenharmony_ci        <td id="target">Over the river, Charlie</td>
171cb0ef41Sopenharmony_ci        <td>Dorian</td>
181cb0ef41Sopenharmony_ci    </tr>
191cb0ef41Sopenharmony_ci    </tbody>
201cb0ef41Sopenharmony_ci</table>
211cb0ef41Sopenharmony_ci<script>
221cb0ef41Sopenharmony_cifunction concatReverse(a) {
231cb0ef41Sopenharmony_ci    return a.concat(a.map(function(x) { return x }).reverse());
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cifunction targetsForDocumentChain(document) {
271cb0ef41Sopenharmony_ci    return [
281cb0ef41Sopenharmony_ci        document,
291cb0ef41Sopenharmony_ci        document.documentElement,
301cb0ef41Sopenharmony_ci        document.getElementsByTagName("body")[0],
311cb0ef41Sopenharmony_ci        document.getElementById("table"),
321cb0ef41Sopenharmony_ci        document.getElementById("table-body"),
331cb0ef41Sopenharmony_ci        document.getElementById("parent")
341cb0ef41Sopenharmony_ci    ];
351cb0ef41Sopenharmony_ci}
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_cifunction testChain(document, targetParents, phases, event_type) {
381cb0ef41Sopenharmony_ci    var target = document.getElementById("target");
391cb0ef41Sopenharmony_ci    var targets = targetParents.concat(target);
401cb0ef41Sopenharmony_ci    var expected_targets = concatReverse(targets);
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci    var actual_targets = [], actual_phases = [];
431cb0ef41Sopenharmony_ci    var test_event = function(evt) {
441cb0ef41Sopenharmony_ci        actual_targets.push(evt.currentTarget);
451cb0ef41Sopenharmony_ci        actual_phases.push(evt.eventPhase);
461cb0ef41Sopenharmony_ci    }
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci    for (var i = 0; i < targets.length; i++) {
491cb0ef41Sopenharmony_ci        targets[i].addEventListener(event_type, test_event, true);
501cb0ef41Sopenharmony_ci        targets[i].addEventListener(event_type, test_event, false);
511cb0ef41Sopenharmony_ci    }
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci    var evt = document.createEvent("Event");
541cb0ef41Sopenharmony_ci    evt.initEvent(event_type, true, true);
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci    target.dispatchEvent(evt);
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci    assert_array_equals(actual_targets, expected_targets, "targets");
591cb0ef41Sopenharmony_ci    assert_array_equals(actual_phases, phases, "phases");
601cb0ef41Sopenharmony_ci}
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_civar phasesForDocumentChain = [
631cb0ef41Sopenharmony_ci    Event.CAPTURING_PHASE,
641cb0ef41Sopenharmony_ci    Event.CAPTURING_PHASE,
651cb0ef41Sopenharmony_ci    Event.CAPTURING_PHASE,
661cb0ef41Sopenharmony_ci    Event.CAPTURING_PHASE,
671cb0ef41Sopenharmony_ci    Event.CAPTURING_PHASE,
681cb0ef41Sopenharmony_ci    Event.CAPTURING_PHASE,
691cb0ef41Sopenharmony_ci    Event.AT_TARGET,
701cb0ef41Sopenharmony_ci    Event.AT_TARGET,
711cb0ef41Sopenharmony_ci    Event.BUBBLING_PHASE,
721cb0ef41Sopenharmony_ci    Event.BUBBLING_PHASE,
731cb0ef41Sopenharmony_ci    Event.BUBBLING_PHASE,
741cb0ef41Sopenharmony_ci    Event.BUBBLING_PHASE,
751cb0ef41Sopenharmony_ci    Event.BUBBLING_PHASE,
761cb0ef41Sopenharmony_ci    Event.BUBBLING_PHASE,
771cb0ef41Sopenharmony_ci];
781cb0ef41Sopenharmony_ci
791cb0ef41Sopenharmony_citest(function () {
801cb0ef41Sopenharmony_ci    var chainWithWindow = [window].concat(targetsForDocumentChain(document));
811cb0ef41Sopenharmony_ci    var phases = [Event.CAPTURING_PHASE].concat(phasesForDocumentChain, Event.BUBBLING_PHASE);
821cb0ef41Sopenharmony_ci    testChain(document, chainWithWindow, phases, "click");
831cb0ef41Sopenharmony_ci}, "In window.document with click event");
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_citest(function () {
861cb0ef41Sopenharmony_ci    testChain(document, targetsForDocumentChain(document), phasesForDocumentChain, "load");
871cb0ef41Sopenharmony_ci}, "In window.document with load event")
881cb0ef41Sopenharmony_ci
891cb0ef41Sopenharmony_citest(function () {
901cb0ef41Sopenharmony_ci    var documentClone = document.cloneNode(true);
911cb0ef41Sopenharmony_ci    testChain(
921cb0ef41Sopenharmony_ci        documentClone, targetsForDocumentChain(documentClone), phasesForDocumentChain, "click");
931cb0ef41Sopenharmony_ci}, "In window.document.cloneNode(true)");
941cb0ef41Sopenharmony_ci
951cb0ef41Sopenharmony_citest(function () {
961cb0ef41Sopenharmony_ci    var newDocument = new Document();
971cb0ef41Sopenharmony_ci    newDocument.appendChild(document.documentElement.cloneNode(true));
981cb0ef41Sopenharmony_ci    testChain(
991cb0ef41Sopenharmony_ci        newDocument, targetsForDocumentChain(newDocument), phasesForDocumentChain, "click");
1001cb0ef41Sopenharmony_ci}, "In new Document()");
1011cb0ef41Sopenharmony_ci
1021cb0ef41Sopenharmony_citest(function () {
1031cb0ef41Sopenharmony_ci    var HTMLDocument = document.implementation.createHTMLDocument();
1041cb0ef41Sopenharmony_ci    HTMLDocument.body.appendChild(document.getElementById("table").cloneNode(true));
1051cb0ef41Sopenharmony_ci    testChain(
1061cb0ef41Sopenharmony_ci        HTMLDocument, targetsForDocumentChain(HTMLDocument), phasesForDocumentChain, "click");
1071cb0ef41Sopenharmony_ci}, "In DOMImplementation.createHTMLDocument()");
1081cb0ef41Sopenharmony_ci</script>
109