Truly independent web browser
LibWeb: Honor the credentials option for module workers
Shannon Boothe1c6c4b70642
diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Libraries/LibWeb/HTML/Scripting/Fetching.cppindex 28890aab7d6..af22ad90687 100644--- a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp+++ b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp@@ -973,9 +973,9 @@ WebIDL::ExceptionOr<GC::Ref<ClassicScript>> fetch_a_classic_worker_imported_scri}// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree-WebIDL::ExceptionOr<void> fetch_module_worker_script_graph(URL::URL const& url, FetchClient const& fetch_client, Fetch::Infrastructure::Request::Destination destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook perform_fetch, OnFetchScriptComplete on_complete)+WebIDL::ExceptionOr<void> fetch_module_worker_script_graph(URL::URL const& url, FetchClient const& fetch_client, Fetch::Infrastructure::Request::Destination destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook perform_fetch, OnFetchScriptComplete on_complete, Fetch::Infrastructure::Request::CredentialsMode credentials_mode){- return fetch_worklet_module_worker_script_graph(url, fetch_client, destination, settings_object, move(perform_fetch), move(on_complete));+ return fetch_worklet_module_worker_script_graph(url, fetch_client, destination, settings_object, move(perform_fetch), move(on_complete), credentials_mode);}// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-worklet/module-worker-script-graphdiff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.h b/Libraries/LibWeb/HTML/Scripting/Fetching.hindex dfc6c231db2..a1a227be7f8 100644--- a/Libraries/LibWeb/HTML/Scripting/Fetching.h+++ b/Libraries/LibWeb/HTML/Scripting/Fetching.h@@ -69,7 +69,7 @@ void set_up_module_script_request(Fetch::Infrastructure::Request&, ScriptFetchOpvoid fetch_classic_script(GC::Ref<HTMLScriptElement>, URL::URL const&, EnvironmentSettingsObject& settings_object, ScriptFetchOptions options, CORSSettingAttribute cors_setting, Utf16String character_encoding, OnFetchScriptComplete on_complete);WEB_API WebIDL::ExceptionOr<void> fetch_classic_worker_script(URL::URL const&, FetchClient const& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete);WebIDL::ExceptionOr<GC::Ref<ClassicScript>> fetch_a_classic_worker_imported_script(URL::URL const&, HTML::EnvironmentSettingsObject&, PerformTheFetchHook = nullptr);-WEB_API WebIDL::ExceptionOr<void> fetch_module_worker_script_graph(URL::URL const&, FetchClient const& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete);+WEB_API WebIDL::ExceptionOr<void> fetch_module_worker_script_graph(URL::URL const&, FetchClient const& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete, Fetch::Infrastructure::Request::CredentialsMode = Fetch::Infrastructure::Request::CredentialsMode::SameOrigin);WebIDL::ExceptionOr<void> fetch_worklet_module_worker_script_graph(URL::URL const&, FetchClient const& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete, Fetch::Infrastructure::Request::CredentialsMode = Fetch::Infrastructure::Request::CredentialsMode::SameOrigin);void fetch_external_module_script_graph(JS::Realm&, URL::URL const&, EnvironmentSettingsObject& settings_object, ScriptFetchOptions const&, OnFetchScriptComplete on_complete);void fetch_modulepreload_module_script_graph(JS::Realm&, URL::URL const&, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, ScriptFetchOptions const&, OnFetchScriptComplete on_complete);diff --git a/Services/WebWorker/WorkerHost.cpp b/Services/WebWorker/WorkerHost.cppindex 134e8297e90..260dc080cab 100644--- a/Services/WebWorker/WorkerHost.cpp+++ b/Services/WebWorker/WorkerHost.cpp@@ -336,8 +336,7 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataEncoder mes// Fetch a module worker script graph given url, outside settings, destination, the value of the credentials// member of options, inside settings, and with onComplete and performFetch as defined below.VERIFY(m_type == Web::HTML::WorkerType::Module);- // FIXME: Pass credentials- if (auto err = Web::HTML::fetch_module_worker_script_graph(m_url, outside_settings, destination, inside_settings, perform_fetch, on_complete); err.is_error()) {+ if (auto err = Web::HTML::fetch_module_worker_script_graph(m_url, outside_settings, destination, inside_settings, perform_fetch, on_complete, static_cast<Web::Fetch::Infrastructure::Request::CredentialsMode>(credentials)); err.is_error()) {dbgln("Failed to run worker script");// FIXME: Abort the worker properlyTODO();diff --git a/Tests/LibWeb/Text/expected/wpt-import/workers/modules/dedicated-worker-options-credentials.txt b/Tests/LibWeb/Text/expected/wpt-import/workers/modules/dedicated-worker-options-credentials.txtnew file mode 100644index 00000000000..8259f43bc49--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/workers/modules/dedicated-worker-options-credentials.txt@@ -0,0 +1,39 @@+Harness status: OK++Found 33 tests++31 Pass+2 Fail+Pass Test initialization: setting up cross-origin cookie+Pass new Worker() with type=module and default credentials option should behave as credentials=same-origin and send the credentials+Pass new Worker() with type=module and credentials=omit should not send the credentials+Pass new Worker() with type=module and credentials=same-origin should send the credentials+Pass new Worker() with type=module and credentials=include should send the credentials+Pass new Worker() with type=module and default credentials option should behave as credentials=same-origin and send the credentials for same-origin static imports+Pass new Worker() with type=module and credentials=omit should not send the credentials for same-origin static imports+Pass new Worker() with type=module and credentials=same-origin should send the credentials for same-origin static imports+Pass new Worker() with type=module and credentials=include should send the credentials for same-origin static imports+Pass new Worker() 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 Worker() with type-module credentials=omit should not send the credentials for cross-origin static imports+Pass new Worker() with type=module and credentials=same-origin should not send the credentials for cross-origin static imports+Fail new Worker() with type=module and credentials=include should send the credentials for cross-origin static imports+Pass new Worker() with type=module and default credentials option should behave as credentials=same-origin and send the credentials for same-origin dynamic imports+Pass new Worker() with type=module and credentials=omit should not send the credentials for same-origin dynamic imports+Pass new Worker() with type=module and credentials=same-origin should send the credentials for same-origin dynamic imports+Pass new Worker() with type=module and credentials=include should send the credentials for same-origin dynamic imports+Pass new Worker() 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 Worker() with type-module credentials=omit should not send the credentials for cross-origin dynamic imports+Pass new Worker() with type=module and credentials=same-origin should not send the credentials for cross-origin dynamic imports+Fail new Worker() with type=module and credentials=include should send the credentials for cross-origin dynamic imports+Pass new Worker() with type=classic should always send the credentials regardless of the credentials option (default).+Pass new Worker() with type=classic should always send the credentials regardless of the credentials option (omit).+Pass new Worker() with type=classic should always send the credentials regardless of the credentials option (same-origin).+Pass new Worker() with type=classic should always send the credentials regardless of the credentials option (include).+Pass new Worker() with type=classic should always send the credentials for same-origin dynamic imports regardless of the credentials option (default).+Pass new Worker() with type=classic should always send the credentials for same-origin dynamic imports regardless of the credentials option (omit).+Pass new Worker() with type=classic should always send the credentials for same-origin dynamic imports regardless of the credentials option (same-origin).+Pass new Worker() with type=classic should always send the credentials for same-origin dynamic imports regardless of the credentials option (include).+Pass new Worker() with type=classic should never send the credentials for cross-origin dynamic imports regardless of the credentials option (default).+Pass new Worker() with type=classic should never send the credentials for cross-origin dynamic imports regardless of the credentials option (omit).+Pass new Worker() with type=classic should never send the credentials for cross-origin dynamic imports regardless of the credentials option (same-origin).+Pass new Worker() with type=classic should never send the credentials for cross-origin dynamic imports regardless of the credentials option (include).\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/workers/modules/shared-worker-options-credentials.txt b/Tests/LibWeb/Text/expected/wpt-import/workers/modules/shared-worker-options-credentials.txtnew file mode 100644index 00000000000..5e3073fd631--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/workers/modules/shared-worker-options-credentials.txt@@ -0,0 +1,39 @@+Harness status: OK++Found 33 tests++31 Pass+2 Fail+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+Pass new SharedWorker() with type=module and credentials=omit should not send the credentials+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+Pass new SharedWorker() with type=module and credentials=omit should not send the credentials for same-origin static imports+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+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+Pass new SharedWorker() with type=module and credentials=omit should not send the credentials for same-origin dynamic imports+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+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).\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/cookies/resources/set-cookie.py b/Tests/LibWeb/Text/input/wpt-import/cookies/resources/set-cookie.pynew file mode 100644index 00000000000..59b5b8006a0--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/cookies/resources/set-cookie.py@@ -0,0 +1,45 @@+from datetime import date++def main(request, response):+ """+ Returns cookie name and path from query params in a Set-Cookie header.++ e.g.++ > GET /cookies/resources/set-cookie.py?name=match-slash&path=%2F HTTP/1.1+ > Host: localhost:8000+ > User-Agent: curl/7.43.0+ > Accept: */*+ >+ < HTTP/1.1 200 OK+ < Content-Type: application/json+ < Set-Cookie: match-slash=1; Path=/; Expires=09 Jun 2021 10:18:14 GMT+ < Server: BaseHTTP/0.3 Python/2.7.12+ < Date: Tue, 04 Oct 2016 18:16:06 GMT+ < Content-Length: 80+ """++ name = request.GET[b'name']+ path = request.GET[b'path']+ samesite = request.GET.get(b'samesite')+ secure = b'secure' in request.GET+ expiry_year = date.today().year + 1+ cookie = b"%s=1; Path=%s; Expires=09 Jun %d 10:18:14 GMT" % (name, path, expiry_year)+ if samesite:+ cookie += b";SameSite=%s" % samesite+ if secure:+ cookie += b";Secure"++ headers = [+ (b"Content-Type", b"application/json"),+ (b"Set-Cookie", cookie)+ ]++ # Set the cors enabled headers.+ origin = request.headers.get(b"Origin")+ if origin is not None and origin != b"null":+ headers.append((b"Access-Control-Allow-Origin", origin))+ headers.append((b"Access-Control-Allow-Credentials", 'true'))++ body = b"var dummy='value';"+ return headers, bodydiff --git a/Tests/LibWeb/Text/input/wpt-import/workers/modules/dedicated-worker-options-credentials.html b/Tests/LibWeb/Text/input/wpt-import/workers/modules/dedicated-worker-options-credentials.htmlnew file mode 100644index 00000000000..13218fcc29c--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/workers/modules/dedicated-worker-options-credentials.html@@ -0,0 +1,304 @@+<!DOCTYPE html>+<title>DedicatedWorker: WorkerOptions 'credentials'</title>+<meta name="timeout" content="long">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../common/get-host-info.sub.js"></script>+<script>+host_info = get_host_info();++// 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, config) {+ // Valid WorkerOptions and test config checking.+ if (config.origin !== 'same' && config.origin !== 'remote')+ assert_unreached('Invalid config.origin was specified: ' + config.origin);+ if (options.credentials && options.credentials !== 'omit' &&+ options.credentials !== 'same-origin' &&+ options.credentials !== 'include') {+ assert_unreached('Invalid credentials option was specified: ' ++ options.credentials);+ }+ if (options.type !== 'classic' && options.type !== 'module')+ assert_unreached('Invalid type option was specified: ' + options.type);++ if (options.type === 'classic')+ return (config.origin === 'same') ? '1' : '';++ if (options.credentials === 'omit')+ return '';+ else if (options.credentials === 'include')+ return '1';+ else+ return (config.origin === 'same') ? '1' : '';+}++// Runs a credentials test with the given WorkerOptions.+//+// |options| is a WorkerOptions dict.+// |config| has options as follows:+//+// config = {+// fetchType: 'top-level' or 'descendant-static' or 'descendant-dynamic'+// origin: 'remote' or 'same'+// };+//+// - |config.fetchType| indicates the type of script to load for the test.+// - |config.origin| indicates same-origin-ness of the script to load.+function credentials_test(options, config, description) {+ promise_test(async () => {+ let workerURL, origin = config.origin;+ if (config.fetchType === 'top-level') {+ workerURL = 'resources/postmessage-credentials.py';+ } else if (config.fetchType === 'descendant-static') {+ workerURL =+ `resources/static-import-${origin}-origin-credentials-checker-worker.${origin === 'same' ? '' : 'sub.'}js`;+ } else if (config.fetchType === 'descendant-dynamic') {+ workerURL =+ `resources/dynamic-import-${origin}-origin-credentials-checker-worker.${origin === 'same' ? '' : 'sub.'}js`;+ } else {+ assert_unreached('Invalid config.fetchType: ' + config.fetchType);+ }++ const worker = new Worker(workerURL, options);++ // Wait until the worker sends the actual cookie value.+ const msg_event = await new Promise(resolve => worker.onmessage = resolve);++ const expectedCookieValue = DetermineExpectedCookieValue(options, config);+ assert_equals(msg_event.data, expectedCookieValue);+ }, description);+}++function init() {+ // Same-origin cookie is set up in the .headers file in this directory.+ promise_test(async () => {+ return fetch(+ `${host_info.HTTP_REMOTE_ORIGIN}/cookies/resources/set-cookie.py?name=COOKIE_NAME&path=/workers/modules/`,+ {+ mode: 'no-cors',+ credentials: 'include'+ });+ }, 'Test initialization: setting up cross-origin cookie');+}++init();++// Tests for module workers.++credentials_test(+ { type: 'module' },+ { fetchType: 'top-level', origin: 'same' },+ 'new Worker() with type=module and default credentials option should ' ++ 'behave as credentials=same-origin and send the credentials');++credentials_test(+ { credentials: 'omit', type: 'module' },+ { fetchType: 'top-level', origin: 'same' },+ 'new Worker() with type=module and credentials=omit should not send the ' ++ 'credentials');++credentials_test(+ { credentials: 'same-origin', type: 'module' },+ { fetchType: 'top-level', origin: 'same' },+ 'new Worker() with type=module and credentials=same-origin should send ' ++ 'the credentials');++credentials_test(+ { credentials: 'include', type: 'module' },+ { fetchType: 'top-level', origin: 'same' },+ 'new Worker() with type=module and credentials=include should send the ' ++ 'credentials');++// Tests for module worker static imports.++credentials_test(+ { type: 'module' },+ { fetchType: 'descendant-static', origin: 'same' },+ 'new Worker() with type=module and default credentials option should ' ++ 'behave as credentials=same-origin and send the credentials for ' ++ 'same-origin static imports');++credentials_test(+ { credentials: 'omit', type: 'module' },+ { fetchType: 'descendant-static', origin: 'same' },+ 'new Worker() with type=module and credentials=omit should not send the ' ++ 'credentials for same-origin static imports');++credentials_test(+ { credentials: 'same-origin', type: 'module' },+ { fetchType: 'descendant-static', origin: 'same' },+ 'new Worker() with type=module and credentials=same-origin should send ' ++ 'the credentials for same-origin static imports');++credentials_test(+ { credentials: 'include', type: 'module' },+ { fetchType: 'descendant-static', origin: 'same' },+ 'new Worker() with type=module and credentials=include should send the ' ++ 'credentials for same-origin static imports');++credentials_test(+ { type: 'module' },+ { fetchType: 'descendant-static', origin: 'remote' },+ 'new Worker() with type=module and default credentials option should ' ++ 'behave as credentials=same-origin and not send the credentials for ' ++ 'cross-origin static imports');++credentials_test(+ { credentials: 'omit', type: 'module' },+ { fetchType: 'descendant-static', origin: 'remote' },+ 'new Worker() with type-module credentials=omit should not send the ' ++ 'credentials for cross-origin static imports');++credentials_test(+ { credentials: 'same-origin', type: 'module' },+ { fetchType: 'descendant-static', origin: 'remote' },+ 'new Worker() with type=module and credentials=same-origin should not ' ++ 'send the credentials for cross-origin static imports');++credentials_test(+ { credentials: 'include', type: 'module' },+ { fetchType: 'descendant-static', origin: 'remote' },+ 'new Worker() with type=module and credentials=include should send the ' ++ 'credentials for cross-origin static imports');++// Tests for module worker dynamic imports.++credentials_test(+ { type: 'module' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new Worker() with type=module and default credentials option should ' ++ 'behave as credentials=same-origin and send the credentials for ' ++ 'same-origin dynamic imports');++credentials_test(+ { credentials: 'omit', type: 'module' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new Worker() with type=module and credentials=omit should not send the ' ++ 'credentials for same-origin dynamic imports');++credentials_test(+ { credentials: 'same-origin', type: 'module' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new Worker() with type=module and credentials=same-origin should send ' ++ 'the credentials for same-origin dynamic imports');++credentials_test(+ { credentials: 'include', type: 'module' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new Worker() with type=module and credentials=include should send the ' ++ 'credentials for same-origin dynamic imports');++credentials_test(+ { type: 'module'},+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ 'new Worker() with type=module and default credentials option should ' ++ 'behave as credentials=same-origin and not send the credentials for ' ++ 'cross-origin dynamic imports');++credentials_test(+ { credentials: 'omit', type: 'module' },+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ 'new Worker() with type-module credentials=omit should not send the ' ++ 'credentials for cross-origin dynamic imports');++credentials_test(+ { credentials: 'same-origin', type: 'module' },+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ 'new Worker() with type=module and credentials=same-origin should not ' ++ 'send the credentials for cross-origin dynamic imports');++credentials_test(+ { credentials: 'include', type: 'module' },+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ 'new Worker() with type=module and credentials=include should send the ' ++ 'credentials for cross-origin dynamic imports');++// Tests for classic workers.+// TODO(domfarolino): Maybe move classic worker tests up a directory?++credentials_test(+ { type: 'classic' },+ { fetchType: 'top-level', origin: 'same' },+ 'new Worker() with type=classic should always send the credentials ' ++ 'regardless of the credentials option (default).');++credentials_test(+ { credentials: 'omit', type: 'classic' },+ { fetchType: 'top-level', origin: 'same' },+ 'new Worker() with type=classic should always send the credentials ' ++ 'regardless of the credentials option (omit).');++credentials_test(+ { credentials: 'same-origin', type: 'classic' },+ { fetchType: 'top-level', origin: 'same' },+ 'new Worker() with type=classic should always send the credentials ' ++ 'regardless of the credentials option (same-origin).');++credentials_test(+ { credentials: 'include', type: 'classic' },+ { fetchType: 'top-level', origin: 'same' },+ 'new Worker() with type=classic should always send the credentials ' ++ 'regardless of the credentials option (include).');++// Tests for classic worker dynamic imports.++credentials_test(+ { type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new Worker() with type=classic should always send the credentials for ' ++ 'same-origin dynamic imports regardless of the credentials option ' ++ '(default).');++credentials_test(+ { credentials: 'omit', type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new Worker() with type=classic should always send the credentials for ' ++ 'same-origin dynamic imports regardless of the credentials option (omit).');++credentials_test(+ { credentials: 'same-origin', type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new Worker() with type=classic should always send the credentials for ' ++ 'same-origin dynamic imports regardless of the credentials option ' ++ '(same-origin).');++credentials_test(+ { credentials: 'include', type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new Worker() with type=classic should always send the credentials for ' ++ 'same-origin dynamic imports regardless of the credentials option ' ++ '(include).');++credentials_test(+ { type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ 'new Worker() with type=classic should never send the credentials for ' ++ 'cross-origin dynamic imports regardless of the credentials option ' ++ '(default).');++credentials_test(+ { credentials: 'omit', type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ 'new Worker() with type=classic should never send the credentials for ' ++ 'cross-origin dynamic imports regardless of the credentials option ' ++ '(omit).');++credentials_test(+ { credentials: 'same-origin', type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ 'new Worker() with type=classic should never send the credentials for ' ++ 'cross-origin dynamic imports regardless of the credentials option ' ++ '(same-origin).');++credentials_test(+ { credentials: 'include', type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ 'new Worker() with type=classic should never send the credentials for ' ++ 'cross-origin dynamic imports regardless of the credentials option ' ++ '(include).');++</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/workers/modules/dedicated-worker-options-credentials.html.headers b/Tests/LibWeb/Text/input/wpt-import/workers/modules/dedicated-worker-options-credentials.html.headersnew file mode 100644index 00000000000..8da851ab736--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/workers/modules/dedicated-worker-options-credentials.html.headers@@ -0,0 +1,2 @@+Set-Cookie: COOKIE_NAME=1+Access-Control-Allow-Credentials: truediff --git a/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/dynamic-import-remote-origin-credentials-checker-worker.sub.js b/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/dynamic-import-remote-origin-credentials-checker-worker.sub.jsnew file mode 100644index 00000000000..3cfbe7c6e4c--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/dynamic-import-remote-origin-credentials-checker-worker.sub.js@@ -0,0 +1,15 @@+// Import a remote origin script.+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));+ };+}diff --git a/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/dynamic-import-same-origin-credentials-checker-worker.js b/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/dynamic-import-same-origin-credentials-checker-worker.jsnew file mode 100644index 00000000000..24dbd551280--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/dynamic-import-same-origin-credentials-checker-worker.js@@ -0,0 +1,13 @@+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));+ };+}diff --git a/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/export-credentials.py b/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/export-credentials.pynew file mode 100644index 00000000000..3d0ba778d13--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/export-credentials.py@@ -0,0 +1,15 @@+def main(request, response):+ cookie = request.cookies.first(b"COOKIE_NAME", None)++ response_headers = [(b"Content-Type", b"text/javascript"),+ (b"Access-Control-Allow-Credentials", b"true")]++ origin = request.headers.get(b"Origin", None)+ if origin:+ response_headers.append((b"Access-Control-Allow-Origin", origin))++ cookie_value = b'';+ if cookie:+ cookie_value = cookie.value;+ return (200, response_headers,+ b"export const cookie = '"+cookie_value+b"';")diff --git a/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/postmessage-credentials.py b/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/postmessage-credentials.pynew file mode 100644index 00000000000..a054a1a923c--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/postmessage-credentials.py@@ -0,0 +1,22 @@+def main(request, response):+ cookie = request.cookies.first(b"COOKIE_NAME", None)++ response_headers = [(b"Content-Type", b"text/javascript"),+ (b"Access-Control-Allow-Credentials", b"true")]++ origin = request.headers.get(b"Origin", None)+ if origin:+ response_headers.append((b"Access-Control-Allow-Origin", origin))++ cookie_value = b'';+ if cookie:+ cookie_value = cookie.value;+ return (200, response_headers,+ b"if ('DedicatedWorkerGlobalScope' in self &&" ++ b" self instanceof DedicatedWorkerGlobalScope) {" ++ b" postMessage('"+cookie_value+b"');" ++ b"} else if (" ++ b" 'SharedWorkerGlobalScope' in self &&" ++ b" self instanceof SharedWorkerGlobalScope) {" ++ b" onconnect = e => e.ports[0].postMessage('"+cookie_value+b"');" ++ b"}")diff --git a/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/static-import-remote-origin-credentials-checker-worker.sub.js b/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/static-import-remote-origin-credentials-checker-worker.sub.jsnew file mode 100644index 00000000000..c543cb49616--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/static-import-remote-origin-credentials-checker-worker.sub.js@@ -0,0 +1,12 @@+// Import a remote origin script.+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);+ };+}diff --git a/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/static-import-same-origin-credentials-checker-worker.js b/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/static-import-same-origin-credentials-checker-worker.jsnew file mode 100644index 00000000000..e83dc92070f--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/workers/modules/resources/static-import-same-origin-credentials-checker-worker.js@@ -0,0 +1,11 @@+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);+ };+}diff --git a/Tests/LibWeb/Text/input/wpt-import/workers/modules/shared-worker-options-credentials.html b/Tests/LibWeb/Text/input/wpt-import/workers/modules/shared-worker-options-credentials.htmlnew file mode 100644index 00000000000..aca320a4b20--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/workers/modules/shared-worker-options-credentials.html@@ -0,0 +1,309 @@+<!DOCTYPE html>+<title>SharedWorker: WorkerOptions 'credentials'</title>+<meta name="timeout" content="long">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../common/get-host-info.sub.js"></script>+<script>+host_info = get_host_info();++// Determines the expected cookie value to be reported by a shared 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:+// "shared-worker-options-credentials.html.headers"+function DetermineExpectedCookieValue(options, config) {+ // Valid WorkerOptions and test config checking.+ if (config.origin !== 'same' && config.origin !== 'remote')+ assert_unreached('Invalid config.origin was specified: ' + config.origin);+ if (options.credentials && options.credentials !== 'omit' &&+ options.credentials !== 'same-origin' &&+ options.credentials !== 'include') {+ assert_unreached('Invalid credentials option was specified: ' ++ options.credentials);+ }+ if (options.type !== 'classic' && options.type !== 'module')+ assert_unreached('Invalid type option was specified: ' + options.type);++ if (options.type === 'classic')+ return (config.origin === 'same') ? '1' : '';++ if (options.credentials === 'omit')+ return '';+ else if (options.credentials === 'include')+ return '1';+ else+ return (config.origin === 'same') ? '1' : '';+}++// Runs a credentials test with the given WorkerOptions.+//+// |options| is a WorkerOptions dict.+// |config| has options as follows:+//+// config = {+// fetchType: 'top-level' or 'descendant-static' or 'descendant-dynamic'+// origin: 'remote' or 'same'+// };+//+// - |config.fetchType| indicates the type of script to load for the test.+// - |config.origin| indicates same-origin-ness of the script to load.+function credentials_test(options, config, description) {+ promise_test(async () => {+ let workerURL, origin = config.origin;+ if (config.fetchType === 'top-level') {+ workerURL = 'resources/postmessage-credentials.py';+ } else if (config.fetchType === 'descendant-static') {+ workerURL =+ `resources/static-import-${origin}-origin-credentials-checker-worker.${origin === 'same' ? '' : 'sub.'}js`;+ } else if (config.fetchType === 'descendant-dynamic') {+ workerURL =+ `resources/dynamic-import-${origin}-origin-credentials-checker-worker.${origin === 'same' ? '' : 'sub.'}js`;+ } else {+ assert_unreached('Invalid config.fetchType: ' + config.fetchType);+ }++ // Name idetically for each test cases so that it connects to the shared+ // worker with specified type and credentials.+ options.name = `${options.type}_${options.credentials || 'default'}_${config.fetchType}_${config.origin}`;++ const worker = new SharedWorker(workerURL, options);++ // Wait until the worker sends the actual cookie value.+ const msg_event = await new Promise(resolve => worker.port.onmessage = resolve);++ const expectedCookieValue = DetermineExpectedCookieValue(options, config);+ assert_equals(msg_event.data, expectedCookieValue);+ }, description);+}++function init() {+ // Same-origin cookie is set up in the .headers file in this directory.+ promise_test(async () => {+ return fetch(+ `${host_info.HTTP_REMOTE_ORIGIN}/cookies/resources/set-cookie.py?name=COOKIE_NAME&path=/workers/modules/`,+ {+ mode: 'no-cors',+ credentials: 'include'+ });+ }, 'Test initialization: setting up cross-origin cookie');+}++init();++// Tests for module workers.++credentials_test(+ { type: 'module' },+ { fetchType: 'top-level', origin: 'same' },+ 'new SharedWorker() with type=module and default credentials option ' ++ 'should behave as credentials=same-origin and send the credentials');++credentials_test(+ { credentials: 'omit', type: 'module' },+ { fetchType: 'top-level', origin: 'same' },+ 'new SharedWorker() with type=module and credentials=omit should not ' ++ 'send the credentials');++credentials_test(+ { credentials: 'same-origin', type: 'module' },+ { fetchType: 'top-level', origin: 'same' },+ 'new SharedWorker() with type=module and credentials=same-origin should ' ++ 'send the credentials');++credentials_test(+ { credentials: 'include', type: 'module' },+ { fetchType: 'top-level', origin: 'same' },+ 'new SharedWorker() with type=module and credentials=include should send ' ++ 'the credentials');++// Tests for module worker static imports.++credentials_test(+ { type: 'module' },+ { fetchType: 'descendant-static', origin: 'same' },+ 'new SharedWorker() with type=module and default credentials option ' ++ 'should behave as credentials=same-origin and send the credentials for ' ++ 'same-origin static imports');++credentials_test(+ { credentials: 'omit', type: 'module' },+ { fetchType: 'descendant-static', origin: 'same' },+ 'new SharedWorker() with type=module and credentials=omit should not ' ++ 'send the credentials for same-origin static imports');++credentials_test(+ { credentials: 'same-origin', type: 'module' },+ { fetchType: 'descendant-static', origin: 'same' },+ 'new SharedWorker() with type=module and credentials=same-origin should ' ++ 'send the credentials for same-origin static imports');++credentials_test(+ { credentials: 'include', type: 'module' },+ { fetchType: 'descendant-static', origin: 'same' },+ 'new SharedWorker() with type=module and credentials=include should send ' ++ 'the credentials for same-origin static imports');++credentials_test(+ { type: 'module' },+ { fetchType: 'descendant-static', origin: 'remote' },+ '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');++credentials_test(+ { credentials: 'omit', type: 'module' },+ { fetchType: 'descendant-static', origin: 'remote' },+ 'new SharedWorker() with type=module and credentials=omit should not ' ++ 'send the credentials for cross-origin static imports');++credentials_test(+ { credentials: 'same-origin', type: 'module' },+ { fetchType: 'descendant-static', origin: 'remote' },+ 'new SharedWorker() with type=module and credentials=same-origin should ' ++ 'not send the credentials for cross-origin static imports');++credentials_test(+ { credentials: 'include', type: 'module' },+ { fetchType: 'descendant-static', origin: 'remote' },+ 'new SharedWorker() with type=module and credentials=include should send ' ++ 'the credentials for cross-origin static imports');++// Tests for module worker dynamic imports.++credentials_test(+ { type: 'module' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new SharedWorker() with type=module and default credentials option ' ++ 'should behave as credentials=same-origin and send the credentials for ' ++ 'same-origin dynamic imports');++credentials_test(+ { credentials: 'omit', type: 'module' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new SharedWorker() with type=module and credentials=omit should not ' ++ 'send the credentials for same-origin dynamic imports');++credentials_test(+ { credentials: 'same-origin', type: 'module' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new SharedWorker() with type=module and credentials=same-origin should ' ++ 'send the credentials for same-origin dynamic imports');++credentials_test(+ { credentials: 'include', type: 'module' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new SharedWorker() with type=module and credentials=include should send ' ++ 'the credentials for same-origin dynamic imports');++credentials_test(+ { type: 'module'},+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ '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');++credentials_test(+ { credentials: 'omit', type: 'module' },+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ 'new SharedWorker() with type=module and credentials=omit should not ' ++ 'send the credentials for cross-origin dynamic imports');++credentials_test(+ { credentials: 'same-origin', type: 'module' },+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ 'new SharedWorker() with type=module and credentials=same-origin should ' ++ 'not send the credentials for cross-origin dynamic imports');++credentials_test(+ { credentials: 'include', type: 'module' },+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ 'new SharedWorker() with type=module and credentials=include should send ' ++ 'the credentials for cross-origin dynamic imports');++// Tests for classic workers.+// TODO(domfarolino): Maybe move classic worker tests up a directory?++credentials_test(+ { type: 'classic' },+ { fetchType: 'top-level', origin: 'same' },+ 'new SharedWorker() with type=classic should always send the credentials ' ++ 'regardless of the credentials option (default).');++credentials_test(+ { credentials: 'omit', type: 'classic' },+ { fetchType: 'top-level', origin: 'same' },+ 'new SharedWorker() with type=classic should always send the credentials ' ++ 'regardless of the credentials option (omit).');++credentials_test(+ { credentials: 'same-origin', type: 'classic' },+ { fetchType: 'top-level', origin: 'same' },+ 'new SharedWorker() with type=classic should always send the credentials ' ++ 'regardless of the credentials option (same-origin).');++credentials_test(+ { credentials: 'include', type: 'classic' },+ { fetchType: 'top-level', origin: 'same' },+ 'new SharedWorker() with type=classic should always send the credentials ' ++ 'regardless of the credentials option (include).');++// Tests for classic worker dynamic imports.++credentials_test(+ { type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new SharedWorker() with type=classic should always send the credentials ' ++ 'for same-origin dynamic imports regardless of the credentials option ' ++ '(default).');++credentials_test(+ { credentials: 'omit', type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new SharedWorker() with type=classic should always send the credentials ' ++ 'for same-origin dynamic imports regardless of the credentials option ' ++ '(omit).');++credentials_test(+ { credentials: 'same-origin', type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new SharedWorker() with type=classic should always send the credentials ' ++ 'for same-origin dynamic imports regardless of the credentials option ' ++ '(same-origin).');++credentials_test(+ { credentials: 'include', type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'same' },+ 'new SharedWorker() with type=classic should always send the credentials ' ++ 'for same-origin dynamic imports regardless of the credentials option ' ++ '(include).');++credentials_test(+ { type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ 'new SharedWorker() with type=classic should never send the credentials ' ++ 'for cross-origin dynamic imports regardless of the credentials option ' ++ '(default).');++credentials_test(+ { credentials: 'omit', type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ 'new SharedWorker() with type=classic should never send the credentials ' ++ 'for cross-origin dynamic imports regardless of the credentials option ' ++ '(omit).');++credentials_test(+ { credentials: 'same-origin', type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ 'new SharedWorker() with type=classic should never send the credentials ' ++ 'for cross-origin dynamic imports regardless of the credentials option ' ++ '(same-origin).');++credentials_test(+ { credentials: 'include', type: 'classic' },+ { fetchType: 'descendant-dynamic', origin: 'remote' },+ 'new SharedWorker() with type=classic should never send the credentials ' ++ 'for cross-origin dynamic imports regardless of the credentials option ' ++ '(include).');++</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/workers/modules/shared-worker-options-credentials.html.headers b/Tests/LibWeb/Text/input/wpt-import/workers/modules/shared-worker-options-credentials.html.headersnew file mode 100644index 00000000000..8da851ab736--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/workers/modules/shared-worker-options-credentials.html.headers@@ -0,0 +1,2 @@+Set-Cookie: COOKIE_NAME=1+Access-Control-Allow-Credentials: true