Bug 1479491 [wpt PR 12234] - Migrate Background Fetch layout tests to WPT, a=testonly
authorPeter Beverloo <peter@chromium.org>
Thu, 02 Aug 2018 09:04:29 +0000
changeset 826254 1a0853f1f489be62ae0cf7d37ed7f27cb911a9e1
parent 826253 a8e939de6cc390d3ef56bec4284b7ac2d4937d33
child 826255 08b5956b5e0a5432982f73348006e03ef755a56d
push id118275
push userbmo:dharvey@mozilla.com
push dateFri, 03 Aug 2018 11:44:33 +0000
reviewerstestonly
bugs1479491, 12234, 864561, 1155118, 579370
milestone63.0a1
Bug 1479491 [wpt PR 12234] - Migrate Background Fetch layout tests to WPT, a=testonly Automatic update from web-platform-testsMigrate Background Fetch layout tests to WPT This CL migrates our Background Fetch layout tests to our WPT suite, and adds coverage in various new areas, together with a few minor bug fixes. Tests related to initializing the Service Worker events haven't been included as the event model has just been updated. New tests will be added based on that soon. One file which was removed without being migrated was "credentials-in-url.https.window.js". This was testing the Fetch API as opposed to Background Fetch. Instead, the requirement to propagate exceptions thrown by the Fetch API is tested in fetch.https.window.js. Bug: 864561 Change-Id: I077be6c5bf8c379e3108f4ec3207011582028477 Reviewed-on: https://chromium-review.googlesource.com/1155118 Commit-Queue: Peter Beverloo <peter@chromium.org> Reviewed-by: Rayan Kanso <rayankans@chromium.org> Cr-Commit-Position: refs/heads/master@{#579370} -- wpt-commits: fb974dd68affa515d39feee51f8fb4ba818ca13b wpt-pr: 12234
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/background-fetch/credentials-in-url.https.window.js
testing/web-platform/tests/background-fetch/fetch.https.window.js
testing/web-platform/tests/background-fetch/get-ids.https.js
testing/web-platform/tests/background-fetch/get-ids.https.window.js
testing/web-platform/tests/background-fetch/get.https.window.js
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -194183,21 +194183,16 @@
      {}
     ]
    ],
    "background-fetch/META.yml": [
     [
      {}
     ]
    ],
-   "background-fetch/get-ids.https.js": [
-    [
-     {}
-    ]
-   ],
    "background-fetch/resources/feature-name.txt": [
     [
      {}
     ]
    ],
    "background-fetch/resources/sw.js": [
     [
      {}
@@ -319999,34 +319994,40 @@
     ]
    ],
    "background-fetch/content-security-policy.https.window.js": [
     [
      "/background-fetch/content-security-policy.https.window.html",
      {}
     ]
    ],
-   "background-fetch/credentials-in-url.https.window.js": [
-    [
-     "/background-fetch/credentials-in-url.https.window.html",
-     {}
-    ]
-   ],
    "background-fetch/dangling-markup.https.window.js": [
     [
      "/background-fetch/dangling-markup.https.window.html",
      {}
     ]
    ],
    "background-fetch/fetch.https.window.js": [
     [
      "/background-fetch/fetch.https.window.html",
      {}
     ]
    ],
+   "background-fetch/get-ids.https.window.js": [
+    [
+     "/background-fetch/get-ids.https.window.html",
+     {}
+    ]
+   ],
+   "background-fetch/get.https.window.js": [
+    [
+     "/background-fetch/get.https.window.html",
+     {}
+    ]
+   ],
    "background-fetch/idlharness.any.js": [
     [
      "/background-fetch/idlharness.any.html",
      {}
     ],
     [
      "/background-fetch/idlharness.any.sharedworker.html",
      {}
@@ -428548,31 +428549,31 @@
   "background-fetch/META.yml": [
    "8ce9f8faa2acdfe7a2ef8dfc6c1ad8cbdf01c72d",
    "support"
   ],
   "background-fetch/content-security-policy.https.window.js": [
    "0b5b1cb5e94d3f27bebbb5a462bf1e823dfc57b4",
    "testharness"
   ],
-  "background-fetch/credentials-in-url.https.window.js": [
-   "df9a6629bed70f85f61545c5a7024dbd30ab3b2f",
-   "testharness"
-  ],
   "background-fetch/dangling-markup.https.window.js": [
    "764257d7d1a8eecfba6735647637055b21dcb94b",
    "testharness"
   ],
   "background-fetch/fetch.https.window.js": [
-   "4cda0efe95235389cabeeb3e084ff2f67cef188c",
-   "testharness"
-  ],
-  "background-fetch/get-ids.https.js": [
-   "ace782d657998725204ba00e4d35c46e06c01136",
-   "support"
+   "cca63289206f75de446852c1b37fb0c0911aadd7",
+   "testharness"
+  ],
+  "background-fetch/get-ids.https.window.js": [
+   "28f5bc3132b7209c343ee264fb0699184e7bb47c",
+   "testharness"
+  ],
+  "background-fetch/get.https.window.js": [
+   "0b272dbaa4961b73049325f7826713682b590f8c",
+   "testharness"
   ],
   "background-fetch/idlharness.any.js": [
    "ad204771c3a009bb94b5e8fbbdca8d4c7df3983b",
    "testharness"
   ],
   "background-fetch/mixed-content-and-allowed-schemes.https.window.js": [
    "9f24f13581819ef444a89cb7549de900f5b98ef6",
    "testharness"
deleted file mode 100644
--- a/testing/web-platform/tests/background-fetch/credentials-in-url.https.window.js
+++ /dev/null
@@ -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(uniqueId(), 'https://example.com');
-}, 'fetch without credentials in URL should register ok');
-
-backgroundFetchTest((t, bgFetch) => {
-  return promise_rejects(
-      t, new TypeError(),
-      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(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(uniqueId(), 'https://:password@example.com'));
-}, 'fetch with empty username and password in URL should reject');
--- a/testing/web-platform/tests/background-fetch/fetch.https.window.js
+++ b/testing/web-platform/tests/background-fetch/fetch.https.window.js
@@ -1,19 +1,76 @@
 // 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
 
+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 = 'resources/sw.js';
+  const scope = 'resources/scope' + 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(
+      test, new TypeError(),
+      serviceWorkerRegistration.backgroundFetch.fetch(
+          uniqueId(), ['resources/sw.js']),
+      '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(
+      test, new 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(
+      test, new 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/sw.js', {mode: 'no-cors'});
+    await promise_rejects(
+        test, new 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(test, new TypeError(), Promise.all([
+    backgroundFetch.fetch('my-id', 'resources/sw.js'),
+    backgroundFetch.fetch('my-id', 'resources/feature-name.txt')
+  ]));
+
+}, 'IDs must be unique among active Background Fetch registrations');
+
 backgroundFetchTest(async (test, backgroundFetch) => {
   const registrationId = uniqueId();
-  const registration = await backgroundFetch.fetch(
-      registrationId, 'resources/feature-name.txt');
+  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);
   // Skip `downloaded`, as the transfer may have started already.
 
   const {type, results} = await getMessageFromServiceWorker();
deleted file mode 100644
--- a/testing/web-platform/tests/background-fetch/get-ids.https.js
+++ /dev/null
@@ -1,19 +0,0 @@
-// 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
-
-backgroundFetchTest(async (test, backgroundFetch) => {
-  const registrationId = uniqueId();
-  const registration = await backgroundFetch.fetch(
-      registrationId, 'resources/feature-name.txt');
-
-  assert_equals(registration.id, registrationId);
-
-  assert_true((await backgroundFetch.getIds()).includes(registrationId));
-
-}, 'The BackgroundFetchManager exposes active fetches');
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/background-fetch/get-ids.https.window.js
@@ -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 = 'resources/sw.js';
+  const scope = 'resources/scope' + 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');
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/background-fetch/get.https.window.js
@@ -0,0 +1,58 @@
+// 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 = 'resources/sw.js';
+  const scope = 'resources/scope' + 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(test, new 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);
+  // 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);
+
+  // 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');