Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServiceWorker: Add the WPT tests to catch an error when fetch a script. #13773

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
<script src="resources/test-helpers.sub.js"></script>
<script src="resources/registration-tests-script.js"></script>
<script>
registration_tests_script((script, options) => navigator.serviceWorker.register(script, options), true);
registration_tests_script((script, options) =>
navigator.serviceWorker.register(script, options), true, 'classic');
registration_tests_script((script, options) =>
navigator.serviceWorker.register(script, options), true, 'module');
</script>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Registration tests that mostly exercise the service worker script contents or
// response.
function registration_tests_script(register_method, check_error_types) {
function registration_tests_script(register_method, check_error_types, script_type) {
promise_test(function(t) {
var script = 'resources/invalid-chunked-encoding.py';
var scope = 'resources/scope/invalid-chunked-encoding/';
return promise_rejects(t,
check_error_types ? new TypeError : null,
register_method(script, {scope: scope}),
register_method(script, {scope: scope, type: script_type}),
'Registration of invalid chunked encoding script should fail.');
}, 'Registering invalid chunked encoding script');

Expand All @@ -15,7 +15,7 @@ function registration_tests_script(register_method, check_error_types) {
var scope = 'resources/scope/invalid-chunked-encoding-with-flush/';
return promise_rejects(t,
check_error_types ? new TypeError : null,
register_method(script, {scope: scope}),
register_method(script, {scope: scope, type: script_type}),
'Registration of invalid chunked encoding script should fail.');
}, 'Registering invalid chunked encoding script with flush');

Expand All @@ -24,7 +24,7 @@ function registration_tests_script(register_method, check_error_types) {
var scope = 'resources/scope/parse-error';
return promise_rejects(t,
check_error_types ? new TypeError : null,
register_method(script, {scope: scope}),
register_method(script, {scope: scope, type: script_type}),
'Registration of script including parse error should fail.');
}, 'Registering script including parse error');

Expand All @@ -33,7 +33,7 @@ function registration_tests_script(register_method, check_error_types) {
var scope = 'resources/scope/undefined-error';
return promise_rejects(t,
check_error_types ? new TypeError : null,
register_method(script, {scope: scope}),
register_method(script, {scope: scope, type: script_type}),
'Registration of script including undefined error should fail.');
}, 'Registering script including undefined error');

Expand All @@ -42,7 +42,7 @@ function registration_tests_script(register_method, check_error_types) {
var scope = 'resources/scope/uncaught-exception';
return promise_rejects(t,
check_error_types ? new TypeError : null,
register_method(script, {scope: scope}),
register_method(script, {scope: scope, type: script_type}),
'Registration of script including uncaught exception should fail.');
}, 'Registering script including uncaught exception');

Expand All @@ -51,7 +51,7 @@ function registration_tests_script(register_method, check_error_types) {
var scope = 'resources/scope/import-malformed-script';
return promise_rejects(t,
check_error_types ? new TypeError : null,
register_method(script, {scope: scope}),
register_method(script, {scope: scope, type: script_type}),
'Registration of script importing malformed script should fail.');
}, 'Registering script importing malformed script');

Expand All @@ -60,7 +60,7 @@ function registration_tests_script(register_method, check_error_types) {
var scope = 'resources/scope/no-such-worker';
return promise_rejects(t,
check_error_types ? new TypeError : null,
register_method(script, {scope: scope}),
register_method(script, {scope: scope, type: script_type}),
'Registration of non-existent script should fail.');
}, 'Registering non-existent script');

Expand All @@ -69,14 +69,14 @@ function registration_tests_script(register_method, check_error_types) {
var scope = 'resources/scope/import-no-such-script';
return promise_rejects(t,
check_error_types ? new TypeError : null,
register_method(script, {scope: scope}),
register_method(script, {scope: scope, type: script_type}),
'Registration of script importing non-existent script should fail.');
}, 'Registering script importing non-existent script');

promise_test(function(t) {
var script = 'resources/malformed-worker.py?caught-exception';
var scope = 'resources/scope/caught-exception';
return register_method(script, {scope: scope})
return register_method(script, {scope: scope, type: script_type})
.then(function(registration) {
assert_true(
registration instanceof ServiceWorkerRegistration,
Expand Down