OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Notifications: Check that showNotifications rejects if actions is set
incorrectly.</title> | 4 <title>Notifications: Check that showNotifications rejects if actions is set
incorrectly.</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 serviceWorkerRegistration.showNotification throws a | 12 // Tests that serviceWorkerRegistration.showNotification throws a |
13 // TypeError if NotificationOptions.actions is set incorrectly. | 13 // TypeError if NotificationOptions.actions is set incorrectly. |
14 var script = 'resources/instrumentation-service-worker.js'; | 14 var script = 'resources/instrumentation-service-worker.js'; |
15 | 15 |
16 testRunner.setPermission('notifications', 'granted', location.origin, loca
tion.origin); | 16 testRunner.setPermission('notifications', 'granted', location.origin, loca
tion.origin); |
17 | 17 |
18 async_test(function(test) { | 18 async_test(function(test) { |
| 19 var scope = 'resources/scope/' + location.pathname + "/noaction"; |
| 20 |
| 21 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { |
| 22 assert_inherits(workerInfo.registration, 'showNotification', 'show
Notification() must be exposed.'); |
| 23 |
| 24 workerInfo.registration.showNotification('Title', { |
| 25 actions: [{ title: "Foo" }] |
| 26 }).then(unreached_fulfillment(test)).catch(function(error) { |
| 27 assert_equals(error.name, 'TypeError'); |
| 28 assert_equals(error.message, "Failed to execute 'showNotificat
ion' on 'ServiceWorkerRegistration': required member action is undefined."); |
| 29 test.done(); |
| 30 }); |
| 31 }).catch(unreached_rejection(test)); |
| 32 |
| 33 }, 'showNotification() must reject if a NotificationAction has no action.'
); |
| 34 |
| 35 async_test(function(test) { |
19 var scope = 'resources/scope/' + location.pathname + "/notitle"; | 36 var scope = 'resources/scope/' + location.pathname + "/notitle"; |
20 | 37 |
21 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { | 38 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { |
22 assert_inherits(workerInfo.registration, 'showNotification', 'show
Notification() must be exposed.'); | 39 assert_inherits(workerInfo.registration, 'showNotification', 'show
Notification() must be exposed.'); |
23 | 40 |
24 workerInfo.registration.showNotification('Title', { | 41 workerInfo.registration.showNotification('Title', { |
25 actions: [{}] | 42 actions: [{ action: "foo" }] |
26 }).then(unreached_fulfillment(test)).catch(function(error) { | 43 }).then(unreached_fulfillment(test)).catch(function(error) { |
27 assert_equals(error.name, 'TypeError'); | 44 assert_equals(error.name, 'TypeError'); |
28 assert_equals(error.message, "Failed to execute 'showNotificat
ion' on 'ServiceWorkerRegistration': required member title is undefined."); | 45 assert_equals(error.message, "Failed to execute 'showNotificat
ion' on 'ServiceWorkerRegistration': required member title is undefined."); |
29 test.done(); | 46 test.done(); |
30 }); | 47 }); |
31 }).catch(unreached_rejection(test)); | 48 }).catch(unreached_rejection(test)); |
32 | 49 |
33 }, 'showNotification() must reject if an action has no title.'); | 50 }, 'showNotification() must reject if a NotificationAction has no title.')
; |
| 51 |
| 52 async_test(function(test) { |
| 53 var scope = 'resources/scope/' + location.pathname + "/emptyaction"; |
| 54 |
| 55 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { |
| 56 assert_inherits(workerInfo.registration, 'showNotification', 'show
Notification() must be exposed.'); |
| 57 |
| 58 workerInfo.registration.showNotification('Title', { |
| 59 actions: [{ action: "", title: "Foo" }] |
| 60 }).then(unreached_fulfillment(test)).catch(function(error) { |
| 61 assert_equals(error.name, 'TypeError'); |
| 62 assert_equals(error.message, 'NotificationAction action must n
ot be empty.'); |
| 63 test.done(); |
| 64 }); |
| 65 }).catch(unreached_rejection(test)); |
| 66 |
| 67 }, 'showNotification() must reject if a NotificationAction has an empty ac
tion.'); |
34 | 68 |
35 async_test(function(test) { | 69 async_test(function(test) { |
36 var scope = 'resources/scope/' + location.pathname + "/emptytitle"; | 70 var scope = 'resources/scope/' + location.pathname + "/emptytitle"; |
37 | 71 |
38 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { | 72 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { |
39 assert_inherits(workerInfo.registration, 'showNotification', 'show
Notification() must be exposed.'); | 73 assert_inherits(workerInfo.registration, 'showNotification', 'show
Notification() must be exposed.'); |
40 | 74 |
41 workerInfo.registration.showNotification('Title', { | 75 workerInfo.registration.showNotification('Title', { |
42 actions: [{title: ""}] | 76 actions: [{ action: "foo", title: "" }] |
43 }).then(unreached_fulfillment(test)).catch(function(error) { | 77 }).then(unreached_fulfillment(test)).catch(function(error) { |
44 assert_equals(error.name, 'TypeError'); | 78 assert_equals(error.name, 'TypeError'); |
45 assert_equals(error.message, 'Notification action titles must
not be empty.'); | 79 assert_equals(error.message, 'NotificationAction title must no
t be empty.'); |
46 test.done(); | 80 test.done(); |
47 }); | 81 }); |
48 }).catch(unreached_rejection(test)); | 82 }).catch(unreached_rejection(test)); |
49 | 83 |
50 }, 'showNotification() must reject if an action has an empty title.'); | 84 }, 'showNotification() must reject if a NotificationAction has an empty ti
tle.'); |
51 </script> | 85 </script> |
52 </body> | 86 </body> |
53 </html> | 87 </html> |
OLD | NEW |