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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const ROOT = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"http://mochi.test:8888"
);
const URL1 = ROOT + "file_backforward_restore_scroll.html";
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
const URL2 = "http://example.net/";
const SCROLL0 = 500;
const SCROLL1 = 1000;
function promiseBrowserLoaded(url) {
return BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, url);
}
add_task(async function test() {
await BrowserTestUtils.openNewForegroundTab(gBrowser, URL1);
// Scroll the 2 frames.
let children = gBrowser.selectedBrowser.browsingContext.children;
await SpecialPowers.spawn(children[0], [SCROLL0], scrollY =>
content.scrollTo(0, scrollY)
);
await SpecialPowers.spawn(children[1], [SCROLL1], scrollY =>
content.scrollTo(0, scrollY)
);
// Navigate forwards then backwards.
let loaded = promiseBrowserLoaded(URL2);
BrowserTestUtils.loadURIString(gBrowser.selectedBrowser, URL2);
await loaded;
loaded = promiseBrowserLoaded(URL1);
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
content.history.back();
});
await loaded;
// And check the results.
children = gBrowser.selectedBrowser.browsingContext.children;
await SpecialPowers.spawn(children[0], [SCROLL0], scrollY => {
Assert.equal(content.scrollY, scrollY, "frame 0 has correct scroll");
});
await SpecialPowers.spawn(children[1], [SCROLL1], scrollY => {
Assert.equal(content.scrollY, scrollY, "frame 1 has correct scroll");
});
gBrowser.removeTab(gBrowser.selectedTab);
});
|