summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/pointerevents/pointerevent_fractional_coordinates.html
blob: f794797704484dbecb22089219bdeef4637bf45d (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
144
145
146
147
148
149
<!doctype html>
<html>
    <head>
        <title>Pointer Events coordinates can have fractional value<</title>
        <meta name="viewport" content="width=device-width">
        <meta name="variant" content="?mouse">
        <meta name="variant" content="?touch">
        <meta name="variant" content="?pen">
        <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 type="text/javascript" src="pointerevent_support.js"></script>
        <style>
            #innerFrame {
                transform: scale(5);
                width: 60px;
                height: 60px;
                margin-left: 120px;
                margin-top: 120px;
                border: 0.01px solid black;
            }
        </style>
        <script>
            var input = location.search.substring(1);
            var eventList = [
                  "pointerdown",
                  "pointerup",
                  "pointermove",
                  "pointerover",
                  "pointerout",
                  "pointerenter",
                  "pointerleave"];
            var eventsRecieved = {};
            var clickedTargetList = [];

            function resetTestState() {
                eventsRecieved = {};
                clickedTargetList = [];
                ['s1', 's2', 's3'].forEach(function(id){
                    var target = document.getElementById('innerFrame').contentDocument.getElementById(id);
                    target.style.background = "black"
                });
            }

            function checkPointerEventCoordinates(event) {
              if (event.clientX != Math.floor(event.clientX) || event.clientY != Math.floor(event.clientY))
                eventsRecieved[event.type] = true;
            }

            function testInputType(inputSource) {
              const scale = 5;
              const width = 3;
              const height = 3;
              var targetFrame = document.querySelector('#innerFrame');
              var frameRect = targetFrame.getBoundingClientRect();
              frameLeft = frameRect.left;
              frameTop = frameRect.top;

              target = [{x: 10, y: 10}, {x: 30, y: 50}, {x: 50, y: 30}]
              xPosition = []
              yPosition = []
              for (var i = 0; i < target.length; i++) {
                xPosition.push((target[i].x + width / 2.0) * scale + frameLeft);
                yPosition.push((target[i].y + height / 2.0) * scale + frameTop);
              }
              return sendInputAt(inputSource, xPosition[0], yPosition[0]).then(function() {
                return sendInputAt(inputSource, xPosition[1], yPosition[1]);
              }).then(function() {
                return sendInputAt(inputSource, xPosition[2], yPosition[2]);
              });

            }

            function sendInputAt(inputSource, xPosition, yPosition) {
              if (inputSource == "touch") {
                return new test_driver.Actions()
                  .addPointer("touchPointer1", "touch")
                  .pointerMove(Math.ceil(xPosition), Math.ceil(yPosition))
                  .pointerDown()
                  .pointerMove(Math.ceil(xPosition + 1), Math.ceil(yPosition + 1))
                  .pointerUp()
                  .send();
              } else {
                return new test_driver.Actions()
                  .pointerMove(Math.ceil(xPosition), Math.ceil(yPosition))
                  .pointerDown()
                  .pointerUp()
                  .send();
              }
            }

            function run() {
                var test_pointerEvent = setup_pointerevent_test("pointerevent events in capturing", [input]);
                var innerFrame = document.getElementById('innerFrame');
                var innerDocument = innerFrame.contentDocument;
                ['s1', 's2', 's3'].forEach(function(id){
                    var target = innerDocument.getElementById(id);
                    eventList.forEach(function(eventName) {
                        on_event(target, eventName, checkPointerEventCoordinates);
                    });

                    on_event(target, "click", function (event) {
                      if (!(event.target.id in clickedTargetList)) {
                          clickedTargetList.push(event.target.id);
                          event.target.style.background = "red"
                      }
                      if (clickedTargetList.length == 3) {
                          test(function () {
                              if (Object.keys(eventsRecieved).length != eventList.length){
                                  eventList.forEach(function(eventName){
                                     assert_true(eventName in eventsRecieved, eventName + " should have fractional coordinates");
                                  });
                              }
                          }, expectedPointerType);
                          test_pointerEvent.done();
                      }
                    });
                });

                testInputType(input);
            }
        </script>
    </head>
    <body onload="run()">
        <h1>Pointer Events coordinates support fractional value</h1>
        <h2 id="pointerTypeDescription"></h2>
        <h4>
            Test Description: This test checks pointer events has fractional client coordinates
            <ol>
                 <li>Move your pointer over one black square</li>
                 <li>Press down the pointer (i.e. press left button with mouse or touch the screen with finger or pen).</li>
                 <li>Release the pointer.</li>
                 <li>Move to next black square and repreat 2 and 3</li>
            </ol>

            Test passes if pointer events has fractional coordinates.
        </h4>
        <iframe id=innerFrame src="resources/pointerevent_fractional_coordinates-iframe.html"></iframe>
        <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>