Skip to content

Commit

Permalink
Worker: Change the default credentials option from 'omit' to 'same-or…
Browse files Browse the repository at this point in the history
…igin'

This is a follow-up for the spec change:
whatwg/html#3656

Note that ES Modules for dedicated workers is still behind the flag and this
change doesn't affect applications in the real world.

Bug: 848247
Change-Id: I25083f3f11f9d13663e16e2f4c137095e9b12b01
Reviewed-on: https://chromium-review.googlesource.com/1080668
Reviewed-by: Matt Falkenhagen <[email protected]>
Commit-Queue: Hiroki Nakagawa <[email protected]>
Cr-Commit-Position: refs/heads/master@{#563465}
  • Loading branch information
nhiroki authored and chromium-wpt-export-bot committed Jun 1, 2018
1 parent 82b2789 commit 72c7cfe
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions workers/modules/dedicated-worker-options-credentials.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,68 @@
return 'COOKIE_VALUE';
assert_equals(options.type, 'module');

if (!options.credentials || options.credentials == 'omit')
return '';
if (options.credentials == 'same-origin' || options.credentials == 'include')
if (!options.credentials ||
options.credentials == 'same-origin' ||
options.credentials == 'include') {
return 'COOKIE_VALUE';
}
if (options.credentials == 'omit')
return '';
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);
function credentials_test(options, description) {
promise_test(async () => {
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);
// 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);
const expectedCookieValue = DetermineExpectedCookieValue(options);
assert_equals(msg_event.data, expectedCookieValue);
}, description);
}

// Tests for module scripts.

promise_test(() => runCredentialsTest({ type: 'module'}),
'new Worker() with the default credentials option should not send ' +
'the credentials');
credentials_test(
{ type: 'module'},
'new Worker() with the default credentials option should behave as ' +
'credentials=same-origin and send the credentials');

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

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

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

// Tests for classic scripts.

promise_test(() => runCredentialsTest({ type: 'classic' }),
credentials_test(
{ 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' }),
credentials_test(
{ 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' }),
credentials_test(
{ 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' }),
credentials_test(
{ credentials: 'include', type: 'classic' },
'new Worker() with type=classic should always send the credentials ' +
'regardless of the credentials option (include).');

Expand Down

0 comments on commit 72c7cfe

Please sign in to comment.