Bug 1252055 P2 Update tests to verify ServiceWorker object equality. r=ehsan
authorBen Kelly <ben@wanderview.com>
Thu, 03 Mar 2016 19:37:59 -0500
changeset 323072 39482a4423f12087db7046d05f626fae2b7e2ebd
parent 323071 7f4e37c4268e03e0b5f2aa7eda3d91e9f925ce1b
child 323073 90fae59aad6e801ca8c4c7226be35b7116c34d60
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1252055
milestone47.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 1252055 P2 Update tests to verify ServiceWorker object equality. r=ehsan
dom/workers/test/serviceworkers/test_claim_oninstall.html
testing/web-platform/mozilla/tests/service-workers/service-worker/controller-on-load.https.html
testing/web-platform/mozilla/tests/service-workers/service-worker/controller-on-reload.https.html
--- a/dom/workers/test/serviceworkers/test_claim_oninstall.html
+++ b/dom/workers/test/serviceworkers/test_claim_oninstall.html
@@ -32,29 +32,29 @@
   function testClaim() {
     ok(registration.installing, "Worker should be in installing state");
 
     navigator.serviceWorker.oncontrollerchange = function() {
       ok(false, "Claim should not succeed when the worker is not active.");
     }
 
     var p = new Promise(function(res, rej) {
-      registration.installing.onstatechange = function(e) {
-        ok(registration.waiting, "Worker should be in waitinging state");
-
-        // The worker will become active only if claim will reject inside the
-        // install handler.
-        registration.waiting.onstatechange = function(e) {
-          ok(registration.active, "Claim should reject if the worker is not active");
+      var worker = registration.installing;
+      worker.onstatechange = function(e) {
+        if (worker.state === 'installed') {
+          is(worker, registration.waiting, "Worker should be in waiting state");
+        } else if (worker.state === 'activated') {
+          // The worker will become active only if claim will reject inside the
+          // install handler.
+          is(worker, registration.active,
+             "Claim should reject if the worker is not active");
           ok(navigator.serviceWorker.controller === null, "Client is not controlled.");
           e.target.onstatechange = null;
           res();
         }
-
-        e.target.onstatechange = null;
       }
     });
 
     return p;
   }
 
   function runTest() {
     register()
--- a/testing/web-platform/mozilla/tests/service-workers/service-worker/controller-on-load.https.html
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/controller-on-load.https.html
@@ -4,28 +4,42 @@
 <script src="/resources/testharnessreport.js"></script>
 <script src="resources/test-helpers.sub.js"></script>
 <body>
 <script>
 var t = async_test('controller is set for a controlled document');
 t.step(function() {
     var url = 'resources/empty-worker.js';
     var scope = 'resources/blank.html';
+    var registration;
+    var controller;
+    var frame;
     service_worker_unregister_and_register(t, url, scope)
-      .then(t.step_func(function(registration) {
+      .then(t.step_func(function(swr) {
+          registration = swr;
           return wait_for_state(t, registration.installing, 'activated');
         }))
       .then(t.step_func(function() {
           return with_iframe(scope)
         }))
-      .then(t.step_func(function(frame) {
+      .then(t.step_func(function(f) {
+          frame = f;
           var w = frame.contentWindow;
-          var controller = w.navigator.serviceWorker.controller;
+          controller = w.navigator.serviceWorker.controller;
           assert_true(controller instanceof w.ServiceWorker,
                       'controller should be a ServiceWorker object');
           assert_equals(controller.scriptURL, normalizeURL(url));
+
+          // objects from different windows should not be equal
+          assert_not_equals(controller, registration.active);
+
+          return w.navigator.serviceWorker.getRegistration();
+        }))
+      .then(t.step_func(function(frameRegistration) {
+          // SW objects from same window should be equal
+          assert_equals(frameRegistration.active, controller);
           frame.remove();
           service_worker_unregister_and_done(t, scope);
         }))
       .catch(unreached_rejection(t));
   });
 </script>
 </body>
--- a/testing/web-platform/mozilla/tests/service-workers/service-worker/controller-on-reload.https.html
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/controller-on-reload.https.html
@@ -3,41 +3,52 @@
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="resources/test-helpers.sub.js"></script>
 <body>
 <script>
 promise_test(function(t) {
     var scope = 'resources/blank.html';
     var frame;
+    var registration;
+    var controller;
     return service_worker_unregister(t, scope)
       .then(function() {
           return with_iframe(scope);
         })
       .then(function(f) {
           frame = f;
           return frame.contentWindow.navigator.serviceWorker.register(
               'resources/empty-worker.js', {scope: scope});
         })
-      .then(function(registration) {
+      .then(function(swr) {
+          registration = swr;
           return wait_for_state(t, registration.installing, 'activated');
         })
       .then(function() {
           var w = frame.contentWindow;
           assert_equals(w.navigator.serviceWorker.controller, null,
                         'controller should be null until the document is ' +
                         'reloaded');
           return new Promise(function(resolve) {
               frame.onload = function() { resolve(); }
               w.location.reload();
             });
         })
       .then(function() {
           var w = frame.contentWindow;
-          assert_true(
-              w.navigator.serviceWorker.controller instanceof w.ServiceWorker,
-              'controller should be a ServiceWorker object upon reload');
+          controller = w.navigator.serviceWorker.controller;
+          assert_true(controller instanceof w.ServiceWorker,
+                      'controller should be a ServiceWorker object upon reload');
+
+          // objects from separate windows should not be equal
+          assert_not_equals(controller, registration.active);
+
+          return w.navigator.serviceWorker.getRegistration();
+        })
+      .then(function(frameRegistration) {
+          assert_equals(frameRegistration.active, controller);
           frame.remove();
           service_worker_unregister_and_done(t, scope);
         });
   }, 'controller is set upon reload after registration');
 </script>
 </body>