summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/pointerevents/pointerevent_releasepointercapture_events_to_original_target-manual.html
blob: 904efa46b76cbac83efcef3ca1eec69053ad8061 (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
<!doctype html>
<html>
    <head>
        <title>Pointer Event: releasePointerCapture() - subsequent events follow normal hitting testing mechanisms</title>
        <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
        <link rel="author" title="Microsoft" href="http://www.microsoft.com/"/>
        <meta name="assert" content="After invoking the releasePointerCapture method on an element, subsequent events for the specified pointer must follow normal hit testing mechanisms for determining the event target"/>
        <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 type="text/javascript">
            var detected_pointertypes = {};
            var test_pointerEvent = async_test("lostpointercapture: subsequent events to target.");  // set up test harness
            // showPointerTypes is defined in pointerevent_support.js
            // Requirements: the callback function will reference the test_pointerEvent object and
            // will fail unless the async_test is created with the var name "test_pointerEvent".
            add_completion_callback(showPointerTypes);

            var captured_event;
            var test_done = false;
            var overEnterEventsFail = false;
            var outLeaveEventsFail = false;
            var f_gotPointerCapture = false;
            var f_lostPointerCapture = false;

            function listenerEventHandler(event) {
                if (test_done)
                    return;
                detected_pointertypes[event.pointerType] = true;
                if (event.type == "gotpointercapture") {
                    f_gotPointerCapture = true;
                    check_PointerEvent(event);
                }
                else if (event.type == "lostpointercapture") {
                    f_lostPointerCapture = true;
                    f_gotPointerCapture = false;
                    check_PointerEvent(event);
                }
                else if(event.type == "pointerover" || event.type == "pointerenter") {
                    if(!overEnterEventsFail) {
                        test(function() {
                            assert_true(f_gotPointerCapture, "pointerover/enter should not be received when the target doesn't have capture and pointer is not over it.");
                        }, "pointerover/enter should not be received when the target doesn't have capture and pointer is not over it.");
                        overEnterEventsFail = true;
                    }
                }
                else if(event.type == "pointerout" || event.type == "pointerleave") {
                    if(!outLeaveEventsFail) {
                        test(function() {
                            assert_true(f_lostPointerCapture, "pointerout/leave should not be received unless the target just lost the capture.");
                        }, "pointerout/leave should not be received unless the target just lost the capture.");
                        outLeaveEventsFail = true;
                    }
                }
                else if (event.pointerId == captured_event.pointerId) {
                    if (f_gotPointerCapture && event.type == "pointermove") {
                        // on first event received for capture, release capture
                        listener.releasePointerCapture(event.pointerId);
                    }
                    else {
                        // if any other events are received after releaseCapture, then the test fails
                        test(function () {
                            assert_unreached(event.target.id + "-" + event.type + " should be handled by target element handler");
                        }, "No other events should be recieved by capturing node after release");
                    }
                }
            }

            function targetEventHandler(event) {
                if (test_done)
                    return;
                if (f_gotPointerCapture) {
                    if(event.type != "pointerout" && event.type != "pointerleave") {
                        test(function () {
                            assert_unreached("The Target element should not have received any events while capture is active. Event recieved:" + event.type + ".  ");
                        }, "The target element should not receive any events while capture is active");
                    }
                }

                if (event.type == "pointerdown") {
                    // pointerdown event received will be used to capture events.
                    listener.setPointerCapture(event.pointerId);
                    captured_event = event;
                }

                if (f_lostPointerCapture) {
                    test_pointerEvent.step(function () {
                        assert_equals(event.pointerId, captured_event.pointerId, "pointerID is same for event captured and after release");
                    });
                    if (event.type == "pointerup") {
                        test_pointerEvent.done(); // complete test
                        test_done = true;
                    }
                }
            }

            function run() {
                var listener = document.getElementById("listener");
                var target0 = document.getElementById("target0");
                target0.style["touchAction"] = "none";

                // target0 and listener - handle all events
                for (var i = 0; i < All_Pointer_Events.length; i++) {
                    on_event(target0, All_Pointer_Events[i], targetEventHandler);
                    on_event(listener, All_Pointer_Events[i], listenerEventHandler);
                }
            }
        </script>
    </head>
    <body onload="run()">
        <div id="listener"></div>
        <h1>Pointer Event: releasePointerCapture() - subsequent events follow normal hitting testing mechanisms</h1>
        <h4>
            Test Description:
            After invoking the releasePointerCapture method on an element, subsequent events for the specified
            pointer must follow normal hit testing mechanisms for determining the event target
        </h4>
        <br />
        <div id="target0">
            Use mouse, touch or pen to contact here and move around.
        </div>
        <div id="complete-notice">
            <p>Test complete:  Scroll to Summary to view Pass/Fail Results.</p>
            <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>