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

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: Rebase. 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 #if defined(OS_LINUX) && defined(USE_AURA)
266 #define MAYBE_TestGetAll DISABLED_TestGetAll
267 #else
268 #define MAYBE_TestGetAll TestGetAll
269 #endif
270
271 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestGetAll) {
272 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
273
274 {
275 scoped_refptr<extensions::NotificationsGetAllFunction>
276 notification_get_all_function(
277 new extensions::NotificationsGetAllFunction());
278 notification_get_all_function->set_extension(empty_extension.get());
279 notification_get_all_function->set_has_callback(true);
280 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
281 notification_get_all_function, "[]", browser(), utils::NONE));
282
283 base::DictionaryValue* return_value;
284 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType());
285 ASSERT_TRUE(result->GetAsDictionary(&return_value));
286 ASSERT_TRUE(return_value->size() == 0);
287 }
288
289 const unsigned int kNotificationsToCreate = 4;
290
291 for (unsigned int i = 0; i < kNotificationsToCreate; i++) {
292 scoped_refptr<extensions::NotificationsCreateFunction>
293 notification_create_function(
294 new extensions::NotificationsCreateFunction());
295
296 notification_create_function->set_extension(empty_extension.get());
297 notification_create_function->set_has_callback(true);
298
299 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
300 notification_create_function,
301 base::StringPrintf("[\"identifier-%u\", "
302 "{"
303 "\"type\": \"list\","
304 "\"iconUrl\": \"an/image/that/does/not/exist.png\","
305 "\"title\": \"Title\","
306 "\"message\": \"Message.\","
307 "\"items\": ["
308 " {\"title\": \"Grace Goe\","
309 " \"message\": \"I saw Frank steal a sandwich :-)\"}"
310 "],"
311 "\"priority\": 1,"
312 "\"eventTime\": 1361488019.9999999"
313 "}]",
314 i),
315 browser(),
316 utils::NONE));
317 }
318
319 {
320 scoped_refptr<extensions::NotificationsGetAllFunction>
321 notification_get_all_function(
322 new extensions::NotificationsGetAllFunction());
323 notification_get_all_function->set_extension(empty_extension.get());
324 notification_get_all_function->set_has_callback(true);
325 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
326 notification_get_all_function, "[]", browser(), utils::NONE));
327
328 base::DictionaryValue* return_value;
329 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType());
330 ASSERT_TRUE(result->GetAsDictionary(&return_value));
331 ASSERT_EQ(return_value->size(), kNotificationsToCreate);
332 bool dictionary_bool = false;
333 for (unsigned int i = 0; i < kNotificationsToCreate; i++) {
334 std::string id = base::StringPrintf("identifier-%u", i);
335 ASSERT_TRUE(return_value->GetBoolean(id, &dictionary_bool));
336 ASSERT_TRUE(dictionary_bool);
337 }
338 }
339 }
340
263 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) { 341 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) {
264 #if defined(OS_MACOSX) 342 #if defined(OS_MACOSX)
265 // TODO(kbr): re-enable: http://crbug.com/222296 343 // TODO(kbr): re-enable: http://crbug.com/222296
266 if (base::mac::IsOSMountainLionOrLater()) 344 if (base::mac::IsOSMountainLionOrLater())
267 return; 345 return;
268 #endif 346 #endif
269 347
270 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_; 348 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_;
271 } 349 }
272 350
(...skipping 24 matching lines...) Expand all
297 } 375 }
298 376
299 { 377 {
300 ResultCatcher catcher; 378 ResultCatcher catcher;
301 g_browser_process->message_center()->RemoveNotification( 379 g_browser_process->message_center()->RemoveNotification(
302 extension->id() + "-BAR", 380 extension->id() + "-BAR",
303 true); 381 true);
304 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 382 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
305 } 383 }
306 } 384 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698