Bug 1481131 [wpt PR 12315] - service worker: Add a couple of tests, a=testonly
authorwanghongjuan <hongjuan.wang@intel.com>
Thu, 16 Aug 2018 09:42:43 +0000
changeset 487105 e74200ec6983d0db9cab23bd7723ff766c0d237b
parent 487104 8a64ff46564165f5d7f876ad2b179bc605726c2a
child 487106 ec6576577039d634b336ce407ea23d8c5b00cc03
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1481131, 12315
milestone63.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 1481131 [wpt PR 12315] - service worker: Add a couple of tests, a=testonly Automatic update from web-platform-testsservice worker: Add a couple of tests (#12315) service worker: Add some tests and improve formatting. Add 5 checkpoints for attributes active/installing/waiting/scriptURL/navigationPreload and format relevant tests using es6: - Verify the scriptURL property with query - The ServiceWorker objects returned from installing attribute getter that represent the same service worker are the same objects. - The ServiceWorker objects returned from waiting attribute getter that represent the same service worker are the same objects. - The ServiceWorker objects returned from active attribute getter that represent the same service worker are the same objects. - The navigationPreload attribute must return service worker registration's NavigationPreloadManager object. -- wpt-commits: 3a498429bfecad03c5d51b6500f3b12db1abb9dd wpt-pr: 12315
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/service-workers/service-worker/active.https.html
testing/web-platform/tests/service-workers/service-worker/installing.https.html
testing/web-platform/tests/service-workers/service-worker/navigation-preload/navigationPreload.https.html
testing/web-platform/tests/service-workers/service-worker/serviceworkerobject-scripturl.https.html
testing/web-platform/tests/service-workers/service-worker/waiting.https.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -389116,16 +389116,22 @@
     ]
    ],
    "service-workers/service-worker/navigation-preload/get-state.https.html": [
     [
      "/service-workers/service-worker/navigation-preload/get-state.https.html",
      {}
     ]
    ],
+   "service-workers/service-worker/navigation-preload/navigationPreload.https.html": [
+    [
+     "/service-workers/service-worker/navigation-preload/navigationPreload.https.html",
+     {}
+    ]
+   ],
    "service-workers/service-worker/navigation-preload/redirect.https.html": [
     [
      "/service-workers/service-worker/navigation-preload/redirect.https.html",
      {}
     ]
    ],
    "service-workers/service-worker/navigation-preload/request-headers.https.html": [
     [
@@ -629314,17 +629320,17 @@
    "ff0990df6ba99be79b069c2cc70ad70c920ba4e0",
    "testharness"
   ],
   "service-workers/service-worker/activation.https.html": [
    "5755758e5716dbc608e7e773bf9b83ab3f2f7e91",
    "testharness"
   ],
   "service-workers/service-worker/active.https.html": [
-   "deee6a50ea009ef541c1154353288242e3c3aeae",
+   "350a34b802f70d6b6c78e6fdba9b2acabe7d143c",
    "testharness"
   ],
   "service-workers/service-worker/appcache-ordering-main.https.html": [
    "609d67e4504c9488780369c15e1b96fc0bd20394",
    "testharness"
   ],
   "service-workers/service-worker/claim-affect-other-registration.https.html": [
    "52555ac271b5bad279ab37352c9d9937c780909a",
@@ -629654,17 +629660,17 @@
    "be9be4968f7b2d0cbc1f18f88b06b7acb6ad096f",
    "testharness"
   ],
   "service-workers/service-worker/install-event-type.https.html": [
    "7e74af85c3aee401f99add7a2a0209ddbe700f86",
    "testharness"
   ],
   "service-workers/service-worker/installing.https.html": [
-   "57d8781119212454c27a2a226c3d6bcb6b067062",
+   "0f257b6aba4f3d65802e7d7f8a7503d6c6aedd42",
    "testharness"
   ],
   "service-workers/service-worker/interfaces-sw.https.html": [
    "50c76d306dc2f43eac0f4d827e9b72464b63220c",
    "testharness"
   ],
   "service-workers/service-worker/interfaces-window.https.html": [
    "d3e85f2c711a627e6517a71a0c801ef344b83489",
@@ -629749,16 +629755,20 @@
   "service-workers/service-worker/navigation-preload/empty-preload-response-body.https.html": [
    "7e8aacdd36a58cdd88d2f1e70fec69c580526f00",
    "testharness"
   ],
   "service-workers/service-worker/navigation-preload/get-state.https.html": [
    "914648bcffbfac5f2d69fb087c87db5901a93e03",
    "testharness"
   ],
+  "service-workers/service-worker/navigation-preload/navigationPreload.https.html": [
+   "392e5c14dc8c7ca7d40df4396a102f379e1d55ad",
+   "testharness"
+  ],
   "service-workers/service-worker/navigation-preload/redirect.https.html": [
    "5970f053e36996f4cad93aec104c55f53055465a",
    "testharness"
   ],
   "service-workers/service-worker/navigation-preload/request-headers.https.html": [
    "09642010218ada72da946f8fdcf1c713f7367936",
    "testharness"
   ],
@@ -631110,17 +631120,17 @@
    "2584485c65ab60e8b429c3db66fc43a8157a8ed5",
    "testharness"
   ],
   "service-workers/service-worker/serviceworker-message-event-historical.https.html": [
    "2f780a604282dc281ebe75a964ed24f832a24e3a",
    "testharness"
   ],
   "service-workers/service-worker/serviceworkerobject-scripturl.https.html": [
-   "58f25f3a442c01387807300b1a278e71e9254d0a",
+   "6004985a34608132825086dab0c0777f3f0fdf1e",
    "testharness"
   ],
   "service-workers/service-worker/shared-worker-controlled.https.html": [
    "33d52e01199c2bdc0e85df7d8106ddd970aae082",
    "testharness"
   ],
   "service-workers/service-worker/skip-waiting-installed.https.html": [
    "21e26be5128454ee05143b10b8039ceb95a48cd5",
@@ -631198,17 +631208,17 @@
    "d8ed94f776650c8a40ba82df9ca5e909b460bb79",
    "testharness"
   ],
   "service-workers/service-worker/update.https.html": [
    "6717d4d7ac289c8a18b1500e21795fd16c5321e7",
    "testharness"
   ],
   "service-workers/service-worker/waiting.https.html": [
-   "2b0dbc9485bf863fcb324f169de2e28ba18d07b0",
+   "499e581eb353a2e433580e413a730bea2a9b7ad9",
    "testharness"
   ],
   "service-workers/service-worker/websocket-in-service-worker.https.html": [
    "cda9d6fe67e233e8b36dbfe12ddec2fa054de425",
    "testharness"
   ],
   "service-workers/service-worker/websocket.https.html": [
    "b9c526d50fb99abbafcb2b8d4f00c2267b25c474",
--- a/testing/web-platform/tests/service-workers/service-worker/active.https.html
+++ b/testing/web-platform/tests/service-workers/service-worker/active.https.html
@@ -1,55 +1,50 @@
 <!DOCTYPE html>
 <title>ServiceWorker: navigator.serviceWorker.active</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="resources/test-helpers.sub.js"></script>
 <body>
 <script>
+
+const SCRIPT = 'resources/empty-worker.js';
+const SCOPE = 'resources/blank.html';
+
 // "active" is set
-async_test(function(t) {
-    var step = t.step_func.bind(t);
-    var url = 'resources/empty-worker.js';
-    var scope = 'resources/blank.html';
-    var frame;
-    var registration;
+promise_test(async t => {
+
+  t.add_cleanup(async() => {
+    if (frame)
+      frame.remove();
+    if (registration)
+      await registration.unregister();
+  });
 
-    service_worker_unregister(t, scope)
-      .then(step(function() { return with_iframe(scope); }))
-      .then(step(function(f) {
-          frame = f;
-          return navigator.serviceWorker.register(url, {scope: scope});
-        }))
-      .then(step(function(r) {
-          registration = r;
-          return wait_for_state(t, r.installing, 'activating');
-        }))
-      .then(step(function() {
-          var container = frame.contentWindow.navigator.serviceWorker;
-          assert_equals(
-            container.controller,
-            null,
-            'On activating state a document should not have a controller');
-          assert_equals(
-            registration.active.scriptURL,
-            normalizeURL(url),
-            'On activating state a document should have an active worker ');
-          assert_equals(
-            registration.waiting,
-            null,
-            'On activating state a document should not have a waiting worker');
-          assert_equals(
-            registration.installing,
-            null,
-            'On activating state a document should not have an installing ' +
-                'worker');
+  await service_worker_unregister(t, SCOPE);
+  const frame = await with_iframe(SCOPE);
+  const registration =
+      await navigator.serviceWorker.register(SCRIPT, {scope: SCOPE});
+  await wait_for_state(t, registration.installing, 'activating');
+  const container = frame.contentWindow.navigator.serviceWorker;
+  assert_equals(container.controller, null, 'controller');
+  assert_equals(registration.active.state, 'activating',
+                'registration.active');
+  assert_equals(registration.waiting, null, 'registration.waiting');
+  assert_equals(registration.installing, null, 'registration.installing');
 
-          // FIXME: Add a test for a frame created after installation.
-          // Should the existing frame ("frame") block activation?
-        }))
-      .then(step(function() {
-          frame.remove();
-          return service_worker_unregister_and_done(t, scope);
-        }))
-      .catch(unreached_rejection(t));
-  }, 'active is set');
+  // FIXME: Add a test for a frame created after installation.
+  // Should the existing frame ("frame") block activation?
+}, 'active is set');
+
+// Tests that the ServiceWorker objects returned from active attribute getter
+// that represent the same service worker are the same objects.
+promise_test(async t => {
+  const registration1 =
+      await service_worker_unregister_and_register(t, SCRIPT, SCOPE);
+  const registration2 = await navigator.serviceWorker.getRegistration(SCOPE);
+  assert_equals(registration1.active, registration2.active,
+                'ServiceWorkerRegistration.active should return the same ' +
+                'object');
+  await registration1.unregister();
+}, 'The ServiceWorker objects returned from active attribute getter that ' +
+   'represent the same service worker are the same objects');
 </script>
--- a/testing/web-platform/tests/service-workers/service-worker/installing.https.html
+++ b/testing/web-platform/tests/service-workers/service-worker/installing.https.html
@@ -1,37 +1,48 @@
 <!DOCTYPE html>
 <title>ServiceWorker: navigator.serviceWorker.installing</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="resources/test-helpers.sub.js"></script>
 <body>
 <script>
+
+const SCRIPT = 'resources/empty-worker.js';
+const SCOPE = 'resources/blank.html';
+
 // "installing" is set
-async_test(function(t) {
-    var step = t.step_func.bind(t);
-    var url = 'resources/empty-worker.js';
-    var scope = 'resources/blank.html';
-    var frame;
+promise_test(async t => {
+
+  t.add_cleanup(async() => {
+    if (frame)
+      frame.remove();
+    if (registration)
+      await registration.unregister();
+  });
 
-    service_worker_unregister(t, scope)
-    .then(step(function() { return with_iframe(scope); }))
-    .then(step(function(f) {
-        frame = f;
-        return navigator.serviceWorker.register(url, {scope: scope});
-    }))
-    .then(step(function(registration) {
-        var container = frame.contentWindow.navigator.serviceWorker;
-        assert_equals(container.controller, null);
-        assert_equals(registration.active, null);
-        assert_equals(registration.waiting, null);
-        assert_equals(registration.installing.scriptURL, normalizeURL(url));
+  await service_worker_unregister(t, SCOPE);
+  const frame = await with_iframe(SCOPE);
+  const registration =
+      await navigator.serviceWorker.register(SCRIPT, {scope: SCOPE});
+  const container = frame.contentWindow.navigator.serviceWorker;
+  assert_equals(container.controller, null, 'controller');
+  assert_equals(registration.active, null, 'registration.active');
+  assert_equals(registration.waiting, null, 'registration.waiting');
+  assert_equals(registration.installing.scriptURL, normalizeURL(SCRIPT),
+                'registration.installing.scriptURL');
+  // FIXME: Add a test for a frame created after installation.
+  // Should the existing frame ("frame") block activation?
+}, 'installing is set');
 
-        // FIXME: Add a test for a frame created after installation.
-        // Should the existing frame ("frame") block activation?
-    }))
-    .then(step(function() {
-        frame.remove();
-        return service_worker_unregister_and_done(t, scope);
-    }))
-    .catch(unreached_rejection(t));
-}, 'installing is set');
+// Tests that The ServiceWorker objects returned from installing attribute getter
+// that represent the same service worker are the same objects.
+promise_test(async t => {
+  const registration1 =
+      await service_worker_unregister_and_register(t, SCRIPT, SCOPE);
+  const registration2 = await navigator.serviceWorker.getRegistration(SCOPE);
+  assert_equals(registration1.installing, registration2.installing,
+                'ServiceWorkerRegistration.installing should return the ' +
+                'same object');
+  await registration1.unregister();
+}, 'The ServiceWorker objects returned from installing attribute getter that ' +
+   'represent the same service worker are the same objects');
 </script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/service-worker/navigation-preload/navigationPreload.https.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>ServiceWorker: navigator.serviceWorker.navigationPreload</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../resources/test-helpers.sub.js"></script>
+<script src="resources/helpers.js"></script>
+<script>
+promise_test(async t => {
+  const SCRIPT = '../resources/empty-worker.js';
+  const SCOPE = '../resources/navigationpreload';
+  const registration =
+      await service_worker_unregister_and_register(t, SCRIPT, SCOPE);
+  const navigationPreload = registration.navigationPreload;
+  assert_true(navigationPreload instanceof NavigationPreloadManager,
+              'ServiceWorkerRegistration.navigationPreload');
+  await registration.unregister();
+}, "The navigationPreload attribute must return service worker " +
+    "registration's NavigationPreloadManager object.");
+</script>
--- a/testing/web-platform/tests/service-workers/service-worker/serviceworkerobject-scripturl.https.html
+++ b/testing/web-platform/tests/service-workers/service-worker/serviceworkerobject-scripturl.https.html
@@ -2,30 +2,25 @@
 <title>ServiceWorker object: scriptURL property</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="resources/test-helpers.sub.js"></script>
 <script>
 'use strict';
 
 function url_test(name, url) {
-  var scope = 'resources/scope/' + name;
-  var expectedURL = normalizeURL(url);
-
-  promise_test(function(t) {
-      return service_worker_unregister_and_register(t, url, scope)
-        .then(function(registration) {
-            var worker = registration.installing;
+  const scope = 'resources/scope/' + name;
+  const expectedURL = normalizeURL(url);
 
-            t.add_cleanup(function() {
-                registration.unregister();
-              });
-
-            assert_equals(worker.scriptURL, expectedURL,
-                          'Returned ServiceWorker object should have scriptURL');
-          });
-    }, 'Verify the scriptURL property: ' + name);
+  promise_test(async t => {
+    const registration =
+        await service_worker_unregister_and_register(t, url, scope);
+    const worker = registration.installing;
+    assert_equals(worker.scriptURL, expectedURL, 'scriptURL');
+    await registration.unregister();
+  }, 'Verify the scriptURL property: ' + name);
 }
 
 url_test('relative', 'resources/empty-worker.js');
 url_test('with-fragment', 'resources/empty-worker.js#ref');
+url_test('with-query', 'resources/empty-worker.js?ref');
 url_test('absolute', normalizeURL('./resources/empty-worker.js'));
 </script>
--- a/testing/web-platform/tests/service-workers/service-worker/waiting.https.html
+++ b/testing/web-platform/tests/service-workers/service-worker/waiting.https.html
@@ -1,40 +1,47 @@
 <!DOCTYPE html>
 <title>ServiceWorker: navigator.serviceWorker.waiting</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="resources/test-helpers.sub.js"></script>
 <body>
 <script>
-promise_test(t => {
-    var script = 'resources/empty-worker.js';
-    var scope = 'resources/blank.html';
-    var frame;
-    var registration;
+
+const SCRIPT = 'resources/empty-worker.js';
+const SCOPE = 'resources/blank.html';
+
+promise_test(async t => {
+
+  t.add_cleanup(async() => {
+    if (frame)
+      frame.remove();
+    if (registration)
+      await registration.unregister();
+  });
 
-    return service_worker_unregister(t, scope)
-      .then(() => { return with_iframe(scope); })
-      .then(f => {
-          frame = f;
-          return navigator.serviceWorker.register(script, {scope: scope});
-        })
-      .then(r => {
-          registration = r;
-          add_result_callback(() => { registration.unregister(); });
-          return wait_for_state(t, r.installing, 'installed');
-        })
-      .then(() => {
-          const controller =
-            frame.contentWindow.navigator.serviceWorker.controller;
-          assert_equals(controller, null, '.controller');
+  await service_worker_unregister(t, SCOPE);
+  const frame = await with_iframe(SCOPE);
+  const registration =
+      await navigator.serviceWorker.register(SCRIPT, {scope: SCOPE});
+  await wait_for_state(t, registration.installing, 'installed');
+  const controller = frame.contentWindow.navigator.serviceWorker.controller;
+  assert_equals(controller, null, 'controller');
+  assert_equals(registration.active, null, 'registration.active');
+  assert_equals(registration.waiting.state, 'installed',
+                'registration.waiting');
+  assert_equals(registration.installing, null, 'registration.installing');
+}, 'waiting is set after installation');
 
-          assert_equals(registration.active, null, '.active');
-          assert_equals(registration.waiting.state, 'installed', '.waiting');
-          assert_equals(registration.installing, null, '.installing');
-        })
-      .then(() => {
-          frame.remove();
-          return registration.unregister();
-        });
-  }, 'waiting is set after installation');
+// Tests that the ServiceWorker objects returned from waiting attribute getter
+// that represent the same service worker are the same objects.
+promise_test(async t => {
+  const registration1 =
+      await service_worker_unregister_and_register(t, SCRIPT, SCOPE);
+  const registration2 = await navigator.serviceWorker.getRegistration(SCOPE);
+  assert_equals(registration1.waiting, registration2.waiting,
+                'ServiceWorkerRegistration.waiting should return the same ' +
+                'object');
+  await registration1.unregister();
+}, 'The ServiceWorker objects returned from waiting attribute getter that ' +
+   'represent the same service worker are the same objects');
 </script>
 </body>