diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/workers/test/test_subworkers_suspended.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/workers/test/test_subworkers_suspended.html')
-rw-r--r-- | dom/workers/test/test_subworkers_suspended.html | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/dom/workers/test/test_subworkers_suspended.html b/dom/workers/test/test_subworkers_suspended.html new file mode 100644 index 000000000..063ccaa64 --- /dev/null +++ b/dom/workers/test/test_subworkers_suspended.html @@ -0,0 +1,135 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta charset="utf-8"> + <title>Test for sub workers+bfcache behavior</title> + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> + <script type="application/javascript"> + + const WORKER_URL = "worker_suspended.js"; + const SUB_WORKERS = 3 + + var testUrl1 = "window_suspended.html?page1Shown"; + var testUrl2 = "window_suspended.html?page2Shown"; + + var testWin; + var counter = 0; + + function cacheData() { + return caches.open("test") + .then(function(cache) { + return cache.match("http://mochi.test:888/foo"); + }) + .then(function(response) { + return response.text(); + }); + } + + function page1Shown(e) { + info("Page1Shown: " + testWin.location.href); + + // First time this page is shown. + if (counter == 0) { + ok(!e.persisted, "test page should have been persisted initially"); + + info("Create a worker and subworkers..."); + let worker = new e.target.defaultView.Worker(WORKER_URL); + + var promise = new Promise((resolve, reject) => { + info("Waiting until workers are ready..."); + worker.addEventListener("message", function onmessage(e) { + is(e.data, "ready", "We want to receive: -ready-"); + worker.removeEventListener("message", onmessage); + resolve(); + }); + worker.postMessage({ type: "page1", count: SUB_WORKERS }); + }); + + promise.then(function() { + info("Retrieving data from cache..."); + return cacheData(); + }) + + .then(function(content) { + is(content.indexOf("page1-"), 0, "We have data from the worker"); + }) + + .then(function() { + info("New location: " + testUrl2); + testWin.location.href = testUrl2; + }); + } else { + is(e.persisted, true, "test page should have been persisted in pageshow"); + + var promise = new Promise((resolve, reject) => { + info("Waiting a few seconds..."); + setTimeout(resolve, 5000); + }); + + promise.then(function() { + info("Retrieving data from cache..."); + return cacheData(); + }) + + .then(function(content) { + is(content.indexOf("page1-"), 0, "We have data from the worker"); + }) + + .then(function() { + testWin.close(); + SimpleTest.finish(); + }); + } + + counter++; + } + + function page2Shown(e) { + info("Page2Shown: " + testWin.location.href); + + info("Create a worker..."); + let worker = new e.target.defaultView.Worker(WORKER_URL); + + var promise = new Promise((resolve, reject) => { + info("Waiting until workers are ready..."); + worker.addEventListener("message", function onmessage(e) { + is(e.data, "ready", "We want to receive: -ready-"); + worker.removeEventListener("message", onmessage); + resolve(); + }); + worker.postMessage({ type: "page2" }); + }); + + promise.then(function() { + info("Retrieving data from cache..."); + return cacheData(); + }) + + .then(function(content) { + is(content, "page2-0", "We have data from the second worker"); + }) + + .then(function() { + info("Going back"); + testWin.history.back(); + }); + } + + SpecialPowers.pushPrefEnv({ set: [ + ["dom.caches.enabled", true], + ["dom.caches.testing.enabled", true], + ] }, + function() { + testWin = window.open(testUrl1); + }); + + SimpleTest.waitForExplicitFinish(); + SimpleTest.requestFlakyTimeout("untriaged"); + + </script> +</body> +</html> + |