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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_utils.js",
this
);
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js",
this
);
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [
["general.autoScroll", true],
["middlemouse.contentLoadURL", false],
["test.events.async.enabled", true],
],
});
});
async function doTest() {
function httpURL(filename) {
const chromeURL = getRootDirectory(gTestPath) + filename;
return chromeURL.replace(
"chrome://mochitests/content/",
"http://mochi.test:8888/"
);
}
function getScrollY(context) {
return SpecialPowers.spawn(context, [], () => content.scrollY);
}
const pageUrl = httpURL("helper_test_autoscrolling_in_oop_frame.html");
await BrowserTestUtils.withNewTab(pageUrl, async function (browser) {
await promiseApzFlushedRepaintsInPopup(browser);
const iframeContext = browser.browsingContext.children[0];
await promiseApzFlushedRepaintsInPopup(iframeContext);
const { screenX, screenY, viewId, presShellId } = await SpecialPowers.spawn(
iframeContext,
[],
() => {
const winUtils = SpecialPowers.getDOMWindowUtils(content);
return {
screenX: content.mozInnerScreenX * content.devicePixelRatio,
screenY: content.mozInnerScreenY * content.devicePixelRatio,
viewId: winUtils.getViewId(content.document.documentElement),
presShellId: winUtils.getPresShellId(),
};
}
);
ok(
iframeContext.startApzAutoscroll(
screenX + 100,
screenY + 50,
viewId,
presShellId
),
"Started autscroll"
);
const scrollEventPromise = SpecialPowers.spawn(
iframeContext,
[],
async () => {
return new Promise(resolve => {
content.addEventListener(
"scroll",
() => {
dump("Got a scroll event in the iframe\n");
resolve();
},
{ once: true }
);
});
}
);
// Send sequential mousemove events to cause autoscrolling.
for (let i = 0; i < 10; i++) {
await promiseNativeMouseEventWithAPZ({
type: "mousemove",
target: browser,
offsetX: 100,
offsetY: 50 + i * 10,
});
}
// Flush APZ repaints and waits for MozAfterPaint to make sure the scroll has
// been reflected on the main thread.
const apzPromise = promiseApzFlushedRepaintsInPopup(browser);
await Promise.all([apzPromise, scrollEventPromise]);
const frameScrollY = await getScrollY(iframeContext);
ok(frameScrollY > 0, "Autoscrolled the iframe");
const rootScrollY = await getScrollY(browser);
ok(rootScrollY == 0, "Didn't scroll the root document");
iframeContext.stopApzAutoscroll(viewId, presShellId);
});
}
add_task(async function test_autoscroll_in_oop_iframe() {
await doTest();
});
add_task(async function test_autoscroll_in_oop_iframe_with_os_zoom() {
await SpecialPowers.pushPrefEnv({ set: [["ui.textScaleFactor", 200]] });
await doTest();
});
|