File: pointerevent_pointerlock_supercedes_capture.html

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (112 lines) | stat: -rw-r--r-- 5,448 bytes parent folder | download | duplicates (26)
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
<!doctype html>
<html>
    <head>
        <title>Pointer Events pointer lock 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>
        <script src="/resources/testdriver.js"></script>
        <script src="/resources/testdriver-actions.js"></script>
        <script src="/resources/testdriver-vendor.js"></script>
        <!-- Additional helper script for common checks across event types -->
        <script type="text/javascript" src="../pointerevent_support.js"></script>
        <script>
            var lock_change_count = 0;
            var capture_count = 0;
            var mouse_move_count = 0;

            function resetTestState() {
            }

            function run() {
                var test_pointerEvent = setup_pointerevent_test("no pointercapture while pointerlock", ['mouse']);
                var div1 = document.getElementById("div1");
                var div2 = document.getElementById("div2");

                on_event(div1, 'pointerdown', function(event) {
                    div2.setPointerCapture(event.pointerId);
                    div1.requestPointerLock();
                });
                on_event(div1, 'pointermove', function(event) {
                    mouse_move_count++
                    if (lock_change_count == 1) {
                        if (mouse_move_count == 2) {
                            try {
                                div2.setPointerCapture(event.pointerId);
                                test_pointerEvent.step(function () {
                                    assert_unreached("DOMException: InvalidStateError should have been thrown.");
                                });
                            } catch (e) {
                                test_pointerEvent.step(function () {
                                    assert_equals(e.name, "InvalidStateError", "DOMException should be InvalidStateError");
                                });
                            }
                        } else if (mouse_move_count == 3) {
                            document.exitPointerLock();
                            mouse_move_count = 0;
                        }

                    }
                });
                on_event(div2, 'gotpointercapture', function(event) {
                    capture_count++;
                });
                on_event(div2, 'lostpointercapture', function(event) {
                    capture_count++;
                });
                on_event(document, 'pointerlockchange', function(event) {
                    lock_change_count++;
                    test_pointerEvent.step(function() {
                        if (lock_change_count == 1)
                            assert_equals(document.pointerLockElement, div1, "document.pointerLockElement should be div1.");
                        else if (lock_change_count == 2)
                            assert_equals(document.pointerLockElement, null, "document.pointerLockElement should be null.");
                    });
                });

                injectInput().then(function(){
                    test_pointerEvent.step(function(){
                        assert_equals(lock_change_count, 2, "Pointer is unlocked");
                        assert_greater_than(mouse_move_count, 1, "More than 1 pointermove has been received after unlocked");
                        assert_equals(capture_count, 0, "There shouldn't be any capture events fired.");
                    });
                    test_pointerEvent.done();
                })
            }
            // Inject mouse input
            function injectInput() {
                var actions = new test_driver.Actions();
                return actions.pointerMove(0, 0, {origin: div1})
                              .pointerDown()
                              .pointerMove(30, 30, {origin: div1})
                              .pointerMove(60, 30, {origin: div1})
                              .pointerMove(30, 20, {origin: div1})
                              .pointerMove(10, 50, {origin: div1})
                              .pointerMove(40, 10, {origin: div1})
                              .pointerMove(5,  30, {origin: div1})
                              .pointerMove(-5, 15, {origin: div1})
                              .pointerUp()
                              .send();
            }
        </script>
    </head>
    <body onload="run()">
        <h1>Pointer Events pointer lock test</h1>
        <h2 id="pointerTypeDescription"></h2>
        <h4>
            Test Description: This test checks that we do not set the pointer capture when any element in the page gets a pointer lock.
            <ol>
                 <li>Press left button down on the green rectangle and hold it.</li>
                 <li>Move the mouse inside the green rectangle.</li>
            </ol>

            Test passes if the pointer capture is not set when the green rectangle gets the pointer lock.
        </h4>
        <div id="testContainer">
            <div id="div1" style="width:800px;height:250px;background:green"></div>
            <div id="div2" style="width:800px;height:250px;background:yellow"></div>
        </div>
        <div class="spacer"></div>
    </body>
</html>