4 https://bugzilla.mozilla.org/show_bug.cgi?id=
7 <title>Test for Bug
1155730</title>
8 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
11 <body onload=
"runTest()">
12 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=1155730">Mozilla Bug
1155730</a>
14 <div id=
"content" style=
"display: none">
18 <script type=
"application/javascript">
19 SimpleTest.waitForExplicitFinish();
20 SimpleTest.requestFlakyTimeout(
"untriaged");
22 function assertCheck(data) {
24 for (const args of data.assertIs) {
25 is(args[
0], args[
1], args[
2]);
29 for (const args of data.assertOk) {
33 if (data.assertIsNot) {
34 for (const args of data.assertIsNot) {
35 isnot(args[
0], args[
1], args[
2]);
40 var bc1, currentCase =
0;
42 bc1 = new BroadcastChannel(
"bug1155730_part1");
43 bc1.onmessage = (msgEvent) =
> {
44 var msg = msgEvent.data;
45 var command = msg.command;
46 if (command ==
"pageshow") {
48 var persisted = msg.persisted;
49 is(persisted, false,
"Shouldn't have persisted session history entry.");
50 bc1.postMessage({command:
"test", currentCase});
51 } else if (command ==
"asserts") {
52 is(msg.currentCase, currentCase,
"correct case");
53 info(`Checking asserts for case ${msg.currentCase}`);
55 if (currentCase ==
3) {
56 // move on to the next test
62 window.open(
"file_scrollRestoration_part1_nobfcache.html",
"",
"width=360,height=480,noopener");
68 bc2 = new BroadcastChannel(
"bug1155730_part2");
69 bc2.onmessage = (msgEvent) =
> {
70 var msg = msgEvent.data;
71 var command = msg.command;
72 if (command ==
"pageshow") {
74 var persisted = msg.persisted;
75 switch (currentCase) {
77 is(persisted, false,
"Shouldn't have persisted session history entry.");
80 is(persisted, true,
"Should have persisted session history entry.");
82 bc2.postMessage({command:
"test", currentCase});
83 } else if (command ==
"asserts") {
84 is(msg.currentCase, currentCase,
"correct case");
85 info(`Checking asserts for case ${msg.currentCase}`);
87 if (currentCase ==
3) {
88 // move on to the next test
92 } else if (command ==
"nextCase") {
97 bc2navigate = new BroadcastChannel(
"navigate");
98 bc2navigate.onmessage = (event) =
> {
99 if (event.data.command ==
"loaded") {
100 bc2navigate.postMessage({command:
"back"})
104 window.open(
"file_scrollRestoration_part2_bfcache.html",
"",
"width=360,height=480,noopener");
107 var bc3, bc3navigate;
110 bc3 = new BroadcastChannel(
"bug1155730_part3");
111 bc3.onmessage = (msgEvent) =
> {
112 var msg = msgEvent.data;
113 var command = msg.command;
114 if (command ==
"pageshow") {
116 if (currentCase ==
3) {
117 var persisted = msg.persisted;
118 is(persisted, false,
"Shouldn't have persisted session history entry.");
121 bc3.postMessage({command:
"test", currentCase});
122 } else if (command ==
"asserts") {
123 is(msg.currentCase, currentCase,
"correct case");
124 info(`Checking asserts for case ${msg.currentCase}`);
126 } else if (command ==
"nextCase") {
128 } else if (command ==
"finishing") {
134 bc3navigate = new BroadcastChannel(
"navigate");
135 bc3navigate.onmessage = (event) =
> {
136 if (event.data.command ==
"loaded") {
137 is(event.data.scrollRestoration, 'auto',
"correct scroll restoration");
138 bc3navigate.postMessage({command:
"back"})
142 window.open(
"file_scrollRestoration_part3_nobfcache.html",
"",
"width=360,height=480,noopener");
145 // test4 opens a new page which can enter bfcache. That page then loads
146 // another page which can't enter bfcache. That second page then scrolls
147 // down. History API is then used to navigate back and forward. When the
148 // second page loads again, it should scroll down automatically.
150 var scrollYCounter =
0;
153 bc4a = new BroadcastChannel(
"bfcached");
154 bc4a.onmessage = (msgEvent) =
> {
155 var msg = msgEvent.data;
156 var command = msg.command;
157 if (command ==
"pageshow") {
159 if (currentCase ==
1) {
160 ok(!msg.persisted,
"The first page should not be persisted initially.");
161 bc4a.postMessage(
"loadNext");
162 } else if (currentCase ==
3) {
163 ok(msg.persisted,
"The first page should be persisted.");
164 bc4a.postMessage(
"forward");
170 bc4b = new BroadcastChannel(
"notbfcached");
171 bc4b.onmessage = (event) =
> {
172 var msg = event.data;
173 var command = msg.command;
174 if (command ==
"pageshow") {
176 if (currentCase ==
2) {
177 ok(!msg.persisted,
"The second page should not be persisted.");
178 bc4b.postMessage(
"getScrollY");
179 bc4b.postMessage(
"scroll");
180 bc4b.postMessage(
"getScrollY");
181 bc4b.postMessage(
"back");
182 } else if (currentCase ==
4) {
183 ok(!msg.persisted,
"The second page should not be persisted.");
184 bc4b.postMessage(
"getScrollY");
186 } else if (msg ==
"closed") {
189 } else if (
"scrollY" in msg) {
191 if (scrollYCounter ==
1) {
192 is(msg.scrollY,
0,
"The page should be initially scrolled to top.");
193 } else if (scrollYCounter ==
2) {
194 isnot(msg.scrollY,
0,
"The page should be then scrolled down.");
195 } else if (scrollYCounter ==
3) {
196 isnot(msg.scrollY,
0,
"The page should be scrolled down after being restored from the session history.");
197 bc4b.postMessage(
"close");
201 window.open(
"file_scrollRestoration_bfcache_and_nobfcache.html",
"",
"width=360,height=480,noopener");
205 // If Fission is disabled, the pref is no-op.
206 SpecialPowers.pushPrefEnv({set: [[
"fission.bfcacheInParent", true]]}, () =
> {