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
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1638458
-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test for Bug 1638458</title>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="apz_test_native_event_utils.js"></script>
<script type="application/javascript" src="apz_test_utils.js"></script>
<style>
#target {
margin-top: 1000px;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div id="target">
<script type="application/javascript">
async function test() {
let utils = SpecialPowers.getDOMWindowUtils(window);
// Do a large visual scroll to scroll the visual viewport to the bottom
// of the layout viewport.
let visualScrollPromise = new Promise(resolve => {
window.visualViewport.addEventListener("scroll", resolve, { once: true });
});
utils.scrollToVisual(0, 900, utils.UPDATE_TYPE_MAIN_THREAD,
utils.SCROLL_MODE_INSTANT);
await visualScrollPromise;
await promiseApzFlushedRepaints();
// Simulate a long-tap on the target. We do this by simply synthesizing
// a touch-start event; eventually, the long-tap timeout will be triggered
// and the "contextmenu" will be fired (on non-Windows platforms).
let target = document.getElementById("target");
let contextmenuEvent = null;
let contextmenuPromise = new Promise(resolve => {
window.addEventListener("contextmenu", function(e) {
contextmenuEvent = e;
// Don't actually open a context menu; it messes up subsequent
// tests unless we take additional action to close it.
e.preventDefault();
resolve();
});
});
await synthesizeNativeTouch(target, 10, 10, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
await contextmenuPromise;
// Check that the "contextmenu" event targets the correct element.
is(contextmenuEvent.target, target, "contextmenu event targeted the correct element");
// Clean up by firing a touch-end to clear the APZ gesture state.
await new Promise(resolve => {
synthesizeNativeTouch(target, 10, 10, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE,
resolve);
});
}
if (getPlatform() == "windows") {
// On Windows, contextmenu events work differently (e.g. they are fired
// after the touch-end) which makes them more involved to synthesize.
// We don't gain much value in terms of extra test coverage from running
// this subtest on windows, so just skip it.
ok(true, "Skipping this subtest on windows");
subtestDone();
} else {
SpecialPowers.getDOMWindowUtils(window).setResolutionAndScaleTo(2.0);
waitUntilApzStable()
.then(test)
.then(subtestDone, subtestFailed);
}
</script>
</body>
</html>
|