Bug 1470412 [wpt PR 11626] - ES Modules: Use an appropriate referrer policy for module script loading, a=testonly
authorHiroki Nakagawa <nhiroki@chromium.org>
Fri, 06 Jul 2018 22:18:22 +0000
changeset 426033 a6400627c0a82ba7e4a6f3565e05999d1ebddddd
parent 426032 8bfad4d9426b0ecc731d4847ca561a3d2ac9bd5c
child 426034 6669507c1d818e2f6a0e4bcca81861fd7fdece22
push id34267
push userrgurzau@mozilla.com
push dateWed, 11 Jul 2018 22:05:21 +0000
treeherdermozilla-central@3aca103e4915 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1470412, 11626, 841673, 842553, 855963, 1111743, 569967
milestone63.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 1470412 [wpt PR 11626] - ES Modules: Use an appropriate referrer policy for module script loading, a=testonly Automatic update from web-platform-testsES Modules: Use an appropriate referrer policy for module script loading This CL fixes ReferrerPolicy handling in module script loading. Before this CL, FetchClientSettingsObjectSnapshot's referrer policy is used, but this is wrong. The spec requires to use ScriptFetchOptions' referrer policy. // The "set up the module script request" algorithm: "Set request's cryptographic nonce metadata to options's cryptographic nonce, ..., and its referrer policy to options's referrer policy." https://html.spec.whatwg.org/multipage/webappapis.html#set-up-the-module-script-request Specifically, this CL introduces |referrer_policy_| field in ScriptFetchOptions class as spec'ed and propagates it to the entire path of module script loading. ScriptFetchOptions's referrer policy can be set to following values: - <script>'s "referrerpolicy" attribute is used for <script type='module'>. This hasn't been implemented yet (see https://crbug.com/841673), so the current document's referrer policy is used to keep the backward compatibility. // The "prepare a script" algorithm: "20. Let referrer policy be the current state of the element's referrerpolicy content attribute." "22. Let options be a script fetch options whose cryptographic nonce is cryptographic nonce, ..., and referrer policy is referrer policy." https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script - <link>'s "referrerpolicy" attribute is used for modulepreload. // The "Link type "modulepreload"" algorithm: "9. Let referrer policy be the current state of the element's referrerpolicy attribute." "10. Let options be a script fetch options whose cryptographic nonce is cryptographic nonce, ..., and referrer policy is referrer policy." https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload - The default referrer policy is used for module workers and worklets. This is the reason why this CL changes test expectations of workers and worklets. // The "fetch a module worker script graph" algorithm: "2. Let options be a script fetch options whose cryptographic nonce is the empty string, ..., and referrer policy is the empty string." https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree Change-Id: Ic0f9e6667cd1b84f74d86fcc948451c1d2f8191f Bug: 842553, 855963 Reviewed-on: https://chromium-review.googlesource.com/1111743 Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org> Reviewed-by: Hiroshige Hayashizaki <hiroshige@chromium.org> Reviewed-by: Kentaro Hara <haraken@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Cr-Commit-Position: refs/heads/master@{#569967} -- wpt-commits: 50b0943d82d36bb92977002bebd5a7990e0ed388 wpt-pr: 11626
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/workers/modules/dedicated-worker-import-referrer.html
testing/web-platform/tests/worklets/resources/referrer-checker.py
testing/web-platform/tests/worklets/resources/referrer-tests.js
testing/web-platform/tests/worklets/resources/referrer-window.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -630970,17 +630970,17 @@
    "63b2320a3ecf6133a3525574bf5a1d185d1f3aa7",
    "testharness"
   ],
   "workers/modules/dedicated-worker-import-meta.html": [
    "32cd3419ff904a2440d9a6eaa7cb28f78d4a7e32",
    "testharness"
   ],
   "workers/modules/dedicated-worker-import-referrer.html": [
-   "309df42ef9329addc1fc59e2d3c0443454e14ad7",
+   "9495c1f58acf7062267fd59e682541950a659731",
    "testharness"
   ],
   "workers/modules/dedicated-worker-import.any.js": [
    "8a3a5bdcf6034d99cb244cc6ff36ada8f422ef37",
    "testharness"
   ],
   "workers/modules/dedicated-worker-options-credentials.html": [
    "f182ac364e933ce744b18c0ca6e03ae975a883a3",
@@ -631630,25 +631630,25 @@
    "e2f65e87d6d7b885201b4371ce0c4f21af5efe90",
    "support"
   ],
   "worklets/resources/import-tests.js": [
    "fdc5ee273fa5b4bf3b820f8c0404a5ca9580e2b4",
    "support"
   ],
   "worklets/resources/referrer-checker.py": [
-   "9e4cce637b7402da3b6a17d4cb33dc706f222c41",
+   "3de9f5d0d90e5c360edd453a539cc2b83f45d42e",
    "support"
   ],
   "worklets/resources/referrer-tests.js": [
-   "bfa2e28259a44abf3aac6be528e51976c9ff782d",
+   "e072f492d6aa19866245b357a623c60ec3382c9a",
    "support"
   ],
   "worklets/resources/referrer-window.html": [
-   "adfb1c116fedb6396f970ed8072ee73edfc755fc",
+   "5900ef7037397bc3eb956b97c40cfd7a3a12c95f",
    "support"
   ],
   "worklets/resources/service-worker-interception-tests.js": [
    "42ebe0dd946d39dcf3c211581a15d0f648a67a08",
    "support"
   ],
   "worklets/resources/service-worker.js": [
    "cd87e26ff28300d6ccbe0bc80378725c14c580db",
--- a/testing/web-platform/tests/workers/modules/dedicated-worker-import-referrer.html
+++ b/testing/web-platform/tests/workers/modules/dedicated-worker-import-referrer.html
@@ -31,27 +31,26 @@ function removeParams(url_string) {
 // that starts a dedicated worker.
 //
 // |settings| has options as follows:
 //
 //   settings = {
 //     scriptURL: 'resources/referrer-checker.sub.js',
 //     windowReferrerPolicy: 'no-referrer',
 //     workerReferrerPolicy: 'same-origin',
-//     expectedReferrer: 'https://example.com/referrer-checker.py'
+//     moduleGraphLevel: 'top-level' (or 'descendant')
 //   };
 //
 // - |scriptURL| is used for starting a new worker.
 // - |windowReferrerPolicy| is set to the ReferrerPolicy HTTP header of the
 //   window. This policy should be applied to top-level worker module script
 //   loading and static imports.
 // - |workerReferrerPolicy| is set to the ReferrerPolicy HTTP header of the
 //   worker. This policy should be applied to dynamic imports.
-// - |expectedReferrer| is compared with the actual referrer. URL parameters are
-//   ignored.
+// - |moduleGraphLevel| indicates a script whose referrer will be tested.
 function import_referrer_test(settings, description) {
   promise_test(async () => {
     let windowURL = 'resources/new-worker-window.html';
     if (settings.windowReferrerPolicy) {
       windowURL +=
           `?pipe=header(Referrer-Policy, ${settings.windowReferrerPolicy})`;
     }
 
@@ -64,146 +63,149 @@ function import_referrer_test(settings, 
       scriptURL +=
           `?pipe=sub|header(Referrer-Policy, ${settings.workerReferrerPolicy})`;
     }
 
     const win = await openWindow(windowURL);
     win.postMessage(scriptURL, '*');
     const msgEvent = await new Promise(resolve => window.onmessage = resolve);
 
-    // Delete query parameters from the referrers to make it easy to match the
-    // actual referrer with the expected referrer.
-    const expectedReferrer = removeParams(settings.expectedReferrer);
+    let expectedReferrer;
+    if (settings.moduleGraphLevel == 'top-level')
+      expectedReferrer = createURLString('resources/new-worker-window.html');
+    else
+      expectedReferrer = createURLString('resources/' + settings.scriptURL);
+
+    // Delete query parameters from the actual referrer to make it easy to match
+    // it with the expected referrer.
     const actualReferrer = removeParams(msgEvent.data);
+
     assert_equals(actualReferrer, expectedReferrer);
   }, description);
 }
 
 // Tests for top-level worker module script loading.
 //
-// Top-level worker module script loading should obey the window's
-// ReferrerPolicy, and send the window's URL as a referrer.
+// Top-level worker module script loading should obey the default referrer
+// policy (not the window's referrer policy), and send the window's URL as a
+// referrer.
 //
 // [Current document]
 // --(open)--> [Window] whose referrer policy is |windowReferrerPolicy|.
 //   --(new Worker)--> [Worker] should be loaded with [Window]'s URL as a
-//                     referrer if it's allowed by |windowReferrerPolicy|.
+//                     referrer regardless of |windowReferrerPolicy|.
 
 import_referrer_test(
     { scriptURL: 'referrer-checker.py',
       windowReferrerPolicy: 'no-referrer',
-      expectedReferrer: '' },
+      moduleGraphLevel: 'top-level' },
     'Same-origin top-level module script loading with "no-referrer" referrer ' +
         'policy');
 
 import_referrer_test(
     { scriptURL: 'referrer-checker.py',
       windowReferrerPolicy: 'origin',
-      expectedReferrer: window.location.origin + '/' },
+      moduleGraphLevel: 'top-level' },
     'Same-origin top-level module script loading with "origin" referrer ' +
         'policy');
 
 import_referrer_test(
     { scriptURL: 'referrer-checker.py',
       windowReferrerPolicy: 'same-origin',
-      expectedReferrer: createURLString('resources/new-worker-window.html') },
+      moduleGraphLevel: 'top-level' },
     'Same-origin top-level module script loading with "same-origin" referrer ' +
         'policy');
 
 // Tests for static imports.
 //
-// Static imports should obey the window's ReferrerPolicy, and send the worker's
+// Static imports should obey the default referrer policy, and send the worker's
 // URL as a referrer.
 //
 // [Current document]
 // --(open)--> [Window] whose referrer policy is |windowReferrerPolicy|.
 //   --(new Worker)--> [Worker]
 //     --(static import)--> [Script] should be loaded with [Worker]'s URL as a
-//                          referrer if it's allowed by |windowReferrerPolicy|.
+//                          referrer regardless of |windowReferrerPolicy|.
 
 import_referrer_test(
     { scriptURL: 'static-import-same-origin-referrer-checker-worker.js',
       windowReferrerPolicy: 'no-referrer',
-      expectedReferrer: '' },
+      moduleGraphLevel: 'descendant' },
     'Same-origin static import with "no-referrer" referrer policy.');
 
 import_referrer_test(
     { scriptURL: 'static-import-same-origin-referrer-checker-worker.js',
       windowReferrerPolicy: 'origin',
-      expectedReferrer: window.location.origin + '/' },
+      moduleGraphLevel: 'descendant' },
     'Same-origin static import with "origin" referrer policy.');
 
 import_referrer_test(
     { scriptURL: 'static-import-same-origin-referrer-checker-worker.js',
       windowReferrerPolicy: 'same-origin',
-      expectedReferrer: createURLString(
-          'resources/static-import-same-origin-referrer-checker-worker.js') },
+      moduleGraphLevel: 'descendant' },
     'Same-origin static import with "same-origin" referrer policy.');
 
 import_referrer_test(
     { scriptURL: 'static-import-remote-origin-referrer-checker-worker.sub.js',
       windowReferrerPolicy: 'no-referrer',
-      expectedReferrer: '' },
+      moduleGraphLevel: 'descendant' },
     'Cross-origin static import with "no-referrer" referrer policy.');
 
 import_referrer_test(
     { scriptURL: 'static-import-remote-origin-referrer-checker-worker.sub.js',
       windowReferrerPolicy: 'origin',
-      expectedReferrer: window.location.origin + '/' },
+      moduleGraphLevel: 'descendant' },
     'Cross-origin static import with "origin" referrer policy.');
 
 import_referrer_test(
     { scriptURL: 'static-import-remote-origin-referrer-checker-worker.sub.js',
       windowReferrerPolicy: 'same-origin',
-      expectedReferrer: '' },
+      moduleGraphLevel: 'descendant' },
     'Cross-origin static import with "same-origin" referrer policy.');
 
 // Tests for dynamic imports.
 //
-// Dynamic imports should obey the worker's ReferrerPolicy, and send the
-// worker's URL as a referrer. Note that the worker doesn't inherit the window's
-// referrer policy and it's set by the ReferrerPolicy HTTP header on the
-// response of the top-level worker module script.
+// Dynamic imports should obey the default referrer policy (not the worker's
+// referrer policy), and send the worker's URL as a referrer.
 //
 // [Current document]
 // --(open)--> [Window]
 //   --(new Worker)--> [Worker] whose referrer policy is |workerReferrerPolicy|.
 //     --(dynamic import)--> [Script] should be loaded with [Worker]'s URL as a
-//                           referrer if it's allowed by |workerReferrerPolicy|.
+//                           referrer regardless of |workerReferrerPolicy|.
 
 import_referrer_test(
     { scriptURL: 'dynamic-import-same-origin-referrer-checker-worker.js',
       workerReferrerPolicy: 'no-referrer',
-      expectedReferrer: '' },
+      moduleGraphLevel: 'descendant' },
     'Same-origin dynamic import with "no-referrer" referrer policy.');
 
 import_referrer_test(
     { scriptURL: 'dynamic-import-same-origin-referrer-checker-worker.js',
       workerReferrerPolicy: 'origin',
-      expectedReferrer: window.location.origin + '/' },
+      moduleGraphLevel: 'descendant' },
     'Same-origin dynamic import with "origin" referrer policy.');
 
 import_referrer_test(
     { scriptURL: 'dynamic-import-same-origin-referrer-checker-worker.js',
       workerReferrerPolicy: 'same-origin',
-      expectedReferrer: createURLString(
-          'resources/dynamic-import-same-origin-referrer-checker-worker.js') },
+      moduleGraphLevel: 'descendant' },
     'Same-origin dynamic import with "same-origin" referrer policy.');
 
 import_referrer_test(
     { scriptURL: 'dynamic-import-remote-origin-referrer-checker-worker.sub.js',
       workerReferrerPolicy: 'no-referrer',
-      expectedReferrer: '' },
+      moduleGraphLevel: 'descendant' },
     'Cross-origin dynamic import with "no-referrer" referrer policy.');
 
 import_referrer_test(
     { scriptURL: 'dynamic-import-remote-origin-referrer-checker-worker.sub.js',
       workerReferrerPolicy: 'origin',
-      expectedReferrer: window.location.origin + '/' },
+      moduleGraphLevel: 'descendant' },
     'Cross-origin dynamic import with "origin" referrer policy.');
 
 import_referrer_test(
     { scriptURL: 'dynamic-import-remote-origin-referrer-checker-worker.sub.js',
       workerReferrerPolicy: 'same-origin',
-      expectedReferrer: '' },
+      moduleGraphLevel: 'descendant' },
     'Cross-origin dynamic import with "same-origin" referrer policy.');
 
 </script>
--- a/testing/web-platform/tests/worklets/resources/referrer-checker.py
+++ b/testing/web-platform/tests/worklets/resources/referrer-checker.py
@@ -1,26 +1,15 @@
 # Returns a valid response when request's |referrer| matches
 # |expected_referrer|.
 def main(request, response):
     referrer = request.headers.get("referer", "")
-    referrer_policy = request.GET.first("referrer_policy")
     expected_referrer = request.GET.first("expected_referrer", "")
 
     response_headers = [("Content-Type", "text/javascript"),
                         ("Access-Control-Allow-Origin", "*")]
 
-    if referrer_policy == "no-referrer" or referrer_policy == "origin":
-        if referrer == expected_referrer:
-            return (200, response_headers, "")
-        return (404, response_headers)
-
-    if referrer_policy == "same-origin":
-        if referrer == expected_referrer:
-            return (200, response_headers, "")
-        # The expected referrer doesn't contain query params for simplification,
-        # so we check the referrer by startswith() here.
-        if (expected_referrer != "" and
-            referrer.startswith(expected_referrer + "?")):
-            return (200, response_headers, "")
-        return (404, response_headers)
-
+    # The expected referrer doesn't contain query params for simplification, so
+    # we check the referrer by startswith() here.
+    if (expected_referrer != "" and
+        referrer.startswith(expected_referrer + "?")):
+        return (200, response_headers, "")
     return (404, response_headers)
--- a/testing/web-platform/tests/worklets/resources/referrer-tests.js
+++ b/testing/web-platform/tests/worklets/resources/referrer-tests.js
@@ -24,148 +24,150 @@ function runReferrerTest(settings) {
       `?pipe=header(Referrer-Policy, ${settings.referrerPolicy})`;
   return openWindow(kWindowURL).then(win => {
     const promise = new Promise(resolve => window.onmessage = resolve);
     win.postMessage(settings, '*');
     return promise;
   }).then(msg_event => assert_equals(msg_event.data, 'RESOLVED'));
 }
 
-// Runs a series of tests related to the referrer policy on a worklet.
+// Runs a series of tests related to the referrer policy on a worklet. Referrer
+// on worklet module loading should always be handled with the default referrer
+// policy.
 //
 // Usage:
 // runReferrerTests("paint");
 function runReferrerTests(workletType) {
   const worklet = get_worklet(workletType);
 
   // Tests for top-level script fetch -----------------------------------------
 
   promise_test(() => {
     return runReferrerTest({ workletType: workletType,
                              fetchType: 'top-level',
                              referrerPolicy: 'no-referrer',
                              scriptOrigins: { topLevel: 'same' } });
   }, 'Importing a same-origin script from a page that has "no-referrer" ' +
-     'referrer policy should not send referrer.');
+     'referrer policy.');
 
   promise_test(() => {
     return runReferrerTest({ workletType: workletType,
                              fetchType: 'top-level',
                              referrerPolicy: 'no-referrer',
                              scriptOrigins: { topLevel: 'remote' } });
   }, 'Importing a remote-origin script from a page that has "no-referrer" ' +
-     'referrer policy should not send referrer.');
+     'referrer policy.');
 
   promise_test(() => {
     return runReferrerTest({ workletType: workletType,
                              fetchType: 'top-level',
                              referrerPolicy: 'origin',
                              scriptOrigins: { topLevel: 'same' } });
   }, 'Importing a same-origin script from a page that has "origin" ' +
-     'referrer policy should send only an origin as referrer.');
+     'referrer policy.');
 
   promise_test(() => {
     return runReferrerTest({ workletType: workletType,
                              fetchType: 'top-level',
                              referrerPolicy: 'origin',
                              scriptOrigins: { topLevel: 'remote' } });
   }, 'Importing a remote-origin script from a page that has "origin" ' +
-     'referrer policy should send only an origin as referrer.');
+     'referrer policy.');
 
   promise_test(() => {
     return runReferrerTest({ workletType: workletType,
                              fetchType: 'top-level',
                              referrerPolicy: 'same-origin',
                              scriptOrigins: { topLevel: 'same' } });
   }, 'Importing a same-origin script from a page that has "same-origin" ' +
-     'referrer policy should send referrer.');
+     'referrer policy.');
 
   promise_test(() => {
     return runReferrerTest({ workletType: workletType,
                              fetchType: 'top-level',
                              referrerPolicy: 'same-origin',
                              scriptOrigins: { topLevel: 'remote' } });
   }, 'Importing a remote-origin script from a page that has "same-origin" ' +
-     'referrer policy should not send referrer.');
+     'referrer policy.');
 
   // Tests for descendant script fetch -----------------------------------------
 
   promise_test(() => {
     return runReferrerTest({ workletType: workletType,
                              fetchType: 'descendant',
                              referrerPolicy: 'no-referrer',
                              scriptOrigins: { topLevel: 'same',
                                               descendant: 'same' } });
   }, 'Importing a same-origin script from a same-origin worklet script that ' +
-     'has "no-referrer" referrer policy should not send referrer.');
+     'has "no-referrer" referrer policy.');
 
   promise_test(() => {
     return runReferrerTest({ workletType: workletType,
                              fetchType: 'descendant',
                              referrerPolicy: 'no-referrer',
                              scriptOrigins: { topLevel: 'same',
                                               descendant: 'remote' } });
   }, 'Importing a remote-origin script from a same-origin worklet script ' +
-     'that has "no-referrer" referrer policy should not send referrer.');
+     'that has "no-referrer" referrer policy.');
 
   promise_test(() => {
     return runReferrerTest({ workletType: workletType,
                              fetchType: 'descendant',
                              referrerPolicy: 'no-referrer',
                              scriptOrigins: { topLevel: 'remote',
                                               descendant: 'remote' } });
   }, 'Importing a remote-origin script from a remote-origin worklet script ' +
-     'that has "no-referrer" referrer policy should not send referrer.');
+     'that has "no-referrer" referrer policy.');
 
   promise_test(() => {
     return runReferrerTest({ workletType: workletType,
                              fetchType: 'descendant',
                              referrerPolicy: 'origin',
                              scriptOrigins: { topLevel: 'same',
                                               descendant: 'same' } });
   }, 'Importing a same-origin script from a same-origin worklet script that ' +
-     'has "origin" referrer policy should send referrer.');
+     'has "origin" referrer policy.');
 
   promise_test(() => {
     return runReferrerTest({ workletType: workletType,
                              fetchType: 'descendant',
                              referrerPolicy: 'origin',
                              scriptOrigins: { topLevel: 'same',
                                               descendant: 'remote' } });
   }, 'Importing a remote-origin script from a same-origin worklet script ' +
-     'that has "origin" referrer policy should send referrer.');
+     'that has "origin" referrer policy.');
 
   promise_test(() => {
     return runReferrerTest({ workletType: workletType,
                              fetchType: 'descendant',
                              referrerPolicy: 'origin',
                              scriptOrigins: { topLevel: 'remote',
                                               descendant: 'remote' } });
   }, 'Importing a remote-origin script from a remote-origin worklet script ' +
-     'that has "origin" referrer policy should send referrer.');
+     'that has "origin" referrer policy.');
 
   promise_test(() => {
     return runReferrerTest({ workletType: workletType,
                              fetchType: 'descendant',
                              referrerPolicy: 'same-origin',
                              scriptOrigins: { topLevel: 'same',
                                               descendant: 'same' } });
   }, 'Importing a same-origin script from a same-origin worklet script that ' +
-     'has "same-origin" referrer policy should send referrer.');
+     'has "same-origin" referrer policy.');
 
   promise_test(() => {
     return runReferrerTest({ workletType: workletType,
                              fetchType: 'descendant',
                              referrerPolicy: 'same-origin',
                              scriptOrigins: { topLevel: 'same',
                                               descendant: 'remote' } });
   }, 'Importing a remote-origin script from a same-origin worklet script ' +
-     'that has "same-origin" referrer policy should not send referrer.');
+     'that has "same-origin" referrer policy.');
 
   promise_test(() => {
     return runReferrerTest({ workletType: workletType,
                              fetchType: 'descendant',
                              referrerPolicy: 'same-origin',
                              scriptOrigins: { topLevel: 'remote',
                                               descendant: 'remote' } });
   }, 'Importing a remote-origin script from a remote-origin worklet script ' +
-     'that has "same-origin" referrer policy should not send referrer.');
+     'that has "same-origin" referrer policy.');
 }
--- a/testing/web-platform/tests/worklets/resources/referrer-window.html
+++ b/testing/web-platform/tests/worklets/resources/referrer-window.html
@@ -43,57 +43,40 @@ function createScriptURLForDecendant(scr
 function isDestinationCrossOrigin(fetchType, scriptOrigins) {
   if (fetchType === 'top-level')
     return scriptOrigins.topLevel === 'remote';
   if (fetchType === 'descendant')
     return scriptOrigins.descendant === 'remote';
   assert_unreached('fetchType has an invalid value.');
 }
 
-function createExpectedReferrer(
-    importerURL, fetchType, referrerPolicy, scriptOrigins) {
-  if (referrerPolicy === 'no-referrer')
-    return "";
-  if (referrerPolicy === 'same-origin') {
-    if (isDestinationCrossOrigin(fetchType, scriptOrigins))
-      return "";
-    // Delete query params to make it easier to match with an actual referrer in
-    // the referrer-checker.py.
-    const expectedReferrer = new URL(importerURL);
-    for (var key of expectedReferrer.searchParams.keys())
-      expectedReferrer.searchParams.delete(key);
-    return expectedReferrer;
-  }
-  if (referrerPolicy === 'origin')
-    return (new URL(importerURL)).origin + '/';
-  assert_unreached('referrerPolicy has an invalid value.');
-}
-
 window.onmessage = e => {
   const workletType = e.data.workletType;
   const fetchType = e.data.fetchType;
-  const referrerPolicy = e.data.referrerPolicy;
   const scriptOrigins = e.data.scriptOrigins;
 
   let scriptURL;
   let expectedReferrer;
   if (fetchType === 'top-level') {
     scriptURL = createScriptURLForTopLevel(scriptOrigins.topLevel);
-    expectedReferrer = createExpectedReferrer(
-        location.href, fetchType, referrerPolicy, scriptOrigins);
+    // The referrer of the top-level script should be this file.
+    // Delete query params to make it easier to match with an actual referrer in
+    // the referrer-checker.py.
+    expectedReferrer = new URL(location.href);
+    for (var key of expectedReferrer.searchParams.keys())
+      expectedReferrer.searchParams.delete(key);
   } else if (fetchType === 'descendant') {
     scriptURL = createScriptURLForDecendant(scriptOrigins);
-    expectedReferrer = createExpectedReferrer(
-        scriptURL, fetchType, referrerPolicy, scriptOrigins);
+    // The referrer of the imported script should be the importer script.
+    expectedReferrer = scriptURL;
   } else {
     assert_unreached('fetchType should be \'top-level\' or \'descendant\'');
   }
 
   const params = new URLSearchParams;
-  params.append('referrer_policy', referrerPolicy);
   params.append('expected_referrer', expectedReferrer);
 
   get_worklet(workletType).addModule(scriptURL + '?' + params)
       .then(() => window.opener.postMessage('RESOLVED', '*'))
       .catch(e => window.opener.postMessage(e.message, '*'));
 };
 
 window.opener.postMessage('LOADED', '*');