get-ids.https.window.js (1542B)
1 // META: script=/service-workers/service-worker/resources/test-helpers.sub.js 2 // META: script=resources/utils.js 3 'use strict'; 4 5 // Covers functionality provided by BackgroundFetchManager.getIds(), which 6 // exposes the keys of active background fetches. 7 // 8 // https://wicg.github.io/background-fetch/#background-fetch-manager-getIds 9 10 promise_test(async test => { 11 const script = 'service_workers/sw.js'; 12 const scope = 'service_workers/' + location.pathname; 13 14 const serviceWorkerRegistration = 15 await service_worker_unregister_and_register(test, script, scope); 16 17 assert_equals( 18 serviceWorkerRegistration.active, null, 19 'There must not be an activated worker'); 20 21 const ids = await serviceWorkerRegistration.backgroundFetch.getIds(); 22 assert_equals(ids.length, 0); 23 24 }, 'BackgroundFetchManager.getIds() does not require an activated worker'); 25 26 backgroundFetchTest(async (test, backgroundFetch) => { 27 // There should not be any active background fetches at this point. 28 { 29 const ids = await backgroundFetch.getIds(); 30 assert_equals(ids.length, 0); 31 } 32 33 const registrationId = uniqueId(); 34 const registration = 35 await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt'); 36 assert_equals(registration.id, registrationId); 37 38 // The |registrationId| should be active, and thus be included in getIds(). 39 { 40 const ids = await backgroundFetch.getIds(); 41 assert_equals(ids.length, 1); 42 assert_equals(ids[0], registrationId); 43 } 44 45 }, 'The BackgroundFetchManager exposes active fetches');