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
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1686037
-->
<head>
<title>Bug 1686037</title>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<style>
#target {
width: 100px;
height: 100px;
background-color: green;
}
iframe {
width: 400px;
height: 300px;
border: 1px solid blue;
}
</style>
</head>
<body>
<a target="_blank"href="https://bugzilla.mozilla.org/show_bug.cgi?id=1686037">Mozilla Bug 1686037</a>
<div id="target"></div>
<iframe srcdoc="<div style='width: 100px; height: 100px; background-color: blue;'></div>"></iframe>
<pre id="test">
<script type="text/javascript">
/**
* Test for Bug 1686037
*/
function waitForEvent(aTarget, aEventName, aCallback = null) {
return new Promise((aResolve) => {
aTarget.addEventListener(aEventName, async (e) => {
ok(true, `got ${e.type} event on ${e.target}, pointerid: ${e.pointerId}`);
if (aCallback) {
await aCallback(e);
}
aResolve();
}, { once: true });
});
}
function waitForPointerDownAndSetPointerCapture(aTarget) {
return waitForEvent(aTarget, "pointerdown", async (event) => {
return new Promise((aResolve) => {
aTarget.addEventListener("gotpointercapture", (e) => {
ok(true, `got ${e.type} event on ${e.target}, pointerid: ${e.pointerId}`);
aResolve();
}, { once: true });
aTarget.setPointerCapture(event.pointerId);
});
});
}
add_task(async function test_remove_iframe_after_pointer_capture() {
await SimpleTest.promiseFocus();
let iframe = document.querySelector("iframe");
let iframeWin = iframe.contentWindow;
let targetInIframe = iframe.contentDocument.querySelector("div");
let promise = Promise.all([
waitForPointerDownAndSetPointerCapture(targetInIframe),
waitForEvent(targetInIframe, "pointermove")
]);
synthesizeTouch(targetInIframe, 10, 10, { type: "touchstart", id: 10 }, iframeWin);
synthesizeTouch(targetInIframe, 11, 11, { type: "touchmove", id: 10 }, iframeWin);
await promise;
// Intentionally not synthesize touchend event to not trigger implicit releasing
// pointer capture. And iframe removal should trigger pointer capture clean up.
iframe.remove();
});
</script>
</pre>
</body>
</html>
|