Bug 1170543 P5 Import actiation.https.html wpt test from blink. r=asuth
authorBen Kelly <ben@wanderview.com>
Wed, 27 Jul 2016 20:36:11 -0400
changeset 349073 a3489ac13c44be5d0635cd32458beb9bb2b6d4f3
parent 349072 6ea4b2c81b2213b8ce1a24c378dc130199058c3a
child 349074 3531847a7419ec572bce11d97dfb8de81b7a0177
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1170543
milestone50.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 1170543 P5 Import actiation.https.html wpt test from blink. r=asuth
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/service-workers/service-worker/activation.https.html
testing/web-platform/tests/service-workers/service-worker/resources/mint-new-worker.py
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -36082,22 +36082,22 @@
       {
         "path": "webdriver/navigation.py",
         "url": "/webdriver/navigation.py"
       }
     ]
   },
   "local_changes": {
     "deleted": [
-      "WebCryptoAPI/generateKey/failures.worker.js",
-      "web-animations/interfaces/AnimationTimeline/document-timeline.html",
+      "WebCryptoAPI/generateKey/successes.worker.js",
       "WebCryptoAPI/generateKey/test_failures.html",
-      "WebCryptoAPI/generateKey/test_successes.html",
+      "web-animations/interfaces/AnimationTimeline/document-timeline.html",
       "web-animations/interfaces/AnimationTimeline/idlharness.html",
-      "WebCryptoAPI/generateKey/successes.worker.js"
+      "WebCryptoAPI/generateKey/failures.worker.js",
+      "WebCryptoAPI/generateKey/test_successes.html"
     ],
     "deleted_reftests": {},
     "items": {
       "testharness": {
         "2dcontext/drawing-text-to-the-canvas/2d.text.draw.fill.maxWidth.NaN.html": [
           {
             "path": "2dcontext/drawing-text-to-the-canvas/2d.text.draw.fill.maxWidth.NaN.html",
             "url": "/2dcontext/drawing-text-to-the-canvas/2d.text.draw.fill.maxWidth.NaN.html"
@@ -36410,16 +36410,22 @@
           }
         ],
         "fetch/api/policies/referrer-origin-when-cross-origin.html": [
           {
             "path": "fetch/api/policies/referrer-origin-when-cross-origin.html",
             "url": "/fetch/api/policies/referrer-origin-when-cross-origin.html"
           }
         ],
+        "service-workers/service-worker/activation.https.html": [
+          {
+            "path": "service-workers/service-worker/activation.https.html",
+            "url": "/service-workers/service-worker/activation.https.html"
+          }
+        ],
         "service-workers/service-worker/client-navigate.https.html": [
           {
             "path": "service-workers/service-worker/client-navigate.https.html",
             "url": "/service-workers/service-worker/client-navigate.https.html"
           }
         ],
         "service-workers/service-worker/controller-on-disconnect.https.html": [
           {
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/service-worker/activation.https.html
@@ -0,0 +1,148 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>service worker: activation</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
+<script>
+// Registers, waits for activation, then unregisters on a dummy scope.
+//
+// This helper can be used in tests that assert that activation doesn't happen.
+// It would not be sufficient to check the .waiting/.active properties once,
+// since activation could be scheduled and just hasn't happened yet. Since this
+// helper shows that activation of another registration completed, we can be
+// sure that activation really will not happen.
+function wait_for_activation_on_dummy_scope(t) {
+  var dummy_scope = 'resources/there/is/no/there/there';
+  var registration;
+  return navigator.serviceWorker.register('resources/empty-worker.js',
+      { scope: dummy_scope })
+    .then(r => {
+        registration = r;
+        return wait_for_state(t, registration.installing, 'activated');
+      })
+    .then(() => registration.unregister());
+}
+// Returns {registration, iframe}, where |registration| has an active and
+// waiting worker. The active worker controls |iframe| and has an inflight
+// message event that can be finished by calling
+// |registration.active.postMessage('go')|.
+function setup_activation_test(t, scope, worker_url) {
+  var registration;
+  var iframe;
+  return navigator.serviceWorker.getRegistration(scope)
+    .then(r => {
+        if (r)
+          return r.unregister();
+      })
+    .then(() => {
+        // Create an in-scope iframe. Do this prior to registration to avoid
+        // racing between an update triggered by navigation and the update()
+        // call below.
+        return with_iframe(scope);
+      })
+    .then(f => {
+        iframe = f;
+        // Create an active worker.
+        return navigator.serviceWorker.register(worker_url, { scope: scope });
+      })
+    .then(r => {
+        registration = r;
+        add_result_callback(() => registration.unregister());
+        return wait_for_state(t, r.installing, 'activated');
+      })
+    .then(() => {
+        // Check that the frame was claimed.
+        assert_not_equals(
+            iframe.contentWindow.navigator.serviceWorker.controller, null);
+        // Create an in-flight request.
+        registration.active.postMessage('wait');
+        // Now there is both a controllee and an in-flight request.
+        // Initiate an update.
+        return registration.update();
+      })
+    .then(() => {
+        // Wait for a waiting worker.
+        return wait_for_state(t, registration.installing, 'installed');
+      })
+    .then(() => {
+        return wait_for_activation_on_dummy_scope(t);
+      })
+    .then(() => {
+        assert_not_equals(registration.waiting, null);
+        assert_not_equals(registration.active, null);
+        return Promise.resolve({registration: registration, iframe: iframe});
+      });
+}
+promise_test(t => {
+    var scope = 'resources/no-controllee';
+    var worker_url = 'resources/mint-new-worker.py';
+    var registration;
+    var iframe;
+    var new_worker;
+    return setup_activation_test(t, scope, worker_url)
+      .then(result => {
+          registration = result.registration;
+          iframe = result.iframe;
+          // Finish the in-flight request.
+          registration.active.postMessage('go');
+          return wait_for_activation_on_dummy_scope(t);
+        })
+      .then(() => {
+          // The new worker is still waiting. Remove the frame and it should
+          // activate.
+          new_worker = registration.waiting;
+          assert_equals(new_worker.state, 'installed');
+          var reached_active = wait_for_state(t, new_worker, 'activating');
+          iframe.remove();
+          return reached_active;
+        })
+      .then(() => {
+          assert_equals(new_worker, registration.active);
+        });
+  }, 'loss of controllees triggers activation');
+promise_test(t => {
+    var scope = 'resources/no-request';
+    var worker_url = 'resources/mint-new-worker.py';
+    var registration;
+    var iframe;
+    var new_worker;
+    return setup_activation_test(t, scope, worker_url)
+      .then(result => {
+          registration = result.registration;
+          iframe = result.iframe;
+          // Remove the iframe.
+          iframe.remove();
+          return new Promise(resolve => setTimeout(resolve, 0));
+        })
+      .then(() => {
+          // Finish the request.
+          new_worker = registration.waiting;
+          var reached_active = wait_for_state(t, new_worker, 'activating');
+          registration.active.postMessage('go');
+          return reached_active;
+        })
+      .then(() => {
+          assert_equals(registration.active, new_worker);
+        });
+  }, 'finishing a request triggers activation');
+promise_test(t => {
+    var scope = 'resources/skip-waiting';
+    var worker_url = 'resources/mint-new-worker.py?skip-waiting';
+    var registration;
+    var new_worker;
+    return setup_activation_test(t, scope, worker_url)
+      .then(result => {
+          registration = result.registration;
+          // Finish the request. The iframe does not need to be removed because
+          // skipWaiting() was called.
+          new_worker = registration.waiting;
+          var reached_active = wait_for_state(t, new_worker, 'activating');
+          registration.active.postMessage('go');
+          return reached_active;
+        })
+      .then(() => {
+          assert_equals(registration.active, new_worker);
+        });
+  }, 'skipWaiting bypasses no controllee requirement');
+</script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/service-worker/resources/mint-new-worker.py
@@ -0,0 +1,25 @@
+import time
+
+body = '''
+onactivate = (e) => e.waitUntil(clients.claim());
+var resolve_wait_until;
+var wait_until = new Promise(resolve => {
+    resolve_wait_until = resolve;
+  });
+onmessage = (e) => {
+    if (e.data == 'wait')
+      e.waitUntil(wait_until);
+    if (e.data == 'go')
+      resolve_wait_until();
+  };'''
+
+def main(request, response):
+    headers = [('Cache-Control', 'no-cache, must-revalidate'),
+               ('Pragma', 'no-cache'),
+               ('Content-Type', 'application/javascript')]
+
+    skipWaiting = ''
+    if 'skip-waiting' in request.GET:
+      skipWaiting = 'skipWaiting();'
+
+    return headers, '/* %s %s */ %s %s' % (time.time(), time.clock(), skipWaiting, body)