summaryrefslogtreecommitdiffstats
path: root/dom/workers/test/window_suspended.html
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dom/workers/test/window_suspended.html71
1 files changed, 71 insertions, 0 deletions
diff --git a/dom/workers/test/window_suspended.html b/dom/workers/test/window_suspended.html
new file mode 100644
index 0000000000..ae5d25df58
--- /dev/null
+++ b/dom/workers/test/window_suspended.html
@@ -0,0 +1,71 @@
+<script>
+const WORKER_URL = "worker_suspended.js";
+var testUrl2 = "window_suspended.html?page2Shown";
+
+let cacheDataPromise = {};
+cacheDataPromise.promise = new Promise(resolve => {
+ cacheDataPromise.resolve = resolve;
+});
+var bcName = location.search.split('?')[1];
+var bc = new BroadcastChannel(bcName);
+if (bcName == "page1Shown") {
+ bc.onmessage = async (msgEvent) => {
+ var msg = msgEvent.data;
+ var command = msg.command;
+ if (command == "startWorker") {
+ // Create a worker and subworkers
+ let { worker, promise } = postMessageWorker(msg.workerMessage);
+ promise.then(function() {
+ bc.postMessage({command: "verifyCacheData"});
+ return cacheDataPromise.promise;
+ })
+ .then(function() {
+ location.href = testUrl2;
+ });
+ } else if (command == "changeLocation") {
+ cacheDataPromise.resolve();
+ } else if (command == "finish") {
+ bc.postMessage({command: "finished"});
+ bc.close();
+ window.close();
+ }
+ }
+} else if (bcName == "page2Shown") {
+ bc.onmessage = (msgEvent) => {
+ var msg = msgEvent.data;
+ var command = msg.command;
+ if (command == "startWorker") {
+ let { worker, promise } = postMessageWorker(msg.workerMessage);
+ promise.then(function() {
+ bc.postMessage({command: "verifyCacheData"});
+ return cacheDataPromise.promise;
+ })
+ .then(function() {
+ bc.close();
+ history.back();
+ });
+ } else if (command == "goBack") {
+ cacheDataPromise.resolve();
+ }
+ }
+}
+
+function postMessageWorker(message) {
+ let worker = new window.Worker(WORKER_URL);
+
+ var promise = new Promise((resolve, reject) => {
+ // Waiting until workers are ready
+ worker.addEventListener("message", function onmessage(msg) {
+ bc.postMessage({command: "workerMessage", workerMessage: msg.data});
+ worker.removeEventListener("message", onmessage);
+ resolve();
+ });
+ worker.postMessage(message);
+ });
+ return { worker, promise };
+}
+
+onpageshow = function(e) {
+ bc.postMessage({command: "onpageshow", persisted: e.persisted, location: location.href});
+}
+</script>