4 https://bugzilla.mozilla.org/show_bug.cgi?id=646641
7 <title>Test for Bug
646641</title>
8 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
9 <script src=
"/tests/SimpleTest/WindowSnapshot.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=646641">Mozilla Bug
646641</a>
15 <div id=
"content" style=
"display: none">
19 <script type=
"application/javascript">
21 /** Test for Bug
646641 */
25 * - Main page (this one) opens file_bfcache_plus_hash_1.html (subpage
1)
26 * - subpage
1 sends msg {
"childLoad",
1 }
27 * - subpage
1 sends msg {
"childPageshow",
1 }
28 * - main page sends message
"pushState"
29 * - subpage
1 does pushState()
30 * - subpage
1 navigates to file_bfcache_plus_hash_2.html (subpage
2)
31 * - subpage
2 sends msg {
"childLoad",
2 }
32 * - subpage
2 sends msg {
"childPageshow",
2 }
33 * - main page sends msg
"go-2"
34 * - subpage
2 goes back two history entries
35 * - subpage
1 sends msg {
"childPageshow",
1 }
36 * - Receiving only this msg shows we have retrieved the document from bfcache
37 * - main page sends msg
"close"
38 * - subpage
1 sends msg
"closed"
40 SimpleTest.waitForExplicitFinish();
43 // Wrap dump so we can turn debug messages on and off easily.
47 var expectedLoadNum = -
1;
48 var expectedPageshowNum = -
1;
50 function waitForLoad(n) {
51 debug(
"Waiting for load " + n);
55 function waitForShow(n) {
56 debug(
"Waiting for show " + n);
57 expectedPageshowNum = n;
62 function executeTest() {
64 window.open(
"file_bfcache_plus_hash_1.html",
"",
"noopener");
70 bc1.postMessage(
"pushState");
77 // Now go back
2. The first page should be retrieved from bfcache.
78 bc2.postMessage(
"go-2");
82 bc1.postMessage(
"close");
85 var bc1 = new BroadcastChannel(
"bug646641_1");
86 var bc2 = new BroadcastChannel(
"bug646641_2");
87 bc1.onmessage = (msgEvent) =
> {
88 var msg = msgEvent.data.message;
89 var n = msgEvent.data.num;
90 if (msg ==
"childLoad") {
91 if (n == expectedLoadNum) {
92 debug(
"Got load " + n);
95 // Spin the event loop before calling gGen.next() so the generator runs
96 // outside the onload handler. This prevents us from encountering all
97 // sorts of docshell quirks.
98 setTimeout(function() { gGen.next(); },
0);
100 debug(
"Got unexpected load " + n);
101 ok(false,
"Got unexpected load " + n);
103 } else if (msg ==
"childPageshow") {
104 if (n == expectedPageshowNum) {
105 debug(
"Got expected pageshow " + n);
106 expectedPageshowNum = -
1;
107 ok(true,
"Got expected pageshow " + n);
108 setTimeout(function() { gGen.next(); },
0);
110 debug(
"Got unexpected pageshow " + n);
111 ok(false,
"Got unexpected pageshow " + n);
113 } else if (msg ==
"closed") {
120 bc2.onmessage = bc1.onmessage;
124 // If Fission is disabled, the pref is no-op.
125 SpecialPowers.pushPrefEnv({set: [[
"fission.bfcacheInParent", true]]}, () =
> {
130 // Bug
1746646: Make mochitests work with TCP enabled (cookieBehavior =
5)
131 // Acquire storage access permission here so that the BroadcastChannel used to
132 // communicate with the opened windows works in xorigin tests. Otherwise,
133 // the iframe containing this page is isolated from first-party storage access,
134 // which isolates BroadcastChannel communication.
135 SpecialPowers.wrap(document).notifyUserGestureActivation();
136 SpecialPowers.addPermission(
"storageAccessAPI", true, window.location.href).then(() =
> {
137 SpecialPowers.wrap(document).requestStorageAccess().then(() =
> {
138 SpecialPowers.pushPrefEnv({
139 set: [[
"privacy.partition.always_partition_third_party_non_cookie_storage", false]],