Bug 1413056 - Use utils.js in test_bug1408734.html for waitForState and waitForControlled. r=bkelly, a=test-only FIREFOX_57b_RELBRANCH
authorEden Chuang <echuang@mozilla.com>
Tue, 31 Oct 2017 10:34:22 +0800
branchFIREFOX_57b_RELBRANCH
changeset 440583 de5b0fe8f4e556abb4f449809059758cf0b28be7
parent 440582 48d9303105bdc1a6b734a39146c90668ab56001d
child 440584 7ce2c31171767b171236f3c5df5ff139ca1746b0
push id8116
push userryanvm@gmail.com
push dateThu, 02 Nov 2017 18:11:27 +0000
treeherdermozilla-beta@8c3926699de4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly, test-only
bugs1413056, 1408734
milestone57.0
Bug 1413056 - Use utils.js in test_bug1408734.html for waitForState and waitForControlled. r=bkelly, a=test-only
dom/workers/test/serviceworkers/test_bug1408734.html
--- a/dom/workers/test/serviceworkers/test_bug1408734.html
+++ b/dom/workers/test/serviceworkers/test_bug1408734.html
@@ -5,16 +5,17 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Bug 1408734</title>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script src="/tests/SimpleTest/SimpleTest.js"></script>
   <script src="/tests/SimpleTest/SpawnTask.js"></script>
   <script src="error_reporting_helpers.js"></script>
+  <script src="utils.js"></script>
 </head>
 <body>
 <p id="display"></p>
 <div id="content" style="display: none"></div>
 <pre id="test"></pre>
 <script class="testbody" type="text/javascript">
 
 // setup prefs
@@ -22,27 +23,26 @@ add_task(() => {
   return SpecialPowers.pushPrefEnv({"set": [
     ["dom.serviceWorkers.enabled", true],
     ["dom.serviceWorkers.testing.enabled", true],
   ]});
 });
 
 // test for bug 1408734
 add_task(async () => {
-  let waitForControlled = new Promise((resolve) => {
-    navigator.serviceWorker.oncontrollerchange = resolve;
-  });
-
   // register a service worker
   let registration = await navigator.serviceWorker.register("fetch.js", {scope: "./"});
-  let worker = registration.installing || registration.active;
+  let sw = registration.installing || registration.active;
+
+  // wait for service worker be activated
+  await waitForState(sw, 'activated');
 
   // wait for control changed
-  worker.postMessage('claim');
-  await waitForControlled;
+  sw.postMessage('claim');
+  await waitForControlled(window);
 
   // get the ServiceWorkerRegistration we just register through GetRegistration
   registration = await navigator.serviceWorker.getRegistration("./");
   ok(registration, "should get the registration under scope './'");
 
   // call unregister()
   await registration.unregister();