Commit bef4d94c authored by Peter Beverloo's avatar Peter Beverloo Committed by Commit Bot

Migrate 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: default avatarRayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579370}
parent 645f34ee
...@@ -219,6 +219,12 @@ void BackgroundFetchContext::AbandonFetches( ...@@ -219,6 +219,12 @@ void BackgroundFetchContext::AbandonFetches(
.service_worker_registration_id() == .service_worker_registration_id() ==
service_worker_registration_id) { service_worker_registration_id) {
DCHECK(saved_iter->second); DCHECK(saved_iter->second);
// TODO(peter): Temporary work-around for a crash where fetches for a
// given Service Worker registration are abandoned twice.
if (saved_iter->second->aborted())
continue;
saved_iter->second->Abort( saved_iter->second->Abort(
BackgroundFetchReasonToAbort::SERVICE_WORKER_UNAVAILABLE); BackgroundFetchReasonToAbort::SERVICE_WORKER_UNAVAILABLE);
} }
......
...@@ -333,7 +333,7 @@ void BackgroundFetchDelegateProxy::Abort(const std::string& job_unique_id) { ...@@ -333,7 +333,7 @@ void BackgroundFetchDelegateProxy::Abort(const std::string& job_unique_id) {
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::BindOnce(&Core::Abort, ui_core_ptr_, job_unique_id)); base::BindOnce(&Core::Abort, ui_core_ptr_, job_unique_id));
job_details_map_.erase(job_details_map_.find(job_unique_id)); job_details_map_.erase(job_unique_id);
} }
void BackgroundFetchDelegateProxy::OnJobCancelled( void BackgroundFetchDelegateProxy::OnJobCancelled(
......
// 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');
...@@ -5,10 +5,67 @@ ...@@ -5,10 +5,67 @@
// Covers basic functionality provided by BackgroundFetchManager.fetch(). // Covers basic functionality provided by BackgroundFetchManager.fetch().
// https://wicg.github.io/background-fetch/#background-fetch-manager-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) => { backgroundFetchTest(async (test, backgroundFetch) => {
const registrationId = uniqueId(); const registrationId = uniqueId();
const registration = await backgroundFetch.fetch( const registration =
registrationId, 'resources/feature-name.txt'); await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
assert_equals(registration.id, registrationId); assert_equals(registration.id, registrationId);
assert_equals(registration.uploadTotal, 0); assert_equals(registration.uploadTotal, 0);
......
...@@ -7,13 +7,39 @@ ...@@ -7,13 +7,39 @@
// //
// https://wicg.github.io/background-fetch/#background-fetch-manager-getIds // 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) => { backgroundFetchTest(async (test, backgroundFetch) => {
const registrationId = uniqueId(); // There should not be any active background fetches at this point.
const registration = await backgroundFetch.fetch( {
registrationId, 'resources/feature-name.txt'); 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); assert_equals(registration.id, registrationId);
assert_true((await backgroundFetch.getIds()).includes(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'); }, 'The BackgroundFetchManager exposes active fetches');
// 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');
This is a testharness.js-based test.
PASS Exposed interfaces in a Document.
PASS Partial interface ServiceWorkerGlobalScope: original interface defined
PASS Partial interface ServiceWorkerRegistration: original interface defined
PASS ServiceWorkerRegistration interface: attribute backgroundFetch
PASS Unscopable handled correctly for backgroundFetch property on ServiceWorkerRegistration
PASS ServiceWorkerGlobalScope interface: existence and properties of interface object
PASS BackgroundFetchManager interface: existence and properties of interface object
PASS BackgroundFetchManager interface object length
PASS BackgroundFetchManager interface object name
PASS BackgroundFetchManager interface: existence and properties of interface prototype object
PASS BackgroundFetchManager interface: existence and properties of interface prototype object's "constructor" property
PASS BackgroundFetchManager interface: existence and properties of interface prototype object's @@unscopables property
PASS BackgroundFetchManager interface: operation fetch(DOMString, [object Object],[object Object], BackgroundFetchOptions)
PASS Unscopable handled correctly for fetch(DOMString, [object Object],[object Object], BackgroundFetchOptions) on BackgroundFetchManager
PASS BackgroundFetchManager interface: operation get(DOMString)
PASS Unscopable handled correctly for get(DOMString) on BackgroundFetchManager
PASS BackgroundFetchManager interface: operation getIds()
PASS Unscopable handled correctly for getIds() on BackgroundFetchManager
PASS BackgroundFetchRegistration interface: existence and properties of interface object
PASS BackgroundFetchRegistration interface object length
PASS BackgroundFetchRegistration interface object name
PASS BackgroundFetchRegistration interface: existence and properties of interface prototype object
PASS BackgroundFetchRegistration interface: existence and properties of interface prototype object's "constructor" property
PASS BackgroundFetchRegistration interface: existence and properties of interface prototype object's @@unscopables property
PASS BackgroundFetchRegistration interface: attribute id
PASS Unscopable handled correctly for id property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute uploadTotal
PASS Unscopable handled correctly for uploadTotal property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute uploaded
PASS Unscopable handled correctly for uploaded property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute downloadTotal
PASS Unscopable handled correctly for downloadTotal property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute downloaded
PASS Unscopable handled correctly for downloaded property on BackgroundFetchRegistration
FAIL BackgroundFetchRegistration interface: attribute activeFetches assert_true: The prototype object must have a property "activeFetches" expected true got false
PASS Unscopable handled correctly for activeFetches property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute onprogress
PASS Unscopable handled correctly for onprogress property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: operation abort()
PASS Unscopable handled correctly for abort() on BackgroundFetchRegistration
PASS BackgroundFetchFetch interface: existence and properties of interface object
PASS BackgroundFetchFetch interface object length
PASS BackgroundFetchFetch interface object name
PASS BackgroundFetchFetch interface: existence and properties of interface prototype object
PASS BackgroundFetchFetch interface: existence and properties of interface prototype object's "constructor" property
PASS BackgroundFetchFetch interface: existence and properties of interface prototype object's @@unscopables property
PASS BackgroundFetchFetch interface: attribute request
PASS Unscopable handled correctly for request property on BackgroundFetchFetch
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface object assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface object length assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface object name assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface prototype object assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface prototype object's @@unscopables property assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: operation match(RequestInfo) assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
PASS Unscopable handled correctly for match(RequestInfo) on BackgroundFetchActiveFetches
FAIL BackgroundFetchActiveFetches interface: operation values() assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
PASS Unscopable handled correctly for values() on BackgroundFetchActiveFetches
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface object assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface object length assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface object name assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface prototype object assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface prototype object's @@unscopables property assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: attribute responseReady assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
PASS Unscopable handled correctly for responseReady property on BackgroundFetchActiveFetch
PASS BackgroundFetchEvent interface: existence and properties of interface object
PASS BackgroundFetchSettledEvent interface: existence and properties of interface object
PASS BackgroundFetchSettledFetches interface: existence and properties of interface object
PASS BackgroundFetchSettledFetch interface: existence and properties of interface object
PASS BackgroundFetchUpdateEvent interface: existence and properties of interface object
PASS BackgroundFetchClickEvent interface: existence and properties of interface object
Harness: the test ran to completion.
This is a testharness.js-based test.
PASS background-fetch interfaces
PASS Partial interface ServiceWorkerGlobalScope: original interface defined
PASS Partial interface ServiceWorkerRegistration: original interface defined
PASS BackgroundFetchManager interface: existence and properties of interface object
PASS BackgroundFetchManager interface object length
PASS BackgroundFetchManager interface object name
PASS BackgroundFetchManager interface: existence and properties of interface prototype object
PASS BackgroundFetchManager interface: existence and properties of interface prototype object's "constructor" property
PASS BackgroundFetchManager interface: existence and properties of interface prototype object's @@unscopables property
PASS BackgroundFetchManager interface: operation fetch(DOMString, [object Object],[object Object], BackgroundFetchOptions)
PASS Unscopable handled correctly for fetch(DOMString, [object Object],[object Object], BackgroundFetchOptions) on BackgroundFetchManager
PASS BackgroundFetchManager interface: operation get(DOMString)
PASS Unscopable handled correctly for get(DOMString) on BackgroundFetchManager
PASS BackgroundFetchManager interface: operation getIds()
PASS Unscopable handled correctly for getIds() on BackgroundFetchManager
PASS BackgroundFetchRegistration interface: existence and properties of interface object
PASS BackgroundFetchRegistration interface object length
PASS BackgroundFetchRegistration interface object name
PASS BackgroundFetchRegistration interface: existence and properties of interface prototype object
PASS BackgroundFetchRegistration interface: existence and properties of interface prototype object's "constructor" property
PASS BackgroundFetchRegistration interface: existence and properties of interface prototype object's @@unscopables property
PASS BackgroundFetchRegistration interface: attribute id
PASS Unscopable handled correctly for id property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute uploadTotal
PASS Unscopable handled correctly for uploadTotal property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute uploaded
PASS Unscopable handled correctly for uploaded property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute downloadTotal
PASS Unscopable handled correctly for downloadTotal property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute downloaded
PASS Unscopable handled correctly for downloaded property on BackgroundFetchRegistration
FAIL BackgroundFetchRegistration interface: attribute activeFetches assert_true: The prototype object must have a property "activeFetches" expected true got false
PASS Unscopable handled correctly for activeFetches property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute onprogress
PASS Unscopable handled correctly for onprogress property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: operation abort()
PASS Unscopable handled correctly for abort() on BackgroundFetchRegistration
PASS BackgroundFetchFetch interface: existence and properties of interface object
PASS BackgroundFetchFetch interface object length
PASS BackgroundFetchFetch interface object name
PASS BackgroundFetchFetch interface: existence and properties of interface prototype object
PASS BackgroundFetchFetch interface: existence and properties of interface prototype object's "constructor" property
PASS BackgroundFetchFetch interface: existence and properties of interface prototype object's @@unscopables property
PASS BackgroundFetchFetch interface: attribute request
PASS Unscopable handled correctly for request property on BackgroundFetchFetch
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface object assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface object length assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface object name assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface prototype object assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface prototype object's @@unscopables property assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: operation match(RequestInfo) assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
PASS Unscopable handled correctly for match(RequestInfo) on BackgroundFetchActiveFetches
FAIL BackgroundFetchActiveFetches interface: operation values() assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
PASS Unscopable handled correctly for values() on BackgroundFetchActiveFetches
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface object assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface object length assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface object name assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface prototype object assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface prototype object's @@unscopables property assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: attribute responseReady assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
PASS Unscopable handled correctly for responseReady property on BackgroundFetchActiveFetch
PASS BackgroundFetchEvent interface: existence and properties of interface object
PASS BackgroundFetchSettledEvent interface: existence and properties of interface object
PASS BackgroundFetchSettledFetches interface: existence and properties of interface object
PASS BackgroundFetchSettledFetch interface: existence and properties of interface object
PASS BackgroundFetchUpdateEvent interface: existence and properties of interface object
PASS BackgroundFetchClickEvent interface: existence and properties of interface object
PASS ServiceWorkerRegistration interface: attribute backgroundFetch
PASS Unscopable handled correctly for backgroundFetch property on ServiceWorkerRegistration
PASS ServiceWorkerGlobalScope interface: existence and properties of interface object
PASS ExtendableEvent interface: existence and properties of interface object
PASS WorkerGlobalScope interface: existence and properties of interface object
Harness: the test ran to completion.
This is a testharness.js-based test.
PASS background-fetch interfaces
PASS Partial interface ServiceWorkerGlobalScope: original interface defined
PASS Partial interface ServiceWorkerRegistration: original interface defined
PASS BackgroundFetchManager interface: existence and properties of interface object
PASS BackgroundFetchManager interface object length
PASS BackgroundFetchManager interface object name
PASS BackgroundFetchManager interface: existence and properties of interface prototype object
PASS BackgroundFetchManager interface: existence and properties of interface prototype object's "constructor" property
PASS BackgroundFetchManager interface: existence and properties of interface prototype object's @@unscopables property
PASS BackgroundFetchManager interface: operation fetch(DOMString, [object Object],[object Object], BackgroundFetchOptions)
PASS Unscopable handled correctly for fetch(DOMString, [object Object],[object Object], BackgroundFetchOptions) on BackgroundFetchManager
PASS BackgroundFetchManager interface: operation get(DOMString)
PASS Unscopable handled correctly for get(DOMString) on BackgroundFetchManager
PASS BackgroundFetchManager interface: operation getIds()
PASS Unscopable handled correctly for getIds() on BackgroundFetchManager
PASS BackgroundFetchRegistration interface: existence and properties of interface object
PASS BackgroundFetchRegistration interface object length
PASS BackgroundFetchRegistration interface object name
PASS BackgroundFetchRegistration interface: existence and properties of interface prototype object
PASS BackgroundFetchRegistration interface: existence and properties of interface prototype object's "constructor" property
PASS BackgroundFetchRegistration interface: existence and properties of interface prototype object's @@unscopables property
PASS BackgroundFetchRegistration interface: attribute id
PASS Unscopable handled correctly for id property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute uploadTotal
PASS Unscopable handled correctly for uploadTotal property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute uploaded
PASS Unscopable handled correctly for uploaded property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute downloadTotal
PASS Unscopable handled correctly for downloadTotal property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute downloaded
PASS Unscopable handled correctly for downloaded property on BackgroundFetchRegistration
FAIL BackgroundFetchRegistration interface: attribute activeFetches assert_true: The prototype object must have a property "activeFetches" expected true got false
PASS Unscopable handled correctly for activeFetches property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute onprogress
PASS Unscopable handled correctly for onprogress property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: operation abort()
PASS Unscopable handled correctly for abort() on BackgroundFetchRegistration
PASS BackgroundFetchFetch interface: existence and properties of interface object
PASS BackgroundFetchFetch interface object length
PASS BackgroundFetchFetch interface object name
PASS BackgroundFetchFetch interface: existence and properties of interface prototype object
PASS BackgroundFetchFetch interface: existence and properties of interface prototype object's "constructor" property
PASS BackgroundFetchFetch interface: existence and properties of interface prototype object's @@unscopables property
PASS BackgroundFetchFetch interface: attribute request
PASS Unscopable handled correctly for request property on BackgroundFetchFetch
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface object assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface object length assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface object name assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface prototype object assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface prototype object's @@unscopables property assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: operation match(RequestInfo) assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
PASS Unscopable handled correctly for match(RequestInfo) on BackgroundFetchActiveFetches
FAIL BackgroundFetchActiveFetches interface: operation values() assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
PASS Unscopable handled correctly for values() on BackgroundFetchActiveFetches
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface object assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface object length assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface object name assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface prototype object assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface prototype object's @@unscopables property assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: attribute responseReady assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
PASS Unscopable handled correctly for responseReady property on BackgroundFetchActiveFetch
PASS BackgroundFetchEvent interface: existence and properties of interface object
PASS BackgroundFetchSettledEvent interface: existence and properties of interface object
PASS BackgroundFetchSettledFetches interface: existence and properties of interface object
PASS BackgroundFetchSettledFetch interface: existence and properties of interface object
PASS BackgroundFetchUpdateEvent interface: existence and properties of interface object
PASS BackgroundFetchClickEvent interface: existence and properties of interface object
PASS ServiceWorkerRegistration interface: attribute backgroundFetch
PASS Unscopable handled correctly for backgroundFetch property on ServiceWorkerRegistration
PASS ServiceWorkerGlobalScope interface: existence and properties of interface object
PASS ExtendableEvent interface: existence and properties of interface object
Harness: the test ran to completion.
This is a testharness.js-based test.
PASS Exposed interfaces in a Service Worker.
PASS Partial interface ServiceWorkerGlobalScope: original interface defined
PASS Partial interface ServiceWorkerRegistration: original interface defined
FAIL ServiceWorkerRegistration interface: existence and properties of interface object assert_false: expected false got true
FAIL ServiceWorkerGlobalScope interface: attribute onbackgroundfetched assert_own_property: self does not have own property "ServiceWorkerGlobalScope" expected property "ServiceWorkerGlobalScope" missing
PASS Unscopable handled correctly for onbackgroundfetched property on ServiceWorkerGlobalScope
FAIL ServiceWorkerGlobalScope interface: attribute onbackgroundfetchfail assert_own_property: self does not have own property "ServiceWorkerGlobalScope" expected property "ServiceWorkerGlobalScope" missing
PASS Unscopable handled correctly for onbackgroundfetchfail property on ServiceWorkerGlobalScope
FAIL ServiceWorkerGlobalScope interface: attribute onbackgroundfetchabort assert_own_property: self does not have own property "ServiceWorkerGlobalScope" expected property "ServiceWorkerGlobalScope" missing
PASS Unscopable handled correctly for onbackgroundfetchabort property on ServiceWorkerGlobalScope
FAIL ServiceWorkerGlobalScope interface: attribute onbackgroundfetchclick assert_own_property: self does not have own property "ServiceWorkerGlobalScope" expected property "ServiceWorkerGlobalScope" missing
PASS Unscopable handled correctly for onbackgroundfetchclick property on ServiceWorkerGlobalScope
PASS ExtendableEvent interface: existence and properties of interface object
PASS BackgroundFetchManager interface: existence and properties of interface object
PASS BackgroundFetchManager interface object length
PASS BackgroundFetchManager interface object name
PASS BackgroundFetchManager interface: existence and properties of interface prototype object
PASS BackgroundFetchManager interface: existence and properties of interface prototype object's "constructor" property
PASS BackgroundFetchManager interface: existence and properties of interface prototype object's @@unscopables property
PASS BackgroundFetchManager interface: operation fetch(DOMString, [object Object],[object Object], BackgroundFetchOptions)
PASS Unscopable handled correctly for fetch(DOMString, [object Object],[object Object], BackgroundFetchOptions) on BackgroundFetchManager
PASS BackgroundFetchManager interface: operation get(DOMString)
PASS Unscopable handled correctly for get(DOMString) on BackgroundFetchManager
PASS BackgroundFetchManager interface: operation getIds()
PASS Unscopable handled correctly for getIds() on BackgroundFetchManager
PASS BackgroundFetchRegistration interface: existence and properties of interface object
PASS BackgroundFetchRegistration interface object length
PASS BackgroundFetchRegistration interface object name
PASS BackgroundFetchRegistration interface: existence and properties of interface prototype object
PASS BackgroundFetchRegistration interface: existence and properties of interface prototype object's "constructor" property
PASS BackgroundFetchRegistration interface: existence and properties of interface prototype object's @@unscopables property
PASS BackgroundFetchRegistration interface: attribute id
PASS Unscopable handled correctly for id property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute uploadTotal
PASS Unscopable handled correctly for uploadTotal property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute uploaded
PASS Unscopable handled correctly for uploaded property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute downloadTotal
PASS Unscopable handled correctly for downloadTotal property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute downloaded
PASS Unscopable handled correctly for downloaded property on BackgroundFetchRegistration
FAIL BackgroundFetchRegistration interface: attribute activeFetches assert_true: The prototype object must have a property "activeFetches" expected true got false
PASS Unscopable handled correctly for activeFetches property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: attribute onprogress
PASS Unscopable handled correctly for onprogress property on BackgroundFetchRegistration
PASS BackgroundFetchRegistration interface: operation abort()
PASS Unscopable handled correctly for abort() on BackgroundFetchRegistration
PASS BackgroundFetchFetch interface: existence and properties of interface object
PASS BackgroundFetchFetch interface object length
PASS BackgroundFetchFetch interface object name
PASS BackgroundFetchFetch interface: existence and properties of interface prototype object
PASS BackgroundFetchFetch interface: existence and properties of interface prototype object's "constructor" property
PASS BackgroundFetchFetch interface: existence and properties of interface prototype object's @@unscopables property
PASS BackgroundFetchFetch interface: attribute request
PASS Unscopable handled correctly for request property on BackgroundFetchFetch
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface object assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface object length assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface object name assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface prototype object assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: existence and properties of interface prototype object's @@unscopables property assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
FAIL BackgroundFetchActiveFetches interface: operation match(RequestInfo) assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
PASS Unscopable handled correctly for match(RequestInfo) on BackgroundFetchActiveFetches
FAIL BackgroundFetchActiveFetches interface: operation values() assert_own_property: self does not have own property "BackgroundFetchActiveFetches" expected property "BackgroundFetchActiveFetches" missing
PASS Unscopable handled correctly for values() on BackgroundFetchActiveFetches
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface object assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface object length assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface object name assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface prototype object assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: existence and properties of interface prototype object's @@unscopables property assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
FAIL BackgroundFetchActiveFetch interface: attribute responseReady assert_own_property: self does not have own property "BackgroundFetchActiveFetch" expected property "BackgroundFetchActiveFetch" missing
PASS Unscopable handled correctly for responseReady property on BackgroundFetchActiveFetch
PASS BackgroundFetchEvent interface: existence and properties of interface object
PASS BackgroundFetchSettledEvent interface: existence and properties of interface object
PASS BackgroundFetchSettledFetches interface: existence and properties of interface object
PASS BackgroundFetchSettledFetch interface: existence and properties of interface object
PASS BackgroundFetchUpdateEvent interface: existence and properties of interface object
PASS BackgroundFetchClickEvent interface: existence and properties of interface object
Harness: the test ran to completion.
<!doctype html>
<meta charset="utf-8">
<title>Background Fetch API: BackgroundFetchClickEvent tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/serviceworker/resources/test-helpers.js"></script>
<!-- TODO(peter): Upstream this test to WPT when the directory has been imported. -->
<h1>BackgroundFetchClickEvent</h1>
<p>This test validates that the BackgroundFetchClickEvent is exposed and can
be constructed with an id and a valid state.</p>
<script>
'use strict';
// This test needs to be run in a Service Worker.
service_worker_test('resources/background-fetch-click-event-worker.js');
</script>
<!doctype html>
<meta charset="utf-8">
<title>Background Fetch API: BackgroundFetchEvent tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/serviceworker/resources/test-helpers.js"></script>
<!-- TODO(peter): Upstream this test to WPT when the directory has been imported. -->
<h1>BackgroundFetchEvent</h1>
<p>This test validates that the BackgroundFetchEvent is exposed and can
be constructed with an id.</p>
<script>
'use strict';
// This test needs to be run in a Service Worker.
service_worker_test('resources/background-fetch-event-worker.js');
</script>
<!doctype html>
<meta charset="utf-8">
<title>Background Fetch API: BackgroundFetchFailEvent tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/serviceworker/resources/test-helpers.js"></script>
<!-- TODO(peter): Upstream this test to WPT when the directory has been imported. -->
<h1>BackgroundFetchFailEvent</h1>
<p>This test validates that the BackgroundFetchFailEvent is exposed, and can be
constructed with an id and a sequence of settled responses.</p>
<script>
'use strict';
// This test needs to be run in a Service Worker.
service_worker_test('resources/background-fetch-fail-event-worker.js');
</script>
<!doctype html>
<meta charset="utf-8">
<title>Background Fetch API: fetch() tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/serviceworker/resources/test-helpers.js"></script>
<h1>BackgroundFetchManager.fetch()</h1>
<p>This test validates the behaviour of the fetch() method.</p>
<!-- TODO(peter): Move this to the WPT directory when it's merged and the
behaviour of fetch() for null and empty sequences is defined. -->
<script>
'use strict';
const workerUrl = 'resources/empty-worker.js';
const scope = 'resources/scope/' + location.pathname;
const id = 'my-background-fetch';
promise_test(function(test) {
return service_worker_unregister_and_register(test, workerUrl, scope)
.then(registration => {
assert_equals(null, registration.active);
return registration.backgroundFetch.fetch('id', ['resources/non-existing-file.png']);
})
.then(unreached_fulfillment(test), error => {
assert_equals(error.name, 'TypeError');
});
}, 'BackgroundFetchManager.fetch() 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.fetch(id, null))
.then(() => unreached_fulfillment(test), () => true /* pass */);
}, 'BackgroundFetchManager.fetch() throws when given a null request.');
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.fetch(id, []))
.then(() => unreached_fulfillment(test), () => true /* pass */);
}, 'BackgroundFetchManager.fetch() throws when given an empty sequence.');
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.fetch(id, ['resources/non-existing-file.png', null]))
.then(() => unreached_fulfillment(test), () => true /* pass */);
}, 'BackgroundFetchManager.fetch() throws when given a sequence with a null request.');
promise_test(function(test) {
const options = {
icons: [
{
src: 'resources/non-existing-large-icon.png',
sizes: '256x256',
type: 'image/png'
},
{
src: 'resources/non-existing-small-icon.jpg',
sizes: '64x64',
type: 'image/jpg'
}
],
title: 'My Background Fetch',
downloadTotal: 1024
};
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.fetch(id, ['resources/non-existing-file.png'], options))
.then(backgroundFetchRegistration => {
assert_true(backgroundFetchRegistration instanceof BackgroundFetchRegistration);
assert_equals(backgroundFetchRegistration.id, id);
assert_equals(backgroundFetchRegistration.downloadTotal, options.downloadTotal);
});
}, 'BackgroundFetchManager.fetch() returns a BackgroundFetchRegistration object.');
</script>
<!doctype html>
<meta charset="utf-8">
<title>Background Fetch API: get() tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/serviceworker/resources/test-helpers.js"></script>
<h1>BackgroundFetchManager.get()</h1>
<p>This test validates the behaviour of the get() 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.get('id');
})
.then(unreached_fulfillment(test), error => {
assert_equals(error.name, 'TypeError');
});
}, 'BackgroundFetchManager.get() 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.get('invalid-fetch-id'))
.then(backgroundFetchRegistration => {
assert_equals(backgroundFetchRegistration, null);
});
}, 'BackgroundFetchManager.get() returns NULL for non-existing fetches.');
promise_test(function(test) {
const id = 'my-id';
const options = {
icons: [
{
src: 'resources/non-existing-large-icon.png',
sizes: '256x256',
type: 'image/png'
},
{
src: 'resources/non-existing-small-icon.jpg',
sizes: '64x64',
type: 'image/jpg'
}
],
title: 'My Background Fetch',
downloadTotal: 1024
};
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.fetch(id, ['resources/non-existing-file.png'], options))
.then(backgroundFetchRegistration => {
assert_true(backgroundFetchRegistration instanceof BackgroundFetchRegistration);
return registration.backgroundFetch.get(id)
.then(secondBackgroundFetchRegistration => {
assert_true(secondBackgroundFetchRegistration instanceof BackgroundFetchRegistration);
assert_equals(secondBackgroundFetchRegistration.id, id);
assert_equals(secondBackgroundFetchRegistration.downloadTotal, options.downloadTotal);
});
});
}, 'BackgroundFetchManager.get() can return created fetches.');
promise_test(function(test) {
const id = 'my-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(() => registration.backgroundFetch.fetch(id, ['resources/non-existing-file.png']))
.then(backgroundFetchRegistration => {
assert_true(backgroundFetchRegistration instanceof BackgroundFetchRegistration);
return registration.backgroundFetch.get(id);
})
.then(secondBackgroundFetchRegistration => {
assert_true(secondBackgroundFetchRegistration instanceof BackgroundFetchRegistration);
return secondBackgroundFetchRegistration.abort();
})
.then(() => registration.backgroundFetch.get(id))
.then(thirdBackgroundFetchRegistration => {
assert_equals(thirdBackgroundFetchRegistration, null);
});
}, 'BackgroundFetchManager.get() returned fetches can be aborted.');
</script>
<!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>
<!doctype html>
<meta charset="utf-8">
<title>Background Fetch API: BackgroundFetchRegistration.abort() tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/serviceworker/resources/test-helpers.js"></script>
<h1>BackgroundFetchRegistration.abort()</h1>
<p>This test validates the behaviour of the abort() method.</p>
<!-- TODO(peter): Move this to the WPT directory when it's merged and we
can successfully create a new Background Fetch registration. -->
<script>
'use strict';
const workerUrl = 'resources/empty-worker.js';
const scope = 'resources/scope/' + location.pathname;
promise_test(function(test) {
const id = 'my-background-fetch';
let registration = null;
let backgroundFetchRegistration = 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.fetch(id, ['resources/non-existing-file.png']))
.then(r => {
backgroundFetchRegistration = r;
assert_true(backgroundFetchRegistration instanceof BackgroundFetchRegistration);
assert_inherits(backgroundFetchRegistration, 'abort');
return backgroundFetchRegistration.abort();
})
.then(success => {
// The registration was valid, so aborting it should be successful.
assert_true(success);
return backgroundFetchRegistration.abort();
})
.then(success => {
// The registration had already been aborted, so aborting it again should fail.
assert_false(success);
});
}, 'BackgroundFetchRegistration.abort() return a Promise indicating success.');
</script>
<!doctype html>
<meta charset="utf-8">
<title>Background Fetch API: BackgroundFetchUpdateEvent tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/serviceworker/resources/test-helpers.js"></script>
<h1>BackgroundFetchUpdateEvent</h1>
<p>This test validates that the BackgroundFetchUpdateEvent is exposed, and can be
constructed with an id and a sequence of settled responses.</p>
<script>
'use strict';
// This test needs to be run in a Service Worker.
service_worker_test('resources/background-fetch-update-event-worker.js');
</script>
'use strict';
importScripts('/resources/testharness.js');
test(function() {
assert_own_property(self, 'BackgroundFetchClickEvent');
// The `id` and `state` are required in the BackgroundFetchClickEventInit.
assert_throws({name: "TypeError"}, () => new BackgroundFetchClickEvent('BackgroundFetchClickEvent'));
assert_throws({name: "TypeError"}, () => new BackgroundFetchClickEvent('BackgroundFetchClickEvent', {}));
assert_throws({name: "TypeError"}, () => new BackgroundFetchClickEvent('BackgroundFetchClickEvent', { id: 'foo' }));
assert_throws({name: "TypeError"}, () => new BackgroundFetchClickEvent('BackgroundFetchClickEvent', { id: 'foo', state: 'foo' }));
// The `state` must be one of { pending, succeeded, failed }. This should not throw.
for (let state of ['pending', 'succeeded', 'failed'])
new BackgroundFetchClickEvent('BackgroundFetchClickEvent', { id: 'foo', state });
const event = new BackgroundFetchClickEvent('BackgroundFetchClickEvent', {
id: 'my-id',
state: 'succeeded'
});
assert_equals(event.type, 'BackgroundFetchClickEvent');
assert_equals(event.cancelable, false);
assert_equals(event.bubbles, false);
assert_equals(event.id, 'my-id');
assert_equals(event.state, 'succeeded');
assert_inherits(event, 'waitUntil');
}, 'Verifies that the BackgroundFetchClickEvent can be constructed.');
'use strict';
importScripts('/resources/testharness.js');
test(function() {
assert_own_property(self, 'BackgroundFetchEvent');
// The `id` is required in the BackgroundFetchEventInit.
assert_throws({name: "TypeError"}, () => new BackgroundFetchEvent('BackgroundFetchEvent'));
assert_throws({name: "TypeError"}, () => new BackgroundFetchEvent('BackgroundFetchEvent', {}));
const event = new BackgroundFetchEvent('BackgroundFetchEvent', {
id: 'my-id'
});
assert_equals(event.type, 'BackgroundFetchEvent');
assert_equals(event.cancelable, false);
assert_equals(event.bubbles, false);
assert_equals(event.id, 'my-id');
assert_inherits(event, 'waitUntil');
}, 'Verifies that the BackgroundFetchEvent can be constructed.');
'use strict';
importScripts('/resources/testharness.js');
test(function() {
assert_own_property(self, 'BackgroundFetchFailEvent');
// The `id` and `fetches` are required options in the
// BackgroundFetchFailEventInit. The latter must be a sequence of
// BackgroundFetchSettledFetch instances.
assert_throws({name: "TypeError"}, () => new BackgroundFetchFailEvent('BackgroundFetchFailEvent'));
assert_throws({name: "TypeError"}, () => new BackgroundFetchFailEvent('BackgroundFetchFailEvent', {}));
assert_throws({name: "TypeError"}, () => new BackgroundFetchFailEvent('BackgroundFetchFailEvent', { id: 'foo' }));
assert_throws({name: "TypeError"}, () => new BackgroundFetchFailEvent('BackgroundFetchFailEvent', { id: 'foo', fetches: 'bar' }));
const fetches = [
new BackgroundFetchSettledFetch(new Request('non-existing-image.png'), new Response()),
new BackgroundFetchSettledFetch(new Request('non-existing-image-2.png'), new Response())
];
const event = new BackgroundFetchFailEvent('BackgroundFetchFailEvent', {
id: 'my-id',
fetches
});
assert_equals(event.type, 'BackgroundFetchFailEvent');
assert_equals(event.cancelable, false);
assert_equals(event.bubbles, false);
assert_equals(event.id, 'my-id');
assert_true(Array.isArray(event.fetches));
assert_array_equals(event.fetches, fetches);
assert_inherits(event, 'waitUntil');
}, 'Verifies that the BackgroundFetchFailEvent can be constructed.');
'use strict';
importScripts('/resources/testharness.js');
promise_test(async function() {
assert_own_property(self, 'BackgroundFetchUpdateEvent');
// The `id` and `fetches` are required options in the
// BackgroundFetchUpdateEventInit. The latter must be an instance of
// BackgroundFetchSettledFetches.
assert_throws({name: "TypeError"}, () => new BackgroundFetchUpdateEvent('BackgroundFetchUpdateEvent'));
assert_throws({name: "TypeError"}, () => new BackgroundFetchUpdateEvent('BackgroundFetchUpdateEvent', {}));
assert_throws({name: "TypeError"}, () => new BackgroundFetchUpdateEvent('BackgroundFetchUpdateEvent', { id: 'foo' }));
// TODO(rayankans): Add actual construction test to BackgroundFetchUpdateEvent after
// https://github.com/WICG/background-fetch/issues/64 is resolved.
}, 'Verifies that the BackgroundFetchUpdateEvent can be constructed.');
...@@ -209,6 +209,13 @@ ScriptPromise BackgroundFetchManager::fetch( ...@@ -209,6 +209,13 @@ ScriptPromise BackgroundFetchManager::fetch(
"that URL is invalid"); "that URL is invalid");
} }
// 6.3.1.7.2: If |internalRequest|’s mode is "no-cors", then return a
// promise rejected with a TypeError.
if (web_request.Mode() == network::mojom::FetchRequestMode::kNoCORS) {
return RejectWithTypeError(script_state, request_url,
"the request mode must not be no-cors");
}
// Check this before mixed content, so that if mixed content is blocked by // Check this before mixed content, so that if mixed content is blocked by
// CSP they get a CSP warning rather than a mixed content warning. // CSP they get a CSP warning rather than a mixed content warning.
if (ShouldBlockDueToCSP(execution_context, request_url)) { if (ShouldBlockDueToCSP(execution_context, request_url)) {
...@@ -267,8 +274,8 @@ ScriptPromise BackgroundFetchManager::fetch( ...@@ -267,8 +274,8 @@ ScriptPromise BackgroundFetchManager::fetch(
return promise; return promise;
} }
DidLoadIcons(id, std::move(web_requests), std::move(options_ptr), DidLoadIcons(id, std::move(web_requests), std::move(options_ptr), resolver,
WrapPersistent(resolver), SkBitmap()); SkBitmap());
return promise; return promise;
} }
...@@ -287,6 +294,9 @@ void BackgroundFetchManager::DidFetch( ...@@ -287,6 +294,9 @@ void BackgroundFetchManager::DidFetch(
ScriptPromiseResolver* resolver, ScriptPromiseResolver* resolver,
mojom::blink::BackgroundFetchError error, mojom::blink::BackgroundFetchError error,
BackgroundFetchRegistration* registration) { BackgroundFetchRegistration* registration) {
ScriptState* script_state = resolver->GetScriptState();
ScriptState::Scope scope(script_state);
switch (error) { switch (error) {
case mojom::blink::BackgroundFetchError::NONE: case mojom::blink::BackgroundFetchError::NONE:
DCHECK(registration); DCHECK(registration);
...@@ -295,18 +305,18 @@ void BackgroundFetchManager::DidFetch( ...@@ -295,18 +305,18 @@ void BackgroundFetchManager::DidFetch(
case mojom::blink::BackgroundFetchError::DUPLICATED_DEVELOPER_ID: case mojom::blink::BackgroundFetchError::DUPLICATED_DEVELOPER_ID:
DCHECK(!registration); DCHECK(!registration);
resolver->Reject(V8ThrowException::CreateTypeError( resolver->Reject(V8ThrowException::CreateTypeError(
resolver->GetScriptState()->GetIsolate(), script_state->GetIsolate(),
"There already is a registration for the given id.")); "There already is a registration for the given id."));
return; return;
case mojom::blink::BackgroundFetchError::STORAGE_ERROR: case mojom::blink::BackgroundFetchError::STORAGE_ERROR:
DCHECK(!registration); DCHECK(!registration);
resolver->Reject(V8ThrowException::CreateTypeError( resolver->Reject(V8ThrowException::CreateTypeError(
resolver->GetScriptState()->GetIsolate(), script_state->GetIsolate(),
"Failed to store registration due to I/O error.")); "Failed to store registration due to I/O error."));
return; return;
case mojom::blink::BackgroundFetchError::SERVICE_WORKER_UNAVAILABLE: case mojom::blink::BackgroundFetchError::SERVICE_WORKER_UNAVAILABLE:
resolver->Reject(V8ThrowException::CreateTypeError( resolver->Reject(V8ThrowException::CreateTypeError(
resolver->GetScriptState()->GetIsolate(), script_state->GetIsolate(),
"There is no service worker available to service the fetch.")); "There is no service worker available to service the fetch."));
return; return;
case mojom::blink::BackgroundFetchError::INVALID_ARGUMENT: case mojom::blink::BackgroundFetchError::INVALID_ARGUMENT:
...@@ -320,13 +330,10 @@ void BackgroundFetchManager::DidFetch( ...@@ -320,13 +330,10 @@ void BackgroundFetchManager::DidFetch(
ScriptPromise BackgroundFetchManager::get(ScriptState* script_state, ScriptPromise BackgroundFetchManager::get(ScriptState* script_state,
const String& id) { const String& id) {
if (!registration_->active()) { // Creating a Background Fetch registration requires an activated worker, so
return ScriptPromise::Reject( // if |registration_| has not been activated we can skip the Mojo roundtrip.
script_state, if (!registration_->active())
V8ThrowException::CreateTypeError(script_state->GetIsolate(), return ScriptPromise::CastUndefined(script_state);
"No active registration available on "
"the ServiceWorkerRegistration."));
}
ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
ScriptPromise promise = resolver->Promise(); ScriptPromise promise = resolver->Promise();
...@@ -401,11 +408,18 @@ void BackgroundFetchManager::DidGetRegistration( ...@@ -401,11 +408,18 @@ void BackgroundFetchManager::DidGetRegistration(
ScriptPromiseResolver* resolver, ScriptPromiseResolver* resolver,
mojom::blink::BackgroundFetchError error, mojom::blink::BackgroundFetchError error,
BackgroundFetchRegistration* registration) { BackgroundFetchRegistration* registration) {
ScriptState* script_state = resolver->GetScriptState();
ScriptState::Scope scope(script_state);
switch (error) { switch (error) {
case mojom::blink::BackgroundFetchError::NONE: case mojom::blink::BackgroundFetchError::NONE:
case mojom::blink::BackgroundFetchError::INVALID_ID: DCHECK(registration);
resolver->Resolve(registration); resolver->Resolve(registration);
return; return;
case mojom::blink::BackgroundFetchError::INVALID_ID:
DCHECK(!registration);
resolver->Resolve(v8::Undefined(script_state->GetIsolate()));
return;
case mojom::blink::BackgroundFetchError::STORAGE_ERROR: case mojom::blink::BackgroundFetchError::STORAGE_ERROR:
DCHECK(!registration); DCHECK(!registration);
resolver->Reject( resolver->Reject(
...@@ -427,12 +441,11 @@ void BackgroundFetchManager::DidGetRegistration( ...@@ -427,12 +441,11 @@ void BackgroundFetchManager::DidGetRegistration(
} }
ScriptPromise BackgroundFetchManager::getIds(ScriptState* script_state) { ScriptPromise BackgroundFetchManager::getIds(ScriptState* script_state) {
// Creating a Background Fetch registration requires an activated worker, so
// if |registration_| has not been activated we can skip the Mojo roundtrip.
if (!registration_->active()) { if (!registration_->active()) {
return ScriptPromise::Reject( return ScriptPromise::Cast(script_state,
script_state, v8::Array::New(script_state->GetIsolate()));
V8ThrowException::CreateTypeError(script_state->GetIsolate(),
"No active registration available on "
"the ServiceWorkerRegistration."));
} }
ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
...@@ -449,6 +462,8 @@ void BackgroundFetchManager::DidGetDeveloperIds( ...@@ -449,6 +462,8 @@ void BackgroundFetchManager::DidGetDeveloperIds(
ScriptPromiseResolver* resolver, ScriptPromiseResolver* resolver,
mojom::blink::BackgroundFetchError error, mojom::blink::BackgroundFetchError error,
const Vector<String>& developer_ids) { const Vector<String>& developer_ids) {
ScriptState::Scope scope(resolver->GetScriptState());
switch (error) { switch (error) {
case mojom::blink::BackgroundFetchError::NONE: case mojom::blink::BackgroundFetchError::NONE:
resolver->Resolve(developer_ids); resolver->Resolve(developer_ids);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment