Skip to content

Commit

Permalink
ServiceWorker: Add the WPT tests to catch an error when fetch a script.
Browse files Browse the repository at this point in the history
This tests makes sure to catch a network error when fetch a script.

Implementing CL: https://chromium-review.googlesource.com/c/chromium/src/+/1304274

Bug: 824647
Change-Id: I3d7b3df7ae6a6ca39cd3d1dbf4e8e86817a9ffe6
  • Loading branch information
d0iasm authored and chromium-wpt-export-bot committed Oct 30, 2018
1 parent 1f06d26 commit 4becbdb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
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

0 comments on commit 4becbdb

Please sign in to comment.