summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/events/Event-dispatch-order-at-target.html
blob: 79673c32564cbe785858266d4737de6bd5f7bade (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!DOCTYPE html>
<meta charset="utf-8">
<title>Listeners are invoked in correct order (AT_TARGET phase)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
"use strict";

test(() => {
    const el = document.createElement("div");
    const expectedOrder = ["capturing", "bubbling"];

    let actualOrder = [];
    el.addEventListener("click", evt => {
        assert_equals(evt.eventPhase, Event.AT_TARGET);
        actualOrder.push("bubbling");
    }, false);
    el.addEventListener("click", evt => {
        assert_equals(evt.eventPhase, Event.AT_TARGET);
        actualOrder.push("capturing");
    }, true);

    el.dispatchEvent(new Event("click", {bubbles: true}));
    assert_array_equals(actualOrder, expectedOrder, "bubbles: true");

    actualOrder = [];
    el.dispatchEvent(new Event("click", {bubbles: false}));
    assert_array_equals(actualOrder, expectedOrder, "bubbles: false");
}, "Listeners are invoked in correct order (AT_TARGET phase)");
</script>