summaryrefslogtreecommitdiffstats
path: root/dom/events/test/pointerevents/wpt/pointerevent_attributes_hoverable_pointers-manual.html
blob: 0922ae7448ec1629e75fe96c06e3c115e341f3b2 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!doctype html>
<html>
    <head>
        <title>Pointer Events properties tests</title>
        <meta name="viewport" content="width=device-width">
        <link rel="stylesheet" type="text/css" href="pointerevent_styles.css">
        <script src="/resources/testharness.js"></script>
        <script src="/resources/testharnessreport.js"></script>
        <!-- Additional helper script for common checks across event types -->
        <script type="text/javascript" src="pointerevent_support.js"></script>
        <script>
            var detected_pointertypes = {};
            var detected_eventTypes = {};
            var eventList = ['pointerover', 'pointerenter', 'pointermove', 'pointerdown', 'pointerup', 'pointerout', 'pointerleave'];
            var expectedPointerId = NaN;

            function resetTestState() {
                detected_eventTypes = {};
                document.getElementById("square1").style.visibility = 'visible';
                document.getElementById('innerFrame').contentDocument.getElementById("square2").style.visibility = 'hidden';
                expectedPointerId = NaN;
            }
            function checkPointerEventAttributes(event, targetBoundingClientRect, testNamePrefix) {
                if (detected_eventTypes[event.type])
                    return;
                var expectedEventType =  eventList[Object.keys(detected_eventTypes).length];
                detected_eventTypes[event.type] = true;
                var pointerTestName = testNamePrefix + ' ' + expectedPointerType + ' ' + expectedEventType;

                detected_pointertypes[event.pointerType] = true;

                test(function() {
                    assert_equals(event.type, expectedEventType, "Event.type should be " + expectedEventType)
                }, pointerTestName + "'s type should be " + expectedEventType);

                // Test button and buttons
                if (event.type == 'pointerdown') {
                    test(function() {
                        assert_true(event.button == 0, "Button attribute is 0")
                    }, pointerTestName + "'s button attribute is 0 when left mouse button is pressed.");
                    test(function() {
                        assert_true(event.buttons == 1, "Buttons attribute is 1")
                    }, pointerTestName + "'s buttons attribute is 1 when left mouse button is pressed.");
                } else if (event.type == 'pointerup') {
                    test(function() {
                        assert_true(event.button == 0, "Button attribute is 0")
                    }, pointerTestName + "'s button attribute is 0 when left mouse button is just released.");
                    test(function() {
                        assert_true(event.buttons == 0, "Buttons attribute is 0")
                    }, pointerTestName + "'s buttons attribute is 0 when left mouse button is just released.");
                } else {
                    test(function() {
                        assert_true(event.button == -1, "Button attribute is -1")
                    }, pointerTestName + "'s button is -1 when mouse buttons are in released state.");
                    test(function() {
                        assert_true(event.buttons == 0, "Buttons attribute is 0")
                    }, pointerTestName + "'s buttons is 0 when mouse buttons are in released state.");
                }

                // Test clientX and clientY
                if (event.type != 'pointerout' && event.type != 'pointerleave' ) {
                    test(function () {
                        assert_true(event.clientX >= targetBoundingClientRect.left && event.clientX < targetBoundingClientRect.right && event.clientY >= targetBoundingClientRect.top && event.clientY < targetBoundingClientRect.bottom, "ClientX/Y should be in the boundaries of the box");
                    }, pointerTestName + "'s ClientX and ClientY attributes are correct.");
                } else {
                    test(function () {
                        assert_true(event.clientX < targetBoundingClientRect.left || event.clientX > targetBoundingClientRect.right - 1 || event.clientY < targetBoundingClientRect.top || event.clientY > targetBoundingClientRect.bottom - 1, "ClientX/Y should be out of the boundaries of the box");
                    }, pointerTestName + "'s ClientX and ClientY attributes are correct.");
                }

                check_PointerEvent(event, testNamePrefix);

                // Test isPrimary value
                test(function () {
                    assert_equals(event.isPrimary, true, "isPrimary should be true");
                }, pointerTestName + ".isPrimary attribute is correct.");

                // Test pointerId value
                if (isNaN(expectedPointerId)) {
                    expectedPointerId = event.pointerId;
                } else {
                    test(function () {
                        assert_equals(event.pointerId, expectedPointerId, "pointerId should remain the same for the same active pointer");
                    }, pointerTestName + ".pointerId should be the same as previous pointer events for this active pointer.");
                }
            }

            function run() {
                var test_pointerEvent = setup_pointerevent_test("pointerevent attributes", HOVERABLE_POINTERS);
                var square1 = document.getElementById("square1");
                var rectSquare1 = square1.getBoundingClientRect();
                var innerFrame = document.getElementById('innerFrame');
                var square2 = innerFrame.contentDocument.getElementById('square2');
                var rectSquare2 = square2.getBoundingClientRect();

                eventList.forEach(function(eventName) {
                    on_event(square1, eventName, function (event) {
                        if (square1.style.visibility == 'hidden')
                            return;
                        checkPointerEventAttributes(event, rectSquare1, "");
                        if (Object.keys(detected_eventTypes).length == eventList.length) {
                            square1.style.visibility = 'hidden';
                            detected_eventTypes = {};
                            square2.style.visibility = 'visible';
                            expectedPointerId = NaN;
                        }
                    });
                    on_event(square2, eventName, function (event) {
                        checkPointerEventAttributes(event, rectSquare2, "Inner frame ");
                        if (Object.keys(detected_eventTypes).length == eventList.length) {
                            square2.style.visibility = 'hidden';
                            test_pointerEvent.done();
                        }
                    });
                });
            }
        </script>
    </head>
    <body onload="run()">
        <h1>Pointer Events hoverable pointer attributes test</h1>
        <h2 id="pointerTypeDescription"></h2>
        <h4>
            Test Description: This test checks the properties of hoverable pointer events. If you are using hoverable pen don't leave the range of digitizer while doing the instructions.
            <ol>
                 <li>Move your pointer over the black square and click on it.</li>
                 <li>Then move it off the black square so that it disappears.</li>
                 <li>When red square appears move your pointer over the red square and click on it.</li>
                 <li>Then move it off the red square.</li>
            </ol>

            Test passes if the proper behavior of the events is observed.
        </h4>
        <div id="square1" class="square"></div>
        <iframe id="innerFrame" src="resources/pointerevent_attributes_hoverable_pointers-iframe.html"></iframe>
        <div class="spacer"></div>
        <div id="complete-notice">
            <p>The following pointer types were detected: <span id="pointertype-log"></span>.</p>
            <p>Refresh the page to run the tests again with a different pointer type.</p>
        </div>
        <div id="log"></div>
    </body>
</html>