Skip to content

Commit

Permalink
Bug 1462278 [wpt PR 11040] - Worker: Add credentials tests for dedica…
Browse files Browse the repository at this point in the history
…ted workers, a=testonly

Automatic update from web-platform-testsWorker: Add credentials tests for dedicated workers

This CL adds web-platform-tests for the "credentials" option of WorkerOptions:
https://html.spec.whatwg.org/multipage/workers.html#workeroptions

The current spec defines that the default value of this option is "omit", but
there is an ongoing spec discussion to change it to "same-origin":
whatwg/html#3656

This CL adds the tests based on the current spec, and a subsequent CL will
update them based on the decision.

Bug: 843875
Change-Id: I50eb0c7971587b9d84865498d67abef8ed2d8fc6
Reviewed-on: https://chromium-review.googlesource.com/1063524
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Kouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#559888}

--

wpt-commits: d9a5af281709894851abcaff5c3af967dc0b474e
wpt-pr: 11040
  • Loading branch information
nhiroki authored and moz-wptsync-bot committed May 22, 2018
1 parent e0320d6 commit 1d9d378
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
28 changes: 28 additions & 0 deletions testing/web-platform/meta/MANIFEST.json
Original file line number Diff line number Diff line change
Expand Up @@ -302119,6 +302119,16 @@
{}
]
],
"workers/modules/dedicated-worker-options-credentials.html.headers": [
[
{}
]
],
"workers/modules/resources/credentials.py": [
[
{}
]
],
"workers/modules/resources/dynamic-import-and-then-static-import-worker.js": [
[
{}
Expand Down Expand Up @@ -378188,6 +378198,12 @@
{}
]
],
"workers/modules/dedicated-worker-options-credentials.html": [
[
"/workers/modules/dedicated-worker-options-credentials.html",
{}
]
],
"workers/modules/dedicated-worker-options-type.html": [
[
"/workers/modules/dedicated-worker-options-type.html",
Expand Down Expand Up @@ -621097,10 +621113,22 @@
"b9f5a7a0384ac3f34c48f32a378b758880f59b06",
"testharness"
],
"workers/modules/dedicated-worker-options-credentials.html": [
"1d6a1629f81d26efcd05bf1c7d40011609238f4f",
"testharness"
],
"workers/modules/dedicated-worker-options-credentials.html.headers": [
"0de4f6326452e016161eabf248e047253507b79d",
"support"
],
"workers/modules/dedicated-worker-options-type.html": [
"9f6f1be759beb885e2baa746e36ace83685f649b",
"testharness"
],
"workers/modules/resources/credentials.py": [
"62927510808ddb19a3e6fb11df3d894b3696c2b8",
"support"
],
"workers/modules/resources/dynamic-import-and-then-static-import-worker.js": [
"f4df69196f64cd81e92705186325004ac94db659",
"support"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!DOCTYPE html>
<title>DedicatedWorker: WorkerOptions 'credentials'</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>

// Determines the expected cookie value to be reported by a dedicated worker
// based on the given option. The worker reports an empty string as the actual
// cookie value if the cookie wasn't sent to the server. Otherwise, it's the
// value set by the headers file:
// "dedicated-worker-options-credentials.html.headers"
function DetermineExpectedCookieValue(options) {
// Classic script loading should always send credentials regardless of the
// 'credentials' option because the spec says the option takes effect only
// for module script loading.
if (options.type == 'classic')
return 'COOKIE_VALUE';
assert_equals(options.type, 'module');

if (!options.credentials || options.credentials == 'omit')
return '';
if (options.credentials == 'same-origin' || options.credentials == 'include')
return 'COOKIE_VALUE';
assert_unreached('Invalid credentials option was specified: ' +
options.credentials);
}

// Runs a credentials test with the given WorkerOptions.
async function runCredentialsTest(options) {
const worker = new Worker('resources/credentials.py', options);

// Wait until the worker sends the actual cookie value.
const msg_event = await new Promise(resolve => worker.onmessage = resolve);

const expectedCookieValue = DetermineExpectedCookieValue(options);
assert_equals(msg_event.data, expectedCookieValue);
}

// Tests for module scripts.

promise_test(() => runCredentialsTest({ type: 'module'}),
'new Worker() with the default credentials option should not send ' +
'the credentials');

promise_test(() => runCredentialsTest({ credentials: 'omit',
type: 'module' }),
'new Worker() with credentials=omit should not send the credentials');

promise_test(() => runCredentialsTest({ credentials: 'same-origin',
type: 'module' }),
'new Worker() with credentials=same-origin should send the credentials');

promise_test(() => runCredentialsTest({ credentials: 'include',
type: 'module' }),
'new Worker() with credentials=include should send the credentials');

// Tests for classic scripts.

promise_test(() => runCredentialsTest({ type: 'classic' }),
'new Worker() with type=classic should always send the credentials ' +
'regardless of the credentials option (default).');

promise_test(() => runCredentialsTest({ credentials: 'omit',
type: 'classic' }),
'new Worker() with type=classic should always send the credentials ' +
'regardless of the credentials option (omit).');

promise_test(() => runCredentialsTest({ credentials: 'same-origin',
type: 'classic' }),
'new Worker() with type=classic should always send the credentials ' +
'regardless of the credentials option (same-origin).');

promise_test(() => runCredentialsTest({ credentials: 'include',
type: 'classic' }),
'new Worker() with type=classic should always send the credentials ' +
'regardless of the credentials option (include).');

</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Set-Cookie: COOKIE_NAME=COOKIE_VALUE
Access-Control-Allow-Credentials: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def main(request, response):
cookie = request.cookies.first("COOKIE_NAME", None)

response_headers = [("Content-Type", "text/javascript"),
("Access-Control-Allow-Credentials", "true")]

cookie_value = '';
if cookie:
cookie_value = cookie.value;
return (200, response_headers, "postMessage('"+cookie_value+"');")

0 comments on commit 1d9d378

Please sign in to comment.