summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/uievents/legacy-domevents-tests/approved/dispatchEvent.click.checkbox.html
blob: 8cb548f84c60eb6b528c1049884649b26c4f18ba (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
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html>
<head>
<title> MouseEvent: Default action and synthetic click event </title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id=log></div>

<div style="display: none">
    <input type="checkbox" id="target">
    <button id="button"> Click Here </button>
</div>

<script>
    setup({explicit_done:true});
    var EVENT = "click";
    var TARGET = document.getElementById("target");
    var BUTTON = document.getElementById("button");
    var state;

    var description = "Test Description: " +
                      "MouseEvent: Default action is performed when a synthetic click event is dispatched on a checkbox element";

    BUTTON.addEventListener(EVENT, TestEvent, true);
    TARGET.addEventListener(EVENT, TestEvent, true);

    window.onload = function()
    {
        state = TARGET.checked;
        BUTTON.click();
    }

    function TestEvent(evt)
    {
        if (BUTTON == evt.target)
        {
            var e;
            test(function()
            {
                BUTTON.removeEventListener(EVENT, TestEvent, true);

                e = document.createEvent("MouseEvent");
                e.initMouseEvent(EVENT,  /* type */
                                 false,  /* bubbles */
                                 true,   /* cancelable */
                                 window, /* view */
                                 1,      /* detail */
                                 0,      /* screenX */
                                 0,      /* screenY */
                                 0,      /* clientX */
                                 0,      /* clientY */
                                 false,  /* ctrlKey */
                                 false,  /* altKey */
                                 false,  /* shiftKey */
                                 false,  /* metaKey */
                                 0,      /* button */
                                 null    /* relatedTarget */);

                assert_array_equals([TARGET.checked, e.type, e.bubbles], [state, EVENT, false]);

            }, "Checkbox state is unchanged before the synthetic click event is dispatched");

            TARGET.dispatchEvent(e);
        }
        else if (TARGET == evt.target)
        {
            test(function()
            {
                assert_array_equals([TARGET.checked, evt.type, evt.bubbles], [!state, EVENT, false]);

            }, description);

            done();
        }
    }
</script>
</body>
</html>