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

Side by Side Diff: chrome/browser/extensions/api/notification/notification_apitest.cc

Issue 12212037: Update notifications API after review. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge conflict resolved Created 7 years, 10 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 (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 #include "chrome/browser/extensions/api/notification/notification_api.h" 5 #include "chrome/browser/extensions/api/notification/notification_api.h"
6 #include "chrome/browser/extensions/extension_apitest.h" 6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_function_test_utils.h" 7 #include "chrome/browser/extensions/extension_function_test_utils.h"
8 #include "chrome/common/chrome_switches.h" 8 #include "chrome/common/chrome_switches.h"
9 9
10 using extensions::Extension; 10 using extensions::Extension;
(...skipping 22 matching lines...) Expand all
33 notification_function( 33 notification_function(
34 new extensions::NotificationCreateFunction()); 34 new extensions::NotificationCreateFunction());
35 35
36 notification_function->set_extension(empty_extension.get()); 36 notification_function->set_extension(empty_extension.get());
37 notification_function->set_has_callback(true); 37 notification_function->set_has_callback(true);
38 38
39 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 39 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
40 notification_function, 40 notification_function,
41 "[\"\", " // Empty string: ask API to generate ID 41 "[\"\", " // Empty string: ask API to generate ID
42 "{" 42 "{"
43 "\"type\": \"simple\"," 43 "\"templateType\": \"simple\","
44 "\"iconUrl\": \"http://www.google.com/intl/en/chrome/assets/" 44 "\"iconUrl\": \"http://www.google.com/intl/en/chrome/assets/"
45 "common/images/chrome_logo_2x.png\"," 45 "common/images/chrome_logo_2x.png\","
46 "\"title\": \"Attention!\"," 46 "\"title\": \"Attention!\","
47 "\"message\": \"Check out Cirque du Soleil\"" 47 "\"message\": \"Check out Cirque du Soleil\""
48 "}]", 48 "}]",
49 browser(), utils::NONE)); 49 browser(), utils::NONE));
50 50
51 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); 51 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType());
52 ASSERT_TRUE(result->GetAsString(&notification_id)); 52 ASSERT_TRUE(result->GetAsString(&notification_id));
53 ASSERT_TRUE(notification_id.length() > 0); 53 ASSERT_TRUE(notification_id.length() > 0);
54 } 54 }
55 55
56 // Update the existing notification. 56 // Update the existing notification.
57 { 57 {
58 scoped_refptr<extensions::NotificationUpdateFunction> 58 scoped_refptr<extensions::NotificationUpdateFunction>
59 notification_function( 59 notification_function(
60 new extensions::NotificationUpdateFunction()); 60 new extensions::NotificationUpdateFunction());
61 61
62 notification_function->set_extension(empty_extension.get()); 62 notification_function->set_extension(empty_extension.get());
63 notification_function->set_has_callback(true); 63 notification_function->set_has_callback(true);
64 64
65 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 65 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
66 notification_function, 66 notification_function,
67 "[\"" + notification_id + "\", " 67 "[\"" + notification_id + "\", "
68 "{" 68 "{"
69 "\"type\": \"simple\"," 69 "\"templateType\": \"simple\","
70 "\"iconUrl\": \"http://www.google.com/intl/en/chrome/assets/" 70 "\"iconUrl\": \"http://www.google.com/intl/en/chrome/assets/"
71 "common/images/chrome_logo_2x.png\"," 71 "common/images/chrome_logo_2x.png\","
72 "\"title\": \"Attention!\"," 72 "\"title\": \"Attention!\","
73 "\"message\": \"Too late! The show ended yesterday\"" 73 "\"message\": \"Too late! The show ended yesterday\""
74 "}]", 74 "}]",
75 browser(), utils::NONE)); 75 browser(), utils::NONE));
76 76
77 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); 77 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType());
78 bool copy_bool_value = false; 78 bool copy_bool_value = false;
79 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value)); 79 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value));
(...skipping 12 matching lines...) Expand all
92 notification_function( 92 notification_function(
93 new extensions::NotificationUpdateFunction()); 93 new extensions::NotificationUpdateFunction());
94 94
95 notification_function->set_extension(empty_extension.get()); 95 notification_function->set_extension(empty_extension.get());
96 notification_function->set_has_callback(true); 96 notification_function->set_has_callback(true);
97 97
98 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 98 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
99 notification_function, 99 notification_function,
100 "[\"xxxxxxxxxxxx\", " 100 "[\"xxxxxxxxxxxx\", "
101 "{" 101 "{"
102 "\"type\": \"simple\"," 102 "\"templateType\": \"simple\","
103 "\"iconUrl\": \"http://www.google.com/intl/en/chrome/assets/" 103 "\"iconUrl\": \"http://www.google.com/intl/en/chrome/assets/"
104 "common/images/chrome_logo_2x.png\"," 104 "common/images/chrome_logo_2x.png\","
105 "\"title\": \"!\"," 105 "\"title\": \"!\","
106 "\"message\": \"!\"" 106 "\"message\": \"!\""
107 "}]", 107 "}]",
108 browser(), utils::NONE)); 108 browser(), utils::NONE));
109 109
110 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); 110 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType());
111 bool copy_bool_value = false; 111 bool copy_bool_value = false;
112 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value)); 112 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 new extensions::NotificationCreateFunction()); 158 new extensions::NotificationCreateFunction());
159 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); 159 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
160 160
161 notification_create_function->set_extension(empty_extension.get()); 161 notification_create_function->set_extension(empty_extension.get());
162 notification_create_function->set_has_callback(true); 162 notification_create_function->set_has_callback(true);
163 163
164 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 164 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
165 notification_create_function, 165 notification_create_function,
166 "[\"\", " 166 "[\"\", "
167 "{" 167 "{"
168 "\"type\": \"base\"," 168 "\"templateType\": \"basic\","
169 "\"iconUrl\": \"http://www.google.com/intl/en/chrome/assets/" 169 "\"iconUrl\": \"http://www.google.com/intl/en/chrome/assets/"
170 "common/images/chrome_logo_2x.png\"," 170 "common/images/chrome_logo_2x.png\","
171 "\"title\": \"Attention!\"," 171 "\"title\": \"Attention!\","
172 "\"message\": \"Check out Cirque du Soleil\"," 172 "\"message\": \"Check out Cirque du Soleil\","
173 "\"priority\": 1," 173 "\"priority\": 1,"
174 "\"timestamp\": \"Tue, 15 Nov 1994 12:45:26 GMT\"," 174 "\"eventTime\": \"Tue, 15 Nov 1994 12:45:26 GMT\","
175 "\"secondIconUrl\": \"http://www.google.com/logos/2012/" 175 "\"buttons\": ["
176 "Day-Of-The-Dead-12-hp.jpg\"," 176 " {"
177 "\"unreadCount\": 42," 177 " \"title\": \"Up\","
178 "\"buttonOneTitle\": \"Up\"," 178 " \"iconUrl\":\"http://www.google.com/logos/2012/\""
179 "\"buttonTwoTitle\": \"Down\"," 179 " },"
180 " {"
181 " \"title\": \"Down\"" // note: no iconUrl
182 " }"
183 "],"
180 "\"expandedMessage\": \"This is a longer expanded message.\"," 184 "\"expandedMessage\": \"This is a longer expanded message.\","
181 "\"imageUrl\": \"http://www.google.com/logos/2012/election12-hp.jpg\"" 185 "\"imageUrl\": \"http://www.google.com/logos/2012/election12-hp.jpg\""
182 "}]", 186 "}]",
183 browser(), utils::NONE)); 187 browser(), utils::NONE));
184 188
185 std::string notification_id; 189 std::string notification_id;
186 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); 190 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType());
187 ASSERT_TRUE(result->GetAsString(&notification_id)); 191 ASSERT_TRUE(result->GetAsString(&notification_id));
188 ASSERT_TRUE(notification_id.length() > 0); 192 ASSERT_TRUE(notification_id.length() > 0);
189 } 193 }
190 194
191 IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestMultipleItemNotification) { 195 IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestMultipleItemNotification) {
192 scoped_refptr<extensions::NotificationCreateFunction> 196 scoped_refptr<extensions::NotificationCreateFunction>
193 notification_create_function( 197 notification_create_function(
194 new extensions::NotificationCreateFunction()); 198 new extensions::NotificationCreateFunction());
195 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); 199 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
196 200
197 notification_create_function->set_extension(empty_extension.get()); 201 notification_create_function->set_extension(empty_extension.get());
198 notification_create_function->set_has_callback(true); 202 notification_create_function->set_has_callback(true);
199 203
200 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 204 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
201 notification_create_function, 205 notification_create_function,
202 "[\"\", " 206 "[\"\", "
203 "{" 207 "{"
204 "\"type\": \"multiple\"," 208 "\"templateType\": \"list\","
205 "\"iconUrl\": \"https://code.google.com/p/chromium/logo\"," 209 "\"iconUrl\": \"https://code.google.com/p/chromium/logo\","
206 "\"title\": \"Multiple Item Notification Title\"," 210 "\"title\": \"Multiple Item Notification Title\","
207 "\"message\": \"Multiple item notification message.\"," 211 "\"message\": \"Multiple item notification message.\","
208 "\"items\": [" 212 "\"items\": ["
209 " {\"title\": \"Brett Boe\"," 213 " {\"title\": \"Brett Boe\","
210 " \"message\": \"This is an important message!\"}," 214 " \"message\": \"This is an important message!\"},"
211 " {\"title\": \"Carla Coe\"," 215 " {\"title\": \"Carla Coe\","
212 " \"message\": \"Just took a look at the proposal\"}," 216 " \"message\": \"Just took a look at the proposal\"},"
213 " {\"title\": \"Donna Doe\"," 217 " {\"title\": \"Donna Doe\","
214 " \"message\": \"I see that you went to the conference\"}," 218 " \"message\": \"I see that you went to the conference\"},"
215 " {\"title\": \"Frank Foe\"," 219 " {\"title\": \"Frank Foe\","
216 " \"message\": \"I ate Harry's sandwich!\"}," 220 " \"message\": \"I ate Harry's sandwich!\"},"
217 " {\"title\": \"Grace Goe\"," 221 " {\"title\": \"Grace Goe\","
218 " \"message\": \"I saw Frank steal a sandwich :-)\"}" 222 " \"message\": \"I saw Frank steal a sandwich :-)\"}"
219 "]," 223 "],"
220 "\"priority\": 1," 224 "\"priority\": 1,"
221 "\"timestamp\": \"Fri, 16 Nov 2012 01:17:15 GMT\"" 225 "\"eventTime\": \"Fri, 16 Nov 2012 01:17:15 GMT\""
222 "}]", 226 "}]",
223 browser(), utils::NONE)); 227 browser(), utils::NONE));
224 // TODO(dharcourt): [...], items = [{title: foo, message: bar}, ...], [...] 228 // TODO(dharcourt): [...], items = [{title: foo, message: bar}, ...], [...]
225 229
226 std::string notification_id; 230 std::string notification_id;
227 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); 231 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType());
228 ASSERT_TRUE(result->GetAsString(&notification_id)); 232 ASSERT_TRUE(result->GetAsString(&notification_id));
229 ASSERT_TRUE(notification_id.length() > 0); 233 ASSERT_TRUE(notification_id.length() > 0);
230 } 234 }
231 235
232 IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestEvents) { 236 IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestEvents) {
233 ASSERT_TRUE(RunExtensionTest("notification/api/events")) << message_; 237 ASSERT_TRUE(RunExtensionTest("notification/api/events")) << message_;
234 } 238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698