Bug 1413056 - Use utils.js in test_bug1408734.html for waitForState and waitForControlled. r=bkelly
authorEden Chuang <echuang@mozilla.com>
Tue, 31 Oct 2017 10:34:22 +0800
changeset 389550 a137a0d96fb663b8f90af9f1ec985534c11d6e40
parent 389549 388ffddeb4623b932ed67554f2ddc434b1fed8fb
child 389551 d99a96c8da9209124506be1760f7be6db23103bb
push id96871
push userryanvm@gmail.com
push dateWed, 01 Nov 2017 12:41:10 +0000
treeherdermozilla-inbound@a137a0d96fb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1413056, 1408734
milestone58.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 1413056 - Use utils.js in test_bug1408734.html for waitForState and waitForControlled. r=bkelly
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();