Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: chrome/test/data/extensions/api_test/notification_provider/basic_usage/background.js

Issue 456223002: Add NotifyOnShowSettings implementation of notification provider API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 notificationProvider = chrome.notificationProvider; 5 const notificationProvider = chrome.notificationProvider;
6 6
7 function createNotification(notificationId, options) { 7 function createNotification(notificationId, options) {
8 return new Promise(function (resolve, reject) { 8 return new Promise(function (resolve, reject) {
9 chrome.notifications.create(notificationId, options, function (id) { 9 chrome.notifications.create(notificationId, options, function (id) {
10 if (chrome.runtime.lastError) { 10 if (chrome.runtime.lastError) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 resolve(notifierExists); 90 resolve(notifierExists);
91 return; 91 return;
92 }); 92 });
93 }); 93 });
94 }; 94 };
95 95
96 function failTest(testName) { 96 function failTest(testName) {
97 chrome.test.fail(testName); 97 chrome.test.fail(testName);
98 }; 98 };
99 99
100 function listenForShowSettings() {}
101
100 function testFunctions() { 102 function testFunctions() {
101 var myId = chrome.runtime.id; 103 var myId = chrome.runtime.id;
102 var id1 = "id1"; 104 var id1 = "id1";
103 var returnId = myId + "-" + id1; 105 var returnId = myId + "-" + id1;
104 var content = { 106 var content = {
105 type: "basic", 107 type: "basic",
106 iconUrl: "icon.png", 108 iconUrl: "icon.png",
107 title: "Title", 109 title: "Title",
108 message: "This is the message." 110 message: "This is the message."
109 }; 111 };
110 112
113 // Add listener to onShowSettings to show that this extension has advanced
114 // settings.
115 chrome.notifications.onShowSettings.addListener(listenForShowSettings);
116
111 // Create a notification, so there will be one existing notification 117 // Create a notification, so there will be one existing notification
112 createNotification(id1, content) 118 createNotification(id1, content)
dewittj 2014/08/12 18:21:05 it would be better if this test also verified that
liyanhou 2014/08/13 21:06:26 Done.
113 .catch(function() { failTest("notifications.create"); }) 119 .catch(function() { failTest("notifications.create"); })
114 // Notify the sender that a notificaion was clicked. 120 // Notify the sender that a notificaion was clicked.
115 .then(function() { return notifyOnClicked(myId, returnId); }) 121 .then(function() { return notifyOnClicked(myId, returnId); })
116 .catch(function() { failTest("NotifyOnClicked1"); }) 122 .catch(function() { failTest("NotifyOnClicked"); })
117 // Try to notify that an non-existent notification was clicked. 123 // Try to notify that an non-existent notification was clicked.
118 .then(function() { return notifyOnClicked(myId, "doesNotExist"); }) 124 .then(function() { return notifyOnClicked(myId, "doesNotExist"); })
119 // Fail if it returns true. 125 // Fail if it returns true.
120 .then(function() { failTest("NotifyOnClicked2"); }) 126 .then(function() { failTest("NotifyOnClicked"); })
121 // Notify the sender that a notificaion button was clicked. 127 // Notify the sender that a notificaion button was clicked.
122 .catch(function() { return notifyOnButtonClicked(myId, returnId, 0); }) 128 .catch(function() { return notifyOnButtonClicked(myId, returnId, 0); })
123 .catch(function() { failTest("NotifyOnButtonClicked"); }) 129 .catch(function() { failTest("NotifyOnButtonClicked"); })
124 // Try to notify that a non-existent notification button was clicked. 130 // Try to notify that a non-existent notification button was clicked.
125 .then(function() { return notifyOnButtonClicked(myId, "doesNotExist", 0)}) 131 .then(function() { return notifyOnButtonClicked(myId, "doesNotExist", 0)})
126 .then(function() { failTest("NotifyOnButtonClicked"); }) 132 .then(function() { failTest("NotifyOnButtonClicked"); })
127 // Try to notify that an non-existent notification was cleared. 133 // Try to notify that an non-existent notification was cleared.
128 .catch(function () { return notifyOnCleared(myId, "doesNotExist"); }) 134 .catch(function () { return notifyOnCleared(myId, "doesNotExist"); })
129 .then(function() { failTest("NotifyOnCleared"); }) 135 .then(function() { failTest("NotifyOnCleared"); })
130 // Notify that the original notification was cleared. 136 // Notify that the original notification was cleared.
131 .catch(function() { return notifyOnCleared(myId, returnId); }) 137 .catch(function() { return notifyOnCleared(myId, returnId); })
132 .catch(function() { failTest("NotifyOnCleared"); }) 138 .catch(function() { failTest("NotifyOnCleared"); })
139 // Notify the sender that the permission level is changed by the user
133 .then(function () { return notifyOnPermissionLevelChanged(myId, 140 .then(function () { return notifyOnPermissionLevelChanged(myId,
134 "granted"); }) 141 "granted"); })
135 .catch(function() { failTest("NotifyOnPermissionLevelChanged"); }) 142 .catch(function() { failTest("NotifyOnPermissionLevelChanged"); })
136 .then(function () { return notifyOnShowSettings(myId); }) 143 .then(function () { return notifyOnShowSettings(myId); })
137 .catch(function() { failTest("NotifyOnShowSettings"); }) 144 .catch(function() { failTest("NotifyOnShowSettings"); })
138 .then(function() { chrome.test.succeed(); }); 145 // Try to notify a non existent sender that a user checked its settings
146 .then(function () { return notifyOnShowSettings("DoesNotExist"); })
147 // Fail if it returns true
148 .then(function() { failTest("NotifyOnShowSettings"); })
149 .catch(function() { chrome.test.succeed(); })
139 }; 150 };
140 151
141 chrome.test.runTests([ testFunctions ]); 152 chrome.test.runTests([ testFunctions ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698