Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/register-foreign-fetch-errors-worker.js |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/register-foreign-fetch-errors-worker.js b/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/register-foreign-fetch-errors-worker.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..70dd95133cde8606d18f15a932bd591dffc6fed1 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/register-foreign-fetch-errors-worker.js |
| @@ -0,0 +1,67 @@ |
| + |
|
falken
2015/10/16 11:58:43
This is in http/tests/serviceworker so should use
Marijn Kruisselbrink
2015/10/16 17:23:24
Done.
|
| +self.addEventListener('install', function(event) { |
| + var scope = registration.scope; |
| + var scopeUrl = new URL(scope); |
|
falken
2015/10/16 11:58:43
nit: scope_url (and snake_case throughout this fil
Marijn Kruisselbrink
2015/10/16 17:23:24
Done
|
| + |
| + test(function() { |
| + assert_throws(new TypeError(), function() { |
| + event.registerForeignFetchScopes(scope); |
| + }); |
| + }, 'Not an array'); |
| + |
| + test(function() { |
| + assert_throws(new TypeError(), function() { |
| + event.registerForeignFetchScopes([{}]); |
| + }); |
| + }, 'Not a string in array'); |
| + |
| + test(function() { |
| + assert_throws(new TypeError(), function() { |
| + event.registerForeignFetchScopes(["/foo"]); |
|
falken
2015/10/16 11:58:43
nit: single-quotes for javascript string literals
Marijn Kruisselbrink
2015/10/16 17:23:24
Done
|
| + }); |
| + }, "Relative url not under scope"); |
| + |
| + test(function() { |
| + var url = new URL(scopeUrl); |
| + url.host = "example.com"; |
| + assert_throws(new TypeError(), function() { |
| + event.registerForeignFetchScopes([url.href]); |
| + }); |
| + }, 'Absolute url not under scope'); |
| + |
| + async_test(function(t) { |
| + self.setTimeout(t.step_func(function() { |
| + assert_throws('InvalidStateError', function() { |
| + event.registerForeignFetchScopes([scope]); |
| + }); |
| + t.done(); |
| + }), 1); |
| + }, 'Call after event returned'); |
| + |
| + test(function() { |
| + event.registerForeignFetchScopes([]); |
| + }, 'Empty array'); |
| + |
| + test(function() { |
| + event.registerForeignFetchScopes([scope, scope + '/foo']); |
| + }, 'Absolute urls'); |
| + |
| + test(function() { |
| + // Figure out scope relative to location of this script: |
| + var localDir = location.pathname; |
| + localDir = localDir.substr(0, localDir.lastIndexOf('/')); |
| + assert_true(scopeUrl.pathname.startsWith(localDir)); |
| + var relativeScope = scopeUrl.pathname.substr(localDir.length + 1); |
| + |
| + event.registerForeignFetchScopes([ |
| + scopeUrl.pathname, |
| + relativeScope, |
| + './' + relativeScope, |
| + relativeScope + '/foo']); |
| + }, "Relative urls"); |
| + |
| +}); |
| + |
| +// Import testharness after install handler to make sure our install handler |
| +// runs first. |
|
falken
2015/10/16 11:58:43
Curious: why does that matter?
Marijn Kruisselbrink
2015/10/16 17:23:24
It matters because the install handler in testharn
|
| +importScripts('../../resources/testharness.js'); |