Bug 1451124 Add a WPT test to verify dedicated workers have a separate client ID from their owning document. r=asuth
authorBen Kelly <ben@wanderview.com>
Tue, 03 Apr 2018 20:00:33 -0700
changeset 411592 aed7d4d9be32f8806138d2a23f4b8b0332498085
parent 411591 b054a5905c4b6e39ceaaff1589d4c91a774b8203
child 411593 fe50f8117503b67a0b003d5570eadc8886d69881
push id101698
push userbkelly@mozilla.com
push dateWed, 04 Apr 2018 03:00:42 +0000
treeherdermozilla-inbound@aed7d4d9be32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1451124
milestone61.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 1451124 Add a WPT test to verify dedicated workers have a separate client ID from their owning document. r=asuth
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/service-workers/service-worker/resources/worker-client-id-worker.js
testing/web-platform/tests/service-workers/service-worker/worker-client-id.https.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -292536,16 +292536,21 @@
      {}
     ]
    ],
    "service-workers/service-worker/resources/windowclient-navigate-worker.js": [
     [
      {}
     ]
    ],
+   "service-workers/service-worker/resources/worker-client-id-worker.js": [
+    [
+     {}
+    ]
+   ],
    "service-workers/service-worker/resources/worker-interception-iframe.https.html": [
     [
      {}
     ]
    ],
    "service-workers/service-worker/resources/worker-load-interceptor.js": [
     [
      {}
@@ -360250,16 +360255,22 @@
     ]
    ],
    "service-workers/service-worker/windowclient-navigate.https.html": [
     [
      "/service-workers/service-worker/windowclient-navigate.https.html",
      {}
     ]
    ],
+   "service-workers/service-worker/worker-client-id.https.html": [
+    [
+     "/service-workers/service-worker/worker-client-id.https.html",
+     {}
+    ]
+   ],
    "service-workers/service-worker/worker-in-sandboxed-iframe-by-csp-fetch-event.https.html": [
     [
      "/service-workers/service-worker/worker-in-sandboxed-iframe-by-csp-fetch-event.https.html",
      {}
     ]
    ],
    "service-workers/service-worker/worker-interception.https.html": [
     [
@@ -592443,16 +592454,20 @@
   "service-workers/service-worker/resources/websocket.js": [
    "dbf752f9a356f51f6ddf96053b39b5cd3515ddc8",
    "support"
   ],
   "service-workers/service-worker/resources/windowclient-navigate-worker.js": [
    "f7a925c1fe330839ea52d45cd052c387303defd6",
    "support"
   ],
+  "service-workers/service-worker/resources/worker-client-id-worker.js": [
+   "22fc24fa277508cabfdfa500745b3446e7a8c076",
+   "support"
+  ],
   "service-workers/service-worker/resources/worker-interception-iframe.https.html": [
    "b9fd4ea281b328c1f21573d1563c968dac52cf22",
    "support"
   ],
   "service-workers/service-worker/resources/worker-load-interceptor.js": [
    "de9cfcbef6528a4b5e6b2552f260501e4d165ea4",
    "support"
   ],
@@ -592583,16 +592598,20 @@
   "service-workers/service-worker/webvtt-cross-origin.https.html": [
    "121299a30b5f75218c1e460578473066a011db46",
    "testharness"
   ],
   "service-workers/service-worker/windowclient-navigate.https.html": [
    "828d8d920459541a37e747ac01376fdcac51ffb3",
    "testharness"
   ],
+  "service-workers/service-worker/worker-client-id.https.html": [
+   "2d39130ccf8401d8bd71e494f5276c9309122dd6",
+   "testharness"
+  ],
   "service-workers/service-worker/worker-in-sandboxed-iframe-by-csp-fetch-event.https.html": [
    "c9cff3f5fb5c205020ad39df6d22ad19ce0cbb0a",
    "testharness"
   ],
   "service-workers/service-worker/worker-interception.https.html": [
    "41f7e5e8da2c305370fddad83518cd0fa57547eb",
    "testharness"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/service-worker/resources/worker-client-id-worker.js
@@ -0,0 +1,25 @@
+addEventListener('fetch', evt => {
+  if (evt.request.url.includes('worker-echo-client-id.js')) {
+    evt.respondWith(new Response(
+      'fetch("fetch-echo-client-id").then(r => r.text()).then(t => self.postMessage(t));',
+      { headers: { 'Content-Type': 'application/javascript' }}));
+    return;
+  }
+
+  if (evt.request.url.includes('fetch-echo-client-id')) {
+    evt.respondWith(new Response(evt.clientId));
+    return;
+  }
+
+  if (evt.request.url.includes('frame.html')) {
+    evt.respondWith(new Response(''));
+    return;
+  }
+});
+
+addEventListener('message', evt => {
+  if (evt.data === 'echo-client-id') {
+    evt.ports[0].postMessage(evt.source.id);
+    return;
+  }
+});
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/service-worker/worker-client-id.https.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<title>Service Worker: Workers should have their own unique client Id</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
+<body>
+<script>
+
+// Get the iframe client ID by calling postMessage() on its controlling
+// worker.  This will cause the service worker to post back the
+// MessageEvent.source.id value.
+function getFrameClientId(frame) {
+  return new Promise(resolve => {
+    let mc = new MessageChannel();
+    frame.contentWindow.navigator.serviceWorker.controller.postMessage(
+      'echo-client-id', [mc.port2]);
+    mc.port1.onmessage = evt => {
+      resolve(evt.data);
+    };
+  });
+}
+
+// Get the worker client ID by creating a worker that performs an intercepted
+// fetch().  The synthetic fetch() response will contain the FetchEvent.clientId
+// value.  This is then posted back to here.
+function getWorkerClientId(frame) {
+  return new Promise(resolve => {
+    let w = new frame.contentWindow.Worker('worker-echo-client-id.js');
+    w.onmessage = evt => {
+      resolve(evt.data);
+    };
+  });
+}
+
+promise_test(async function(t) {
+  const script = './resources/worker-client-id-worker.js';
+  const scope = './resources/worker-client-id';
+  const frame = scope + '/frame.html';
+
+  let reg = await navigator.serviceWorker.register(script, { scope });
+  t.add_cleanup(async _ => await reg.unregister());
+  await wait_for_state(t, reg.installing, 'activated');
+
+  let f = await with_iframe(frame);
+  t.add_cleanup(_ => f.remove());
+
+  let frameClientId = await getFrameClientId(f);
+  assert_not_equals(frameClientId, null, 'frame client id should exist');
+
+  let workerClientId = await getWorkerClientId(f);
+  assert_not_equals(workerClientId, null, 'worker client id should exist');
+
+  assert_not_equals(frameClientId, workerClientId,
+                    'frame and worker client ids should be different');
+}, 'Verify workers have a unique client id separate from their owning documents window');
+
+</script>
+</body>