[Background Fetch] Rename "tag" to "id", and add some documentation
Change-Id: I9271490f9a5b68129797ba6b9062247d1b1b2c2a
Reviewed-on: https://chromium-review.googlesource.com/1135324
Reviewed-by: Alexander Timin <altimin@chromium.org>
Commit-Queue: Peter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575726}
diff --git a/third_party/WebKit/LayoutTests/external/wpt/background-fetch/content-security-policy.https.window.js b/third_party/WebKit/LayoutTests/external/wpt/background-fetch/content-security-policy.https.window.js
index a6dc7c30..0b5b1cb5 100644
--- a/third_party/WebKit/LayoutTests/external/wpt/background-fetch/content-security-policy.https.window.js
+++ b/third_party/WebKit/LayoutTests/external/wpt/background-fetch/content-security-policy.https.window.js
@@ -16,5 +16,5 @@
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(
t, new TypeError(),
- bgFetch.fetch(uniqueTag(), 'https://example.com'));
+ bgFetch.fetch(uniqueId(), 'https://example.com'));
}, 'fetch blocked by CSP should reject');
diff --git a/third_party/WebKit/LayoutTests/external/wpt/background-fetch/credentials-in-url.https.window.js b/third_party/WebKit/LayoutTests/external/wpt/background-fetch/credentials-in-url.https.window.js
index 28b37b3..df9a662 100644
--- a/third_party/WebKit/LayoutTests/external/wpt/background-fetch/credentials-in-url.https.window.js
+++ b/third_party/WebKit/LayoutTests/external/wpt/background-fetch/credentials-in-url.https.window.js
@@ -10,23 +10,23 @@
// https://url.spec.whatwg.org/#include-credentials
backgroundFetchTest((t, bgFetch) => {
- return bgFetch.fetch(uniqueTag(), 'https://example.com');
+ return bgFetch.fetch(uniqueId(), 'https://example.com');
}, 'fetch without credentials in URL should register ok');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(
t, new TypeError(),
- bgFetch.fetch(uniqueTag(), 'https://username:password@example.com'));
+ bgFetch.fetch(uniqueId(), 'https://username:password@example.com'));
}, 'fetch with username and password in URL should reject');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(
t, new TypeError(),
- bgFetch.fetch(uniqueTag(), 'https://username:@example.com'));
+ bgFetch.fetch(uniqueId(), 'https://username:@example.com'));
}, 'fetch with username and empty password in URL should reject');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(
t, new TypeError(),
- bgFetch.fetch(uniqueTag(), 'https://:password@example.com'));
+ bgFetch.fetch(uniqueId(), 'https://:password@example.com'));
}, 'fetch with empty username and password in URL should reject');
diff --git a/third_party/WebKit/LayoutTests/external/wpt/background-fetch/dangling-markup.https.window.js b/third_party/WebKit/LayoutTests/external/wpt/background-fetch/dangling-markup.https.window.js
index af7c395..764257d 100644
--- a/third_party/WebKit/LayoutTests/external/wpt/background-fetch/dangling-markup.https.window.js
+++ b/third_party/WebKit/LayoutTests/external/wpt/background-fetch/dangling-markup.https.window.js
@@ -13,5 +13,5 @@
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(
t, new TypeError(),
- bgFetch.fetch(uniqueTag(), 'https://example.com/?\n<'));
+ bgFetch.fetch(uniqueId(), 'https://example.com/?\n<'));
}, 'fetch to URL containing \\n and < should reject');
diff --git a/third_party/WebKit/LayoutTests/external/wpt/background-fetch/mixed-content-and-allowed-schemes.https.window.js b/third_party/WebKit/LayoutTests/external/wpt/background-fetch/mixed-content-and-allowed-schemes.https.window.js
index f9ebafc..9f24f13 100644
--- a/third_party/WebKit/LayoutTests/external/wpt/background-fetch/mixed-content-and-allowed-schemes.https.window.js
+++ b/third_party/WebKit/LayoutTests/external/wpt/background-fetch/mixed-content-and-allowed-schemes.https.window.js
@@ -15,65 +15,65 @@
// intended to check that blocking is enabled.
backgroundFetchTest((t, bgFetch) => {
- return bgFetch.fetch(uniqueTag(), 'https://example.com');
+ return bgFetch.fetch(uniqueId(), 'https://example.com');
}, 'https: fetch should register ok');
backgroundFetchTest((t, bgFetch) => {
- return bgFetch.fetch(uniqueTag(), 'http://127.0.0.1');
+ return bgFetch.fetch(uniqueId(), 'http://127.0.0.1');
}, 'loopback IPv4 http: fetch should register ok');
backgroundFetchTest((t, bgFetch) => {
- return bgFetch.fetch(uniqueTag(), 'http://[::1]');
+ return bgFetch.fetch(uniqueId(), 'http://[::1]');
}, 'loopback IPv6 http: fetch should register ok');
backgroundFetchTest((t, bgFetch) => {
- return bgFetch.fetch(uniqueTag(), 'http://localhost');
+ return bgFetch.fetch(uniqueId(), 'http://localhost');
}, 'localhost http: fetch should register ok');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(t, new TypeError(),
- bgFetch.fetch(uniqueTag(), 'http://example.com'));
+ bgFetch.fetch(uniqueId(), 'http://example.com'));
}, 'non-loopback http: fetch should reject');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(t, new TypeError(),
- bgFetch.fetch(uniqueTag(), 'http://192.0.2.0'));
+ bgFetch.fetch(uniqueId(), 'http://192.0.2.0'));
}, 'non-loopback IPv4 http: fetch should reject');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(t, new TypeError(),
- bgFetch.fetch(uniqueTag(), 'http://[2001:db8::1]'));
+ bgFetch.fetch(uniqueId(), 'http://[2001:db8::1]'));
}, 'non-loopback IPv6 http: fetch should reject');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(t, new TypeError(),
- bgFetch.fetch(uniqueTag(), ['https://example.com',
- 'http://example.com']));
+ bgFetch.fetch(uniqueId(), ['https://example.com',
+ 'http://example.com']));
}, 'https: and non-loopback http: fetch should reject');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(t, new TypeError(),
- bgFetch.fetch(uniqueTag(), ['http://example.com',
- 'https://example.com']));
+ bgFetch.fetch(uniqueId(), ['http://example.com',
+ 'https://example.com']));
}, 'non-loopback http: and https: fetch should reject');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(t, new TypeError(),
- bgFetch.fetch(uniqueTag(), 'wss:127.0.0.1'));
+ bgFetch.fetch(uniqueId(), 'wss:127.0.0.1'));
}, 'wss: fetch should reject');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(t, new TypeError(),
- bgFetch.fetch(uniqueTag(), 'file:///'));
+ bgFetch.fetch(uniqueId(), 'file:///'));
}, 'file: fetch should reject');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(t, new TypeError(),
- bgFetch.fetch(uniqueTag(), 'data:text/plain,foo'));
+ bgFetch.fetch(uniqueId(), 'data:text/plain,foo'));
}, 'data: fetch should reject');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(t, new TypeError(),
- bgFetch.fetch(uniqueTag(), 'foobar:bazqux'));
+ bgFetch.fetch(uniqueId(), 'foobar:bazqux'));
}, 'unknown scheme fetch should reject');
diff --git a/third_party/WebKit/LayoutTests/external/wpt/background-fetch/port-blocking.https.window.js b/third_party/WebKit/LayoutTests/external/wpt/background-fetch/port-blocking.https.window.js
index dbf8a1a..564a1113 100644
--- a/third_party/WebKit/LayoutTests/external/wpt/background-fetch/port-blocking.https.window.js
+++ b/third_party/WebKit/LayoutTests/external/wpt/background-fetch/port-blocking.https.window.js
@@ -9,27 +9,27 @@
// check that blocking is enabled.
backgroundFetchTest((t, bgFetch) => {
- return bgFetch.fetch(uniqueTag(), 'https://example.com');
+ return bgFetch.fetch(uniqueId(), 'https://example.com');
}, 'fetch to default https port should register ok');
backgroundFetchTest((t, bgFetch) => {
- return bgFetch.fetch(uniqueTag(), 'http://127.0.0.1');
+ return bgFetch.fetch(uniqueId(), 'http://127.0.0.1');
}, 'fetch to default http port should register ok');
backgroundFetchTest((t, bgFetch) => {
- return bgFetch.fetch(uniqueTag(), 'https://example.com:443');
+ return bgFetch.fetch(uniqueId(), 'https://example.com:443');
}, 'fetch to port 443 should register ok');
backgroundFetchTest((t, bgFetch) => {
- return bgFetch.fetch(uniqueTag(), 'https://example.com:80');
+ return bgFetch.fetch(uniqueId(), 'https://example.com:80');
}, 'fetch to port 80 should register ok, even over https');
backgroundFetchTest((t, bgFetch) => {
- return bgFetch.fetch(uniqueTag(), 'https://example.com:8080');
+ return bgFetch.fetch(uniqueId(), 'https://example.com:8080');
}, 'fetch to non-default non-bad port (8080) should register ok');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(
t, new TypeError(),
- bgFetch.fetch(uniqueTag(), 'https://example.com:587'));
+ bgFetch.fetch(uniqueId(), 'https://example.com:587'));
}, 'fetch to bad port (SMTP) should reject');
diff --git a/third_party/WebKit/LayoutTests/external/wpt/background-fetch/resources/utils.js b/third_party/WebKit/LayoutTests/external/wpt/background-fetch/resources/utils.js
index f630f10..7a497f8 100644
--- a/third_party/WebKit/LayoutTests/external/wpt/background-fetch/resources/utils.js
+++ b/third_party/WebKit/LayoutTests/external/wpt/background-fetch/resources/utils.js
@@ -1,18 +1,28 @@
'use strict';
+let nextBackgroundFetchId = 0;
+
+// Registers the instrumentation Service Worker located at "resources/sw.js"
+// with a scope unique to the test page that's running, and waits for it to be
+// activated. The Service Worker will be unregistered automatically.
+//
// Depends on /service-workers/service-worker/resources/test-helpers.sub.js
async function registerAndActivateServiceWorker(test) {
const script = 'resources/sw.js';
const scope = 'resources/scope' + location.pathname;
+
let serviceWorkerRegistration =
await service_worker_unregister_and_register(test, script, scope);
- add_completion_callback(() => {
- serviceWorkerRegistration.unregister();
- });
+
+ add_completion_callback(() => serviceWorkerRegistration.unregister());
+
await wait_for_state(test, serviceWorkerRegistration.installing, 'activated');
return serviceWorkerRegistration;
}
+// Creates a Promise test for |func| given the |description|. The |func| will be
+// executed with the `backgroundFetch` object of an activated Service Worker
+// Registration.
function backgroundFetchTest(func, description) {
promise_test(async t => {
const serviceWorkerRegistration = await registerAndActivateServiceWorker(t);
@@ -20,7 +30,7 @@
}, description);
}
-let _nextBackgroundFetchTag = 0;
-function uniqueTag() {
- return 'tag' + _nextBackgroundFetchTag++;
-}
\ No newline at end of file
+// Returns a Background Fetch ID that's unique for the current page.
+function uniqueId() {
+ return 'id' + nextBackgroundFetchId++;
+}