OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Notifications: Showing a notification with an image having a redirect
.</title> | 4 <title>Notifications: Showing a notification with an image having a redirect
.</title> |
5 <script src="../resources/testharness.js"></script> | 5 <script src="../resources/testharness.js"></script> |
6 <script src="../resources/testharnessreport.js"></script> | 6 <script src="../resources/testharnessreport.js"></script> |
7 <script src="../serviceworker/resources/test-helpers.js"></script> | 7 <script src="../serviceworker/resources/test-helpers.js"></script> |
8 <script src="resources/test-helpers.js"></script> | 8 <script src="resources/test-helpers.js"></script> |
9 </head> | 9 </head> |
10 <body> | 10 <body> |
11 <script> | 11 <script> |
12 // Tests that showing a notification with an image that redirect to anothe
r | 12 // Tests that showing a notification with an image that redirect to anothe
r |
13 // location will still resolve the showNotification() promise. | 13 // location will still resolve the showNotification() promise. |
14 | 14 |
15 async_test(function(test) { | 15 async_test(function(test) { |
16 var scope = 'resources/scope/' + location.pathname, | 16 var scope = 'resources/scope/' + location.pathname, |
17 script = 'resources/instrumentation-service-worker.js'; | 17 script = 'instrumentation-service-worker.js'; |
18 | 18 |
19 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); | 19 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); |
20 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(info) { | 20 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(info) { |
21 // (1) Display a Web Notification through the Service Worker with | 21 // (1) Display a Web Notification through the Service Worker with |
22 // an image that takes redirects to another image. | 22 // an image that takes redirects to another image. |
23 info.port.postMessage({ | 23 return sendCommand(info.port, { |
24 command: 'show', | 24 command: 'show', |
25 | 25 |
26 title: 'My Notification', | 26 title: 'My Notification', |
27 options: { body: 'Hello, world!', | 27 options: { body: 'Hello, world!', |
28 icon: '/resources/redirect.php?url=square100.png&re
fresh=0' } | 28 icon: '/resources/redirect.php?url=square100.png&re
fresh=0' } |
29 }); | 29 }); |
| 30 }).then(function(data) { |
| 31 // (2) Confirm that the service worker displayed the notification
successfully. |
| 32 assert_true(data.success); |
30 | 33 |
31 info.port.addEventListener('message', function(event) { | 34 test.done(); |
32 if (typeof event.data != 'object' || !event.data.command) { | |
33 assert_unreached('Invalid message from the Service Worker.
'); | |
34 return; | |
35 } | |
36 | |
37 // (2) Listen for confirmation from the Service Worker that th
e | |
38 // notification could be displayed as expected. | |
39 assert_equals(event.data.command, 'show'); | |
40 assert_true(event.data.success); | |
41 | |
42 test.done(); | |
43 }); | |
44 }).catch(unreached_rejection(test)); | 35 }).catch(unreached_rejection(test)); |
45 | 36 |
46 }, 'Displaying a notification with an image that redirects still resolves
the promise.'); | 37 }, 'Displaying a notification with an image that redirects still resolves
the promise.'); |
47 </script> | 38 </script> |
48 </body> | 39 </body> |
49 </html> | 40 </html> |
OLD | NEW |