Bug 1507063 [wpt PR 14045] - Worklet: Modernize service worker interception tests for worklets using async/await, a=testonly
☠☠ backed out by 46ad93280b06 ☠ ☠
authorHiroki Nakagawa <nhiroki@chromium.org>
Mon, 19 Nov 2018 18:44:44 +0000
changeset 503710 dfbc81d5e5187d2e804f8fad2f8dedd9f51734ef
parent 503709 378d0c633eaee8cac785d3f0aa0e24f397efa6e2
child 503711 8e13752959d689e01d7ba51c3a1460d90f9bcbc5
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1507063, 14045, 1335047, 607892
milestone65.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 1507063 [wpt PR 14045] - Worklet: Modernize service worker interception tests for worklets using async/await, a=testonly Automatic update from web-platform-testsWorklet: Modernize service worker interception tests for worklets using async/await This is just a cleanup CL, and there're no functional changes. Bug: n/a Change-Id: I60820045469eed4a0903b37af9e4f8927bcc884d Reviewed-on: https://chromium-review.googlesource.com/c/1335047 Reviewed-by: Makoto Shimazu <shimazu@chromium.org> Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org> Cr-Commit-Position: refs/heads/master@{#607892} -- wpt-commits: d16eb1ce23500e7234f58df86a59d5c00d222118 wpt-pr: 14045
testing/web-platform/tests/worklets/resources/service-worker-interception-tests.js
--- a/testing/web-platform/tests/worklets/resources/service-worker-interception-tests.js
+++ b/testing/web-platform/tests/worklets/resources/service-worker-interception-tests.js
@@ -1,123 +1,108 @@
-function openWindow(url) {
+function openWindow(t, url) {
   return new Promise(resolve => {
-      let win = window.open(url, '_blank');
-      add_result_callback(() => win.close());
-      window.onmessage = e => {
-        assert_equals(e.data, 'LOADED');
-        resolve(win);
-      };
-    });
+    const win = window.open(url, '_blank');
+    t.add_cleanup(() => win.close());
+    window.onmessage = e => {
+      assert_equals(e.data, 'LOADED');
+      resolve(win);
+    };
+  });
 }
 
 // Runs a series of tests related to service worker interception for a worklet.
 //
 // Usage:
 // runServiceWorkerInterceptionTests("paint");
 function runServiceWorkerInterceptionTests(worklet_type) {
-    const worklet = get_worklet(worklet_type);
+  const worklet = get_worklet(worklet_type);
 
-    // Tests that a worklet should be served by the owner document's service
-    // worker.
-    //
-    // [Current document] registers a service worker for Window's URL.
-    // --(open)--> [Window] should be controlled by the service worker.
-    //   --(addModule)--> [Worklet] should be served by the service worker.
-    promise_test(t => {
-        const kWindowURL = 'resources/addmodule-window.html';
-        const kServiceWorkerScriptURL = 'resources/service-worker.js';
-        // This doesn't contain the 'resources/' prefix because this will be
-        // imported from a html file under resources/.
-        const kWorkletScriptURL = 'non-existent-worklet-script.js';
+  // Tests that a worklet should be served by the owner document's service
+  // worker.
+  //
+  // [Current document] registers a service worker for Window's URL.
+  // --(open)--> [Window] should be controlled by the service worker.
+  //   --(addModule)--> [Worklet] should be served by the service worker.
+  promise_test(async t => {
+    const kWindowURL = 'resources/addmodule-window.html';
+    const kServiceWorkerScriptURL = 'resources/service-worker.js';
+    // This doesn't contain the 'resources/' prefix because this will be
+    // imported from a html file under resources/.
+    const kWorkletScriptURL = 'non-existent-worklet-script.js';
+
+    const registration = await service_worker_unregister_and_register(
+        t, kServiceWorkerScriptURL, kWindowURL);
+    t.add_cleanup(() => registration.unregister());
+    await wait_for_state(t, registration.installing, 'activated');
 
-        return service_worker_unregister_and_register(
-            t, kServiceWorkerScriptURL, kWindowURL)
-          .then(r => {
-              add_result_callback(() => r.unregister());
-              return wait_for_state(t, r.installing, 'activated');
-            })
-          .then(() => openWindow(kWindowURL))
-          .then(win => {
-              assert_not_equals(win.navigator.serviceWorker.controller, null,
-                                'The document should be controlled.');
-              const promise = new Promise(r => window.onmessage = r);
-              // The worklet script on kWorkletScriptURL doesn't exist but the
-              // service worker serves it, so the addModule() should succeed.
-              win.postMessage({ type: worklet_type,
-                                script_url: kWorkletScriptURL }, '*');
-              return promise;
-            })
-          .then(msg_event => assert_equals(msg_event.data, 'RESOLVED'));
-    }, 'addModule() on a controlled document should be intercepted by a ' +
-       'service worker.');
+    const win = await openWindow(t, kWindowURL);
+    assert_not_equals(win.navigator.serviceWorker.controller, null,
+                      'The document should be controlled.');
+
+    // The worklet script on kWorkletScriptURL doesn't exist but the service
+    // worker serves it, so the addModule() should succeed.
+    win.postMessage({ type: worklet_type, script_url: kWorkletScriptURL }, '*');
+    const msgEvent = await new Promise(resolve => window.onmessage = resolve);
+    assert_equals(msgEvent.data, 'RESOLVED');
+  }, 'addModule() on a controlled document should be intercepted by a ' +
+     'service worker.');
 
-    // Tests that a worklet should not be served by a service worker other than
-    // the owner document's service worker.
-    //
-    // [Current document] registers a service worker for Worklet's URL.
-    // --(open)--> [Window] should not be controlled by the service worker.
-    //   --(addModule)--> [Worklet] should not be served by the service worker.
-    promise_test(t => {
-        const kWindowURL = 'resources/addmodule-window.html';
-        const kServiceWorkerScriptURL = 'resources/service-worker.js';
-        // This doesn't contain the 'resources/' prefix because this will be
-        // imported from a html file under resources/.
-        const kWorkletScriptURL = 'non-existent-worklet-script.js';
+  // Tests that a worklet should not be served by a service worker other than
+  // the owner document's service worker.
+  //
+  // [Current document] registers a service worker for Worklet's URL.
+  // --(open)--> [Window] should not be controlled by the service worker.
+  //   --(addModule)--> [Worklet] should not be served by the service worker.
+  promise_test(async t => {
+    const kWindowURL = 'resources/addmodule-window.html';
+    const kServiceWorkerScriptURL = 'resources/service-worker.js';
+    // This doesn't contain the 'resources/' prefix because this will be
+    // imported from a html file under resources/.
+    const kWorkletScriptURL = 'non-existent-worklet-script.js';
 
-        return service_worker_unregister_and_register(
-            t, kServiceWorkerScriptURL, 'resources/' + kWorkletScriptURL)
-          .then(r =>  {
-              add_result_callback(() => r.unregister());
-              return wait_for_state(t, r.installing, 'activated');
-            })
-          .then(() => openWindow(kWindowURL))
-          .then(win => {
-              assert_equals(win.navigator.serviceWorker.controller, null,
-                            'The document should not be controlled.');
-              const promise = new Promise(r => window.onmessage = r);
-              // The worklet script on kWorkletScriptURL doesn't exist and the
-              // service worker doesn't serve it, so the addModule() should
-              // fail.
-              win.postMessage({ type: worklet_type,
-                                script_url: kWorkletScriptURL }, '*');
-              return promise;
-            })
-          .then(msg_event => assert_equals(msg_event.data, 'REJECTED'));
-    }, 'addModule() on a non-controlled document should not be intercepted ' +
-       'by a service worker even if the script is under the service worker ' +
-       'scope.');
+    const registration = await service_worker_unregister_and_register(
+        t, kServiceWorkerScriptURL, 'resources/' + kWorkletScriptURL);
+    t.add_cleanup(() => registration.unregister());
+    await wait_for_state(t, registration.installing, 'activated');
+
+    const win = await openWindow(t, kWindowURL);
+    assert_equals(win.navigator.serviceWorker.controller, null,
+                  'The document should not be controlled.');
+
+    // The worklet script on kWorkletScriptURL doesn't exist and the service
+    // worker doesn't serve it, so the addModule() should fail.
+    win.postMessage({ type: worklet_type, script_url: kWorkletScriptURL }, '*');
+    const msgEvent = await new Promise(resolve => window.onmessage = resolve);
+    assert_equals(msgEvent.data, 'REJECTED');
+  }, 'addModule() on a non-controlled document should not be intercepted by ' +
+     'a service worker even if the script is under the service worker scope.');
 
-    // Tests that static import should be served by the owner document's service
-    // worker.
-    //
-    // [Current document] registers a service worker for Window's URL.
-    // --(open)--> [Window] should be controlled by the service worker.
-    //   --(addModule)--> [Worklet] should be served by the service worker.
-    //     --(static import)--> [Script] should be served by the service worker.
-    promise_test(t => {
-        const kWindowURL = 'resources/addmodule-window.html';
-        const kServiceWorkerScriptURL = 'resources/service-worker.js';
-        // This doesn't contain the 'resources/' prefix because this will be
-        // imported from a html file under resources/.
-        const kWorkletScriptURL = 'import-non-existent-worklet-script.js';
+  // Tests that static import should be served by the owner document's service
+  // worker.
+  //
+  // [Current document] registers a service worker for Window's URL.
+  // --(open)--> [Window] should be controlled by the service worker.
+  //   --(addModule)--> [Worklet] should be served by the service worker.
+  //     --(static import)--> [Script] should be served by the service worker.
+  promise_test(async t => {
+    const kWindowURL = 'resources/addmodule-window.html';
+    const kServiceWorkerScriptURL = 'resources/service-worker.js';
+    // This doesn't contain the 'resources/' prefix because this will be
+    // imported from a html file under resources/.
+    const kWorkletScriptURL = 'import-non-existent-worklet-script.js';
 
-        return service_worker_unregister_and_register(
-            t, kServiceWorkerScriptURL, kWindowURL)
-          .then(r => {
-              add_result_callback(() => r.unregister());
-              return wait_for_state(t, r.installing, 'activated');
-            })
-          .then(() => openWindow(kWindowURL))
-          .then(win => {
-              assert_not_equals(win.navigator.serviceWorker.controller, null,
-                                'The document should be controlled.');
-              const promise = new Promise(r => window.onmessage = r);
-              // A script statically imported by the worklet doesn't exist but
-              // the service worker serves it, so the addModule() should
-              // succeed.
-              win.postMessage({ type: worklet_type,
-                                script_url: kWorkletScriptURL }, '*');
-              return promise;
-            })
-          .then(msg_event => assert_equals(msg_event.data, 'RESOLVED'));
-    }, 'Static import should be intercepted by a service worker.');
+    const registration = await service_worker_unregister_and_register(
+        t, kServiceWorkerScriptURL, kWindowURL);
+    t.add_cleanup(() => registration.unregister());
+    await wait_for_state(t, registration.installing, 'activated');
+
+    const win = await openWindow(t, kWindowURL);
+    assert_not_equals(win.navigator.serviceWorker.controller, null,
+                      'The document should be controlled.');
+
+    // A script statically imported by the worklet doesn't exist but the service
+    // worker serves it, so the addModule() should succeed.
+    win.postMessage({ type: worklet_type, script_url: kWorkletScriptURL }, '*');
+    const msgEvent = await new Promise(resolve => window.onmessage = resolve);
+    assert_equals(msgEvent.data, 'RESOLVED');
+  }, 'Static import should be intercepted by a service worker.');
 }