summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/background-fetch/get.https.window.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/background-fetch/get.https.window.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/background-fetch/get.https.window.js')
-rw-r--r--testing/web-platform/tests/background-fetch/get.https.window.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/testing/web-platform/tests/background-fetch/get.https.window.js b/testing/web-platform/tests/background-fetch/get.https.window.js
new file mode 100644
index 0000000000..d4448d184a
--- /dev/null
+++ b/testing/web-platform/tests/background-fetch/get.https.window.js
@@ -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');