1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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');
|