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
|
<!DOCTYPE HTML>
<html>
<head>
<title>preventDefault() in touchmove prevents scrolling even after a long tap event</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<script type="application/javascript" src="apz_test_utils.js"></script>
<script type="application/javascript" src="apz_test_native_event_utils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
</head>
<body>
<!-- An anchor to open a context menu -->
<a href="about:blank" style="position:absolute; top: 100px; left: 100px;">about:blank</a>
<!-- make the root scroll container scrollable -->
<div style="height: 200vh;"></div>
</body>
<script type="application/javascript">
const searchParams = new URLSearchParams(location.search);
const isAndroid = getPlatform() == "android";
async function test() {
// Setup a touchmove event listener where we do preventDefault() to prevent
// scrolling.
let touchmoveCount = 0;
document.scrollingElement.addEventListener("touchmove", e => {
info("Got a touchmove");
touchmoveCount++;
e.preventDefault();
}, { passive: false });
// Setup touchstart/touchend event listeners just for debugging purpose.
document.scrollingElement.addEventListener("touchstart", () => {
info("Got a touchstart");
}, { passive: false });
document.scrollingElement.addEventListener("touchend", () => {
info("Got a touchend");
}, { passive: false });
window.addEventListener("scroll", () => {
ok(false, "The content should never be scrolled");
});
let contextmenuPromise = promiseOneEvent(window, "contextmenu", e => {
if (searchParams.get("prevent") == "contextmenu") {
e.preventDefault();
}
return true;
});
// Ensure that the setup-ed information has reached to APZ.
await promiseApzFlushedRepaints();
// Start a touch on the anchor.
await synthesizeNativeTouch(window, 100, 100, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
// And wait for a contextmenu event (i.e. a long-tap event)
await contextmenuPromise;
// Extend apz.content_response_timeout to avoid timeout on waiting the content
// response.
await SpecialPowers.pushPrefEnv({ set: [["apz.content_response_timeout", 40000]] });
// Make sure the touch start does nothing.
is(window.scrollY, 0, "The original scroll position is zero");
// Try to scroll down by touch moving.
for (let i = 1; i < 50; i++) {
synthesizeNativeTouch(window, 100, 100 - i, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
}
await synthesizeNativeTouch(window, 100, 50, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE);
await waitToClearOutAnyPotentialScrolls();
if (searchParams.get("prevent") == "contextmenu") {
ok(touchmoveCount > 0, "There should be at least one touch-move event");
} else {
is(touchmoveCount, 0, "There should be no touch-move event when the context menu opened");
}
is(window.scrollY, 0, "The scroll position should stay the original position");
if (searchParams.get("prevent") != "contextmenu") {
// If we've opened the context menu, close it.
await closeContextMenu();
}
}
if (getPlatform() == "windows") {
// On Windows every context menu on touch screens opens __after__ lifting the
// finger.
ok(true, "Test doesn't need to run on Windows");
subtestDone();
} else {
waitUntilApzStable()
.then(test)
.then(subtestDone, subtestFailed);
}
</script>
</html>
|