blob: 220fa8ff1c7413b65ad1f47db210e8bd301355f2 [file] [log] [blame]
<!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>