2 <script src=
"../../../resources/js-test.js"></script>
14 <div id=
"target" class=
"test"></div>
16 <div id=
"console"></div>
19 description("Verifies that pointercancel events are fired correctly on touch.");
21 var eventToPreventDefault
= "";
24 var eventList
= ["pointerdown", "pointerup", "pointermove", "pointercancel",
25 "touchstart", "touchend", "touchmove", "touchcancel"];
27 eventList
.forEach(function(eventName
) {
28 document
.getElementById("target").addEventListener(eventName
, function(event
) {
30 if (event
.type
.startsWith("pointer"))
31 idMsg
= ", pointerId=" + event
.pointerId
;
33 idMsg
= ", touchIds=";
34 touches
= event
.changedTouches
;
35 for (var i
= 0; i
< touches
.length
; ++i
) {
36 idMsg
+= touches
[i
].identifier
;
40 var preventDefaultMsg
= "";
42 if (event
.type
== eventToPreventDefault
) {
43 event
.preventDefault();
44 preventDefaultMsg
= ", prevented default";
47 debug("Received " + event
.type
+ idMsg
+ preventDefaultMsg
);
52 function testSingleDrag(uncanceledMoveCausesScroll
) {
53 var rect
= document
.getElementById("target").getBoundingClientRect();
54 var x
= rect
.left
+ 50;
55 var y
= rect
.top
+ 50;
57 eventSender
.addTouchPoint(x
, y
);
58 eventSender
.touchStart();
60 eventSender
.updateTouchPoint(0, x
, y
+50);
61 eventSender
.touchMove();
63 eventSender
.updateTouchPoint(0, x
, y
+100);
64 if (uncanceledMoveCausesScroll
)
65 eventSender
.touchMoveCausingScrollIfUncanceled();
67 eventSender
.touchMove();
69 eventSender
.updateTouchPoint(0, x
, y
+150);
70 eventSender
.touchMove();
72 eventSender
.releaseTouchPoint(0);
73 eventSender
.touchEnd();
76 function testMultiDrag(uncanceledMoveCausesScroll
) {
79 rect
= document
.getElementById("target").getBoundingClientRect();
80 var x0
= rect
.left
+ 30;
81 var x1
= rect
.left
+ 50;
82 var x2
= rect
.left
+ 70;
83 var x3
= rect
.left
+ 55;
84 var y
= rect
.top
+ 50;
86 eventSender
.addTouchPoint(x0
, y
);
87 eventSender
.addTouchPoint(x1
, y
);
88 eventSender
.addTouchPoint(x2
, y
);
89 eventSender
.touchStart();
92 eventSender
.updateTouchPoint(0, x0
, y
);
93 eventSender
.updateTouchPoint(1, x1
, y
);
94 eventSender
.updateTouchPoint(2, x2
, y
);
95 eventSender
.touchMove();
98 eventSender
.updateTouchPoint(0, x0
, y
);
99 eventSender
.updateTouchPoint(1, x1
, y
);
100 eventSender
.updateTouchPoint(2, x2
, y
);
101 if (uncanceledMoveCausesScroll
)
102 eventSender
.touchMoveCausingScrollIfUncanceled();
104 eventSender
.touchMove();
106 eventSender
.addTouchPoint(x3
, y
);
107 eventSender
.touchStart();
110 eventSender
.updateTouchPoint(0, x0
, y
);
111 eventSender
.updateTouchPoint(1, x1
, y
);
112 eventSender
.updateTouchPoint(2, x2
, y
);
113 eventSender
.updateTouchPoint(3, x3
, y
);
114 eventSender
.touchMove();
116 eventSender
.releaseTouchPoint(0);
117 eventSender
.releaseTouchPoint(1);
118 eventSender
.releaseTouchPoint(2);
119 eventSender
.releaseTouchPoint(3);
120 eventSender
.touchEnd();
123 function testMultiCancel() {
126 rect
= document
.getElementById("target").getBoundingClientRect();
127 var x0
= rect
.left
+ 30;
128 var x1
= rect
.left
+ 50;
129 var x2
= rect
.left
+ 70;
130 var y
= rect
.top
+ 50;
132 eventSender
.addTouchPoint(x0
, y
);
133 eventSender
.addTouchPoint(x1
, y
);
134 eventSender
.addTouchPoint(x2
, y
);
135 eventSender
.touchStart();
137 eventSender
.cancelTouchPoint(2);
138 eventSender
.touchCancel();
141 eventSender
.updateTouchPoint(0, x0
, y
);
142 eventSender
.updateTouchPoint(1, x2
, y
);
143 eventSender
.touchMove();
145 eventSender
.cancelTouchPoint(0);
146 eventSender
.cancelTouchPoint(1);
147 eventSender
.touchCancel();
150 function runTests() {
151 debug("--- single drag tests ---");
154 debug("-- preventDefault on none, without uncanceledMoveCausesScroll --");
155 eventToPreventDefault
= "-none-";
156 testSingleDrag(false);
159 debug("-- preventDefault on pointermove, without uncanceledMoveCausesScroll --");
160 eventToPreventDefault
= "pointermove";
161 testSingleDrag(false);
164 debug("-- preventDefault on touchmove, without uncanceledMoveCausesScroll --");
165 eventToPreventDefault
= "touchmove";
166 testSingleDrag(false);
169 debug("-- preventDefault on none, with uncanceledMoveCausesScroll --");
170 eventToPreventDefault
= "-none-";
171 testSingleDrag(true);
174 debug("-- preventDefault on pointermove, with uncanceledMoveCausesScroll --");
175 eventToPreventDefault
= "pointermove";
176 testSingleDrag(true);
179 debug("-- preventDefault on touchmove, with uncanceledMoveCausesScroll --");
180 eventToPreventDefault
= "touchmove";
181 testSingleDrag(true);
184 debug("--- multi drag tests ---");
187 debug("-- preventDefault on none, without uncanceledMoveCausesScroll --");
188 eventToPreventDefault
= "-none-";
189 testMultiDrag(false);
192 debug("-- preventDefault on none, with uncanceledMoveCausesScroll --");
193 eventToPreventDefault
= "-none-";
197 debug("--- multi cancel tests ---");
205 if (window
.eventSender
)
208 debug("This test requires eventSender");