mirror of
https://github.com/servo/servo.git
synced 2025-08-21 21:35:32 +01:00
Update web-platform-tests to revision fb15e14b52049f952612623ee0d7fb7a620a57c9
This commit is contained in:
parent
200cc8aa6b
commit
4a942c982f
141 changed files with 2563 additions and 1589 deletions
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Tests for importScripts: MIME types</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/test-helpers.sub.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
/**
|
||||
* Test that a Service Worker's importScript() only accepts valid MIME types.
|
||||
*/
|
||||
let serviceWorker = null;
|
||||
|
||||
promise_test(async t => {
|
||||
const scope = 'resources/import-scripts-mime-types';
|
||||
const registration = await service_worker_unregister_and_register(t,
|
||||
'resources/import-scripts-mime-types-worker.js', scope);
|
||||
|
||||
add_completion_callback(() => { registration.unregister(); });
|
||||
|
||||
await wait_for_state(t, registration.installing, 'activated');
|
||||
|
||||
serviceWorker = registration.active;
|
||||
}, 'Global setup');
|
||||
|
||||
promise_test(async t => {
|
||||
await fetch_tests_from_worker(serviceWorker);
|
||||
}, 'Fetch importScripts tests from service worker')
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,49 @@
|
|||
const badMimeTypes = [
|
||||
null, // no MIME type
|
||||
'text/plain',
|
||||
];
|
||||
|
||||
const validMimeTypes = [
|
||||
'application/ecmascript',
|
||||
'application/javascript',
|
||||
'application/x-ecmascript',
|
||||
'application/x-javascript',
|
||||
'text/ecmascript',
|
||||
'text/javascript',
|
||||
'text/javascript1.0',
|
||||
'text/javascript1.1',
|
||||
'text/javascript1.2',
|
||||
'text/javascript1.3',
|
||||
'text/javascript1.4',
|
||||
'text/javascript1.5',
|
||||
'text/jscript',
|
||||
'text/livescript',
|
||||
'text/x-ecmascript',
|
||||
'text/x-javascript',
|
||||
];
|
||||
|
||||
function importScriptsWithMimeType(mimeType) {
|
||||
importScripts(`./mime-type-worker.py${mimeType ? '?mime=' + mimeType : ''}`);
|
||||
}
|
||||
|
||||
importScripts('/resources/testharness.js');
|
||||
|
||||
for (const mimeType of badMimeTypes) {
|
||||
test(() => {
|
||||
assert_throws(
|
||||
'NetworkError',
|
||||
() => { importScriptsWithMimeType(mimeType); },
|
||||
`importScripts with ${mimeType ? 'bad' : 'no'} MIME type ${mimeType || ''} throws NetworkError`,
|
||||
);
|
||||
}, `Importing script with ${mimeType ? 'bad' : 'no'} MIME type ${mimeType || ''}`);
|
||||
}
|
||||
|
||||
for (const mimeType of validMimeTypes) {
|
||||
test(() => {
|
||||
try {
|
||||
importScriptsWithMimeType(mimeType);
|
||||
} catch {
|
||||
assert_unreached(`importScripts with MIME type ${mimeType} should not throw`);
|
||||
}
|
||||
}, `Importing script with valid JavaScript MIME type ${mimeType}`);
|
||||
}
|
|
@ -21,11 +21,21 @@ function registration_tests_mime_types(register_method, check_error_types) {
|
|||
'Registration of plain text script should fail.');
|
||||
}, 'Registering script with bad MIME type');
|
||||
|
||||
/**
|
||||
* ServiceWorkerContainer.register() should throw a TypeError, according to
|
||||
* step 17.1 of https://w3c.github.io/ServiceWorker/#importscripts
|
||||
*
|
||||
* "[17] If an uncaught runtime script error occurs during the above step, then:
|
||||
* [17.1] Invoke Reject Job Promise with job and TypeError"
|
||||
*
|
||||
* (Where the "uncaught runtime script error" is thrown by an unsuccessful
|
||||
* importScripts())
|
||||
*/
|
||||
promise_test(function(t) {
|
||||
var script = 'resources/import-mime-type-worker.py';
|
||||
var scope = 'resources/scope/no-mime-type-worker/';
|
||||
return promise_rejects(t,
|
||||
check_error_types ? 'SecurityError' : null,
|
||||
check_error_types ? new TypeError() : null,
|
||||
register_method(script, {scope: scope}),
|
||||
'Registration of no MIME type imported script should fail.');
|
||||
}, 'Registering script that imports script with no MIME type');
|
||||
|
@ -34,7 +44,7 @@ function registration_tests_mime_types(register_method, check_error_types) {
|
|||
var script = 'resources/import-mime-type-worker.py?mime=text/plain';
|
||||
var scope = 'resources/scope/bad-mime-type-worker/';
|
||||
return promise_rejects(t,
|
||||
check_error_types ? 'SecurityError' : null,
|
||||
check_error_types ? new TypeError() : null,
|
||||
register_method(script, {scope: scope}),
|
||||
'Registration of plain text imported script should fail.');
|
||||
}, 'Registering script that imports script with bad MIME type');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue