Bug 1226441 - Part 1: Add wpt test verifying fetch event waits for activate to complete; r=catalinb
authorBen Kelly <ben@wanderview.com>
Tue, 24 Nov 2015 10:47:55 -0500
changeset 273925 d0823da696baf3a06db1c3c780cd6b40fa25a5fa
parent 273924 0ac7ee2441e58d18ecac91a19a9a886b92794c5e
child 273926 671bc38157d290576fa910484289be8f66bbccd6
push id68431
push usereakhgari@mozilla.com
push dateTue, 24 Nov 2015 15:50:17 +0000
treeherdermozilla-inbound@671bc38157d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscatalinb
bugs1226441
milestone45.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 1226441 - Part 1: Add wpt test verifying fetch event waits for activate to complete; r=catalinb
testing/web-platform/mozilla/meta/MANIFEST.json
testing/web-platform/mozilla/tests/service-workers/service-worker/fetch-waits-for-activate.https.html
testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-waits-for-activate-worker.js
--- a/testing/web-platform/mozilla/meta/MANIFEST.json
+++ b/testing/web-platform/mozilla/meta/MANIFEST.json
@@ -231,16 +231,23 @@
           }
         ],
         "service-workers/service-worker/fetch-response-xhr.https.html": [
           {
             "path": "service-workers/service-worker/fetch-response-xhr.https.html",
             "url": "/_mozilla/service-workers/service-worker/fetch-response-xhr.https.html"
           }
         ],
+        "service-workers/service-worker/fetch-waits-for-activate.https.html": [
+          {
+            "path": "service-workers/service-worker/fetch-waits-for-activate.https.html",
+            "timeout": "long",
+            "url": "/_mozilla/service-workers/service-worker/fetch-waits-for-activate.https.html"
+          }
+        ],
         "service-workers/service-worker/getregistration.https.html": [
           {
             "path": "service-workers/service-worker/getregistration.https.html",
             "url": "/_mozilla/service-workers/service-worker/getregistration.https.html"
           }
         ],
         "service-workers/service-worker/getregistrations.https.html": [
           {
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/fetch-waits-for-activate.https.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<title>Service Worker: Fetch Event Waits for Activate Event</title>
+<meta name=timeout content=long>
+<script src="/resources/testharness.js"></script>
+<script src="resources/testharness-helpers.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/get-host-info.sub.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
+<body>
+<script>
+
+var worker = 'resources/fetch-waits-for-activate-worker.js';
+var expected_url = normalizeURL(worker);
+var scope = 'resources/fetch-waits-for-activate/';
+
+async_test(function(t) {
+  var registration;
+  var frameLoadPromise;
+  var frame;
+  service_worker_unregister_and_register(t, worker, scope).then(function(reg) {
+    registration = reg;
+    return wait_for_state(t, reg.installing, 'activating');
+  }).then(function() {
+    assert_equals(registration.active.scriptURL, expected_url,
+                  'active worker should be present');
+    assert_equals(registration.active.state, 'activating',
+                  'active worker should be in activating state');
+
+    // This should block until we message the worker to tell it to complete
+    // the activate event.
+    frameLoadPromise = with_iframe(scope).then(function(f) {
+      frame = f;
+    });
+
+    // Wait some time to allow frame loading to proceed.  It should not,
+    // however, if the fetch event is blocked on the activate.  I don't
+    // see any way to force this race without a timeout, unfortunately.
+    return new Promise(function(resolve) {
+      setTimeout(resolve, 1000);
+    });
+  }).then(function() {
+    assert_equals(frame, undefined, 'frame should not be loaded');
+    assert_equals(registration.active.scriptURL, expected_url,
+                  'active worker should be present');
+    assert_equals(registration.active.state, 'activating',
+                  'active worker should be in activating state');
+
+    // This signals the activate event to complete.  The frame should now
+    // load.
+    registration.active.postMessage('GO');
+    return frameLoadPromise;
+  }).then(function() {
+    assert_equals(frame.contentWindow.navigator.serviceWorker.controller.scriptURL,
+                  expected_url, 'frame should now be loaded and controlled');
+    assert_equals(registration.active.state, 'activated',
+                  'active worker should be in activated state');
+    return service_worker_unregister_and_done(t, scope);
+  }).catch(unreached_rejection(t));
+}, 'Fetch events should wait for the activate event to complete.');
+
+</script>
+</body>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-waits-for-activate-worker.js
@@ -0,0 +1,17 @@
+var activatePromiseResolve;
+
+addEventListener('activate', function(evt) {
+  evt.waitUntil(new Promise(function(resolve) {
+    activatePromiseResolve = resolve;
+  }));
+});
+
+addEventListener('message', function(evt) {
+  if (typeof activatePromiseResolve === 'function') {
+    activatePromiseResolve();
+  }
+});
+
+addEventListener('fetch', function(evt) {
+  evt.respondWith(new Response('Hello world'));
+});