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 #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 Loading... |
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(¬ification_id)); | 261 ASSERT_TRUE(result->GetAsString(¬ification_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 } |
| 333 } |
| 334 |
263 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) { | 335 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) { |
264 #if defined(OS_MACOSX) | 336 #if defined(OS_MACOSX) |
265 // TODO(kbr): re-enable: http://crbug.com/222296 | 337 // TODO(kbr): re-enable: http://crbug.com/222296 |
266 if (base::mac::IsOSMountainLionOrLater()) | 338 if (base::mac::IsOSMountainLionOrLater()) |
267 return; | 339 return; |
268 #endif | 340 #endif |
269 | 341 |
270 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_; | 342 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_; |
271 } | 343 } |
272 | 344 |
(...skipping 24 matching lines...) Expand all Loading... |
297 } | 369 } |
298 | 370 |
299 { | 371 { |
300 ResultCatcher catcher; | 372 ResultCatcher catcher; |
301 g_browser_process->message_center()->RemoveNotification( | 373 g_browser_process->message_center()->RemoveNotification( |
302 extension->id() + "-BAR", | 374 extension->id() + "-BAR", |
303 true); | 375 true); |
304 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 376 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
305 } | 377 } |
306 } | 378 } |
OLD | NEW |