summaryrefslogtreecommitdiffstats
path: root/dom/workers/test/test_suspend.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/workers/test/test_suspend.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-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_suspend.html')
-rw-r--r--dom/workers/test/test_suspend.html138
1 files changed, 138 insertions, 0 deletions
diff --git a/dom/workers/test/test_suspend.html b/dom/workers/test/test_suspend.html
new file mode 100644
index 000000000..806b97f6c
--- /dev/null
+++ b/dom/workers/test/test_suspend.html
@@ -0,0 +1,138 @@
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <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;
+
+ var suspended = false;
+ var resumed = false;
+ var finished = false;
+
+ var interval;
+ var oldMessageCount;
+ var waitCount = 0;
+
+ function finishTest() {
+ if (finished) {
+ return;
+ }
+ finished = true;
+ SpecialPowers.flushPrefEnv(function () {
+ iframe.terminateWorker();
+ SimpleTest.finish();
+ });
+ }
+
+ function waitInterval() {
+ if (finished) {
+ return;
+ }
+ is(String(iframe.location), "about:blank", "Wrong url!");
+ is(suspended, true, "Not suspended?");
+ is(resumed, false, "Already resumed?!");
+ is(lastCount, oldMessageCount, "Received a message while suspended!");
+ if (++waitCount == 5) {
+ clearInterval(interval);
+ resumed = true;
+ iframe.history.back();
+ }
+ }
+
+ function badOnloadCallback() {
+ if (finished) {
+ return;
+ }
+ ok(false, "We don't want suspend_iframe.html to fire a new load event, we want it to come out of the bfcache!");
+ finishTest();
+ }
+
+ function suspendCallback() {
+ if (finished) {
+ return;
+ }
+ is(String(iframe.location), "about:blank", "Wrong url!");
+ is(suspended, false, "Already suspended?");
+ is(resumed, false, "Already resumed?");
+ SpecialPowers.popPrefEnv(function () {
+ suspended = true;
+ var iframeElement = document.getElementById("workerFrame");
+ iframeElement.onload = badOnloadCallback;
+ oldMessageCount = lastCount;
+ interval = setInterval(waitInterval, 1000);
+ });
+ }
+
+ function messageCallback(data) {
+ if (finished) {
+ return;
+ }
+
+ if (!suspended) {
+ ok(lastCount === undefined || lastCount == data - 1,
+ "Got good data, lastCount = " + lastCount + ", data = " + data);
+ lastCount = data;
+ if (lastCount == 25) {
+ SpecialPowers.pushPrefEnv({"set": [["browser.sessionhistory.cache_subframes", true]]}, function () {
+ iframe.location = "about:blank";
+ // 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;
+ });
+ }
+ return;
+ }
+
+ var newLocation =
+ window.location.toString().replace("test_suspend.html",
+ "suspend_iframe.html");
+ is(newLocation.indexOf(iframe.location.toString()), 0, "Wrong url!");
+ is(resumed, true, "Got message before resumed!");
+ is(lastCount, data - 1, "Missed a message, suspend failed!");
+ finishTest();
+ }
+
+ function errorCallback(data) {
+ if (finished) {
+ return;
+ }
+ ok(false, "Iframe had an error: '" + data + "'");
+ finishTest();
+ }
+
+ function subframeLoaded() {
+ if (finished) {
+ return;
+ }
+ var iframeElement = document.getElementById("workerFrame");
+ iframeElement.onload = suspendCallback;
+
+ iframe = iframeElement.contentWindow;
+ ok(iframe, "No iframe?!");
+
+ iframe.startWorker(messageCallback, errorCallback);
+ }
+
+</script>
+</pre>
+</body>
+</html>