| <!doctype html> |
| <meta charset="utf-8"> |
| <title>Background Fetch API: getIds() tests</title> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <script src="/serviceworker/resources/test-helpers.js"></script> |
| |
| <h1>BackgroundFetchManager.getIds()</h1> |
| <p>This test validates the behaviour of the getIds() method.</p> |
| |
| <!-- TODO(peter): Move this to the WPT directory when it's merged. --> |
| |
| <script> |
| 'use strict'; |
| |
| const workerUrl = 'resources/empty-worker.js'; |
| const scope = 'resources/scope/' + location.pathname; |
| |
| promise_test(function(test) { |
| return service_worker_unregister_and_register(test, workerUrl, scope) |
| .then(registration => { |
| assert_equals(null, registration.active); |
| return registration.backgroundFetch.getIds(); |
| }) |
| .then(unreached_fulfillment(test), error => { |
| assert_equals(error.name, 'TypeError'); |
| }); |
| |
| }, 'BackgroundFetchManager.getIds() requires an activated Service Worker.'); |
| |
| promise_test(function(test) { |
| let registration = null; |
| |
| return service_worker_unregister_and_register(test, workerUrl, scope) |
| .then(r => { |
| registration = r; |
| return wait_for_state(test, r.installing, 'activated'); |
| }) |
| .then(() => registration.backgroundFetch.getIds()) |
| .then(ids => { |
| assert_true(Array.isArray(ids)); |
| assert_equals(ids.length, 0); |
| }); |
| |
| }, 'BackgroundFetchManager.getIds() returns an empty sequence by default.'); |
| |
| promise_test(function(test) { |
| const ids = ['first-id', 'second-id', 'third-id']; |
| |
| let registration = null; |
| |
| return service_worker_unregister_and_register(test, workerUrl, scope) |
| .then(r => { |
| registration = r; |
| return wait_for_state(test, r.installing, 'activated'); |
| }) |
| .then(() => { |
| return Promise.all( |
| ids.map(id => registration.backgroundFetch.fetch(id, ['resources/non-existing-file.png']))); |
| }) |
| .then(() => registration.backgroundFetch.getIds()) |
| .then(receivedIds => { |
| assert_array_equals(receivedIds, ids); |
| }); |
| |
| }, 'BackgroundFetchManager.getIds() returns a sequence of active fetches.'); |
| |
| </script> |