Title: [264542] trunk/LayoutTests
Revision
264542
Author
[email protected]
Date
2020-07-17 15:57:05 -0700 (Fri, 17 Jul 2020)

Log Message

Resync web-platform-tests/background-fetch from upstream
https://bugs.webkit.org/show_bug.cgi?id=214495

Reviewed by Geoffrey Garen.

Resync web-platform-tests/background-fetch from upstream 81de986322a0de90f2.

* resources/import-expectations.json:
* web-platform-tests/background-fetch/META.yml: Added.
* web-platform-tests/background-fetch/OWNERS: Removed.
* web-platform-tests/background-fetch/abort.https.window.html: Added.
* web-platform-tests/background-fetch/abort.https.window.js: Added.
(backgroundFetchTest.async test):
(backgroundFetch.await.new.Promise.resolve.registration.onprogress.async event):
* web-platform-tests/background-fetch/content-security-policy.https.window.html: Added.
* web-platform-tests/background-fetch/content-security-policy.https.window.js:
(backgroundFetchTest):
* web-platform-tests/background-fetch/credentials-in-url.https.window.js: Removed.
* web-platform-tests/background-fetch/dangling-markup.https.window.js: Removed.
* web-platform-tests/background-fetch/fetch-uploads.https.window.html: Added.
* web-platform-tests/background-fetch/fetch-uploads.https.window.js: Added.
(backgroundFetchTest.async test):
* web-platform-tests/background-fetch/fetch.https.window.html: Added.
* web-platform-tests/background-fetch/fetch.https.window.js: Added.
(promise_test.async test):
(backgroundFetchTest.async test):
* web-platform-tests/background-fetch/get-ids.https.window.html: Added.
* web-platform-tests/background-fetch/get-ids.https.window.js: Added.
(promise_test.async test):
(backgroundFetchTest.async test):
* web-platform-tests/background-fetch/get.https.window.html: Added.
* web-platform-tests/background-fetch/get.https.window.js: Added.
(promise_test.async test):
(backgroundFetchTest.async test):
* web-platform-tests/background-fetch/idlharness.https.any.html: Added.
* web-platform-tests/background-fetch/idlharness.https.any.js: Added.
* web-platform-tests/background-fetch/idlharness.https.any.worker.html: Added.
* web-platform-tests/background-fetch/interfaces-worker.https-expected.txt: Removed.
* web-platform-tests/background-fetch/interfaces-worker.https.html: Removed.
* web-platform-tests/background-fetch/interfaces.html: Removed.
* web-platform-tests/background-fetch/interfaces.worker.js: Removed.
* web-platform-tests/background-fetch/match.https.window.html: Added.
* web-platform-tests/background-fetch/match.https.window.js: Added.
(backgroundFetchTest.async test):
* web-platform-tests/background-fetch/mixed-content-and-allowed-schemes.https.window.html: Added.
* web-platform-tests/background-fetch/mixed-content-and-allowed-schemes.https.window.js:
(backgroundFetchTest):
* web-platform-tests/background-fetch/port-blocking.https.window.html: Added.
* web-platform-tests/background-fetch/port-blocking.https.window.js:
(backgroundFetchTest):
* web-platform-tests/background-fetch/resources/feature-name.txt: Added.
* web-platform-tests/background-fetch/resources/sw.js: Removed.
* web-platform-tests/background-fetch/resources/upload.py: Added.
(main):
* web-platform-tests/background-fetch/resources/utils.js:
(async getMessageFromServiceWorker.return.new.Promise):
(async getMessageFromServiceWorker):
(async registerAndActivateServiceWorker):
(backgroundFetchTest):
(async uniqueId):
* web-platform-tests/background-fetch/resources/w3c-import.log:
* web-platform-tests/background-fetch/service_workers/sw-abort.js: Added.
(async getFetchResult):
* web-platform-tests/background-fetch/service_workers/sw-helpers.js: Added.
(sendMessageToDocument):
(cloneRegistration.deepCopy):
(cloneRegistration):
* web-platform-tests/background-fetch/service_workers/sw-update-ui.js: Added.
(async updateUI):
* web-platform-tests/background-fetch/service_workers/sw.js: Added.
(async getFetchResult):
(handleBackgroundFetchEvent.switch.async bind):
* web-platform-tests/background-fetch/service_workers/w3c-import.log: Copied from LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/w3c-import.log.
* web-platform-tests/background-fetch/update-ui.https.window.html: Added.
* web-platform-tests/background-fetch/update-ui.https.window.js: Added.
(backgroundFetchTest.async test):
* web-platform-tests/background-fetch/w3c-import.log:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-07-17 22:57:05 UTC (rev 264542)
@@ -1,5 +1,85 @@
 2020-07-17  Chris Dumez  <[email protected]>
 
+        Resync web-platform-tests/background-fetch from upstream
+        https://bugs.webkit.org/show_bug.cgi?id=214495
+
+        Reviewed by Geoffrey Garen.
+
+        Resync web-platform-tests/background-fetch from upstream 81de986322a0de90f2.
+
+        * resources/import-expectations.json:
+        * web-platform-tests/background-fetch/META.yml: Added.
+        * web-platform-tests/background-fetch/OWNERS: Removed.
+        * web-platform-tests/background-fetch/abort.https.window.html: Added.
+        * web-platform-tests/background-fetch/abort.https.window.js: Added.
+        (backgroundFetchTest.async test):
+        (backgroundFetch.await.new.Promise.resolve.registration.onprogress.async event):
+        * web-platform-tests/background-fetch/content-security-policy.https.window.html: Added.
+        * web-platform-tests/background-fetch/content-security-policy.https.window.js:
+        (backgroundFetchTest):
+        * web-platform-tests/background-fetch/credentials-in-url.https.window.js: Removed.
+        * web-platform-tests/background-fetch/dangling-markup.https.window.js: Removed.
+        * web-platform-tests/background-fetch/fetch-uploads.https.window.html: Added.
+        * web-platform-tests/background-fetch/fetch-uploads.https.window.js: Added.
+        (backgroundFetchTest.async test):
+        * web-platform-tests/background-fetch/fetch.https.window.html: Added.
+        * web-platform-tests/background-fetch/fetch.https.window.js: Added.
+        (promise_test.async test):
+        (backgroundFetchTest.async test):
+        * web-platform-tests/background-fetch/get-ids.https.window.html: Added.
+        * web-platform-tests/background-fetch/get-ids.https.window.js: Added.
+        (promise_test.async test):
+        (backgroundFetchTest.async test):
+        * web-platform-tests/background-fetch/get.https.window.html: Added.
+        * web-platform-tests/background-fetch/get.https.window.js: Added.
+        (promise_test.async test):
+        (backgroundFetchTest.async test):
+        * web-platform-tests/background-fetch/idlharness.https.any.html: Added.
+        * web-platform-tests/background-fetch/idlharness.https.any.js: Added.
+        * web-platform-tests/background-fetch/idlharness.https.any.worker.html: Added.
+        * web-platform-tests/background-fetch/interfaces-worker.https-expected.txt: Removed.
+        * web-platform-tests/background-fetch/interfaces-worker.https.html: Removed.
+        * web-platform-tests/background-fetch/interfaces.html: Removed.
+        * web-platform-tests/background-fetch/interfaces.worker.js: Removed.
+        * web-platform-tests/background-fetch/match.https.window.html: Added.
+        * web-platform-tests/background-fetch/match.https.window.js: Added.
+        (backgroundFetchTest.async test):
+        * web-platform-tests/background-fetch/mixed-content-and-allowed-schemes.https.window.html: Added.
+        * web-platform-tests/background-fetch/mixed-content-and-allowed-schemes.https.window.js:
+        (backgroundFetchTest):
+        * web-platform-tests/background-fetch/port-blocking.https.window.html: Added.
+        * web-platform-tests/background-fetch/port-blocking.https.window.js:
+        (backgroundFetchTest):
+        * web-platform-tests/background-fetch/resources/feature-name.txt: Added.
+        * web-platform-tests/background-fetch/resources/sw.js: Removed.
+        * web-platform-tests/background-fetch/resources/upload.py: Added.
+        (main):
+        * web-platform-tests/background-fetch/resources/utils.js:
+        (async getMessageFromServiceWorker.return.new.Promise):
+        (async getMessageFromServiceWorker):
+        (async registerAndActivateServiceWorker):
+        (backgroundFetchTest):
+        (async uniqueId):
+        * web-platform-tests/background-fetch/resources/w3c-import.log:
+        * web-platform-tests/background-fetch/service_workers/sw-abort.js: Added.
+        (async getFetchResult):
+        * web-platform-tests/background-fetch/service_workers/sw-helpers.js: Added.
+        (sendMessageToDocument):
+        (cloneRegistration.deepCopy):
+        (cloneRegistration):
+        * web-platform-tests/background-fetch/service_workers/sw-update-ui.js: Added.
+        (async updateUI):
+        * web-platform-tests/background-fetch/service_workers/sw.js: Added.
+        (async getFetchResult):
+        (handleBackgroundFetchEvent.switch.async bind):
+        * web-platform-tests/background-fetch/service_workers/w3c-import.log: Copied from LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/w3c-import.log.
+        * web-platform-tests/background-fetch/update-ui.https.window.html: Added.
+        * web-platform-tests/background-fetch/update-ui.https.window.js: Added.
+        (backgroundFetchTest.async test):
+        * web-platform-tests/background-fetch/w3c-import.log:
+
+2020-07-17  Chris Dumez  <[email protected]>
+
         Unreviewed, drop a couple of Fetch WPT tests that were dropped upstream
 
         Those failed to get dropped during the recent resync in r264144.

Modified: trunk/LayoutTests/imported/w3c/resources/import-expectations.json (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/resources/import-expectations.json	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/resources/import-expectations.json	2020-07-17 22:57:05 UTC (rev 264542)
@@ -50,6 +50,7 @@
     "web-platform-tests/assumptions": "skip", 
     "web-platform-tests/audio-output": "skip", 
     "web-platform-tests/auxclick": "skip", 
+    "web-platform-tests/background-fetch": "import", 
     "web-platform-tests/battery-status": "skip", 
     "web-platform-tests/beacon": "import", 
     "web-platform-tests/bluetooth": "skip", 

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/META.yml (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/META.yml	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/META.yml	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1,4 @@
+spec: https://wicg.github.io/background-fetch/
+suggested_reviewers:
+  - beverloo
+  - jakearchibald

Deleted: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/OWNERS (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/OWNERS	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/OWNERS	2020-07-17 22:57:05 UTC (rev 264542)
@@ -1,2 +0,0 @@
-@beverloo
-@jakearchibald

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/abort.https.window.html (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/abort.https.window.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/abort.https.window.html	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/abort.https.window.js (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/abort.https.window.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/abort.https.window.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1,74 @@
+// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
+// META: script=resources/utils.js
+'use strict';
+
+// Covers basic functionality provided by BackgroundFetchManager.abort().
+// https://wicg.github.io/background-fetch/#background-fetch-registration-abort
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registration = await backgroundFetch.fetch(
+      uniqueId(),
+      ['resources/feature-name.txt', '/common/slow.py']);
+
+  assert_true(await registration.abort());
+  assert_false(await registration.abort());
+
+}, 'Aborting the same registration twice fails');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registration = await backgroundFetch.fetch(
+      uniqueId(),
+      ['resources/feature-name.txt', '/common/slow.py']);
+
+  await new Promise(resolve => {
+    let aborted = false;
+    const expectedResultText = 'Background Fetch';
+
+    registration._onprogress_ = async event => {
+      if (event.target.downloaded < expectedResultText.length)
+        return;
+
+      if (aborted)
+        return;
+
+      // Abort after the first file has been downloaded and check the results.
+
+      aborted = true;
+      assert_true(await registration.abort());
+
+      const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+
+      assert_equals(eventRegistration.result, 'failure');
+      assert_equals(eventRegistration.failureReason, 'aborted');
+      assert_equals(registration.result, 'failure');
+      assert_equals(registration.failureReason, 'aborted');
+
+      assert_equals(type, 'backgroundfetchabort');
+
+      assert_equals(results.length, 2);
+
+      const completedResult = results[0] || results[1];
+      // The abort might have gone through before the first result was persisted.
+      if (completedResult) {
+        assert_true(completedResult.url.includes('resources/feature-name.txt'));
+        assert_equals(completedResult.status, 200);
+        assert_equals(completedResult.text, expectedResultText);
+      }
+
+      resolve();
+    };
+  });
+
+}, 'Calling BackgroundFetchRegistration.abort sets the correct fields and responses are still available');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registration = await backgroundFetch.fetch(
+      uniqueId(), '/common/slow.py');
+  assert_true(await registration.abort());
+
+  const {results} = await getMessageFromServiceWorker();
+  assert_equals(results.length, 1);
+  assert_false(results[0].response);
+  assert_equals(results[0].name, 'AbortError');
+
+}, 'An aborted fetch throws a DOM exception when accessing an incomplete record', 'sw-abort.js');
\ No newline at end of file

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/content-security-policy.https.window.html (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/content-security-policy.https.window.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/content-security-policy.https.window.html	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/content-security-policy.https.window.js (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/content-security-policy.https.window.js	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/content-security-policy.https.window.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -14,7 +14,7 @@
 document.head.appendChild(meta);
 
 backgroundFetchTest((t, bgFetch) => {
-  return promise_rejects(
-      t, new TypeError(),
-      bgFetch.fetch(uniqueTag(), 'https://example.com'));
+  return promise_rejects_js(
+      t, TypeError,
+      bgFetch.fetch(uniqueId(), 'https://example.com'));
 }, 'fetch blocked by CSP should reject');

Deleted: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/credentials-in-url.https.window.js (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/credentials-in-url.https.window.js	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/credentials-in-url.https.window.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -1,32 +0,0 @@
-// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
-// META: script=resources/utils.js
-'use strict';
-
-// "If parsedURL includes credentials, then throw a TypeError."
-// https://fetch.spec.whatwg.org/#dom-request
-// (Added by https://github.com/whatwg/fetch/issues/26).
-// "A URL includes credentials if its username or password is not the empty
-// string."
-// https://url.spec.whatwg.org/#include-credentials
-
-backgroundFetchTest((t, bgFetch) => {
-  return bgFetch.fetch(uniqueTag(), '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:[email protected]'));
-}, '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'));
-}, 'fetch with username and empty password in URL should reject');
-
-backgroundFetchTest((t, bgFetch) => {
-  return promise_rejects(
-      t, new TypeError(),
-      bgFetch.fetch(uniqueTag(), 'https://:[email protected]'));
-}, 'fetch with empty username and password in URL should reject');

Deleted: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/dangling-markup.https.window.js (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/dangling-markup.https.window.js	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/dangling-markup.https.window.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -1,17 +0,0 @@
-// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
-// META: script=resources/utils.js
-'use strict';
-
-// "If request's url's potentially-dangling-markup flag is set, and request's
-// url's scheme is an HTTP(S) scheme, then set response to a network error."
-// https://github.com/whatwg/fetch/pull/519
-// https://github.com/whatwg/fetch/issues/546
-
-// This is not a comprehensive test of dangling markup detection - it is just
-// intended to check that detection is enabled.
-
-backgroundFetchTest((t, bgFetch) => {
-  return promise_rejects(
-      t, new TypeError(),
-      bgFetch.fetch(uniqueTag(), 'https://example.com/?\n<'));
-}, 'fetch to URL containing \\n and < should reject');

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/fetch-uploads.https.window.html (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/fetch-uploads.https.window.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/fetch-uploads.https.window.html	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/fetch-uploads.https.window.js (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/fetch-uploads.https.window.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/fetch-uploads.https.window.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1,64 @@
+// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
+// META: script=resources/utils.js
+'use strict';
+
+// Covers basic functionality provided by BackgroundFetchManager.fetch().
+// Specifically, when `fetch` contains request uploads.
+// https://wicg.github.io/background-fetch/#background-fetch-manager-fetch
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const uploadData = 'Background Fetch!';
+  const request =
+      new Request('resources/upload.py', {method: 'POST', body: uploadData});
+
+  const registration = await backgroundFetch.fetch(uniqueId(), request);
+  assert_equals(registration.uploadTotal, uploadData.length);
+
+  const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+  assert_equals(type, 'backgroundfetchsuccess');
+  assert_equals(results.length, 1);
+  assert_equals(eventRegistration.result, 'success');
+  assert_equals(eventRegistration.failureReason, '');
+  assert_equals(eventRegistration.uploaded, uploadData.length);
+  assert_equals(results[0].text, uploadData);
+}, 'Fetch with an upload should work');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const uploadData = 'Background Fetch!';
+  const uploadRequest =
+      new Request('resources/upload.py', {method: 'POST', body: uploadData});
+
+  const registration = await backgroundFetch.fetch(
+      uniqueId(),
+      [uploadRequest, '/common/slow.py']);
+
+    const uploaded = await new Promise(resolve => {
+      registration._onprogress_ = event => {
+        if (event.target.downloaded === 0)
+          return;
+        // If a progress event with downloaded bytes was received, then
+        // everything was uploaded.
+        resolve(event.target.uploaded);
+      };
+    });
+
+  assert_equals(uploaded, uploadData.length);
+}, 'Progress event includes uploaded bytes');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const uploadRequest1 =
+      new Request('resources/upload.py', {method: 'POST', body: 'upload1'});
+  const uploadRequest2 =
+      new Request('resources/upload.py', {method: 'POST', body: 'upload2'});
+
+  await backgroundFetch.fetch(uniqueId(), [uploadRequest1, uploadRequest2]);
+
+  const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+  assert_equals(type, 'backgroundfetchsuccess');
+  assert_equals(results.length, 2);
+  assert_equals(eventRegistration.result, 'success');
+  assert_equals(eventRegistration.failureReason, '');
+
+  assert_array_equals([results[0].text, results[1].text].sort(),
+                      ['upload1', 'upload2']);
+}, 'Duplicate upload requests work and can be distinguished.');

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/fetch.https.window.html (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/fetch.https.window.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/fetch.https.window.html	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/fetch.https.window.js (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/fetch.https.window.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/fetch.https.window.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1,280 @@
+// META: script=/common/get-host-info.sub.js
+// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
+// META: script=resources/utils.js
+
+'use strict';
+
+// Covers basic functionality provided by BackgroundFetchManager.fetch().
+// https://wicg.github.io/background-fetch/#background-fetch-manager-fetch
+
+const wait = milliseconds =>
+  new Promise(resolve => step_timeout(resolve, milliseconds));
+
+promise_test(async test => {
+  // 6.3.1.9.2: If |registration|’s active worker is null, then reject promise
+  //            with a TypeError and abort these steps.
+  const script = 'service_workers/sw.js';
+  const scope = 'service_workers/' + location.pathname;
+
+  const serviceWorkerRegistration =
+    await service_worker_unregister_and_register(test, script, scope);
+
+  assert_equals(
+    serviceWorkerRegistration.active, null,
+    'There must not be an activated worker');
+
+  await promise_rejects_js(
+    test, TypeError,
+    serviceWorkerRegistration.backgroundFetch.fetch(
+      uniqueId(), ['resources/feature-name.txt']),
+      'fetch() must reject on pending and installing workers');
+
+}, 'Background Fetch requires an activated Service Worker');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  // 6.3.1.6: If |requests| is empty, then return a promise rejected with a
+  //          TypeError.
+  await promise_rejects_js(
+    test, TypeError, backgroundFetch.fetch(uniqueId(), []),
+    'Empty sequences are treated as NULL');
+
+  // 6.3.1.7.1: Let |internalRequest| be the request of the result of invoking
+  //            the Request constructor with |request|. If this throws an
+  //            exception, return a promise rejected with the exception.
+  await promise_rejects_js(
+    test, TypeError,
+    backgroundFetch.fetch(uniqueId(), 'https://user:pass@domain/secret.txt'),
+    'Exceptions thrown in the Request constructor are rethrown');
+
+  // 6.3.1.7.2: If |internalRequest|’s mode is "no-cors", then return a
+  //            promise rejected with a TypeError.
+  {
+    const request =
+      new Request('resources/feature-name.txt', {mode: 'no-cors'});
+
+    await promise_rejects_js(
+      test, TypeError, backgroundFetch.fetch(uniqueId(), request),
+      'Requests must not be in no-cors mode');
+  }
+
+}, 'Argument verification is done for BackgroundFetchManager.fetch()');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  // 6.3.1.9.2: If |bgFetchMap[id]| exists, reject |promise| with a TypeError
+  //            and abort these steps.
+  return promise_rejects_js(test, TypeError, Promise.all([
+    backgroundFetch.fetch('my-id', 'resources/feature-name.txt?1'),
+    backgroundFetch.fetch('my-id', 'resources/feature-name.txt?2')
+  ]));
+
+}, 'IDs must be unique among active Background Fetch registrations');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = uniqueId();
+  const registration =
+    await backgroundFetch.fetch(registrationId, '');
+
+  assert_equals(registration.id, registrationId);
+
+  const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+
+  assert_equals('backgroundfetchsuccess', type);
+  assert_equals(eventRegistration.result, 'success');
+  assert_equals(eventRegistration.failureReason, '');
+
+}, 'Empty URL is OK.');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = uniqueId();
+  const registration =
+    await backgroundFetch.fetch(registrationId,
+        new Request('https://example/com', {
+        method: 'PUT',
+      }));
+
+  assert_equals(registration.id, registrationId);
+
+  const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+
+  assert_equals(type, 'backgroundfetchsuccess');
+  assert_equals(eventRegistration.result, 'success');
+  assert_equals(eventRegistration.failureReason, '');
+}, 'Requests with PUT method require CORS Preflight and succeed.');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = uniqueId();
+  const registration =
+    await backgroundFetch.fetch(registrationId,
+        new Request('https://example/com', {
+        method: 'POST',
+        headers: {'Content-Type': 'text/json'}
+      }));
+
+  assert_equals(registration.id, registrationId);
+
+  const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+
+  assert_equals(type, 'backgroundfetchsuccess');
+  assert_equals(eventRegistration.result, 'success');
+  assert_equals(eventRegistration.failureReason, '');
+}, 'Requests with text/json content type require CORS Preflight and succeed.');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = uniqueId();
+  const registration =
+    await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
+
+  assert_equals(registration.id, registrationId);
+  assert_equals(registration.uploadTotal, 0);
+  assert_equals(registration.uploaded, 0);
+  assert_equals(registration.downloadTotal, 0);
+  assert_equals(registration.result, '');
+  assert_equals(registration.failureReason, '');
+  assert_true(registration.recordsAvailable);
+  // Skip `downloaded`, as the transfer may have started already.
+
+  const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+  assert_equals('backgroundfetchsuccess', type);
+  assert_equals(results.length, 1);
+
+  assert_equals(eventRegistration.id, registration.id);
+  assert_equals(eventRegistration.result, 'success');
+  assert_equals(eventRegistration.failureReason, '');
+
+  assert_true(results[0].url.includes('resources/feature-name.txt'));
+  assert_equals(results[0].status, 200);
+  assert_equals(results[0].text, 'Background Fetch');
+
+}, 'Using Background Fetch to successfully fetch a single resource');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = uniqueId();
+  const registration =
+    await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
+
+  assert_equals(registration.result, '');
+  assert_equals(registration.failureReason, '');
+
+  const {type, eventRegistration, results} =
+    await getMessageFromServiceWorker();
+  assert_equals('backgroundfetchsuccess', type);
+
+  assert_equals(eventRegistration.id, registration.id);
+  assert_equals(registration.result, 'success');
+  assert_equals(registration.failureReason, '');
+
+}, 'Registration object gets updated values when a background fetch completes.');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = uniqueId();
+
+  // Very large download total that will definitely exceed the quota.
+  const options = {downloadTotal: Number.MAX_SAFE_INTEGER};
+  await promise_rejects_dom(
+    test, 'QUOTA_EXCEEDED_ERR',
+    backgroundFetch.fetch(registrationId, 'resources/feature-name.txt', options),
+    'This fetch should have thrown a quota exceeded error');
+
+}, 'Background Fetch that exceeds the quota throws a QuotaExceededError');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registration = await backgroundFetch.fetch(
+    'my-id', ['resources/feature-name.txt', 'resources/feature-name.txt']);
+
+  const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+  assert_equals('backgroundfetchsuccess', type);
+  assert_equals(results.length, 2);
+
+  assert_equals(eventRegistration.id, registration.id);
+  assert_equals(eventRegistration.result, 'success');
+  assert_equals(eventRegistration.failureReason, '');
+
+  for (const result of results) {
+    assert_true(result.url.includes('resources/feature-name.txt'));
+    assert_equals(result.status, 200);
+    assert_equals(result.text, 'Background Fetch');
+  }
+
+}, 'Fetches can have requests with duplicate URLs');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = uniqueId();
+  const registration =
+    await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
+  assert_true(registration.recordsAvailable);
+
+  const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+  assert_equals('backgroundfetchsuccess', type);
+  assert_equals(results.length, 1);
+
+  // Wait for up to 5 seconds for the |eventRegistration|'s recordsAvailable
+  // flag to be set to false, which happens after the successful invocation
+  // of the ServiceWorker event has finished.
+  for (let i = 0; i < 50; ++i) {
+    if (!registration.recordsAvailable)
+      break;
+    await wait(100);
+  }
+
+  assert_false(registration.recordsAvailable);
+}, 'recordsAvailable is false after onbackgroundfetchsuccess finishes execution.');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = uniqueId();
+  const registration =
+    await backgroundFetch.fetch(registrationId, 'resources/missing-cat.txt');
+
+  assert_equals(registration.id, registrationId);
+  assert_equals(registration.result, '');
+  assert_equals(registration.failureReason, '');
+
+  const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+  assert_equals(type, 'backgroundfetchfail');
+  assert_equals(results.length, 1);
+  assert_true(results[0].url.includes('resources/missing-cat.txt'));
+  assert_equals(results[0].status, 404);
+  assert_equals(results[0].text, '');
+
+  assert_equals(eventRegistration.id, registration.id);
+  assert_equals(eventRegistration.result, 'failure');
+  assert_equals(eventRegistration.failureReason, 'bad-status');
+
+  assert_equals(registration.result, 'failure');
+  assert_equals(registration.failureReason, 'bad-status');
+
+}, 'Using Background Fetch to fetch a non-existent resource should fail.');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registration = await backgroundFetch.fetch(
+      'my-id',
+      [location.origin, location.origin.replace('https', 'http')]);
+
+  const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+
+  assert_equals('backgroundfetchfail', type);
+  assert_equals(eventRegistration.failureReason, 'fetch-error');
+
+  assert_equals(results.length, 2);
+
+  const validResponse = results[0] ? results[0] : results[1];
+  const nullResponse = !results[0] ? results[0] : results[1];
+
+  assert_true(validResponse.url.includes(location.origin));
+  assert_equals(nullResponse, null);
+
+}, 'Fetches with mixed content should fail.');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const filePath = '/background-fetch/resources/feature-name.txt';
+  const registration = await backgroundFetch.fetch(
+    uniqueId(),
+    `https://${get_host_info().REMOTE_HOST}${filePath}`);
+
+  const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+  assert_equals(type, 'backgroundfetchfail');
+  assert_equals(results.length, 1);
+
+  assert_equals(results[0], null);
+  assert_equals(eventRegistration.id, registration.id);
+  assert_equals(eventRegistration.downloaded, 0);
+}, 'Responses failing CORS checks are not leaked');

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/get-ids.https.window.html (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/get-ids.https.window.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/get-ids.https.window.html	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/get-ids.https.window.js (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/get-ids.https.window.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/get-ids.https.window.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1,45 @@
+// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
+// META: script=resources/utils.js
+'use strict';
+
+// Covers functionality provided by BackgroundFetchManager.getIds(), which
+// exposes the keys of active background fetches.
+//
+// https://wicg.github.io/background-fetch/#background-fetch-manager-getIds
+
+promise_test(async test => {
+  const script = 'service_workers/sw.js';
+  const scope = 'service_workers/' + location.pathname;
+
+  const serviceWorkerRegistration =
+      await service_worker_unregister_and_register(test, script, scope);
+
+  assert_equals(
+      serviceWorkerRegistration.active, null,
+      'There must not be an activated worker');
+
+  const ids = await serviceWorkerRegistration.backgroundFetch.getIds();
+  assert_equals(ids.length, 0);
+
+}, 'BackgroundFetchManager.getIds() does not require an activated worker');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  // There should not be any active background fetches at this point.
+  {
+    const ids = await backgroundFetch.getIds();
+    assert_equals(ids.length, 0);
+  }
+
+  const registrationId = uniqueId();
+  const registration =
+      await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
+  assert_equals(registration.id, registrationId);
+
+  // The |registrationId| should be active, and thus be included in getIds().
+  {
+    const ids = await backgroundFetch.getIds();
+    assert_equals(ids.length, 1);
+    assert_equals(ids[0], registrationId);
+  }
+
+}, 'The BackgroundFetchManager exposes active fetches');

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/get.https.window.html (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/get.https.window.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/get.https.window.html	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/get.https.window.js (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/get.https.window.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/get.https.window.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1,64 @@
+// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
+// META: script=resources/utils.js
+'use strict';
+
+// Covers functionality provided by BackgroundFetchManager.get(), which
+// exposes the keys of active background fetches.
+//
+// https://wicg.github.io/background-fetch/#background-fetch-manager-get
+
+promise_test(async test => {
+  const script = 'service_workers/sw.js';
+  const scope = 'service_workers/' + location.pathname;
+
+  const serviceWorkerRegistration =
+      await service_worker_unregister_and_register(test, script, scope);
+
+  assert_equals(
+      serviceWorkerRegistration.active, null,
+      'There must not be an activated worker');
+
+  const registration = await serviceWorkerRegistration.backgroundFetch.get('x');
+  assert_equals(registration, undefined);
+
+}, 'BackgroundFetchManager.get() does not require an activated worker');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  // The |id| parameter to the BackgroundFetchManager.get() method is required.
+  await promise_rejects_js(test, TypeError, backgroundFetch.get());
+  await promise_rejects_js(test, TypeError, backgroundFetch.get(''));
+
+  const registration = await backgroundFetch.get('my-id');
+  assert_equals(registration, undefined);
+
+}, 'Getting non-existing registrations yields `undefined`');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = uniqueId();
+  const registration = await backgroundFetch.fetch(
+      registrationId, 'resources/feature-name.txt', {downloadTotal: 1234});
+
+  assert_equals(registration.id, registrationId);
+  assert_equals(registration.uploadTotal, 0);
+  assert_equals(registration.uploaded, 0);
+  assert_equals(registration.downloadTotal, 1234);
+  assert_equals(registration.result, '');
+  assert_equals(registration.failureReason, '');
+  assert_true(registration.recordsAvailable);
+  // Skip `downloaded`, as the transfer may have started already.
+
+  const secondRegistration = await backgroundFetch.get(registrationId);
+  assert_not_equals(secondRegistration, null);
+
+  assert_equals(secondRegistration.id, registration.id);
+  assert_equals(secondRegistration.uploadTotal, registration.uploadTotal);
+  assert_equals(secondRegistration.uploaded, registration.uploaded);
+  assert_equals(secondRegistration.downloadTotal, registration.downloadTotal);
+  assert_equals(secondRegistration.failureReason, registration.failureReason);
+  assert_equals(secondRegistration.recordsAvailable, registration.recordsAvailable);
+
+  // While the transfer might have started, both BackgroundFetchRegistration
+  // objects should have the latest progress values.
+  assert_equals(secondRegistration.downloaded, registration.downloaded);
+
+}, 'Getting an existing registration has the expected values');

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/idlharness.https.any.html (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/idlharness.https.any.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/idlharness.https.any.html	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/idlharness.https.any.js (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/idlharness.https.any.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/idlharness.https.any.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1,25 @@
+// META: global=window,worker
+// META: script=/resources/WebIDLParser.js
+// META: script=/resources/idlharness.js
+// META: timeout=long
+
+'use strict';
+
+// https://wicg.github.io/background-fetch/
+
+idl_test(
+  ['background-fetch'],
+  ['service-workers', 'html', 'dom'],
+  idl_array => {
+    const isServiceWorker = location.pathname.includes('.serviceworker.');
+    if (isServiceWorker) {
+      idl_array.add_objects({
+        ServiceWorkerGlobalScope: ['self'],
+        ServiceWorkerRegistration: ['registration'],
+        BackgroundFetchManager: ['registration.backgroundFetch'],
+        BackgroundFetchEvent: ['new BackgroundFetchEvent("type")'],
+        BackgroundFetchUpdateEvent: ['new BackgroundFetchUpdateEvent("type")'],
+      });
+    }
+  }
+);

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/idlharness.https.any.worker.html (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/idlharness.https.any.worker.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/idlharness.https.any.worker.html	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Deleted: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/interfaces-worker.https-expected.txt (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/interfaces-worker.https-expected.txt	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/interfaces-worker.https-expected.txt	2020-07-17 22:57:05 UTC (rev 264542)
@@ -1,7 +0,0 @@
-idlharness test
-
-This test validates the WebIDL included in the Background Fetch API (Service Workers).
-
-
-FAIL Service Worker-scoped tests. assert_unreached: unregister should not fail: serviceWorker.getRegistration() is not yet implemented Reached unreachable code
-

Deleted: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/interfaces-worker.https.html (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/interfaces-worker.https.html	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/interfaces-worker.https.html	2020-07-17 22:57:05 UTC (rev 264542)
@@ -1,15 +0,0 @@
-<!doctype html>
-<meta charset="utf-8">
-<title>Background Fetch API IDL tests</title>
-<script src=""
-<script src=""
-<script src=""
-
-<h1>idlharness test</h1>
-<p>This test validates the WebIDL included in the Background Fetch API (Service Workers).</p>
-
-<script>
-'use strict';
-
-service_worker_test('interfaces.worker.js', 'Service Worker-scoped tests.');
-</script>

Deleted: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/interfaces.html (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/interfaces.html	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/interfaces.html	2020-07-17 22:57:05 UTC (rev 264542)
@@ -1,28 +0,0 @@
-<!doctype html>
-<meta charset="utf-8">
-<title>Background Fetch API IDL tests</title>
-<script src=""
-<script src=""
-<script src=""
-<script src=""
-
-<h1>idlharness test</h1>
-<p>This test validates the WebIDL included in the Background Fetch API (Documents).</p>
-
-<script>
-'use strict';
-
-promise_test(async function () {
-  const idls = await fetch('/interfaces/background-fetch.idl').then(r => r.text());
-  const dom = await fetch('/interfaces/dom.idl').then(r => r.text());
-
-  var idlArray = new IdlArray();
-  idlArray.add_untested_idls('interface ServiceWorkerRegistration {};');
-  idlArray.add_untested_idls('[Exposed=ServiceWorker] interface ServiceWorkerGlobalScope {};');
-  idlArray.add_untested_idls('interface ExtendableEvent{};');
-  idlArray.add_untested_idls('dictionary ExtendableEventInit{};');
-  idlArray.add_untested_idls(dom, { only: ['EventTarget'] });
-  idlArray.add_idls(idls);
-  idlArray.test();
-}, 'Exposed interfaces in a Document.');
-</script>

Deleted: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/interfaces.worker.js (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/interfaces.worker.js	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/interfaces.worker.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -1,20 +0,0 @@
-'use strict';
-
-importScripts('/resources/testharness.js');
-importScripts('/resources/WebIDLParser.js', '/resources/idlharness.js');
-
-promise_test(async function() {
-  const idls = await fetch('/interfaces/background-fetch.idl').then(r => r.text());
-  const dom = await fetch('/interfaces/dom.idl').then(r => r.text());
-
-  var idlArray = new IdlArray();
-  idlArray.add_untested_idls('interface ServiceWorkerRegistration {};');
-  idlArray.add_untested_idls('[SecureContext, Exposed = (Window, Worker)] interface ServiceWorkerGlobalScope {};');
-  idlArray.add_untested_idls('interface ExtendableEvent{};');
-  idlArray.add_untested_idls('dictionary ExtendableEventInit{};');
-  idlArray.add_untested_idls(dom, { only: ['EventTarget'] });
-  idlArray.add_idls(idls);
-  idlArray.test();
-}, 'Exposed interfaces in a Service Worker.');
-
-done();

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/match.https.window.html (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/match.https.window.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/match.https.window.html	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/match.https.window.js (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/match.https.window.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/match.https.window.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1,113 @@
+// META: script=/common/get-host-info.sub.js
+// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
+// META: script=resources/utils.js
+
+'use strict';
+
+// Covers basic functionality provided by BackgroundFetchRegistration.match(All)?.
+// https://wicg.github.io/background-fetch/#dom-backgroundfetchregistration-match
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = 'matchexistingrequest';
+  const registration =
+      await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
+
+  assert_equals(registration.id, registrationId);
+
+  const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+  assert_equals('backgroundfetchsuccess', type);
+  assert_equals(results.length, 1);
+
+  assert_equals(eventRegistration.id, registration.id);
+  assert_equals(eventRegistration.result, 'success');
+  assert_equals(eventRegistration.failureReason, '');
+
+  assert_true(results[0].url.includes('resources/feature-name.txt'));
+  assert_equals(results[0].status, 200);
+  assert_equals(results[0].text, 'Background Fetch');
+
+}, 'Matching to a single request should work');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = 'matchmissingrequest';
+  const registration =
+      await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
+
+  assert_equals(registration.id, registrationId);
+
+  const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+  assert_equals('backgroundfetchsuccess', type);
+  assert_equals(results.length, 0);
+
+  assert_equals(eventRegistration.id, registration.id);
+  assert_equals(eventRegistration.result, 'success');
+  assert_equals(eventRegistration.failureReason, '');
+
+}, 'Matching to a non-existing request should work');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = 'matchexistingrequesttwice';
+  const registration =
+      await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
+
+  assert_equals(registration.id, registrationId);
+
+  const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+  assert_equals('backgroundfetchsuccess', type);
+  assert_equals(results.length, 2);
+
+  assert_equals(eventRegistration.id, registration.id);
+  assert_equals(eventRegistration.result, 'success');
+  assert_equals(eventRegistration.failureReason, '');
+
+  assert_true(results[0].url.includes('resources/feature-name.txt'));
+  assert_equals(results[0].status, 200);
+  assert_equals(results[0].text, 'Background Fetch');
+
+  assert_true(results[1].url.includes('resources/feature-name.txt'));
+  assert_equals(results[1].status, 200);
+  assert_equals(results[1].text, 'Background Fetch');
+
+}, 'Matching multiple times on the same request works as expected.');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registration = await backgroundFetch.fetch(
+      uniqueId(), ['resources/feature-name.txt', '/common/slow.py']);
+
+  const record = await registration.match('resources/feature-name.txt');
+  const response = await record.responseReady;
+  assert_true(response.url.includes('resources/feature-name.txt'));
+  const completedResponseText = await response.text();
+  assert_equals(completedResponseText, 'Background Fetch');
+
+}, 'Access to active fetches is supported.');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registration = await backgroundFetch.fetch(
+      uniqueId(), [
+          'resources/feature-name.txt',
+          'resources/feature-name.txt',
+          'resources/feature-name.txt?id=3',
+          new Request('resources/feature-name.txt', {method: 'PUT'}),
+          '/common/slow.py',
+      ]);
+
+  let matchedRecords = null;
+
+  // We should match all the duplicates.
+  matchedRecords = await registration.matchAll('resources/feature-name.txt');
+  assert_equals(matchedRecords.length, 2);
+
+  // We should match the request with the query param as well.
+  matchedRecords = await registration.matchAll('resources/feature-name.txt', {ignoreSearch: true});
+  assert_equals(matchedRecords.length, 3);
+
+  // We should match the PUT request as well.
+  matchedRecords = await registration.matchAll('resources/feature-name.txt', {ignoreMethod: true});
+  assert_equals(matchedRecords.length, 3);
+
+  // We should match all requests.
+  matchedRecords = await registration.matchAll('resources/feature-name.txt', {ignoreSearch: true, ignoreMethod: true});
+  assert_equals(matchedRecords.length, 4);
+
+}, 'Match with query options.');

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/mixed-content-and-allowed-schemes.https.window.html (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/mixed-content-and-allowed-schemes.https.window.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/mixed-content-and-allowed-schemes.https.window.html	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/mixed-content-and-allowed-schemes.https.window.js (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/mixed-content-and-allowed-schemes.https.window.js	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/mixed-content-and-allowed-schemes.https.window.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -15,65 +15,37 @@
 // 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'));
-}, 'non-loopback http: fetch should reject');
-
-backgroundFetchTest((t, bgFetch) => {
-  return promise_rejects(t, new TypeError(),
-                         bgFetch.fetch(uniqueTag(), '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]'));
-}, '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']));
-}, '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']));
-}, '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'));
+  return promise_rejects_js(t, TypeError,
+                         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:///'));
+  return promise_rejects_js(t, TypeError,
+                         bgFetch.fetch(uniqueId(), 'file:///'));
 }, 'file: fetch should reject');
 
 backgroundFetchTest((t, bgFetch) => {
-  return promise_rejects(t, new TypeError(),
-                         bgFetch.fetch(uniqueTag(), 'data:text/plain,foo'));
+  return promise_rejects_js(t, TypeError,
+                         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'));
+  return promise_rejects_js(t, TypeError,
+                         bgFetch.fetch(uniqueId(), 'foobar:bazqux'));
 }, 'unknown scheme fetch should reject');

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/port-blocking.https.window.html (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/port-blocking.https.window.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/port-blocking.https.window.html	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/port-blocking.https.window.js (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/port-blocking.https.window.js	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/port-blocking.https.window.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -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'));
+  return promise_rejects_js(
+      t, TypeError,
+      bgFetch.fetch(uniqueId(), 'https://example.com:587'));
 }, 'fetch to bad port (SMTP) should reject');

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/feature-name.txt (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/feature-name.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/feature-name.txt	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1 @@
+Background Fetch
\ No newline at end of file

Deleted: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/sw.js (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/sw.js	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/sw.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -1 +0,0 @@
-// Deliberately left empty for now.
\ No newline at end of file

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/upload.py (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/upload.py	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/upload.py	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1,3 @@
+# Simply returns the request body to check if the upload succeeded.
+def main(request, response):
+    return 200, [(b"Content-Type", request.headers[b'content-type'])], request.body

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/utils.js (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/utils.js	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/utils.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -1,26 +1,55 @@
 'use strict';
 
+let nextBackgroundFetchId = 0;
+
+// Waits for a single message received from a registered Service Worker.
+async function getMessageFromServiceWorker() {
+  return new Promise(resolve => {
+    function listener(event) {
+      navigator.serviceWorker.removeEventListener('message', listener);
+      resolve(event.data);
+    }
+
+    navigator.serviceWorker.addEventListener('message', listener);
+  });
+}
+
+// Registers the |name| instrumentation Service Worker located at "service_workers/"
+// 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;
+async function registerAndActivateServiceWorker(test, name) {
+  const script = `service_workers/${name}`;
+  const scope = 'service_workers/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;
 }
 
-function backgroundFetchTest(func, description) {
+// Creates a Promise test for |func| given the |description|. The |func| will be
+// executed with the `backgroundFetch` object of an activated Service Worker
+// Registration.
+// |workerName| is the name of the service worker file in the service_workers
+// directory to register.
+function backgroundFetchTest(func, description, workerName = 'sw.js') {
   promise_test(async t => {
-    const serviceWorkerRegistration = await registerAndActivateServiceWorker(t);
+    const serviceWorkerRegistration =
+        await registerAndActivateServiceWorker(t, workerName);
+    serviceWorkerRegistration.active.postMessage(null);
+
+    assert_equals(await getMessageFromServiceWorker(), 'ready');
+
     return func(t, serviceWorkerRegistration.backgroundFetch);
   }, 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++;
+}

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/w3c-import.log (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/w3c-import.log	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/w3c-import.log	2020-07-17 22:57:05 UTC (rev 264542)
@@ -1,7 +1,7 @@
 The tests in this directory were imported from the W3C repository.
 Do NOT modify these tests directly in WebKit.
 Instead, create a pull request on the WPT github:
-	https://github.com/w3c/web-platform-tests
+	https://github.com/web-platform-tests/wpt
 
 Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport
 
@@ -14,5 +14,6 @@
 None
 ------------------------------------------------------------------------
 List of files:
-/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/sw.js
+/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/feature-name.txt
+/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/upload.py
 /LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/utils.js

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw-abort.js (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw-abort.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw-abort.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1,23 @@
+importScripts('sw-helpers.js');
+
+async function getFetchResult(record) {
+  try {
+    await record.responseReady;
+  } catch (e) {
+    return {
+      response: false,
+      name: e.name,
+    };
+  }
+
+  return {
+    response: true,
+  };
+}
+self.addEventListener('backgroundfetchabort', event => {
+  event.waitUntil(
+    event.registration.matchAll()
+      .then(records =>
+            Promise.all(records.map(record => getFetchResult(record))))
+      .then(results => sendMessageToDocument({results})));
+});

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw-helpers.js (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw-helpers.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw-helpers.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1,31 @@
+// The source to post setup and completion results to.
+let source = null;
+
+function sendMessageToDocument(msg) {
+  source.postMessage(msg);
+}
+
+// This is needed to create a local _javascript_ object identical to the
+// one returned by a BackgroundFetchEvent, so that it can be serialized
+// and transmitted from the service worker context to the document.
+function cloneRegistration(registration) {
+  function deepCopy(src) {
+    if (typeof src !== 'object' || src ="" null)
+        return src;
+    var dst = Array.isArray(src) ? [] : {};
+    for (var property in src) {
+        if (typeof src[property] === 'function')
+            continue;
+        dst[property] = deepCopy(src[property]);
+    }
+    return dst;
+  }
+
+  return deepCopy(registration);
+}
+
+// Notify the document that the SW is registered and ready.
+self.addEventListener('message', event => {
+  source = event.source;
+  sendMessageToDocument('ready');
+});

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw-update-ui.js (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw-update-ui.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw-update-ui.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1,33 @@
+importScripts('/resources/testharness.js');
+importScripts('sw-helpers.js');
+
+async function updateUI(event) {
+  let updateParams = [];
+  switch (event.registration.id) {
+    case 'update-once':
+      updateParams = [{title: 'Title1'}];
+      break;
+    case 'update-twice':
+      updateParams = [{title: 'Title1'}, {title: 'Title2'}];
+      break;
+  }
+
+  return Promise.all(updateParams.map(param => event.updateUI(param)))
+           .then(() => 'update success')
+           .catch(e => e.name);
+}
+
+self.addEventListener('backgroundfetchsuccess', event => {
+  if (event.registration.id === 'update-inactive') {
+    // Post an async task before calling updateUI from the inactive event.
+    // Any async behaviour outside `waitUntil` should mark the event as
+    // inactive, and subsequent calls to `updateUI` should fail.
+    new Promise(r => step_timeout(r, 0))
+        .then(() => event.updateUI({ title: 'New title' }))
+        .catch(e => sendMessageToDocument({ update: e.name }));
+    return;
+  }
+
+  event.waitUntil(updateUI(event)
+      .then(update => sendMessageToDocument({ update })));
+});

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw.js (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1,60 @@
+
+importScripts('sw-helpers.js');
+
+async function getFetchResult(record) {
+  const response = await record.responseReady.catch(() => null);
+  if (!response) return null;
+
+  return {
+    url: response.url,
+    status: response.status,
+    text: await response.text().catch(() => 'error'),
+  };
+}
+
+function handleBackgroundFetchEvent(event) {
+  let matchFunction = null;
+
+  switch (event.registration.id) {
+    case 'matchexistingrequest':
+      matchFunction = event.registration.match.bind(
+          event.registration, '/background-fetch/resources/feature-name.txt');
+      break;
+    case 'matchexistingrequesttwice':
+      matchFunction = (async () => {
+        const match1 = await event.registration.match('/background-fetch/resources/feature-name.txt');
+        const match2 = await event.registration.match('/background-fetch/resources/feature-name.txt');
+        return [match1, match2];
+    }).bind(event.registration);
+      break;
+    case 'matchmissingrequest':
+      matchFunction = event.registration.match.bind(
+          event.registration, '/background-fetch/resources/missing.txt');
+      break;
+    default:
+      matchFunction = event.registration.matchAll.bind(event.registration);
+      break;
+  }
+
+  event.waitUntil(
+    matchFunction()
+      // Format `match(All)?` function results.
+      .then(records => {
+        if (!records) return [];  // Nothing was matched.
+        if (!records.map) return [records];  // One entry was returned.
+        return records;  // Already in a list.
+      })
+      // Extract responses.
+      .then(records =>
+        Promise.all(records.map(record => getFetchResult(record))))
+      // Clone registration and send message.
+      .then(results => {
+        const registrationCopy = cloneRegistration(event.registration);
+        sendMessageToDocument(
+          { type: event.type, eventRegistration: registrationCopy, results })
+      }));
+}
+
+self.addEventListener('backgroundfetchsuccess', handleBackgroundFetchEvent);
+self.addEventListener('backgroundfetchfail', handleBackgroundFetchEvent);
+self.addEventListener('backgroundfetchabort', handleBackgroundFetchEvent);

Copied: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/w3c-import.log (from rev 264541, trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/resources/w3c-import.log) (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/w3c-import.log	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/w3c-import.log	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1,20 @@
+The tests in this directory were imported from the W3C repository.
+Do NOT modify these tests directly in WebKit.
+Instead, create a pull request on the WPT github:
+	https://github.com/web-platform-tests/wpt
+
+Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport
+
+Do NOT modify or remove this file.
+
+------------------------------------------------------------------------
+Properties requiring vendor prefixes:
+None
+Property values requiring vendor prefixes:
+None
+------------------------------------------------------------------------
+List of files:
+/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw-abort.js
+/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw-helpers.js
+/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw-update-ui.js
+/LayoutTests/imported/w3c/web-platform-tests/background-fetch/service_workers/sw.js

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/update-ui.https.window.html (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/update-ui.https.window.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/update-ui.https.window.html	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/update-ui.https.window.js (0 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/update-ui.https.window.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/update-ui.https.window.js	2020-07-17 22:57:05 UTC (rev 264542)
@@ -0,0 +1,43 @@
+// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
+// META: script=resources/utils.js
+'use strict';
+
+// Covers functionality provided by BackgroundFetchUpdateUIEvent.updateUI().
+//
+// https://wicg.github.io/background-fetch/#backgroundfetchupdateuievent
+
+const swName = 'sw-update-ui.js';
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = 'update-once';
+  const registration =
+      await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
+  assert_equals(registration.id, registrationId);
+
+  const message = await getMessageFromServiceWorker();
+  assert_equals(message.update, 'update success');
+
+}, 'Background Fetch updateUI resolves', swName);
+
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = 'update-twice';
+  const registration =
+      await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
+  assert_equals(registration.id, registrationId);
+
+  const message = await getMessageFromServiceWorker();
+  assert_equals(message.update, 'InvalidStateError');
+
+}, 'Background Fetch updateUI called twice fails', swName);
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = 'update-inactive';
+  const registration =
+      await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
+  assert_equals(registration.id, registrationId);
+
+  const message = await getMessageFromServiceWorker();
+  assert_equals(message.update, 'InvalidStateError');
+
+}, 'Background Fetch updateUI fails when event is not active', swName);

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/w3c-import.log (264541 => 264542)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/w3c-import.log	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/background-fetch/w3c-import.log	2020-07-17 22:57:05 UTC (rev 264542)
@@ -1,7 +1,7 @@
 The tests in this directory were imported from the W3C repository.
 Do NOT modify these tests directly in WebKit.
 Instead, create a pull request on the WPT github:
-	https://github.com/w3c/web-platform-tests
+	https://github.com/web-platform-tests/wpt
 
 Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport
 
@@ -14,12 +14,15 @@
 None
 ------------------------------------------------------------------------
 List of files:
-/LayoutTests/imported/w3c/web-platform-tests/background-fetch/OWNERS
+/LayoutTests/imported/w3c/web-platform-tests/background-fetch/META.yml
+/LayoutTests/imported/w3c/web-platform-tests/background-fetch/abort.https.window.js
 /LayoutTests/imported/w3c/web-platform-tests/background-fetch/content-security-policy.https.window.js
-/LayoutTests/imported/w3c/web-platform-tests/background-fetch/credentials-in-url.https.window.js
-/LayoutTests/imported/w3c/web-platform-tests/background-fetch/dangling-markup.https.window.js
-/LayoutTests/imported/w3c/web-platform-tests/background-fetch/interfaces-worker.https.html
-/LayoutTests/imported/w3c/web-platform-tests/background-fetch/interfaces.html
-/LayoutTests/imported/w3c/web-platform-tests/background-fetch/interfaces.worker.js
+/LayoutTests/imported/w3c/web-platform-tests/background-fetch/fetch-uploads.https.window.js
+/LayoutTests/imported/w3c/web-platform-tests/background-fetch/fetch.https.window.js
+/LayoutTests/imported/w3c/web-platform-tests/background-fetch/get-ids.https.window.js
+/LayoutTests/imported/w3c/web-platform-tests/background-fetch/get.https.window.js
+/LayoutTests/imported/w3c/web-platform-tests/background-fetch/idlharness.https.any.js
+/LayoutTests/imported/w3c/web-platform-tests/background-fetch/match.https.window.js
 /LayoutTests/imported/w3c/web-platform-tests/background-fetch/mixed-content-and-allowed-schemes.https.window.js
 /LayoutTests/imported/w3c/web-platform-tests/background-fetch/port-blocking.https.window.js
+/LayoutTests/imported/w3c/web-platform-tests/background-fetch/update-ui.https.window.js

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (264541 => 264542)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2020-07-17 22:45:01 UTC (rev 264541)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2020-07-17 22:57:05 UTC (rev 264542)
@@ -970,8 +970,6 @@
 webkit.org/b/175419 [ Release ] http/tests/workers/service/postmessage-after-terminate.https.html [ Pass Failure Timeout ]
 
 # FIXME: This can't be the right bug number.
-webkit.org/b/175419 imported/w3c/web-platform-tests/background-fetch/interfaces-worker.https.html [ Failure ]
-webkit.org/b/175419 imported/w3c/web-platform-tests/background-fetch/interfaces.html [ Failure ]
 webkit.org/b/175419 imported/w3c/web-platform-tests/fetch/api/abort/serviceworker-intercepted.https.html [ Failure Pass ]
 
 # GTK ought to support async clipboard
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to