Bug 983497 - Patch 2: Fire updatefound on ServiceWorkerContainers. r=ehsan
authorNikhil Marathe <nsm.nikhil@gmail.com>
Fri, 11 Jul 2014 16:00:52 -0700
changeset 216179 8111e8d8875b94d7be94f097fc233319fe8cf42f
parent 216178 cd3ee2c040e19bde5ff9fdc4105918f648c3fb75
child 216180 c98c4be7d7bf2c0250ecd1e0b8aeeb5ad04a501f
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs983497
milestone33.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 983497 - Patch 2: Fire updatefound on ServiceWorkerContainers. r=ehsan
dom/workers/ServiceWorkerManager.cpp
dom/workers/test/serviceworkers/test_installation_simple.html
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -911,17 +911,18 @@ ServiceWorkerManager::Install(ServiceWor
   // the event dispatch. On the other hand, networking, IDB and so on do keep
   // the worker alive, so the waitUntil() is only relevant if the Promise is
   // gated on those actions. I (nsm) am not sure if it is worth requiring
   // a special spec mention saying the install event should keep the worker
   // alive indefinitely purely on the basis of calling waitUntil(), since
   // a wait is likely to be required only when performing networking or storage
   // transactions in the first place.
 
-  // FIXME(nsm): Bug 983497. Fire "updatefound" on ServiceWorkerContainers.
+  FireEventOnServiceWorkerContainers(aRegistration,
+                                     NS_LITERAL_STRING("updatefound"));
 }
 
 class ActivationRunnable : public nsRunnable
 {
 public:
   explicit ActivationRunnable(ServiceWorkerRegistration* aRegistration)
   { }
 };
--- a/dom/workers/test/serviceworkers/test_installation_simple.html
+++ b/dom/workers/test/serviceworkers/test_installation_simple.html
@@ -51,21 +51,21 @@
     }, function(e) {
       ok(e.name === "SecurityError", "Should fail with a SecurityError");
     }).then(function() {
       return new Promise((resolve) => SpecialPowers.popPrefEnv(resolve));
     });
   }
 
   function realWorker() {
-    var p = navigator.serviceWorker.register("worker.js");
+    var p = navigator.serviceWorker.register("worker.js", { scope: "realworker*" });
     return p.then(function(w) {
       ok(w instanceof ServiceWorker, "Register a ServiceWorker");
       info(w.scope);
-      ok(w.scope == (new URL("/*", document.baseURI)).href, "Scope should match");
+      ok(w.scope == (new URL("realworker*", document.baseURI)).href, "Scope should match");
       ok(w.url == (new URL("worker.js", document.baseURI)).href, "URL should be of the worker");
     }, function(e) {
       info("Error: " + e.name);
       ok(false, "realWorker Registration should have succeeded!");
     });
   }
 
   function abortPrevious() {
@@ -102,25 +102,38 @@
     }, function(e) {
     info("NSM " + e.name);
       ok(e instanceof Error, "Registration should fail with parse error");
     });
   }
 
   // FIXME(nsm): test for parse error when Update step doesn't happen (directly from register).
 
+  function updatefound() {
+    var p = navigator.serviceWorker.register("worker.js");
+
+    return new Promise(function(resolve, reject) {
+      navigator.serviceWorker.onupdatefound = function(e) {
+        ok(true, "Got updatefound event");
+        navigator.serviceWorker.onupdatefound = null;
+        resolve();
+      }
+    });
+  }
+
   function runTest() {
     simpleRegister()
       .then(sameOriginWorker)
       .then(sameOriginScope)
       .then(httpsOnly)
       .then(realWorker)
       .then(abortPrevious)
       .then(networkError404)
       .then(parseError)
+      .then(updatefound)
       // put more tests here.
       .then(function() {
         SimpleTest.finish();
       }).catch(function(e) {
         ok(false, "Some test failed with error " + e);
         SimpleTest.finish();
       });
   }