Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Unified Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/register-foreign-fetch-errors-worker.js

Issue 1406823002: Start of foreign fetch implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add unit test Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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');

Powered by Google App Engine
This is Rietveld 408576698