summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/pointerevents/pointerevent_setpointercapture_pointerup_touch.html
blob: 8122251a71c370dca7b0379c02bc16341bd7235e (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
<!doctype html>
<html>
    <head>
        <title>setPointerCapture on pointerup</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>
        <script src="/resources/testdriver.js"></script>
        <script src="/resources/testdriver-actions.js"></script>
        <script src="/resources/testdriver-vendor.js"></script>
        <script src="pointerevent_support.js"></script>
    </head>
    <body class="scrollable">
        <h1>Pointer Events Capture Test - setPointerCapture on pointerup</h1>
        <h4>
            Test Description: This test checks if releaseCapture works properly on pointer up. Complete the following actions:
            <ol>
                <li> Touch black rectangle
                <li> Release your touch
            </ol>
        </h4>
        Test passes if the proper behavior of the events is observed.
        <div id="target0" style="background:black; color:white"></div>

        <script type='text/javascript'>
            var count=0;
            var event_log = [];
            var detected_pointertypes = {};
            var test_pointerEvent = async_test("setPointerCapture on pointerup");

            var target0 = document.getElementById('target0');
            var actions_promise;

            add_completion_callback(end_of_test);
            function end_of_test() {
                showLoggedEvents();
                showPointerTypes();
            }

            window.onload = function() {
                on_event(target0, 'pointerdown', function(e) {
                    detected_pointertypes[e.pointerType] = true;
                    event_log.push('pointerdown@target0');
                    test_pointerEvent.step(function () {
                        assert_equals(e.pointerType, "touch", "Test should be run using a touch as input");
                    });
                });

                on_event(target0, 'gotpointercapture', function(e) {
                    event_log.push('gotpointercapture@target0');
                });

                on_event(target0, 'lostpointercapture', function(e) {
                    event_log.push('lostpointercapture@target0');
                });

                on_event(target0, 'pointerup', function(e) {
                    event_log.push('pointerup@target0');
                    try {
                        target0.setPointerCapture(e.pointerId);
                    } catch(error) {
                        test_pointerEvent.step(function () {
                            assert_unreached("target0.setPointerCapture should not throw");
                        });
                    }
                    // Make sure the test finishes after all the input actions are completed.
                    actions_promise.then( () => {
                        test_pointerEvent.done();
                    });
                });

                on_event(target0, 'touchmove', function(e) {
                    // To prevent pointercancel firing.
                    e.preventDefault();
                });

                on_event(target0, 'pointercancel', function(e) {
                    test_pointerEvent.step(function () {
                        assert_unreached("target0 shouldn't receive pointercancel");
                    });
                });

                // Inject touch inputs.
                actions_promise = new test_driver.Actions()
                    .addPointer("touchPointer1", "touch")
                    .pointerMove(10, 10, {origin: target0})
                    .pointerDown()
                    .pause(100)
                    .pointerUp()
                    .send();
            }
        </script>
        <h1>Pointer Events Capture Test</h1>
        <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>The following events were logged: <span id="event-log"></span>.</p>
        </div>
        <div id="log"></div>
    </body>
</html>