Bug 1317266 - Test registration.installing getting collected before all statechange events are dispatched. r=bkelly
authorCatalin Badea <catalin.badea392@gmail.com>
Mon, 21 Nov 2016 02:14:53 +0000
changeset 323555 3c1343636012438a1b8671fcfd2b2a3b8275774d
parent 323554 b322495cb537c818e856bd8e5625d03d82662bd9
child 323556 ac6b94962bf249fb5178cf83524f2944566ed96e
push id30978
push usercbook@mozilla.com
push dateMon, 21 Nov 2016 14:44:46 +0000
treeherdermozilla-central@0534254e9a40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1317266
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1317266 - Test registration.installing getting collected before all statechange events are dispatched. r=bkelly
dom/workers/test/serviceworkers/lazy_worker.js
dom/workers/test/serviceworkers/mochitest.ini
dom/workers/test/serviceworkers/test_worker_reference_gc_timeout.html
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/lazy_worker.js
@@ -0,0 +1,8 @@
+onactivate = function(event) {
+  var promise = new Promise(function(res) {
+    setTimeout(function() {
+      res();
+      }, 500);
+  });
+  event.waitUntil(promise);
+}
--- a/dom/workers/test/serviceworkers/mochitest.ini
+++ b/dom/workers/test/serviceworkers/mochitest.ini
@@ -208,16 +208,17 @@ support-files =
   sw_bad_mime_type.js
   sw_bad_mime_type.js^headers^
   error_reporting_helpers.js
   fetch.js
   hello.html
   create_another_sharedWorker.html
   sharedWorker_fetch.js
   async_waituntil_worker.js
+  lazy_worker.js
 
 [test_bug1151916.html]
 [test_bug1240436.html]
 [test_claim.html]
 [test_claim_fetch.html]
 [test_claim_oninstall.html]
 [test_close.html]
 [test_controller.html]
@@ -312,8 +313,9 @@ tags = openwindow
 [test_third_party_iframes.html]
 [test_unregister.html]
 [test_unresolved_fetch_interception.html]
 [test_workerUnregister.html]
 [test_workerUpdate.html]
 [test_workerupdatefoundevent.html]
 [test_xslt.html]
 [test_async_waituntil.html]
+[test_worker_reference_gc_timeout.html]
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/test_worker_reference_gc_timeout.html
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+  -->
+<head>
+  <title>Test for Bug 1317266</title>
+  <script src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script src="/tests/SimpleTest/SpawnTask.js"></script>
+  <script src="error_reporting_helpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
+</head>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1317266">Mozilla Bug 1317266</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+
+<script class="testbody" type="text/javascript">
+SimpleTest.requestFlakyTimeout("Forcing a race with the cycle collector.");
+
+add_task(function setupPrefs() {
+  return SpecialPowers.pushPrefEnv({"set": [
+    ["dom.serviceWorkers.enabled", true],
+    ["dom.serviceWorkers.testing.enabled", true],
+  ]});
+});
+
+//var worker;
+add_task(function* test_worker_ref_gc() {
+  let registration = yield navigator.serviceWorker.register(
+    "lazy_worker.js", { scope: "./lazy_worker_scope_timeout"} )
+    .then(function(registration) {
+      SpecialPowers.exactGC();
+      var worker = registration.installing;
+      return new Promise(function(resolve) {
+        worker.addEventListener('statechange', function() {
+          info("state is " + worker.state + "\n");
+          SpecialPowers.exactGC();
+          if (worker.state === 'activated') {
+            resolve(registration);
+          }
+        });
+      });
+    });
+
+  ok(true, "Got activated event!");
+
+  yield registration.unregister();
+  yield SpecialPowers.popPrefEnv();
+});
+</script>
+</body>
+</html>