Backed out changeset 06f41c22f3a6 (bug 1888460) for causing linux xpcshell failures...
[gecko.git] / dom / workers / test / test_multi_sharedWorker_lifetimes_nobfcache.html
blob5049ead1a957e08e422e307c41774cebfabbc3d9
1 <!--
2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
4 -->
5 <!DOCTYPE HTML>
6 <html>
7 <head>
8 <title>Test for SharedWorker</title>
9 <script src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
11 <script class="testbody" type="text/javascript">
12 "use strict";
14 function runTest() {
15 const windowRelativeURL = "multi_sharedWorker_frame_nobfcache.html";
16 const storedData = "0123456789abcdefghijklmnopqrstuvwxyz";
17 var bc, bc2;
18 bc = new BroadcastChannel("bugSharedWorkerLiftetime");
19 bc.onmessage = (event) => {
20 var msg = event.data;
21 var command = msg.command;
22 if (command == "finished") {
23 bc.close();
24 bc2.close();
25 SimpleTest.finish();
26 } else if (command == "debug") {
27 info(msg.message);
28 } else if (command == "fromWorker" || command == "loaded") {
29 sendToGenerator(msg.workerMessage);
32 bc2 = new BroadcastChannel("navigate");
33 bc2.onmessage = (event) => {
34 if (event.data.command == "loaded") {
35 sendToGenerator();
39 function postToWorker(workerMessage) {
40 bc.postMessage({command: "postToWorker", workerMessage});
43 let testGenerator = (function*() {
44 SimpleTest.waitForExplicitFinish();
46 // Open the window
47 window.open(windowRelativeURL, "testWin", "noopener");
48 yield undefined;
50 // Retrieve data from worker
51 postToWorker({ command: "retrieve" });
53 let msg = yield undefined;
55 // Verify there is no data stored
56 is(msg.type, "result", "Got a result message");
57 is(msg.data, undefined, "No data stored yet");
59 // Store data, and retrieve it
60 postToWorker({ command: "store", data: storedData });
61 postToWorker({ command: "retrieve" });
63 msg = yield undefined;
64 // Verify there is data stored
65 is(msg.type, "result", "Got a result message");
66 is(msg.data, storedData, "Got stored data");
69 info("Navigating to a different page");
70 // Current subpage should not go into bfcache because of the Cache-Control
71 // headers we have set.
72 bc.postMessage({command: "navigate", location: "navigate.html"});
73 yield undefined;
75 info("Navigating to " + windowRelativeURL);
76 bc2.postMessage({command: "navigate", location: windowRelativeURL });
77 yield undefined;
79 postToWorker({ command: "retrieve" });
81 msg = yield undefined;
82 is(msg.type, "result", "Got a result message");
83 is(msg.data, undefined, "No data stored");
85 postToWorker({ command: "store", data: storedData });
86 postToWorker({ command: "retrieve" });
88 msg = yield undefined;
89 is(msg.type, "result", "Got a result message");
90 is(msg.data, storedData, "Got stored data");
92 bc.postMessage({command: "finish"});
93 })();
95 let sendToGenerator = testGenerator.next.bind(testGenerator);
96 testGenerator.next();
99 SimpleTest.waitForExplicitFinish();
100 if (isXOrigin) {
101 // Bug 1746646: Make mochitests work with TCP enabled (cookieBehavior = 5)
102 // Acquire storage access permission here so that the BroadcastChannel used to
103 // communicate with the opened windows works in xorigin tests. Otherwise,
104 // the iframe containing this page is isolated from first-party storage access,
105 // which isolates BroadcastChannel communication.
106 SpecialPowers.wrap(document).notifyUserGestureActivation();
107 SpecialPowers.pushPrefEnv({
108 set: [["privacy.partition.always_partition_third_party_non_cookie_storage", false]],
109 }).then(() => {
110 SpecialPowers.pushPermissions([{'type': 'storageAccessAPI', 'allow': 1, 'context': document}], () =>{
111 SpecialPowers.wrap(document).requestStorageAccess().then(() => {
112 runTest();
113 }).then(() => {
114 SpecialPowers.removePermission("3rdPartyStorage^http://mochi.test:8888", "http://mochi.xorigin-test:8888");
118 } else {
119 runTest();
122 </script>
123 </head>
124 <body>
125 </body>
126 </html>