OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 const notifications = chrome.notifications; | 5 const notifications = chrome.notifications; |
6 var theOnlyTestDone = null; | 6 var theOnlyTestDone = null; |
7 | 7 |
8 var notificationData = { | 8 var notificationData = { |
9 type: "basic", | 9 type: "basic", |
10 iconUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAA" + | 10 iconUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAA" + |
11 "CNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHw" + | 11 "CNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHw" + |
12 "AAAABJRU5ErkJggg==", | 12 "AAAABJRU5ErkJggg==", |
13 title: "Attention!", | 13 title: "Attention!", |
14 message: "Check out Cirque du Soleil" | 14 message: "Check out Cirque du Soleil" |
15 }; | 15 }; |
16 | 16 |
17 var results = { | 17 var results = { |
18 FOO: false, | 18 FOO: false, |
19 BAR: true, | 19 BAR: true, |
20 BAT: false, | 20 BAT: false, |
21 BIFF: false, | 21 BIFF: false, |
22 BLAT: true, | 22 BLAT: true, |
23 BLOT: true | 23 BLOT: true |
24 }; | 24 }; |
25 | 25 |
26 function createCallback(id) { } | 26 function createCallback(id) { } |
27 | 27 |
| 28 function notifyPass() { chrome.test.notifyPass(); } |
| 29 |
28 var onClosedHooks = { | 30 var onClosedHooks = { |
| 31 FOO: notifyPass, |
| 32 BAR: notifyPass, |
29 BIFF: function() { | 33 BIFF: function() { |
30 notifications.create("BLAT", notificationData, createCallback); | 34 notifications.create("BLAT", notificationData, function () { |
31 notifications.create("BLOT", notificationData, createCallback); | 35 if (chrome.runtime.lastError) { |
| 36 chrome.test.notifyFail(lastError.message); |
| 37 return; |
| 38 } |
| 39 notifications.create("BLOT", notificationData, function () { |
| 40 if (chrome.runtime.lastError) { |
| 41 chrome.test.notifyFail(lastError.message); |
| 42 return; |
| 43 } |
| 44 chrome.test.notifyPass("Created the new notifications."); |
| 45 }); |
| 46 }); |
32 }, | 47 }, |
33 }; | 48 }; |
34 | 49 |
35 function onClosedListener(id, by_user) { | 50 function onClosedListener(id, by_user) { |
36 if (results[id] !== by_user) { | 51 if (results[id] !== by_user) { |
37 chrome.test.notifyFail("Notification " + id + | 52 chrome.test.notifyFail("Notification " + id + |
38 " closed with bad by_user param ( "+ by_user +" )"); | 53 " closed with bad by_user param ( "+ by_user +" )"); |
39 return; | 54 return; |
40 } | 55 } |
41 chrome.test.notifyPass(); | |
42 delete results[id]; | 56 delete results[id]; |
43 | 57 |
44 if (typeof onClosedHooks[id] === "function") | 58 if (typeof onClosedHooks[id] === "function") |
45 onClosedHooks[id](); | 59 onClosedHooks[id](); |
46 | 60 |
47 if (Object.keys(results).length === 0) | 61 if (Object.keys(results).length === 0) { |
| 62 chrome.test.notifyPass("Done!"); |
48 theOnlyTestDone(); | 63 theOnlyTestDone(); |
| 64 } |
49 } | 65 } |
50 | 66 |
51 notifications.onClosed.addListener(onClosedListener); | 67 notifications.onClosed.addListener(onClosedListener); |
52 | 68 |
53 function theOnlyTest() { | 69 function theOnlyTest() { |
| 70 // This test coordinates with the browser test. First, 4 notifications are |
| 71 // created. Then 2 are manually cancelled in C++. Then clearAll is called |
| 72 // with false |by_user|. Then once the BIFF notification is cleared, we |
| 73 // create two more notifications in JS, and C++ calls the clearAll with true |
| 74 // |by_user|. |
54 theOnlyTestDone = chrome.test.callbackAdded(); | 75 theOnlyTestDone = chrome.test.callbackAdded(); |
55 | 76 |
56 notifications.create("FOO", notificationData, createCallback); | 77 notifications.create("FOO", notificationData, createCallback); |
57 notifications.create("BAR", notificationData, createCallback); | 78 notifications.create("BAR", notificationData, createCallback); |
58 notifications.create("BAT", notificationData, createCallback); | 79 notifications.create("BAT", notificationData, createCallback); |
59 notifications.create("BIFF", notificationData, createCallback); | 80 notifications.create("BIFF", notificationData, createCallback); |
60 } | 81 } |
61 | 82 |
62 chrome.test.runTests([ theOnlyTest ]); | 83 chrome.test.runTests([ theOnlyTest ]); |
OLD | NEW |