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