-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Worker: 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
- Loading branch information
1 parent
b47939b
commit fa1b281
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!DOCTYPE html> | ||
<title>DedicatedWorker: WorkerOptions 'credentials'</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
|
||
// Run a credentials test with the given 'credentials' option. | ||
async function runCredentialsTest(credentials_option) { | ||
// Start a dedicated worker with the 'credentials' option if specified. The | ||
// 'type' option must be 'module' because the spec defines the 'credentials' | ||
// option takes effect only for module workers. | ||
let options = { type: 'module' }; | ||
if (credentials_option) | ||
options.credentials = credentials_option; | ||
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); | ||
|
||
// The worker sends 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"). | ||
let expectedCookieValue = ''; | ||
if (credentials_option == 'same-origin' || credentials_option == 'include') | ||
expectedCookieValue = 'COOKIE_VALUE'; | ||
assert_equals(msg_event.data, expectedCookieValue); | ||
} | ||
|
||
promise_test(() => runCredentialsTest(null), | ||
'new Worker() with the default credentials option should not send ' + | ||
'the credentials'); | ||
|
||
promise_test(() => runCredentialsTest('omit'), | ||
'new Worker() with credentials=omit should not send the credentials'); | ||
|
||
promise_test(() => runCredentialsTest('same-origin'), | ||
'new Worker() with credentials=same-origin should send the credentials'); | ||
|
||
promise_test(() => runCredentialsTest('include'), | ||
'new Worker() with credentials=include should send the credentials'); | ||
|
||
</script> |
2 changes: 2 additions & 0 deletions
2
workers/modules/dedicated-worker-options-credentials.html.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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+"');") |