Skip to content

Commit

Permalink
Re-import workers WPT
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=260868
rdar://114647890

Reviewed by Cameron McCormack.

Upstream commit: web-platform-tests/wpt@d9e648d

Some changes landed from Mozilla that improve our Interop 2023 workers score.

* LayoutTests/http/wpt/workers/modules/dedicated-worker-import-csp-expected.txt:
* LayoutTests/http/wpt/workers/modules/dedicated-worker-import-csp.html:
* LayoutTests/imported/w3c/web-platform-tests/workers/WorkerNavigator_userAgentData.https.html:
* LayoutTests/imported/w3c/web-platform-tests/workers/Worker_cross_origin_security_err-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/workers/Worker_cross_origin_security_err.htm:
* LayoutTests/imported/w3c/web-platform-tests/workers/Worker_dispatchEvent_ErrorEvent-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/workers/Worker_dispatchEvent_ErrorEvent.htm:
* LayoutTests/imported/w3c/web-platform-tests/workers/Worker_script_mimetype-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/workers/Worker_script_mimetype.htm:
* LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/SharedWorker-constructor-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/SharedWorker-constructor.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/same-origin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/same-origin.html:
* LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/w3c-import.log:
* LayoutTests/imported/w3c/web-platform-tests/workers/constructors/Worker/AbstractWorker.onerror-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/workers/constructors/Worker/AbstractWorker.onerror.js:
* LayoutTests/imported/w3c/web-platform-tests/workers/constructors/Worker/same-origin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/workers/constructors/Worker/same-origin.html:
* LayoutTests/imported/w3c/web-platform-tests/workers/dedicated-worker-in-data-url-context.window.js:
(promise_test.async t):
* LayoutTests/imported/w3c/web-platform-tests/workers/importscripts_mime.any.js:
* LayoutTests/imported/w3c/web-platform-tests/workers/importscripts_mime_local.any.js: Copied from LayoutTests/imported/w3c/web-platform-tests/workers/importscripts_mime.any.js.
* LayoutTests/imported/w3c/web-platform-tests/workers/importscripts_mime_local.any.sharedworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/workers/importscripts_mime_local.any.sharedworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/workers/importscripts_mime_local.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/workers/importscripts_mime_local.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/navigator/007.js:
* LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/navigator/008.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/navigator/008.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/navigator/008.worker.js: Added.
(test):
* LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/navigator/w3c-import.log:
* LayoutTests/imported/w3c/web-platform-tests/workers/modules/dedicated-worker-import-csp.html:
* LayoutTests/imported/w3c/web-platform-tests/workers/modules/dedicated-worker-import-data-url-cross-origin.html:
* LayoutTests/imported/w3c/web-platform-tests/workers/modules/dedicated-worker-import-data-url.any.js:
(import_data_url_test):
* LayoutTests/imported/w3c/web-platform-tests/workers/modules/dedicated-worker-import-failure-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/workers/modules/dedicated-worker-import-failure.html:
* LayoutTests/imported/w3c/web-platform-tests/workers/modules/dedicated-worker-import-meta-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/workers/modules/dedicated-worker-import-meta.html:
* LayoutTests/imported/w3c/web-platform-tests/workers/modules/shared-worker-import-data-url-cross-origin.html:
* LayoutTests/imported/w3c/web-platform-tests/workers/modules/shared-worker-import-data-url.window.js:
(import_data_url_test):
* LayoutTests/imported/w3c/web-platform-tests/workers/modules/shared-worker-import-failure-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/workers/modules/shared-worker-import-failure.html:
* LayoutTests/imported/w3c/web-platform-tests/workers/modules/shared-worker-parse-error-failure.html:
* LayoutTests/imported/w3c/web-platform-tests/workers/semantics/interface-objects/001.worker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/workers/semantics/interface-objects/001.worker.js:
* LayoutTests/imported/w3c/web-platform-tests/workers/semantics/interface-objects/002.worker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/workers/semantics/interface-objects/002.worker.js:
* LayoutTests/imported/w3c/web-platform-tests/workers/semantics/interface-objects/003.any.js:
* LayoutTests/imported/w3c/web-platform-tests/workers/semantics/interface-objects/003.any.sharedworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/workers/semantics/interface-objects/004.any.js:
* LayoutTests/imported/w3c/web-platform-tests/workers/semantics/interface-objects/004.any.sharedworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/workers/semantics/multiple-workers/004.html:
* LayoutTests/imported/w3c/web-platform-tests/workers/semantics/structured-clone/dedicated.html:
* LayoutTests/imported/w3c/web-platform-tests/workers/semantics/structured-clone/shared.html:
* LayoutTests/imported/w3c/web-platform-tests/workers/shared-worker-in-data-url-context.window.js:
(promise_test.async t):
* LayoutTests/imported/w3c/web-platform-tests/workers/support/WorkerNavigator.js:
(async const):
* LayoutTests/imported/w3c/web-platform-tests/workers/support/w3c-import.log:
* LayoutTests/imported/w3c/web-platform-tests/workers/support/worker-request-animation-frame.js: Added.
(self.onmessage):
* LayoutTests/imported/w3c/web-platform-tests/workers/w3c-import.log:
* LayoutTests/imported/w3c/web-platform-tests/workers/worker-request-animation-frame-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/workers/worker-request-animation-frame.html: Added.
* LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/workers/Worker_script_mimetype-expected.txt: Copied from LayoutTests/imported/w3c/web-platform-tests/workers/Worker_script_mimetype-expected.txt.
* LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/workers/importscripts_mime_local.any.sharedworker-expected.txt: Renamed from LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/workers/interfaces/WorkerGlobalScope/onerror/exception-in-onerror-expected.txt.
* LayoutTests/tests-options.json:

Canonical link: https://commits.webkit.org/267435@main
  • Loading branch information
nt1m committed Aug 30, 2023
1 parent 4552204 commit 1c82329
Show file tree
Hide file tree
Showing 63 changed files with 469 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ FAIL script-src 'self' directive should disallow cross origin static import. ass
PASS script-src * directive should allow cross origin static import.
PASS worker-src * directive should override script-src 'self' directive and allow cross origin static import.
FAIL worker-src 'self' directive should override script-src * directive and disallow cross origin static import. assert_array_equals: expected property 0 to be "ERROR" but got "export-on-load-script.js" (expected array ["ERROR"] got ["export-on-load-script.js"])
PASS script-src-elem 'self' directive should not take effect on static import.
PASS script-src 'self' directive should disallow cross origin dynamic import.
PASS script-src-elem 'self' directive should disallow cross origin dynamic import.
PASS script-src * directive should allow cross origin dynamic import.
PASS worker-src 'self' directive should not take effect on dynamic import.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
? '?pipe=header(Content-Security-Policy, ' + cspHeader + ')'
: ''}`;
// Append CSP header to scriptURL for dynamic import tests since dynamic
// import scripts should obey Worker script's responce's CSP.
// import scripts should obey Worker script's response's CSP.
const scriptURL = `${importType}-import-remote-origin-script-worker.sub.js` +
`${importType === 'dynamic'
? '?pipe=header(Content-Security-Policy, ' + cspHeader + ')'
Expand Down Expand Up @@ -86,6 +86,17 @@
"worker-src 'self' directive should override script-src * directive and " +
"disallow cross origin static import.");

// For static imports on workers, the effective directive should be 'worker-src'.
// https://w3c.github.io/webappsec-csp/#effective-directive-for-a-request
//
// The directive fallback list of 'worker-src' doesn't contain 'script-src-elem'
// https://w3c.github.io/webappsec-csp/#directive-fallback-list
import_csp_test(
"script-src-elem 'self' 'unsafe-inline'",
"static",
["export-on-load-script.js"],
"script-src-elem 'self' directive should not take effect on static import.");

// Tests for dynamic import.
//
// Dynamic import should obey the script-src directive instead of the worker-src
Expand All @@ -105,6 +116,14 @@
['ERROR'],
"script-src 'self' directive should disallow cross origin dynamic import.");

// For dynamic imports, the effective directive should be 'script-src-elem'.
// https://w3c.github.io/webappsec-csp/#effective-directive-for-a-request
import_csp_test(
"script-src-elem 'self' 'unsafe-inline'",
"dynamic",
['ERROR'],
"script-src-elem 'self' directive should disallow cross origin dynamic import.");

import_csp_test(
"script-src * 'unsafe-inline'",
"dynamic",
Expand All @@ -116,5 +135,4 @@
"dynamic",
["export-on-load-script.js"],
"worker-src 'self' directive should not take effect on dynamic import.");

</script>
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,31 @@
assert_equals(workerUA.version, windowUA.version);
}
assert_equals(e.data.mobile, navigator.userAgentData.mobile);
const highEntropyValues = await navigator.userAgentData.getHighEntropyValues(["platform", "platformVersion", "architecture", "model", "uaFullVersion"]);
assert_equals(e.data.platform, navigator.userAgentData.platform);
const highEntropyValues = await navigator.userAgentData.getHighEntropyValues([
"architecture", "bitness", "fullVersionList", "model",
"platformVersion", "uaFullVersion", "wow64", "formFactor",
]);

assert_equals(e.data.fullVersionList.length,
highEntropyValues.fullVersionList.length);
for (let i = 0; i < e.data.fullVersionList.length; ++i) {
const workerFV = e.data.fullVersionList[i];
const windowFV = highEntropyValues.fullVersionList[i];
assert_equals(workerFV.brand, windowFV.brand);
assert_equals(workerFV.version, windowFV.version);
}

assert_equals(e.data.architecture, highEntropyValues.architecture);
assert_equals(e.data.bitness, highEntropyValues.bitness);
assert_equals(e.data.model, highEntropyValues.model);
assert_equals(e.data.platform, highEntropyValues.platform);
assert_equals(e.data.platformVersion, highEntropyValues.platformVersion);
assert_equals(e.data.architecture, highEntropyValues.architecture);
assert_equals(e.data.uaFullVersion, highEntropyValues.uaFullVersion);
assert_equals(e.data.wow64, highEntropyValues.wow64);
assert_equals(e.data.formFactor, highEntropyValues.formFactor);
assert_equals(e.data.NavigatorUADataExposed, true);

// Architecture should be one of two permitted values.
assert_true(["x86", "arm"].some(arch => arch == e.data.architecture))
}, "Test that userAgentData is available in workers in secure contexts");
</script>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

PASS Cross-origin classic workers should fail to fetch
PASS Cross-origin module workers should fail to fetch
FAIL Cross-origin classic workers should fail to fetch The operation is insecure.
FAIL Cross-origin module workers should fail to fetch The operation is insecure.

Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,16 @@
<div id=log></div>
<script>
async_test(function(t) {
try {
var w = new Worker("ftp://example.org/support/WorkerBasic.js");
w.onerror = t.step_func_done(function(e) {
assert_true(e instanceof Event);
});
} catch (e) {
assert_throws_dom("SecurityError", () => {throw e}, "DOMExceptions thrown on cross-origin Worker construction must be SecurityErrors");
t.done();
}
}, "Cross-origin classic workers should fail to fetch");
}, "Cross-origin classic workers should fail to fetch");

async_test(function(t) {
try {
var w = new Worker("ftp://example.org/support/WorkerBasic.js", {type: "module"});
w.onerror = t.step_func_done(function(e) {
assert_true(e instanceof Event);
});
} catch (e) {
assert_throws_dom("SecurityError", () => {throw e}, "DOMExceptions thrown on cross-origin module Worker construction must be SecurityErrors");
t.done();
}
}, "Cross-origin module workers should fail to fetch");
</script>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

PASS ErrorEvent and Worker.dispatchEvent()
PASS initErrorEvent
PASS ErrorEvent constructor called as normal function

Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@
var e = new ErrorEvent("error");
assert_false("initErrorEvent" in e, "should not be supported");
}, "initErrorEvent");

test(function() {
assert_throws_js(
TypeError,
() => ErrorEvent(''),
"Calling ErrorEvent constructor without 'new' must throw"
);
}, "ErrorEvent constructor called as normal function");
</script>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

PASS HTTP(S) URLs which respond with text/plain MIME type must not work
PASS HTTP(S) URLs which respond with text/plain MIME type must not work on SharedWorkers
PASS blob: URLs should load, despite no MIME type for the backing Blob
PASS blob: URLs should load, despite the wrong MIME type for the backing Blob
PASS data: URLs should load, despite the wrong MIME type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<!DOCTYPE html>
<title>Worker constructor with wrong MIME type scripts</title>
<meta charset="utf-8">
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
async_test(t => {
const worker = new Worker('./support/WorkerText.txt');
worker.onmessage = t.unreached_func("Worker should not recieve messages");
worker.onmessage = t.unreached_func("Worker should not receive messages");
worker.onerror = () => t.done();
}, "HTTP(S) URLs which respond with text/plain MIME type must not work");

async_test(t => {
const worker = new SharedWorker('./support/WorkerText.txt');
worker.onmessage = t.unreached_func("Worker should not receive messages");
worker.onerror = () => t.done();
}, "HTTP(S) URLs which respond with text/plain MIME type must not work on SharedWorkers");

async_test(t => {
const url = URL.createObjectURL(new Blob(['postMessage("PASS")'])); // no MIME type parameter
const worker = new Worker(url);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

PASS Test toString propagation exception.
PASS Test Sharedworker creation with no arguments
PASS Test invalid script URL.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<title>Test SharedWorker constructor functionality.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(() => {
assert_throws_js(Error,
function() {
new SharedWorker({toString:function(){throw new Error()}})},
'toString exception should be propagated');
}, 'Test toString propagation exception.');

test(() => {
assert_throws_js(TypeError,
function() { new SharedWorker(); },
'invoking SharedWorker constructor without arguments should result ' +
'in an exception.')
}, 'Test Sharedworker creation with no arguments');


test(() => {
assert_throws_dom("SyntaxError",
function() { var Sharedworker = new SharedWorker('http://invalid:123$'); },
'Invoking SharedWorker constructor with invalid script URL should ' +
'result in an exception.');
}, 'Test invalid script URL.');

</script>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

PASS unsupported_scheme
PASS data_url
PASS javascript_url
PASS about_blank
PASS opera_com
PASS port_81
PASS https_port_80
PASS https_port_8000
PASS http_port_8012
FAIL javascript_url URL of the shared worker is cross-origin
FAIL about_blank URL of the shared worker is cross-origin
FAIL opera_com URL of the shared worker is cross-origin
FAIL port_81 URL of the shared worker is cross-origin
FAIL https_port_80 URL of the shared worker is cross-origin
FAIL https_port_8000 URL of the shared worker is cross-origin
FAIL http_port_8012 URL of the shared worker is cross-origin

Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@
setup({allow_uncaught_exception: true});

testSharedWorkerHelper = (t, script) => {
try {
const worker = new SharedWorker(script, '');
worker.onerror = t.step_func_done(e => {
assert_true(e instanceof Event);
});
} catch (e) {
assert_throws_dom("SecurityError", () => {throw e}, "DOMExceptions thrown on cross-origin SharedWorker construction must be SecurityErrors");
t.done();
}
const worker = new SharedWorker(script, '');
worker.onerror = t.step_func_done(e => {
assert_true(e instanceof Event);
});
}

test(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ List of files:
/LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/1.headers
/LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/Infinity
/LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/Infinity-arguments.html
/LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/Infinity.headers
/LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/NaN
/LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/NaN-arguments.html
/LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/NaN.headers
/LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/SharedWorker-constructor.html
/LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/URLMismatchError.htm
/LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/connect-event.html
/LayoutTests/imported/w3c/web-platform-tests/workers/constructors/SharedWorker/connect-event.js
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CONSOLE MESSAGE: SyntaxError: Unexpected token ')'
CONSOLE MESSAGE: Error: error from onerror.js

PASS AbstractWorker.onerror

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
for (;) // should cause onerror to be invoked, but onerror is null, so
// the error is "not handled". should fire an ErrorEvent on the
// worker.
break;
postMessage(1); // shouldn't do anything since the script doesn't compile
// Throw a runtime error, the UA must report the error for that script.
// https://html.spec.whatwg.org/#runtime-script-errors-2
for (;;)
throw new Error("error from onerror.js");
postMessage(1); // shouldn't do anything since the script doesn't compile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

PASS unsupported_scheme
PASS data_url
PASS about_blank
PASS example_invalid
PASS port_81
PASS https_port_80
PASS https_port_8000
PASS http_post_8012
PASS javascript_url
FAIL about_blank The operation is insecure.
FAIL example_invalid The operation is insecure.
FAIL port_81 The operation is insecure.
FAIL https_port_80 The operation is insecure.
FAIL https_port_8000 The operation is insecure.
FAIL http_post_8012 The operation is insecure.
FAIL javascript_url The operation is insecure.

Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@
setup({allow_uncaught_exception: true});

function testWorkerHelper(t, script) {
try {
var worker = new Worker(script);
worker.onerror = t.step_func_done(function(e) {
assert_true(e instanceof Event);
});
} catch (e) {
assert_throws_dom("SecurityError", () => {throw e}, "DOMExceptions thrown on cross-origin Worker construction must be SecurityErrors");
t.done();
}
var worker = new Worker(script);
worker.onerror = t.step_func_done(function(e) {
assert_true(e instanceof Event);
});
}

test(function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ promise_test(async t => {
</script>
`;

const p = new Promise(r => window.onmessage = e => r(e.data));
const frame = await with_iframe(`data:text/html;base64,${btoa(frameCode)}`);
const result = await new Promise(r => window.onmessage = e => r(e.data));
const result = await p;
assert_equals(result, 'PASS');
}, 'Create a dedicated worker in a data url frame');

Expand Down Expand Up @@ -82,8 +83,9 @@ promise_test(async t => {
</script>
`;

const p = new Promise(r => window.onmessage = e => r(e.data));
const frame = await with_iframe(`data:text/html;base64,${btoa(frameCode)}`);
const result = await new Promise(r => window.onmessage = e => r(e.data));
const result = await p;
assert_equals(result, 'PASS');
}, 'Create a data url dedicated worker in a data url frame');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ let test_cases = [
["TEXT/HTML", false],
];

for (var test_case of test_cases) {
for (const [mimeType, isScriptType] of test_cases) {
test(t => {
let import_url = "/workers/support/imported_script.py?mime=" + test_case[0];
if (test_case[1]) {
let import_url = "/workers/support/imported_script.py?mime=" + mimeType;
if (isScriptType) {
assert_equals(undefined, importScripts(import_url));
} else {
assert_throws_dom("NetworkError", _ => { importScripts(import_url) })
}
}, "importScripts() requires scripty MIME types: " + test_case[0] + " is " + (test_case[1] ? "allowed" : "blocked") + ".");
}, "importScripts() requires scripty MIME types: " + mimeType + " is " + (isScriptType ? "allowed" : "blocked") + ".");
}
Loading

0 comments on commit 1c82329

Please sign in to comment.