зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1304489 - part 1 - Sub-workers must be frozen/thawed, r=bkelly
This commit is contained in:
Родитель
1aa09604f6
Коммит
fbb338bc11
|
@ -5104,6 +5104,11 @@ WorkerPrivate::FreezeInternal()
|
|||
NS_ASSERTION(!mFrozen, "Already frozen!");
|
||||
|
||||
mFrozen = true;
|
||||
|
||||
for (uint32_t index = 0; index < mChildWorkers.Length(); index++) {
|
||||
mChildWorkers[index]->Freeze(nullptr);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -5114,6 +5119,10 @@ WorkerPrivate::ThawInternal()
|
|||
|
||||
NS_ASSERTION(mFrozen, "Not yet frozen!");
|
||||
|
||||
for (uint32_t index = 0; index < mChildWorkers.Length(); index++) {
|
||||
mChildWorkers[index]->Thaw(nullptr);
|
||||
}
|
||||
|
||||
mFrozen = false;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -105,6 +105,8 @@ support-files =
|
|||
worker_setTimeoutWith0.js
|
||||
worker_bug1301094.js
|
||||
script_bug1301094.js
|
||||
worker_suspended.js
|
||||
window_suspended.html
|
||||
!/dom/base/test/file_websocket_basic_wsh.py
|
||||
!/dom/base/test/file_websocket_hello_wsh.py
|
||||
!/dom/base/test/file_websocket_http_resource.txt
|
||||
|
@ -230,3 +232,4 @@ skip-if = buildapp == 'b2g' || toolkit == 'android' #bug 982828
|
|||
[test_bug1278777.html]
|
||||
[test_setTimeoutWith0.html]
|
||||
[test_bug1301094.html]
|
||||
[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 2 seconds...");
|
||||
setTimeout(resolve, 2000);
|
||||
});
|
||||
|
||||
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>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<script>
|
||||
onpageshow = function(e) {
|
||||
opener[location.search.split('?')[1]](e);
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,31 @@
|
|||
var count = 0;
|
||||
|
||||
function do_magic(data) {
|
||||
caches.open("test")
|
||||
.then(function(cache) {
|
||||
return cache.put("http://mochi.test:888/foo", new Response(data.type + "-" + count++));
|
||||
})
|
||||
.then(function() {
|
||||
if (count == 1) {
|
||||
postMessage("ready");
|
||||
}
|
||||
|
||||
if (data.loop) {
|
||||
setTimeout(function() {do_magic(data); }, 500);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onmessage = function(e) {
|
||||
if (e.data.type == 'page1') {
|
||||
if (e.data.count > 0) {
|
||||
var a = new Worker("worker_suspended.js");
|
||||
a.postMessage({ type: "page1", count: e.data - 1 });
|
||||
a.onmessage = function() { postMessage("ready"); }
|
||||
} else {
|
||||
do_magic({ type: e.data.type, loop: true });
|
||||
}
|
||||
} else if (e.data.type == 'page2') {
|
||||
do_magic({ type: e.data.type, loop: false });
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче