summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/events/Event-dispatch-propagation-stopped.html
blob: 889f8cfe11489d0bd070c7550037e83a9e48cbe5 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html>
<head>
<title> Calling stopPropagation() prior to dispatchEvent() </title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id=log></div>

<table id="table" border="1" style="display: none">
    <tbody id="table-body">
    <tr id="table-row">
        <td id="table-cell">Shady Grove</td>
        <td>Aeolian</td>
    </tr>
    <tr id="parent">
        <td id="target">Over the river, Charlie</td>
        <td>Dorian</td>
    </tr>
    </tbody>
</table>

<script>
test(function() {
    var event = "foo";
    var target = document.getElementById("target");
    var parent = document.getElementById("parent");
    var tbody = document.getElementById("table-body");
    var table = document.getElementById("table");
    var body = document.body;
    var html = document.documentElement;
    var current_targets = [window, document, html, body, table, tbody, parent, target];
    var expected_targets = [];
    var actual_targets = [];
    var expected_phases = [];
    var actual_phases = [];

    var test_event = function(evt) {
        actual_targets.push(evt.currentTarget);
        actual_phases.push(evt.eventPhase);
    };

    for (var i = 0; i < current_targets.length; ++i) {
        current_targets[i].addEventListener(event, test_event, true);
        current_targets[i].addEventListener(event, test_event, false);
    }

    var evt = document.createEvent("Event");
    evt.initEvent(event, true, true);
    evt.stopPropagation();
    target.dispatchEvent(evt);

    assert_array_equals(actual_targets, expected_targets, "actual_targets");
    assert_array_equals(actual_phases, expected_phases, "actual_phases");
});
</script>
</body>
</html>