Commit 2aeae229 authored by Eriko Kurimoto's avatar Eriko Kurimoto Committed by Commit Bot

SharedWorker: Add shared-worker-options-credentials.html

This CL adds shared-worker-options-credentials.html for web-platform-test.

Bug: 1048966, 824646
Change-Id: Ib35daf5ba96ddd03bb1881757e86e8251c1a3456
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2037294
Commit-Queue: Eriko Kurimoto <elkurin@google.com>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738441}
parent 26a78d59
...@@ -52,7 +52,7 @@ function credentials_test(options, config, description) { ...@@ -52,7 +52,7 @@ function credentials_test(options, config, description) {
promise_test(async () => { promise_test(async () => {
let workerURL, origin = config.origin; let workerURL, origin = config.origin;
if (config.fetchType === 'top-level') { if (config.fetchType === 'top-level') {
workerURL = 'resources/credentials.py'; workerURL = 'resources/postmessage-credentials.py';
} else if (config.fetchType === 'descendant-static') { } else if (config.fetchType === 'descendant-static') {
workerURL = workerURL =
`resources/static-import-${origin}-origin-credentials-checker-worker.${origin === 'same' ? '' : 'sub.'}js`; `resources/static-import-${origin}-origin-credentials-checker-worker.${origin === 'same' ? '' : 'sub.'}js`;
......
// Import a remote origin script. // Import a remote origin script.
import('http://{{domains[www1]}}:{{ports[http][0]}}/workers/modules/resources/credentials.py'); const import_url =
'http://{{domains[www1]}}:{{ports[http][0]}}/workers/modules/resources/export-credentials.py';
if ('DedicatedWorkerGlobalScope' in self &&
self instanceof DedicatedWorkerGlobalScope) {
import(import_url)
.then(module => postMessage(module.cookie));
} else if (
'SharedWorkerGlobalScope' in self &&
self instanceof SharedWorkerGlobalScope) {
onconnect = e => {
import(import_url)
.then(module => e.ports[0].postMessage(module.cookie));
};
}
import('./credentials.py'); const import_url = './export-credentials.py';
if ('DedicatedWorkerGlobalScope' in self &&
self instanceof DedicatedWorkerGlobalScope) {
import(import_url)
.then(module => postMessage(module.cookie));
} else if (
'SharedWorkerGlobalScope' in self &&
self instanceof SharedWorkerGlobalScope) {
onconnect = e => {
import(import_url)
.then(module => e.ports[0].postMessage(module.cookie));
};
}
...@@ -11,4 +11,5 @@ def main(request, response): ...@@ -11,4 +11,5 @@ def main(request, response):
cookie_value = ''; cookie_value = '';
if cookie: if cookie:
cookie_value = cookie.value; cookie_value = cookie.value;
return (200, response_headers, "postMessage('"+cookie_value+"');") return (200, response_headers,
"export const cookie = '"+cookie_value+"';")
def main(request, response):
cookie = request.cookies.first("COOKIE_NAME", None)
response_headers = [("Content-Type", "text/javascript"),
("Access-Control-Allow-Credentials", "true")]
origin = request.headers.get("Origin", None)
if origin:
response_headers.append(("Access-Control-Allow-Origin", origin))
cookie_value = '';
if cookie:
cookie_value = cookie.value;
return (200, response_headers,
"if ('DedicatedWorkerGlobalScope' in self &&" +
" self instanceof DedicatedWorkerGlobalScope) {" +
" postMessage('"+cookie_value+"');" +
"} else if (" +
" 'SharedWorkerGlobalScope' in self &&" +
" self instanceof SharedWorkerGlobalScope) {" +
" onconnect = e => e.ports[0].postMessage('"+cookie_value+"');" +
"}")
// Import a remote origin script. // Import a remote origin script.
import 'http://{{domains[www1]}}:{{ports[http][0]}}/workers/modules/resources/credentials.py'; import * as module from 'http://{{domains[www1]}}:{{ports[http][0]}}/workers/modules/resources/export-credentials.py';
if ('DedicatedWorkerGlobalScope' in self &&
self instanceof DedicatedWorkerGlobalScope) {
postMessage(module.cookie);
} else if (
'SharedWorkerGlobalScope' in self &&
self instanceof SharedWorkerGlobalScope) {
onconnect = e => {
e.ports[0].postMessage(module.cookie);
};
}
import './credentials.py'; import * as module from './export-credentials.py';
if ('DedicatedWorkerGlobalScope' in self &&
self instanceof DedicatedWorkerGlobalScope) {
postMessage(module.cookie);
} else if (
'SharedWorkerGlobalScope' in self &&
self instanceof SharedWorkerGlobalScope) {
onconnect = e => {
e.ports[0].postMessage(module.cookie);
};
}
This is a testharness.js-based test.
PASS Test initialization: setting up cross-origin cookie
PASS new SharedWorker() with type=module and default credentials option should behave as credentials=same-origin and send the credentials
FAIL new SharedWorker() with type=module and credentials=omit should not send the credentials assert_equals: expected "" but got "1"
PASS new SharedWorker() with type=module and credentials=same-origin should send the credentials
PASS new SharedWorker() with type=module and credentials=include should send the credentials
PASS new SharedWorker() with type=module and default credentials option should behave as credentials=same-origin and send the credentials for same-origin static imports
FAIL new SharedWorker() with type=module and credentials=omit should not send the credentials for same-origin static imports assert_equals: expected "" but got "1"
PASS new SharedWorker() with type=module and credentials=same-origin should send the credentials for same-origin static imports
PASS new SharedWorker() with type=module and credentials=include should send the credentials for same-origin static imports
PASS new SharedWorker() with type=module and default credentials option should behave as credentials=same-origin and not send the credentials for cross-origin static imports
PASS new SharedWorker() with type=module and credentials=omit should not send the credentials for cross-origin static imports
PASS new SharedWorker() with type=module and credentials=same-origin should not send the credentials for cross-origin static imports
FAIL new SharedWorker() with type=module and credentials=include should send the credentials for cross-origin static imports assert_equals: expected "1" but got ""
PASS new SharedWorker() with type=module and default credentials option should behave as credentials=same-origin and send the credentials for same-origin dynamic imports
FAIL new SharedWorker() with type=module and credentials=omit should not send the credentials for same-origin dynamic imports assert_equals: expected "" but got "1"
PASS new SharedWorker() with type=module and credentials=same-origin should send the credentials for same-origin dynamic imports
PASS new SharedWorker() with type=module and credentials=include should send the credentials for same-origin dynamic imports
PASS new SharedWorker() with type=module and default credentials option should behave as credentials=same-origin and not send the credentials for cross-origin dynamic imports
PASS new SharedWorker() with type=module and credentials=omit should not send the credentials for cross-origin dynamic imports
PASS new SharedWorker() with type=module and credentials=same-origin should not send the credentials for cross-origin dynamic imports
FAIL new SharedWorker() with type=module and credentials=include should send the credentials for cross-origin dynamic imports assert_equals: expected "1" but got ""
PASS new SharedWorker() with type=classic should always send the credentials regardless of the credentials option (default).
PASS new SharedWorker() with type=classic should always send the credentials regardless of the credentials option (omit).
PASS new SharedWorker() with type=classic should always send the credentials regardless of the credentials option (same-origin).
PASS new SharedWorker() with type=classic should always send the credentials regardless of the credentials option (include).
PASS new SharedWorker() with type=classic should always send the credentials for same-origin dynamic imports regardless of the credentials option (default).
PASS new SharedWorker() with type=classic should always send the credentials for same-origin dynamic imports regardless of the credentials option (omit).
PASS new SharedWorker() with type=classic should always send the credentials for same-origin dynamic imports regardless of the credentials option (same-origin).
PASS new SharedWorker() with type=classic should always send the credentials for same-origin dynamic imports regardless of the credentials option (include).
PASS new SharedWorker() with type=classic should never send the credentials for cross-origin dynamic imports regardless of the credentials option (default).
PASS new SharedWorker() with type=classic should never send the credentials for cross-origin dynamic imports regardless of the credentials option (omit).
PASS new SharedWorker() with type=classic should never send the credentials for cross-origin dynamic imports regardless of the credentials option (same-origin).
PASS new SharedWorker() with type=classic should never send the credentials for cross-origin dynamic imports regardless of the credentials option (include).
Harness: the test ran to completion.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment