no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / workers / test / test_subworkers_suspended.html
blob01157671d7d12d36b42b4d995b5dae2f5c718bca
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Test for sub workers+bfcache behavior</title>
6 <script src="/tests/SimpleTest/SimpleTest.js"></script>
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
8 </head>
9 <body>
10 <script type="application/javascript">
14 /**
15 * - main page opens testUrl1
16 * - testUrl1 ---"onpageshow"---> to main page
17 * - main page ---"startWorker"---> testUrl1
18 * - testUrl1 starts workers, also ---"verifyCacheData"---> main page
19 * - main page ---"changeLocation"---> testUrl1
20 * - testUrl1 navigated to testUrl2
21 * - testUrl2 ---"onpageshow"---> to main page
22 * - main page ---"startWorker"---> testUrl2
23 * - testUrl2 starts workers, also ---"verifyCacheData"---> main page
24 * - main page ---"goBack"---> testUrl2
25 * - testUrl2 navigates back to testUrl1
26 * - testUrl1 ---"onpageshow"---> to main page
27 * - main page checks cache data and ---"finish"---> testUrl2
28 * - testUrl1 ---"finished"---> to main page
30 var testUrl1 = "window_suspended.html?page1Shown";
31 var counter = 0;
32 const SUB_WORKERS = 3;
34 function cacheData() {
35 return caches.open("test")
36 .then(function(cache) {
37 return cache.match("http://mochi.test:888/foo");
39 .then(function(response) {
40 return response.text();
41 });
44 function runTest() {
45 var bc1 = new BroadcastChannel("page1Shown");
46 bc1.onmessage = async (msgEvent) => {
47 var msg = msgEvent.data;
48 var command = msg.command;
49 info(`Main page, received command=${command}`);
50 if (command == "onpageshow") {
51 info("Page1Shown: " + msg.location);
52 // First time this page is shown.
53 if (counter == 0) {
54 ok(!msg.persisted, "test page should have been persisted initially");
55 var workerMessage = { type: "page1", count: SUB_WORKERS };
56 bc1.postMessage({command: "startWorker", workerMessage});
57 } else {
58 is(msg.persisted, true, "test page should have been persisted in pageshow");
59 var promise = new Promise((resolve, reject) => {
60 info("Waiting a few seconds...");
61 setTimeout(resolve, 10000);
62 });
64 promise.then(function() {
65 info("Retrieving data from cache...");
66 return cacheData();
69 .then(function(content) {
70 is(content.indexOf("page1-"), 0, "We have data from the worker");
72 .then(function() {
73 bc1.postMessage({command: "finish"});
74 });
76 counter++;
77 } else if (command == "workerMessage") {
78 is(msg.workerMessage, "ready", "We want to receive: -ready-");
79 } else if (command == "verifyCacheData") {
80 var content = await cacheData();
81 is(content.indexOf("page1-"), 0, "We have data from the worker");
82 bc1.postMessage({command: "changeLocation"});
83 } else if (command == "finished") {
84 bc1.close();
85 bc2.close();
86 SimpleTest.finish();
89 var bc2 = new BroadcastChannel("page2Shown");
90 bc2.onmessage = async (msgEvent) => {
91 var msg = msgEvent.data;
92 var command = msg.command;
93 if (command == "onpageshow") {
94 info("Page1Shown: " + msg.location);
95 var workerMessage = { type: "page2" };
96 bc2.postMessage({command: "startWorker", workerMessage});
97 } else if (command == "workerMessage") {
98 is(msg.workerMessage, "ready", "We want to receive: -ready-");
99 } else if (command == "verifyCacheData") {
100 var content = await cacheData();
101 is(content, "page2-0", "We have data from the second worker");
102 bc2.postMessage({command: "goBack"});
106 SpecialPowers.pushPrefEnv({ set: [
107 ["dom.caches.testing.enabled", true],
108 // If Fission is disabled, the pref is no-op.
109 ["fission.bfcacheInParent", true],
110 ] },
111 function() {
112 window.open(testUrl1, "", "noopener");
117 if (isXOrigin) {
118 // Bug 1746646: Make mochitests work with TCP enabled (cookieBehavior = 5)
119 // Acquire storage access permission here so that the BroadcastChannel used to
120 // communicate with the opened windows works in xorigin tests. Otherwise,
121 // the iframe containing this page is isolated from first-party storage access,
122 // which isolates BroadcastChannel communication.
123 SpecialPowers.wrap(document).notifyUserGestureActivation();
124 SpecialPowers.pushPrefEnv({
125 set: [["privacy.partition.always_partition_third_party_non_cookie_storage", false]],
126 }).then(() => {
127 SpecialPowers.pushPermissions([{'type': 'storageAccessAPI', 'allow': 1, 'context': document}], () =>{
128 SpecialPowers.wrap(document).requestStorageAccess().then(() => {
129 runTest();
130 }).then(() => {
131 SpecialPowers.removePermission("3rdPartyStorage^http://mochi.test:8888", "http://mochi.xorigin-test:8888");
135 } else {
136 runTest();
139 SimpleTest.waitForExplicitFinish();
140 SimpleTest.requestFlakyTimeout("untriaged");
142 </script>
143 </body>
144 </html>