Skip to content

Commit

Permalink
Add missing worklet referrer tests
Browse files Browse the repository at this point in the history
This CL adds more web-platform-tests for the `Referer` on worklet
descendant requests. This CL introduces tests where we fetch a
same-origin descendant script from a cross-origin worklet script served
with varying referrer policies.

The tests are similar to those introduced in crrev.com/c/1809205 for
module scripts, and will pass once crrev.com/c/1808663 is merged.

R=ikilpatrick@chromium.org, kouhei@chromium.org

Bug: 786862,1004083
Change-Id: I4425be4264424b52e4ec307513a404541869f2a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1813122
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Commit-Queue: Dominic Farolino <dom@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699351}
  • Loading branch information
domfarolino authored and chromium-wpt-export-bot committed Sep 25, 2019
1 parent 7b3ea48 commit 98c8947
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Forward GET parameters to the server.
import '{{GET[requestor_origin]}}/worklets/resources/referrer-checker.py?referrer_policy={{GET[referrer_policy]}}&expected_referrer={{GET[expected_referrer]}}';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Access-Control-Allow-Origin: *
32 changes: 32 additions & 0 deletions worklets/resources/referrer-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function runReferrerTests(workletType) {

// Tests for descendant script fetch -----------------------------------------

// Referrer policy: no-referrer.
promise_test(() => {
return runReferrerTest({ workletType: workletType,
fetchType: 'descendant',
Expand All @@ -106,6 +107,15 @@ function runReferrerTests(workletType) {
}, 'Importing a remote-origin script from a same-origin worklet script ' +
'that has "no-referrer" referrer policy should not send referrer.');

promise_test(() => {
return runReferrerTest({ workletType: workletType,
fetchType: 'descendant',
referrerPolicy: 'no-referrer',
scriptOrigins: { topLevel: 'remote',
descendant: 'same' } });
}, 'Importing a same-origin script from a remote-origin worklet script ' +
'that has "no-referrer" referrer policy should not send referrer.');

promise_test(() => {
return runReferrerTest({ workletType: workletType,
fetchType: 'descendant',
Expand All @@ -115,6 +125,7 @@ function runReferrerTests(workletType) {
}, 'Importing a remote-origin script from a remote-origin worklet script ' +
'that has "no-referrer" referrer policy should not send referrer.');

// Referrer policy: origin.
promise_test(() => {
return runReferrerTest({ workletType: workletType,
fetchType: 'descendant',
Expand All @@ -133,6 +144,15 @@ function runReferrerTests(workletType) {
}, 'Importing a remote-origin script from a same-origin worklet script ' +
'that has "origin" referrer policy should send referrer.');

promise_test(() => {
return runReferrerTest({ workletType: workletType,
fetchType: 'descendant',
referrerPolicy: 'origin',
scriptOrigins: { topLevel: 'remote',
descendant: 'same' } });
}, 'Importing a same-origin script from a remote-origin worklet script ' +
'that has "origin" referrer policy should send referrer.');

promise_test(() => {
return runReferrerTest({ workletType: workletType,
fetchType: 'descendant',
Expand All @@ -142,6 +162,7 @@ function runReferrerTests(workletType) {
}, 'Importing a remote-origin script from a remote-origin worklet script ' +
'that has "origin" referrer policy should send referrer.');

// Referrer policy: same-origin.
promise_test(() => {
return runReferrerTest({ workletType: workletType,
fetchType: 'descendant',
Expand All @@ -160,6 +181,15 @@ function runReferrerTests(workletType) {
}, 'Importing a remote-origin script from a same-origin worklet script ' +
'that has "same-origin" referrer policy should not send referrer.');

promise_test(() => {
return runReferrerTest({ workletType: workletType,
fetchType: 'descendant',
referrerPolicy: 'same-origin',
scriptOrigins: { topLevel: 'remote',
descendant: 'same' } });
}, 'Importing a same-origin script from a remote-origin worklet script ' +
'that has "same-origin" referrer policy should send referrer.');

promise_test(() => {
return runReferrerTest({ workletType: workletType,
fetchType: 'descendant',
Expand All @@ -168,4 +198,6 @@ function runReferrerTests(workletType) {
descendant: 'remote' } });
}, 'Importing a remote-origin script from a remote-origin worklet script ' +
'that has "same-origin" referrer policy should not send referrer.');

// TODO(domfarolino): Add tests for more referrer policies.
}
9 changes: 9 additions & 0 deletions worklets/resources/referrer-window.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
'import-remote-origin-referrer-checker-worklet-script.sub.js',
location.href);
}
if (scriptOrigins.topLevel === 'remote' &&
scriptOrigins.descendant === 'same') {
url = new URL(
get_host_info().HTTPS_REMOTE_ORIGIN +
'/worklets/resources/' +
'import-same-origin-referrer-checker-worklet-script-from-remote-origin.sub.js');
return url;
}
if (scriptOrigins.topLevel === 'remote' &&
scriptOrigins.descendant === 'remote') {
return new URL(
Expand Down Expand Up @@ -88,6 +96,7 @@
}

const params = new URLSearchParams;
params.append('requestor_origin', document.location.origin);
params.append('referrer_policy', referrerPolicy);
params.append('expected_referrer', expectedReferrer);

Expand Down

0 comments on commit 98c8947

Please sign in to comment.