Bug 1621893 [wpt PR 22211] - Add WPT for DedicatedWorker + COEP reporting, a=testonly
authorMakoto Shimazu <shimazu@chromium.org>
Sat, 14 Mar 2020 10:39:05 +0000
changeset 518826 2d987ea12f79e36d69920ac12488e15f954a792f
parent 518825 a9cebd53a328ba387ac8930dc7ec26e3f6462af2
child 518827 e6134f9533d2765414538835cde2ccd1b44ab7e4
push id37217
push userccoroiu@mozilla.com
push dateSun, 15 Mar 2020 21:37:59 +0000
treeherdermozilla-central@f9fc9427476e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1621893, 22211, 1060837, 2100059, 749623
milestone76.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 1621893 [wpt PR 22211] - Add WPT for DedicatedWorker + COEP reporting, a=testonly Automatic update from web-platform-tests Add WPT for DedicatedWorker + COEP reporting This CL adds tests to check the support of COEP reporting for requests initiated by a dedicated worker. So far, Chrome has a bug that the context url is the page's url where the dedicated worker is created. This bug is going to be fixed once PlzDedicatedWorker is shipped (with additional work for integration between PlzDedicatedWorker and COEP reporting). Bug: 1060837 Change-Id: I12291646c4d5a80d89c8894548acdb186f4a14be Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2100059 Commit-Queue: Makoto Shimazu <shimazu@chromium.org> Auto-Submit: Makoto Shimazu <shimazu@chromium.org> Reviewed-by: Yutaka Hirano <yhirano@chromium.org> Cr-Commit-Position: refs/heads/master@{#749623} -- wpt-commits: 1e35b4abf6e896af2ce0b342967cae6da8df612d wpt-pr: 22211
testing/web-platform/tests/html/cross-origin-embedder-policy/reporting.https.html
testing/web-platform/tests/html/cross-origin-embedder-policy/resources/fetch-in-dedicated-worker.js
--- a/testing/web-platform/tests/html/cross-origin-embedder-policy/reporting.https.html
+++ b/testing/web-platform/tests/html/cross-origin-embedder-policy/reporting.https.html
@@ -313,16 +313,113 @@ async_test(async (t) => {
     check(reportsForReportOnly, coepReportOnly, coepReportOnly);
 
     t.done();
   } catch (e) {
     t.step(() => { throw e });
   }
 }, 'COEP violation on nested frame navigation');
 
+async_test(async (t) => {
+  try {
+    const iframe = document.createElement('iframe');
+    t.add_cleanup(() => iframe.remove());
+
+    iframe.src = `resources/reporting-empty-frame.html`
+    document.body.appendChild(iframe);
+    await new Promise(resolve => {
+      iframe.addEventListener('load', resolve, {once: true});
+    });
+    const worker_url = new URL('resources/fetch-in-dedicated-worker.js', location);
+    const worker = new iframe.contentWindow.Worker(worker_url);
+
+    function fetchInWorker(url) {
+      const init = { mode: 'no-cors', cache: 'no-store' };
+      worker.postMessage({url, init});
+      return new Promise((resolve) => {
+        worker.addEventListener('message', resolve);
+      });
+    }
+
+    const suffix = 'subresource-corp-from-dedicated-worker';
+    const sameOriginUrl = `/common/text-plain.txt?${suffix}`;
+    const blockedByPureCorp = `${REMOTE_ORIGIN}${BASE}/nothing-same-origin-corp.txt?${suffix}`;
+    const blockedDueToCoep = `${REMOTE_ORIGIN}/common/text-plain.txt?abc&${suffix}`;
+    const dest = `${REMOTE_ORIGIN}/common/text-plain.txt?xyz&${suffix}`;
+    const redirect = `/common/redirect.py?location=${encodeURIComponent(dest)}&${suffix}`;
+
+    fetchInWorker(sameOriginUrl);
+    fetchInWorker(blockedByPureCorp);
+    fetchInWorker(blockedDueToCoep);
+    fetchInWorker(redirect);
+
+    // Wait 1 seconds for reports to settle.
+    await wait(1000);
+
+    checkReportNonExistence(reports, sameOriginUrl, worker_url.href);
+    checkReportNonExistence(reports, blockedByPureCorp, worker_url.href);
+    checkCorpReportExistence(reports, blockedDueToCoep, worker_url.href);
+    checkCorpReportExistence(reports, redirect, worker_url.href);
+    checkReportNonExistence(reports, dest, worker_url.href);
+    t.done();
+  } catch (e) {
+    t.step(() => { throw e });
+  }
+}, 'subresource requests initiated from DedicatedWorker');
+
+promise_test(async (t) => {
+  const suffix = 'subresource-corp-from-dedicated-worker-via-passthrough-sw';
+  const iframe_src = `resources/reporting-empty-frame.html?passthrough&${suffix}`;
+  // Register a service worker that controls an iframe.
+  const registration = await service_worker_unregister_and_register(
+      t, 'resources/sw.js', iframe_src);
+  t.add_cleanup(() => registration.unregister());
+  await wait_for_state(t, registration.installing, 'activated');
+
+  const iframe = document.createElement('iframe');
+  t.add_cleanup(() => iframe.remove());
+
+  iframe.src = iframe_src;
+  document.body.appendChild(iframe);
+  await new Promise(resolve => {
+    iframe.addEventListener('load', resolve, {once: true});
+  });
+
+  const worker_url = new URL('resources/fetch-in-dedicated-worker.js', location);
+  const worker = new iframe.contentWindow.Worker(worker_url);
+
+  function fetchInWorker(url) {
+    const init = { mode: 'no-cors', cache: 'no-store' };
+    worker.postMessage({url, init});
+    return new Promise((resolve) => {
+      worker.addEventListener('message', resolve);
+    });
+  }
+
+  const sameOriginUrl = `/common/text-plain.txt?${suffix}`;
+  const blockedByPureCorp = `${REMOTE_ORIGIN}${BASE}/nothing-same-origin-corp.txt?${suffix}`;
+  const blockedDueToCoep = `${REMOTE_ORIGIN}/common/text-plain.txt?abc&${suffix}`;
+  const dest = `${REMOTE_ORIGIN}/common/text-plain.txt?xyz&${suffix}`;
+  const redirect = `/common/redirect.py?location=${encodeURIComponent(dest)}&${suffix}`;
+
+  fetchInWorker(sameOriginUrl);
+  fetchInWorker(blockedByPureCorp);
+  fetchInWorker(blockedDueToCoep);
+  fetchInWorker(redirect);
+
+  // Wait 1 seconds for reports to settle.
+  await wait(1000);
+
+  checkReportNonExistence(reports, sameOriginUrl, worker_url.href);
+  checkReportNonExistence(reports, blockedByPureCorp, worker_url.href);
+  checkCorpReportExistence(reports, blockedDueToCoep, worker_url.href);
+  checkCorpReportExistence(reports, redirect, worker_url.href);
+  checkReportNonExistence(reports, dest, worker_url.href);
+}, 'subresource requests initiated from DedicatedWorker controlled by a passthrough service worker');
+
 promise_test(async (t) => {
   const iframe_src = `resources/reporting-empty-frame.html?passthrough`;
   // Register a service worker that controls an iframe.
   const registration = await service_worker_unregister_and_register(
       t, 'resources/sw.js', iframe_src);
   t.add_cleanup(() => registration.unregister());
   await wait_for_state(t, registration.installing, 'activated');
 
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/cross-origin-embedder-policy/resources/fetch-in-dedicated-worker.js
@@ -0,0 +1,6 @@
+self.addEventListener('message', async (e) => {
+  const param = e.data;
+  // Ignore network error.
+  await fetch(param.url, param.init).catch(() => {});
+  self.postMessage(param.url);
+});