| 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 #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\": \"basic\"," |
| 304 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 305 "\"title\": \"Title\"," |
| 306 "\"message\": \"Message.\"," |
| 307 "\"priority\": 1," |
| 308 "\"eventTime\": 1361488019.9999999" |
| 309 "}]", |
| 310 i), |
| 311 browser(), |
| 312 utils::NONE)); |
| 313 } |
| 314 |
| 315 { |
| 316 scoped_refptr<extensions::NotificationsGetAllFunction> |
| 317 notification_get_all_function( |
| 318 new extensions::NotificationsGetAllFunction()); |
| 319 notification_get_all_function->set_extension(empty_extension.get()); |
| 320 notification_get_all_function->set_has_callback(true); |
| 321 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 322 notification_get_all_function, "[]", browser(), utils::NONE)); |
| 323 |
| 324 base::DictionaryValue* return_value; |
| 325 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); |
| 326 ASSERT_TRUE(result->GetAsDictionary(&return_value)); |
| 327 ASSERT_EQ(return_value->size(), kNotificationsToCreate); |
| 328 bool dictionary_bool = false; |
| 329 for (unsigned int i = 0; i < kNotificationsToCreate; i++) { |
| 330 std::string id = base::StringPrintf("identifier-%u", i); |
| 331 ASSERT_TRUE(return_value->GetBoolean(id, &dictionary_bool)); |
| 332 ASSERT_TRUE(dictionary_bool); |
| 333 } |
| 334 } |
| 335 } |
| 336 |
| 263 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) { | 337 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) { |
| 264 #if defined(OS_MACOSX) | 338 #if defined(OS_MACOSX) |
| 265 // TODO(kbr): re-enable: http://crbug.com/222296 | 339 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 266 if (base::mac::IsOSMountainLionOrLater()) | 340 if (base::mac::IsOSMountainLionOrLater()) |
| 267 return; | 341 return; |
| 268 #endif | 342 #endif |
| 269 | 343 |
| 270 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_; | 344 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_; |
| 271 } | 345 } |
| 272 | 346 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 297 } | 371 } |
| 298 | 372 |
| 299 { | 373 { |
| 300 ResultCatcher catcher; | 374 ResultCatcher catcher; |
| 301 g_browser_process->message_center()->RemoveNotification( | 375 g_browser_process->message_center()->RemoveNotification( |
| 302 extension->id() + "-BAR", | 376 extension->id() + "-BAR", |
| 303 true); | 377 true); |
| 304 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 378 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 305 } | 379 } |
| 306 } | 380 } |
| OLD | NEW |