2011-07-17 23:09:13 +04:00
|
|
|
<!--
|
|
|
|
Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
-->
|
2010-11-27 16:52:33 +03:00
|
|
|
<!DOCTYPE HTML>
|
2010-03-11 23:36:44 +03:00
|
|
|
<html>
|
|
|
|
<head>
|
2012-03-24 15:34:42 +04:00
|
|
|
<meta charset="utf-8">
|
2010-03-11 23:36:44 +03:00
|
|
|
<title>Test for DOM Worker Threads</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none"></div>
|
|
|
|
<pre id="test">
|
|
|
|
<iframe id="workerFrame" src="suspend_iframe.html" onload="subframeLoaded();">
|
|
|
|
</iframe>
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
var iframe;
|
|
|
|
var lastCount;
|
|
|
|
|
2010-03-15 23:12:40 +03:00
|
|
|
var suspended = false;
|
|
|
|
var resumed = false;
|
|
|
|
var finished = false;
|
2010-03-11 23:36:44 +03:00
|
|
|
|
|
|
|
var interval;
|
|
|
|
var oldMessageCount;
|
|
|
|
var waitCount = 0;
|
|
|
|
|
|
|
|
function setCachePref(enabled) {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
if (enabled) {
|
|
|
|
prefBranch.setBoolPref("browser.sessionhistory.cache_subframes", true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
try {
|
|
|
|
prefBranch.clearUserPref("browser.sessionhistory.cache_subframes");
|
|
|
|
} catch (e) { /* Pref didn't exist, meh */ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function finishTest() {
|
2010-03-15 23:12:40 +03:00
|
|
|
if (finished) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
finished = true;
|
2010-03-11 23:36:44 +03:00
|
|
|
setCachePref(false);
|
|
|
|
iframe.terminateWorker();
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
function waitInterval() {
|
2010-03-15 23:12:40 +03:00
|
|
|
if (finished) {
|
|
|
|
return;
|
|
|
|
}
|
2010-03-11 23:36:44 +03:00
|
|
|
is(iframe.location, "about:blank", "Wrong url!");
|
|
|
|
is(suspended, true, "Not suspended?");
|
2010-03-15 23:12:40 +03:00
|
|
|
is(resumed, false, "Already resumed?!");
|
2010-03-11 23:36:44 +03:00
|
|
|
is(lastCount, oldMessageCount, "Received a message while suspended!");
|
|
|
|
if (++waitCount == 5) {
|
|
|
|
clearInterval(interval);
|
|
|
|
resumed = true;
|
2010-03-25 01:02:16 +03:00
|
|
|
iframe.history.back();
|
2010-03-11 23:36:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function badOnloadCallback() {
|
2010-03-15 23:12:40 +03:00
|
|
|
if (finished) {
|
|
|
|
return;
|
|
|
|
}
|
2010-11-27 16:52:33 +03:00
|
|
|
ok(false, "We don't want suspend_iframe.html to fire a new load event, we want it to come out of the bfcache!");
|
2010-03-11 23:36:44 +03:00
|
|
|
finishTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function suspendCallback() {
|
2010-03-15 23:12:40 +03:00
|
|
|
if (finished) {
|
|
|
|
return;
|
|
|
|
}
|
2010-03-11 23:36:44 +03:00
|
|
|
is(iframe.location, "about:blank", "Wrong url!");
|
2010-03-25 01:02:16 +03:00
|
|
|
is(suspended, false, "Already suspended?");
|
|
|
|
is(resumed, false, "Already resumed?");
|
|
|
|
setCachePref(false);
|
|
|
|
suspended = true;
|
2010-11-27 16:52:33 +03:00
|
|
|
var iframeElement = document.getElementById("workerFrame");
|
|
|
|
iframeElement.onload = badOnloadCallback;
|
2010-03-11 23:36:44 +03:00
|
|
|
oldMessageCount = lastCount;
|
|
|
|
interval = setInterval(waitInterval, 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function messageCallback(data) {
|
2010-03-15 23:12:40 +03:00
|
|
|
if (finished) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-11 23:36:44 +03:00
|
|
|
if (!suspended) {
|
|
|
|
ok(lastCount === undefined || lastCount == data - 1,
|
2011-07-17 23:09:13 +04:00
|
|
|
"Got good data, lastCount = " + lastCount + ", data = " + data);
|
2010-03-11 23:36:44 +03:00
|
|
|
lastCount = data;
|
2011-07-17 23:09:13 +04:00
|
|
|
if (lastCount == 25) {
|
2010-03-11 23:36:44 +03:00
|
|
|
setCachePref(true);
|
|
|
|
iframe.location = "about:blank";
|
2010-11-27 16:52:33 +03:00
|
|
|
// We want suspend_iframe.html to go into bfcache, so we need to flush
|
|
|
|
// out all pending notifications. Otherwise, if they're flushed too
|
|
|
|
// late, they could kick us out of the bfcache again.
|
|
|
|
iframe.document.body.offsetTop;
|
2010-03-11 23:36:44 +03:00
|
|
|
}
|
2010-03-15 23:12:40 +03:00
|
|
|
return;
|
2010-03-11 23:36:44 +03:00
|
|
|
}
|
2010-03-15 23:12:40 +03:00
|
|
|
|
|
|
|
var newLocation =
|
|
|
|
window.location.toString().replace("test_suspend.html",
|
|
|
|
"suspend_iframe.html");
|
2010-03-25 01:02:16 +03:00
|
|
|
is(newLocation.indexOf(iframe.location.toString()), 0, "Wrong url!");
|
2010-03-15 23:12:40 +03:00
|
|
|
is(resumed, true, "Got message before resumed!");
|
|
|
|
is(lastCount, data - 1, "Missed a message, suspend failed!");
|
|
|
|
finishTest();
|
2010-03-11 23:36:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function errorCallback(data) {
|
2010-03-15 23:12:40 +03:00
|
|
|
if (finished) {
|
|
|
|
return;
|
|
|
|
}
|
2010-03-11 23:36:44 +03:00
|
|
|
ok(false, "Iframe had an error: '" + data + "'");
|
|
|
|
finishTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function subframeLoaded() {
|
2010-03-15 23:12:40 +03:00
|
|
|
if (finished) {
|
|
|
|
return;
|
|
|
|
}
|
2010-03-11 23:36:44 +03:00
|
|
|
var iframeElement = document.getElementById("workerFrame");
|
|
|
|
iframeElement.onload = suspendCallback;
|
|
|
|
|
|
|
|
iframe = iframeElement.contentWindow;
|
|
|
|
ok(iframe, "No iframe?!");
|
|
|
|
|
|
|
|
iframe.startWorker(messageCallback, errorCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|