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

Side by Side Diff: chrome/browser/extensions/api/notifications/notifications_apitest.cc

Issue 14767029: Add API function chrome.notifications.getAll (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge that caused test error. Created 7 years, 7 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 "base/stringprintf.h"
5 #include "chrome/browser/browser_process.h" 6 #include "chrome/browser/browser_process.h"
6 #include "chrome/browser/extensions/api/notifications/notifications_api.h" 7 #include "chrome/browser/extensions/api/notifications/notifications_api.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/extensions/extension_function_test_utils.h" 9 #include "chrome/browser/extensions/extension_function_test_utils.h"
9 #include "chrome/common/chrome_notification_types.h" 10 #include "chrome/common/chrome_notification_types.h"
10 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/extensions/features/feature.h" 12 #include "chrome/common/extensions/features/feature.h"
12 #include "content/public/browser/notification_service.h" 13 #include "content/public/browser/notification_service.h"
13 #include "content/public/test/test_utils.h" 14 #include "content/public/test/test_utils.h"
14 #include "ui/message_center/message_center.h" 15 #include "ui/message_center/message_center.h"
16 #include "ui/message_center/message_center_switches.h"
15 #include "ui/message_center/message_center_util.h" 17 #include "ui/message_center/message_center_util.h"
16 18
17 // TODO(kbr): remove: http://crbug.com/222296 19 // TODO(kbr): remove: http://crbug.com/222296
18 #if defined(OS_MACOSX) 20 #if defined(OS_MACOSX)
19 #import "base/mac/mac_util.h" 21 #import "base/mac/mac_util.h"
20 #endif 22 #endif
21 23
22 using extensions::Extension; 24 using extensions::Extension;
23 25
24 namespace utils = extension_function_test_utils; 26 namespace utils = extension_function_test_utils;
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 "}]", 255 "}]",
254 browser(), utils::NONE)); 256 browser(), utils::NONE));
255 // TODO(dharcourt): [...], items = [{title: foo, message: bar}, ...], [...] 257 // TODO(dharcourt): [...], items = [{title: foo, message: bar}, ...], [...]
256 258
257 std::string notification_id; 259 std::string notification_id;
258 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); 260 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType());
259 ASSERT_TRUE(result->GetAsString(&notification_id)); 261 ASSERT_TRUE(result->GetAsString(&notification_id));
260 ASSERT_TRUE(notification_id.length() > 0); 262 ASSERT_TRUE(notification_id.length() > 0);
261 } 263 }
262 264
265 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestGetAll) {
266 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
267
268 {
269 scoped_refptr<extensions::NotificationsGetAllFunction>
270 notification_get_all_function(
271 new extensions::NotificationsGetAllFunction());
272 notification_get_all_function->set_extension(empty_extension.get());
273 notification_get_all_function->set_has_callback(true);
274 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
275 notification_get_all_function, "[]", browser(), utils::NONE));
276
277 base::DictionaryValue* return_value;
278 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType());
279 ASSERT_TRUE(result->GetAsDictionary(&return_value));
280 ASSERT_TRUE(return_value->size() == 0);
281 }
282
283 const unsigned int kNotificationsToCreate = 4;
284
285 for (unsigned int i = 0; i < kNotificationsToCreate; i++) {
286 scoped_refptr<extensions::NotificationsCreateFunction>
287 notification_create_function(
288 new extensions::NotificationsCreateFunction());
289
290 notification_create_function->set_extension(empty_extension.get());
291 notification_create_function->set_has_callback(true);
292
293 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
294 notification_create_function,
295 base::StringPrintf("[\"identifier-%u\", "
296 "{"
297 "\"type\": \"list\","
298 "\"iconUrl\": \"an/image/that/does/not/exist.png\","
299 "\"title\": \"Title\","
300 "\"message\": \"Message.\","
301 "\"items\": ["
302 " {\"title\": \"Grace Goe\","
303 " \"message\": \"I saw Frank steal a sandwich :-)\"}"
304 "],"
305 "\"priority\": 1,"
306 "\"eventTime\": 1361488019.9999999"
307 "}]",
308 i),
309 browser(),
310 utils::NONE));
311 }
312
313 {
314 scoped_refptr<extensions::NotificationsGetAllFunction>
315 notification_get_all_function(
316 new extensions::NotificationsGetAllFunction());
317 notification_get_all_function->set_extension(empty_extension.get());
318 notification_get_all_function->set_has_callback(true);
319 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
320 notification_get_all_function, "[]", browser(), utils::NONE));
321
322 base::DictionaryValue* return_value;
323 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType());
324 ASSERT_TRUE(result->GetAsDictionary(&return_value));
325 ASSERT_EQ(return_value->size(), kNotificationsToCreate);
326 bool dictionary_bool = false;
327 for (unsigned int i = 0; i < kNotificationsToCreate; i++) {
328 std::string id = base::StringPrintf("identifier-%u", i);
329 ASSERT_TRUE(return_value->GetBoolean(id, &dictionary_bool));
330 ASSERT_TRUE(dictionary_bool);
331 }
332 ASSERT_FALSE(return_value->GetBoolean("test", &dictionary_bool));
Dmitry Titov 2013/05/16 20:39:15 What does this line check?
dewittj 2013/05/16 23:40:34 Probably it is unnecessary but I was checking that
333 }
334 }
335
263 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) { 336 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) {
264 #if defined(OS_MACOSX) 337 #if defined(OS_MACOSX)
265 // TODO(kbr): re-enable: http://crbug.com/222296 338 // TODO(kbr): re-enable: http://crbug.com/222296
266 if (base::mac::IsOSMountainLionOrLater()) 339 if (base::mac::IsOSMountainLionOrLater())
267 return; 340 return;
268 #endif 341 #endif
269 342
270 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_; 343 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_;
271 } 344 }
272 345
(...skipping 24 matching lines...) Expand all
297 } 370 }
298 371
299 { 372 {
300 ResultCatcher catcher; 373 ResultCatcher catcher;
301 g_browser_process->message_center()->RemoveNotification( 374 g_browser_process->message_center()->RemoveNotification(
302 extension->id() + "-BAR", 375 extension->id() + "-BAR",
303 true); 376 true);
304 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 377 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
305 } 378 }
306 } 379 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698