Bug 1621851 [wpt PR 22206] - Plumb COEP reporter for requests initiated from a service worker, a=testonly
authorMakoto Shimazu <shimazu@chromium.org>
Thu, 12 Mar 2020 15:12:32 +0000
changeset 518668 94c2c014b6b57bfd6c5b89000c78564c653f60c1
parent 518667 1b01eabe48b1cd15af00df5c931e6b97d95658ae
child 518669 4c93136ed6158a0bb8b9585dd98cad59fe39e50a
push id110076
push userwptsync@mozilla.com
push dateFri, 13 Mar 2020 16:50:09 +0000
treeherderautoland@7381ff2b16e7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1621851, 22206, 1056122, 2098166, 749584
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 1621851 [wpt PR 22206] - Plumb COEP reporter for requests initiated from a service worker, a=testonly Automatic update from web-platform-tests Plumb COEP reporter for requests initiated from a service worker This adds COEP reporter for service worker contexts. CORP failures happening on subresource requests initiated from a service worker are reported to the COEP reporter owned by EmbeddedWorkerInstance. Bug: 1056122 Change-Id: I7884487e0261b4d85bf98b5844c3e34c0b985ebe Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2098166 Commit-Queue: Makoto Shimazu <shimazu@chromium.org> Reviewed-by: Yutaka Hirano <yhirano@chromium.org> Reviewed-by: Matt Falkenhagen <falken@chromium.org> Cr-Commit-Position: refs/heads/master@{#749584} -- wpt-commits: 418686f8133f02b6bcf9451522342747b266f1e2 wpt-pr: 22206
testing/web-platform/tests/html/cross-origin-embedder-policy/reporting.https.html
--- 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
@@ -115,16 +115,78 @@ async_test(async (t) => {
     t.done();
   } catch (e) {
     t.step(() => { throw e });
   }
 }, 'subresource CORP');
 
 async_test(async (t) => {
   try {
+    const IFRAME_SRC = 'resources/coep-iframe.html';
+    const SCOPE = new URL(IFRAME_SRC, location).pathname;
+    const SCRIPT =
+      'resources/sw.js?' +
+      `pipe=header(service-worker-allowed,${SCOPE})|` +
+      'header(cross-origin-embedder-policy,require-corp%3breport-to=%22endpoint%22)|' +
+      'header(cross-origin-embedder-policy-report-only,require-corp%3breport-to=%22report-only-endpoint%22)';
+
+    const reg = await service_worker_unregister_and_register(t, SCRIPT, SCOPE);
+    await wait_for_state(t, reg.installing, 'activated');
+
+    const iframe = document.createElement('iframe');
+    t.add_cleanup(() => {
+      iframe.remove();
+      reg.unregister();
+    });
+    iframe.src = IFRAME_SRC;
+    document.body.appendChild(iframe);
+    await new Promise(resolve => {
+      iframe.addEventListener('load', resolve, {once: true});
+    });
+
+    document.body.appendChild(iframe);
+    await new Promise(resolve => {
+      iframe.addEventListener('load', resolve, {once: true});
+    });
+
+    function fetchInIframe(url) {
+      const init = { mode: 'no-cors', cache: 'no-store' };
+      iframe.contentWindow.fetch(url, init).catch(() => {});
+    }
+
+    const suffix = 'subresource-corp-sw';
+    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}`;
+
+    fetchInIframe(sameOriginUrl);
+    fetchInIframe(blockedByPureCorp);
+    fetchInIframe(blockedDueToCoep);
+    fetchInIframe(redirect);
+
+    // Wait 3 seconds for reports to settle.
+    await wait(3000);
+
+    const contextUrl = SCRIPT;
+    checkReportNonExistence(reports, sameOriginUrl, contextUrl);
+    checkReportNonExistence(reports, blockedByPureCorp, contextUrl);
+    checkCorpReportExistence(reports, blockedDueToCoep, contextUrl);
+    checkCorpReportExistence(reports, redirect, contextUrl);
+    checkReportNonExistence(reports, dest, contextUrl);
+
+    t.done();
+  } catch (e) {
+    t.step(() => { throw e });
+  }
+}, 'CORP for subresource requests initiated from a service worker');
+
+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});
     });