Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Side by Side Diff: third_party/WebKit/LayoutTests/virtual/pointerevent/fast/events/pointerevents/touch-capture.html

Issue 2098883002: Make PointerEvent an experimental web platform feature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased, fixed js path. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE HTML>
2 <script src="../../../../../resources/js-test.js"></script>
3 <style>
4 div.box {
5 margin: 5px;
6 padding: 20px;
7 float: left;
8 }
9 #grey {
10 width: 50px;
11 height: 50px;
12 }
13 </style>
14
15 <div id="grey" class="box" style="background-color:grey">
16 <div id="green" class="box" style="background-color:green;">
17 </div>
18 </div>
19 <div id="blue" class="box" style="background-color:blue;">
20 </div>
21
22 <div id="console"></div>
23
24 <script>
25 description("Verifies that pointer capture works for touch.");
26
27 var ACTION_NONE = 0;
28 var ACTION_RELEASE = 1;
29 var ACTION_RESET = 2;
30
31 document.captureAction = ACTION_NONE;
32 document.movecount = 0;
33
34 var rect = document.getElementById("green").getBoundingClientRect();
35 var x1 = rect.left + 5;
36 var y1 = rect.top + 5;
37
38 var rect = document.getElementById("blue").getBoundingClientRect();
39 var x2 = rect.left + 5;
40 var y2 = rect.top + 5;
41
42 function init() {
43 var eventList = ["touchstart", "touchmove", "touchend", "touchcancel",
44 "pointerenter", "pointerleave", "pointerover", "pointerout", "pointermove", "pointerdown", "pointerup", "pointercancel",
45 "gotpointercapture", "lostpointercapture"];
46
47 document.addEventListener("lostpointercapture", function(event) {
48 if (event.eventPhase == Event.AT_TARGET) {
49 debug("document received " + event.type + " " + event.pointerId);
50 }
51 });
52 ["grey", "green", "blue"].forEach(function(id) {
53 var targetDiv = document.getElementById(id);
54 eventList.forEach(function(eventName) {
55 targetDiv.addEventListener(eventName, function(event) {
56 if (event.eventPhase == Event.AT_TARGET) {
57 if (event.type.includes("pointer")) {
58 debug(id + " received " + event.type + " " + event.pointerId);
59 if (document.captureAction == ACTION_RESET && event.type == "pointer down") {
60 debug(" --- Set pointer capture to blue " + event.pointerId + " ---");
61 document.getElementById('blue').setPointerCapture(event.pointerId) ;
62 document.captureAction = ACTION_NONE;
63 }
64 if (document.captureAction == ACTION_RELEASE && event.type == "point ermove" && ++document.movecount > 1) {
65 debug(" &&& Releasing pointer capture for " + event.pointerId + " &&&");
66 event.target.releasePointerCapture(event.pointerId);
67 document.captureAction = ACTION_NONE;
68 }
69 } else
70 debug(id + " received " + event.type);
71 }
72 });
73 });
74 });
75 }
76
77 function singleTouchTestScenario(touchCancel, captureAction) {
78 var captureName = captureAction == ACTION_RELEASE ? " with capture release" :
79 captureAction == ACTION_RESET ? " with capture reset" : "";
80
81 debug(" ======= Touch and " + (touchCancel ? "cancel" : "release") + captureNa me + " =======");
82
83 document.captureAction = captureAction;
84 document.movecount = 0;
85
86 debug(" **** First touch on green box & jiggle ****");
87 eventSender.addTouchPoint(x1, y1)
88 eventSender.touchStart();
89 eventSender.updateTouchPoint(0, x1+1, y1+1);
90 eventSender.touchMove();
91
92 debug(" **** Move to blue box & jiggle ****");
93 eventSender.updateTouchPoint(0, x2, y2);
94 eventSender.touchMove();
95 eventSender.updateTouchPoint(0, x2+1, y2+1);
96 eventSender.touchMove();
97
98 if (touchCancel) {
99 debug(" **** Cancel touch ****");
100 eventSender.cancelTouchPoint(0);
101 eventSender.touchCancel();
102 } else {
103 debug(" **** Release touch ****");
104 eventSender.releaseTouchPoint(0);
105 eventSender.touchEnd();
106 }
107
108 debug("");
109 }
110
111
112 function multiTouchTestScenario(touchCancel, captureAction) {
113 var captureName = captureAction == ACTION_RELEASE ? " with capture release" :
114 captureAction == ACTION_RESET ? " with capture reset" : "";
115
116 debug(" ======= Multitouch and " + (touchCancel ? "cancel" : "release") + capt ureName + " =======");
117
118 document.captureAction = captureAction;
119 document.movecount = 0;
120
121 debug(" **** First touch on green & second touch on blue & jiggle ****");
122 eventSender.addTouchPoint(x1, y1)
123 eventSender.touchStart();
124 eventSender.addTouchPoint(x2, y2)
125 eventSender.touchStart();
126 eventSender.updateTouchPoint(0, x1+1, y1+1);
127 eventSender.touchMove();
128 eventSender.updateTouchPoint(1, x2+1, y2+1);
129 eventSender.touchMove();
130
131 debug(" **** Move first touch to blue & second touch to green ****");
132 eventSender.updateTouchPoint(0, x2, y2);
133 eventSender.touchMove();
134 eventSender.updateTouchPoint(1, x1, y1);
135 eventSender.touchMove();
136
137 if (touchCancel) {
138 debug(" **** Cancel first touch ****");
139 eventSender.cancelTouchPoint(0);
140 eventSender.touchCancel();
141 } else {
142 debug(" **** Release first touch ****");
143 eventSender.releaseTouchPoint(0);
144 eventSender.touchEnd();
145 }
146
147 debug(" **** Jiggle second touch on green ****");
148 eventSender.updateTouchPoint(0, x1+1, y1+1);
149 eventSender.touchMove();
150
151 if (touchCancel) {
152 debug(" **** Cancel second touch ****");
153 eventSender.cancelTouchPoint(0);
154 eventSender.touchCancel();
155 } else {
156 debug(" **** Release second touch ****");
157 eventSender.releaseTouchPoint(0);
158 eventSender.touchEnd();
159 }
160
161 debug("");
162 }
163
164 function runTests() {
165 [ACTION_NONE, ACTION_RELEASE, ACTION_RESET].forEach(function(action) {
166 singleTouchTestScenario(false, action);
167 singleTouchTestScenario(true, action);
168 multiTouchTestScenario(false, action);
169 multiTouchTestScenario(true, action);
170 });
171 }
172
173 init();
174 if (window.eventSender)
175 runTests();
176 else
177 debug("This test requires eventSender");
178
179 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698