4 <title>Notifications: Check that showNotifications rejects if actions is set incorrectly.
</title>
5 <script src=
"../resources/testharness.js"></script>
6 <script src=
"../resources/testharnessreport.js"></script>
7 <script src=
"../serviceworker/resources/test-helpers.js"></script>
8 <script src=
"resources/test-helpers.js"></script>
12 // Tests that serviceWorkerRegistration.showNotification throws a
13 // TypeError if NotificationOptions.actions is set incorrectly.
14 var script
= 'resources/instrumentation-service-worker.js';
16 testRunner
.setPermission('notifications', 'granted', location
.origin
, location
.origin
);
18 async_test(function(test
) {
19 var scope
= 'resources/scope/' + location
.pathname
+ "/noaction";
21 getActiveServiceWorkerWithMessagePort(test
, script
, scope
).then(function(workerInfo
) {
22 assert_inherits(workerInfo
.registration
, 'showNotification', 'showNotification() must be exposed.');
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 'showNotification' on 'ServiceWorkerRegistration': required member action is undefined.");
31 }).catch(unreached_rejection(test
));
33 }, 'showNotification() must reject if a NotificationAction has no action.');
35 async_test(function(test
) {
36 var scope
= 'resources/scope/' + location
.pathname
+ "/notitle";
38 getActiveServiceWorkerWithMessagePort(test
, script
, scope
).then(function(workerInfo
) {
39 assert_inherits(workerInfo
.registration
, 'showNotification', 'showNotification() must be exposed.');
41 workerInfo
.registration
.showNotification('Title', {
42 actions
: [{ action
: "foo" }]
43 }).then(unreached_fulfillment(test
)).catch(function(error
) {
44 assert_equals(error
.name
, 'TypeError');
45 assert_equals(error
.message
, "Failed to execute 'showNotification' on 'ServiceWorkerRegistration': required member title is undefined.");
48 }).catch(unreached_rejection(test
));
50 }, 'showNotification() must reject if a NotificationAction has no title.');
52 async_test(function(test
) {
53 var scope
= 'resources/scope/' + location
.pathname
+ "/emptyaction";
55 getActiveServiceWorkerWithMessagePort(test
, script
, scope
).then(function(workerInfo
) {
56 assert_inherits(workerInfo
.registration
, 'showNotification', 'showNotification() must be exposed.');
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
, "Failed to execute 'showNotification' on 'ServiceWorkerRegistration': NotificationAction `action` must not be empty.");
65 }).catch(unreached_rejection(test
));
67 }, 'showNotification() must reject if a NotificationAction has an empty action.');
69 async_test(function(test
) {
70 var scope
= 'resources/scope/' + location
.pathname
+ "/emptytitle";
72 getActiveServiceWorkerWithMessagePort(test
, script
, scope
).then(function(workerInfo
) {
73 assert_inherits(workerInfo
.registration
, 'showNotification', 'showNotification() must be exposed.');
75 workerInfo
.registration
.showNotification('Title', {
76 actions
: [{ action
: "foo", title
: "" }]
77 }).then(unreached_fulfillment(test
)).catch(function(error
) {
78 assert_equals(error
.name
, 'TypeError');
79 assert_equals(error
.message
, "Failed to execute 'showNotification' on 'ServiceWorkerRegistration': NotificationAction `title` must not be empty.");
82 }).catch(unreached_rejection(test
));
84 }, 'showNotification() must reject if a NotificationAction has an empty title.');