OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <meta charset="utf-8"> |
| 3 <title>Background Fetch API: fetch() tests</title> |
| 4 <script src="/resources/testharness.js"></script> |
| 5 <script src="/resources/testharnessreport.js"></script> |
| 6 <script src="/serviceworker/resources/test-helpers.js"></script> |
| 7 |
| 8 <h1>BackgroundFetchManager.fetch()</h1> |
| 9 <p>This test validates the behaviour of the fetch() method.</p> |
| 10 |
| 11 <!-- TODO(peter): Move this to the WPT directory when it's merged. --> |
| 12 |
| 13 <script> |
| 14 'use strict'; |
| 15 |
| 16 const workerUrl = 'resources/empty-worker.js'; |
| 17 const scope = 'resources/scope/' + location.pathname; |
| 18 |
| 19 promise_test(function(test) { |
| 20 return service_worker_unregister_and_register(test, workerUrl, scope) |
| 21 .then(registration => { |
| 22 assert_equals(null, registration.active); |
| 23 return registration.backgroundFetch.fetch('tag', ['resources/non-existing-
file.png']); |
| 24 }) |
| 25 .then(unreached_fulfillment(test), error => { |
| 26 assert_equals(error.name, 'TypeError'); |
| 27 }); |
| 28 |
| 29 }, 'BackgroundFetchManager.fetch() requires an activated Service Worker.'); |
| 30 |
| 31 promise_test(function(test) { |
| 32 const tag = 'my-background-fetch'; |
| 33 const options = { |
| 34 icons: [ |
| 35 { |
| 36 src: 'resources/non-existing-large-icon.png', |
| 37 sizes: '256x256', |
| 38 type: 'image/png' |
| 39 }, |
| 40 { |
| 41 src: 'resources/non-existing-small-icon.jpg', |
| 42 sizes: '64x64', |
| 43 type: 'image/jpg' |
| 44 } |
| 45 ], |
| 46 title: 'My Background Fetch', |
| 47 totalDownloadSize: 1024 |
| 48 }; |
| 49 |
| 50 let registration = null; |
| 51 |
| 52 return service_worker_unregister_and_register(test, workerUrl, scope) |
| 53 .then(r => { |
| 54 registration = r; |
| 55 return wait_for_state(test, r.installing, 'activated'); |
| 56 }) |
| 57 .then(() => registration.backgroundFetch.fetch(tag, ['resources/non-existing
-file.png'], options)) |
| 58 .then(backgroundFetchRegistration => { |
| 59 assert_true(backgroundFetchRegistration instanceof BackgroundFetchRegistra
tion); |
| 60 assert_equals(backgroundFetchRegistration.tag, tag); |
| 61 assert_object_equals(backgroundFetchRegistration.icons, options.icons); |
| 62 assert_equals(backgroundFetchRegistration.totalDownloadSize, options.total
DownloadSize); |
| 63 assert_equals(backgroundFetchRegistration.title, options.title); |
| 64 }); |
| 65 |
| 66 }, 'BackgroundFetchManager.fetch() returns a BackgroundFetchRegistration object.
'); |
| 67 </script> |
OLD | NEW |