summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/uievents/legacy-domevents-tests/approved/stopPropagation.deferred.effect.html
blob: 93489c63b45254efbb15ddbc52b1984897b1525c (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
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html>
<head>
<title> Event.stopPropagation() deferred effect </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>
    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 CurrentTargets = [window, document, HTML, BODY, TABLE, TBODY, PARENT, TARGET];
    var ExpectResult = [window, window, document, document, HTML, HTML, BODY, BODY, TABLE, TABLE];
    var ActualResult = [];
    var ExpectListeners = [0,1,0,1,0,1,0,1,0,1];
    var ActualListeners = [];

    var description = "Test Description: " +
                      "stopPropagation() prevents other event listeners from being triggered but its effect must be " +
                      "deferred until all event listeners attached on the Event.currentTarget have been triggered.";

    test(function()
    {
        for (var i=0; i < CurrentTargets.length; i++)
        {
            CurrentTargets[i].addEventListener(EVENT, function(e){TestEvent(e, 0)}, true);
            CurrentTargets[i].addEventListener(EVENT, function(e){TestEvent(e, 1)}, true);
        }

        var evt = document.createEvent("Event");
        evt.initEvent(EVENT, true, true);
        TARGET.dispatchEvent(evt);

        assert_array_equals(ActualResult, ExpectResult, "ActualResult");
        assert_array_equals(ActualListeners, ExpectListeners, "ActualListeners");

    }, description);

    function TestEvent(evt, i)
    {
        ActualResult.push(evt.currentTarget);
        ActualListeners.push(i);
        if ((1 == evt.eventPhase) && (TABLE == evt.currentTarget) && (0 == i))
        {
            evt.stopPropagation();
        }
    }
</script>
</body>
</html>