5 <meta name=
"viewport" content=
"width=device-width, initial-scale=1, minimum-scale=1">
6 <title>touchmove coalescing
</title>
7 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
8 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css"/>
10 window
.oncontextmenu = function(e
) {
14 window
.addEventListener("touchstart", function(e
) { e
.preventDefault(); },
17 var touchmoveEvents
= [];
18 function touchmove(e
) {
19 // Make touchmove handling slow
20 var start
= performance
.now();
21 while (performance
.now() < (start
+ 10));
22 touchmoveEvents
.push(e
);
25 async
function fireLotsOfSingleTouchMoves() {
26 var ret
= new Promise(function(resolve
) {
27 SpecialPowers
.loadChromeScript(function() {
28 var element
= this.actorParent
.rootFrameLoader
.ownerElement
;
29 var rect
= element
.getBoundingClientRect();
30 var win
= element
.ownerDocument
.defaultView
;
31 var utils
= win
.windowUtils
;
32 var x
= rect
.x
+ (rect
.width
/ 2);
33 var y
= Math
.floor(rect
.y
+ (rect
.height
/ 4));
34 var endY
= Math
.floor(rect
.y
+ ((rect
.height
/ 4) * 2));
35 utils
.sendTouchEvent("touchstart", [0], [x
], [y
], [1], [1], [0], [1],
38 utils
.sendTouchEvent("touchmove", [0], [x
], [y
], [1], [1], [0], [1],
42 utils
.sendTouchEvent("touchend", [0], [x
], [y
], [1], [1], [0], [1],
48 window
.addEventListener("touchmove", touchmove
, true);
49 window
.addEventListener("touchend", function(e
) {
50 window
.removeEventListener("touchmove", touchmove
, true);
51 resolve(touchmoveEvents
);
58 async
function fireTwoSingleTouches() {
59 var ret
= new Promise(function(resolve
) {
60 SpecialPowers
.loadChromeScript(function() {
61 var element
= this.actorParent
.rootFrameLoader
.ownerElement
;
62 var rect
= element
.getBoundingClientRect();
63 var win
= element
.ownerDocument
.defaultView
;
64 var utils
= win
.windowUtils
;
65 var x
= rect
.x
+ (rect
.width
/ 2);
66 var startY
= Math
.floor(rect
.y
+ (rect
.height
/ 4));
67 var endY
= Math
.floor(rect
.y
+ ((rect
.height
/ 4) * 2));
68 utils
.sendTouchEvent("touchstart", [0], [x
], [startY
], [1], [1], [0],
70 utils
.sendTouchEvent("touchmove", [0], [x
], [startY
], [1], [1], [0],
72 utils
.sendTouchEvent("touchmove", [0], [x
], [startY
+ 1], [1], [1], [0],
74 utils
.sendTouchEvent("touchend", [0], [x
], [endY
], [1], [1], [0],
79 window
.addEventListener("touchmove", touchmove
, true);
80 window
.addEventListener("touchend", function(e
) {
81 window
.removeEventListener("touchmove", touchmove
, true);
82 resolve(touchmoveEvents
);
89 async
function fireLotsOfMultiTouchMoves() {
90 var ret
= new Promise(function(resolve
) {
91 SpecialPowers
.loadChromeScript(function() {
92 var element
= this.actorParent
.rootFrameLoader
.ownerElement
;
93 var rect
= element
.getBoundingClientRect();
94 var win
= element
.ownerDocument
.defaultView
;
95 var utils
= win
.windowUtils
;
96 var x
= rect
.x
+ (rect
.width
/ 2);
97 var startY
= Math
.floor(rect
.y
+ (rect
.height
/ 4));
98 var endY
= Math
.floor(rect
.y
+ ((rect
.height
/ 4) * 2));
99 utils
.sendTouchEvent("touchstart", [0, 1], [x
, x
+ 1],
100 [startY
, startY
+ 1], [1, 1], [1, 1], [0, 0],
102 while (startY
!= endY
) {
103 utils
.sendTouchEvent("touchmove", [0, 1], [x
, x
+ 1],
104 [startY
, startY
+ 1], [1, 1], [1, 1], [0, 0],
108 utils
.sendTouchEvent("touchend", [0, 1], [x
, x
+ 1], [endY
, endY
+ 1],
109 [1, 1], [1, 1], [0, 0], [1, 1], 0, false);
113 touchmoveEvents
= [];
114 window
.addEventListener("touchmove", touchmove
, true);
115 window
.addEventListener("touchend", function(e
) {
116 window
.removeEventListener("touchmove", touchmove
, true);
117 resolve(touchmoveEvents
);
124 function disableIPCCompression() {
125 return SpecialPowers
.pushPrefEnv({"set": [["dom.events.compress.touchmove",
127 ["dom.events.coalesce.touchmove",
131 function enableIPCCompression() {
132 return SpecialPowers
.pushPrefEnv({"set": [["dom.events.compress.touchmove",
134 ["dom.events.coalesce.touchmove",
138 async
function runTests() {
139 document
.body
.clientTop
; // Flush layout
141 await
disableIPCCompression();
142 var touchMovesWithoutCoalescing
= await
fireLotsOfSingleTouchMoves();
143 await
enableIPCCompression();
144 var touchMovesWithCoalescing
= await
fireLotsOfSingleTouchMoves();
145 opener
.ok(touchMovesWithoutCoalescing
.length
> touchMovesWithCoalescing
.length
,
146 "Coalescing should reduce the number of touchmove events");
147 opener
.isDeeply(touchMovesWithoutCoalescing
.shift().touches
,
148 touchMovesWithCoalescing
.shift().touches
,
149 "Shouldn't have coalesced the initial touchmove");
150 opener
.isDeeply(touchMovesWithoutCoalescing
.pop().touches
,
151 touchMovesWithCoalescing
.pop().touches
,
152 "The last touchmove event should be up-to-date");
154 await
disableIPCCompression();
155 var twoTouchMovesWithoutCoalescing
= await
fireTwoSingleTouches();
156 await
enableIPCCompression();
157 var twoTouchMovesWithCoalescing
= await
fireTwoSingleTouches();
158 opener
.is(twoTouchMovesWithoutCoalescing
.length
, 2,
159 "Should have got two touchmoves");
160 opener
.is(twoTouchMovesWithoutCoalescing
.length
,
161 twoTouchMovesWithCoalescing
.length
,
162 "Shouldn't have coalesced the touchmove.");
164 await
disableIPCCompression();
165 var multiTouchMovesWithoutCoalescing
= await
fireLotsOfMultiTouchMoves();
166 await
enableIPCCompression();
167 var multiTouchMovesWithCoalescing
= await
fireLotsOfMultiTouchMoves();
168 opener
.ok(multiTouchMovesWithoutCoalescing
.length
> multiTouchMovesWithCoalescing
.length
,
169 "Coalescing should reduce the number of multitouch touchmove events");
170 opener
.isDeeply(multiTouchMovesWithoutCoalescing
.shift().touches
,
171 multiTouchMovesWithCoalescing
.shift().touches
,
172 "Shouldn't have coalesced the initial multitouch touchmove event");
173 opener
.isDeeply(multiTouchMovesWithoutCoalescing
.pop().touches
,
174 multiTouchMovesWithCoalescing
.pop().touches
,
175 "The last multitouch touchmove event should be up-to-date");
182 SpecialPowers
.pushPrefEnv({"set": [["dom.w3c_touch_events.enabled", true]]},
187 <body style=
"height: 100vh;" onload=
"SimpleTest.waitForFocus(init);">