Bug 1159813 - Make sure service worker tests clean up after themselves; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 29 Apr 2015 13:34:20 -0400
changeset 273618 57fc3025cf9968a571cc16af9996acc9b468cabb
parent 273617 0e95b93afba006fc8789690f3a72517d79f3c601
child 273619 3b3b8835cb2ec3575921be638dac64b6d03c377e
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1159813
milestone40.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 1159813 - Make sure service worker tests clean up after themselves; r=baku This makes it possible to run the service workers tests using --run-until-failure, which will hopefully help with reproducing intermittent test failures.
dom/workers/test/serviceworkers/importscript.sjs
dom/workers/test/serviceworkers/periodic.sjs
dom/workers/test/serviceworkers/periodic/unregister.html
dom/workers/test/serviceworkers/test_importscript.html
--- a/dom/workers/test/serviceworkers/importscript.sjs
+++ b/dom/workers/test/serviceworkers/importscript.sjs
@@ -1,9 +1,11 @@
 function handleRequest(request, response) {
-  if (!getState('counter')) {
+  if (request.queryString == 'clearcounter') {
+    setState('counter', '');
+  } else if (!getState('counter')) {
     response.setHeader("Content-Type", "application/javascript", false);
     response.write("callByScript();");
     setState('counter', '1');
   } else {
     response.write("no cache no party!");
   }
 }
--- a/dom/workers/test/serviceworkers/periodic.sjs
+++ b/dom/workers/test/serviceworkers/periodic.sjs
@@ -1,9 +1,13 @@
 function handleRequest(request, response) {
+  if (request.queryString == 'clearcounter') {
+    setState('periodiccounter', '');
+    return;
+  }
   if (!getState('periodiccounter')) {
     setState('periodiccounter', '1');
   } else {
     // Make sure that we pass a string value to setState!
     setState('periodiccounter', "" + (parseInt(getState('periodiccounter')) + 1));
   }
   response.setHeader("Content-Type", "application/javascript", false);
   response.write(getScript());
--- a/dom/workers/test/serviceworkers/periodic/unregister.html
+++ b/dom/workers/test/serviceworkers/periodic/unregister.html
@@ -1,11 +1,13 @@
 <!DOCTYPE html>
 <script>
-  navigator.serviceWorker.getRegistration(".").then(function(registration) {
+  fetch("../periodic.sjs?clearcounter").then(function() {
+    return navigator.serviceWorker.getRegistration(".");
+  }).then(function(registration) {
     registration.unregister().then(function(success) {
       if (success) {
         parent.callback();
       } else {
         dump("Unregister failed\n");
       }
     }, function(e) {
       dump("Unregistering the SW failed with " + e + "\n");
--- a/dom/workers/test/serviceworkers/test_importscript.html
+++ b/dom/workers/test/serviceworkers/test_importscript.html
@@ -14,17 +14,19 @@
 <script class="testbody" type="text/javascript">
   function start() {
     return navigator.serviceWorker.register("importscript_worker.js",
                                             { scope: "./sw_clients/" })
       .then((swr) => registration = swr);
   }
 
   function unregister() {
-    return registration.unregister().then(function(result) {
+    return fetch("importscript.sjs?clearcounter").then(function() {
+      return registration.unregister();
+    }).then(function(result) {
       ok(result, "Unregister should return true.");
     }, function(e) {
       dump("Unregistering the SW failed with " + e + "\n");
     });
   }
 
   function testPostMessage(swr) {
     var p = new Promise(function(res, rej) {