Bug 1175163 - Part 2: Create a testcase for claim() should affect other registrations. r=bkelly
authorHo-Pang Hsu <hopang.hsu@gmail.com>
Wed, 01 Mar 2017 11:31:00 +0800
changeset 345327 e7b9fda58dd570add4a4c2d3cacab2a94fd74654
parent 345326 b719e03aa6f8cb725e9a55244e92280026407e08
child 345328 5ef0e255799d58592fbb7f70636cbb91c8b90c6a
push id31436
push userkwierso@gmail.com
push dateThu, 02 Mar 2017 01:18:52 +0000
treeherdermozilla-central@e91de6fb2b3d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1175163
milestone54.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 1175163 - Part 2: Create a testcase for claim() should affect other registrations. r=bkelly
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/service-workers/service-worker/claim-affect-other-registration.https.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -118577,16 +118577,22 @@
     ]
    ],
    "service-workers/service-worker/appcache-ordering-main.https.html": [
     [
      "/service-workers/service-worker/appcache-ordering-main.https.html",
      {}
     ]
    ],
+   "service-workers/service-worker/claim-affect-other-registration.https.html": [
+    [
+     "/service-workers/service-worker/claim-affect-other-registration.https.html",
+     {}
+    ]
+   ],
    "service-workers/service-worker/claim-fetch.https.html": [
     [
      "/service-workers/service-worker/claim-fetch.https.html",
      {}
     ]
    ],
    "service-workers/service-worker/claim-not-using-registration.https.html": [
     [
@@ -199768,18 +199774,22 @@
   "service-workers/service-worker/active.https.html": [
    "974fc8372db8f06f87919d35be48f922166d6652",
    "testharness"
   ],
   "service-workers/service-worker/appcache-ordering-main.https.html": [
    "a71f51cde17f9d209750877dfbe1bacd26412ab3",
    "testharness"
   ],
+  "service-workers/service-worker/claim-affect-other-registration.https.html": [
+   "79b4a278f0e35646cfdffeebf8f0523e2772bc9b",
+   "testharness"
+  ],
   "service-workers/service-worker/claim-fetch.https.html": [
-   "79b4a278f0e35646cfdffeebf8f0523e2772bc9b",
+   "92d1733358db62804567a642ef405ba74edadf66",
    "testharness"
   ],
   "service-workers/service-worker/claim-not-using-registration.https.html": [
    "72da19e038b6ab32ea04a0e91d117bc67d25a301",
    "testharness"
   ],
   "service-workers/service-worker/claim-using-registration.https.html": [
    "fb56cc3ae802669bb7898e76ac55e75ba6ac1441",
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/service-worker/claim-affect-other-registration.https.html
@@ -0,0 +1,136 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>Service Worker: claim() should affect other registration</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
+<script>
+
+promise_test(function(t) {
+  var frame;
+
+  var init_scope = 'resources/blank.html?affect-other';
+  var init_worker_url = 'resources/empty.js';
+  var init_registration;
+  var init_workers = [undefined, undefined];
+
+  var claim_scope = 'resources/blank.html?affect-other-registration';
+  var claim_worker_url = 'resources/claim-worker.js';
+  var claim_registration;
+  var claim_worker;
+
+  return Promise.resolve()
+    // Register the first service worker to init_scope.
+    .then(() => navigator.serviceWorker.register(init_worker_url + '?v1',
+                                                 {scope: init_scope}))
+    .then(r => {
+      init_registration = r;
+      init_workers[0] = r.installing;
+      return Promise.resolve()
+        .then(() => wait_for_state(t, init_workers[0], 'activated'))
+        .then(() => assert_array_equals([init_registration.active,
+                                         init_registration.waiting,
+                                         init_registration.installing],
+                                        [init_workers[0],
+                                         null,
+                                         null],
+                                        'Wrong workers.'));
+    })
+
+    // Create an iframe as the client of the first service worker of init_scope.
+    .then(() => with_iframe(claim_scope))
+    .then(f => frame = f)
+
+    // Check the controller.
+    .then(() => frame.contentWindow.navigator.serviceWorker.getRegistration(
+                  normalizeURL(init_scope)))
+    .then(r => assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
+                             r.active,
+                             '.controller should belong to init_scope.'))
+
+    // Register the second service worker to init_scope.
+    .then(() => navigator.serviceWorker.register(init_worker_url + '?v2',
+                                                 {scope: init_scope}))
+    .then(r => {
+      assert_equals(r, init_registration, 'Should be the same registration');
+      init_workers[1] = r.installing;
+      return Promise.resolve()
+        .then(() => wait_for_state(t, init_workers[1], 'installed'))
+        .then(() => assert_array_equals([init_registration.active,
+                                         init_registration.waiting,
+                                         init_registration.installing],
+                                        [init_workers[0],
+                                         init_workers[1],
+                                         null],
+                                        'Wrong workers.'));
+    })
+
+    // Register a service worker to claim_scope.
+    .then(() => navigator.serviceWorker.register(claim_worker_url,
+                                                 {scope: claim_scope}))
+    .then(r => {
+      claim_registration = r;
+      claim_worker = r.installing;
+      return wait_for_state(t, claim_worker, 'activated')
+    })
+
+    // Let claim_worker claim the created iframe.
+    .then(function() {
+      var channel = new MessageChannel();
+      var saw_message = new Promise(function(resolve) {
+        channel.port1.onmessage = t.step_func(function(e) {
+          assert_equals(e.data, 'PASS',
+                        'Worker call to claim() should fulfill.');
+          resolve();
+        });
+      });
+
+      claim_worker.postMessage({port: channel.port2}, [channel.port2]);
+      return saw_message;
+    })
+
+    // Check the controller.
+    .then(() => frame.contentWindow.navigator.serviceWorker.getRegistration(
+                  normalizeURL(claim_scope)))
+    .then(r => assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
+                             r.active,
+                             '.controller should belong to claim_scope.'))
+
+    // Check the status of created registrations and service workers.
+    .then(() => wait_for_state(t, init_workers[1], 'activated'))
+    .then(() => {
+      assert_array_equals([claim_registration.active,
+                           claim_registration.waiting,
+                           claim_registration.installing],
+                          [claim_worker,
+                           null,
+                           null],
+                          'claim_worker should be the only worker.')
+
+      assert_array_equals([init_registration.active,
+                           init_registration.waiting,
+                           init_registration.installing],
+                          [init_workers[1],
+                           null,
+                           null],
+                          'The waiting sw should become the active worker.')
+
+      assert_array_equals([init_workers[0].state,
+                           init_workers[1].state,
+                           claim_worker.state],
+                          ['redundant',
+                           'activated',
+                           'activated'],
+                          'Wrong worker states.');
+    })
+
+    // Cleanup and finish testing.
+    .then(() => frame.remove())
+    .then(() => Promise.all([
+      init_registration.unregister(),
+      claim_registration.unregister()
+    ]))
+    .then(() => t.done());
+}, 'claim() should affect the originally controlling registration.');
+
+</script>