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/strings/string_number_conversions.h" | 5 #include "base/strings/string_number_conversions.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/extensions/api/notifications/notifications_api.h" | 10 #include "chrome/browser/extensions/api/notifications/notifications_api.h" |
11 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
12 #include "chrome/browser/extensions/extension_function_test_utils.h" | 12 #include "chrome/browser/extensions/extension_function_test_utils.h" |
13 #include "chrome/browser/notifications/notification.h" | |
14 #include "chrome/browser/notifications/notification_ui_manager.h" | |
15 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
16 #include "content/public/test/test_utils.h" | 14 #include "content/public/test/test_utils.h" |
17 #include "extensions/common/features/feature.h" | 15 #include "extensions/common/features/feature.h" |
18 #include "ui/message_center/message_center.h" | 16 #include "ui/message_center/message_center.h" |
19 #include "ui/message_center/notification_list.h" | 17 #include "ui/message_center/notification_list.h" |
20 #include "ui/message_center/notifier_settings.h" | 18 #include "ui/message_center/notifier_settings.h" |
21 | 19 |
22 using extensions::Extension; | 20 using extensions::Extension; |
23 | 21 |
24 namespace utils = extension_function_test_utils; | 22 namespace utils = extension_function_test_utils; |
(...skipping 11 matching lines...) Expand all Loading... |
36 const extensions::Extension* extension = LoadExtension(extdir); | 34 const extensions::Extension* extension = LoadExtension(extdir); |
37 if (extension) { | 35 if (extension) { |
38 page_created.Wait(); | 36 page_created.Wait(); |
39 } | 37 } |
40 return extension; | 38 return extension; |
41 } | 39 } |
42 }; | 40 }; |
43 | 41 |
44 } // namespace | 42 } // namespace |
45 | 43 |
46 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestBasicUsage) { | 44 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestIdUsage) { |
47 ASSERT_TRUE(RunExtensionTest("notifications/api/basic_usage")) << message_; | 45 // Create a new notification. A lingering output of this block is the |
| 46 // notifications ID, which we'll use in later parts of this test. |
| 47 std::string notification_id; |
| 48 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); |
| 49 { |
| 50 scoped_refptr<extensions::NotificationsCreateFunction> |
| 51 notification_function( |
| 52 new extensions::NotificationsCreateFunction()); |
| 53 |
| 54 notification_function->set_extension(empty_extension.get()); |
| 55 notification_function->set_has_callback(true); |
| 56 |
| 57 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 58 notification_function.get(), |
| 59 "[\"\", " // Empty string: ask API to generate ID |
| 60 "{" |
| 61 "\"type\": \"basic\"," |
| 62 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 63 "\"title\": \"Attention!\"," |
| 64 "\"message\": \"Check out Cirque du Soleil\"" |
| 65 "}]", |
| 66 browser(), |
| 67 utils::NONE)); |
| 68 |
| 69 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); |
| 70 ASSERT_TRUE(result->GetAsString(¬ification_id)); |
| 71 ASSERT_TRUE(notification_id.length() > 0); |
| 72 } |
| 73 |
| 74 // Update the existing notification. |
| 75 { |
| 76 scoped_refptr<extensions::NotificationsUpdateFunction> |
| 77 notification_function( |
| 78 new extensions::NotificationsUpdateFunction()); |
| 79 |
| 80 notification_function->set_extension(empty_extension.get()); |
| 81 notification_function->set_has_callback(true); |
| 82 |
| 83 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 84 notification_function.get(), |
| 85 "[\"" + notification_id + |
| 86 "\", " |
| 87 "{" |
| 88 "\"type\": \"basic\"," |
| 89 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 90 "\"title\": \"Attention!\"," |
| 91 "\"message\": \"Too late! The show ended yesterday\"" |
| 92 "}]", |
| 93 browser(), |
| 94 utils::NONE)); |
| 95 |
| 96 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); |
| 97 bool copy_bool_value = false; |
| 98 ASSERT_TRUE(result->GetAsBoolean(©_bool_value)); |
| 99 ASSERT_TRUE(copy_bool_value); |
| 100 |
| 101 // TODO(miket): add a testing method to query the message from the |
| 102 // displayed notification, and assert it matches the updated message. |
| 103 // |
| 104 // TODO(miket): add a method to count the number of outstanding |
| 105 // notifications, and confirm it remains at one at this point. |
| 106 } |
| 107 |
| 108 // Update a nonexistent notification. |
| 109 { |
| 110 scoped_refptr<extensions::NotificationsUpdateFunction> |
| 111 notification_function( |
| 112 new extensions::NotificationsUpdateFunction()); |
| 113 |
| 114 notification_function->set_extension(empty_extension.get()); |
| 115 notification_function->set_has_callback(true); |
| 116 |
| 117 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 118 notification_function.get(), |
| 119 "[\"xxxxxxxxxxxx\", " |
| 120 "{" |
| 121 "\"type\": \"basic\"," |
| 122 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 123 "\"title\": \"!\"," |
| 124 "\"message\": \"!\"" |
| 125 "}]", |
| 126 browser(), |
| 127 utils::NONE)); |
| 128 |
| 129 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); |
| 130 bool copy_bool_value = false; |
| 131 ASSERT_TRUE(result->GetAsBoolean(©_bool_value)); |
| 132 ASSERT_FALSE(copy_bool_value); |
| 133 } |
| 134 |
| 135 // Clear a nonexistent notification. |
| 136 { |
| 137 scoped_refptr<extensions::NotificationsClearFunction> |
| 138 notification_function( |
| 139 new extensions::NotificationsClearFunction()); |
| 140 |
| 141 notification_function->set_extension(empty_extension.get()); |
| 142 notification_function->set_has_callback(true); |
| 143 |
| 144 scoped_ptr<base::Value> result( |
| 145 utils::RunFunctionAndReturnSingleResult(notification_function.get(), |
| 146 "[\"xxxxxxxxxxx\"]", |
| 147 browser(), |
| 148 utils::NONE)); |
| 149 |
| 150 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); |
| 151 bool copy_bool_value = false; |
| 152 ASSERT_TRUE(result->GetAsBoolean(©_bool_value)); |
| 153 ASSERT_FALSE(copy_bool_value); |
| 154 } |
| 155 |
| 156 // Clear the notification we created. |
| 157 { |
| 158 scoped_refptr<extensions::NotificationsClearFunction> |
| 159 notification_function( |
| 160 new extensions::NotificationsClearFunction()); |
| 161 |
| 162 notification_function->set_extension(empty_extension.get()); |
| 163 notification_function->set_has_callback(true); |
| 164 |
| 165 scoped_ptr<base::Value> result( |
| 166 utils::RunFunctionAndReturnSingleResult(notification_function.get(), |
| 167 "[\"" + notification_id + "\"]", |
| 168 browser(), |
| 169 utils::NONE)); |
| 170 |
| 171 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); |
| 172 bool copy_bool_value = false; |
| 173 ASSERT_TRUE(result->GetAsBoolean(©_bool_value)); |
| 174 ASSERT_TRUE(copy_bool_value); |
| 175 } |
| 176 } |
| 177 |
| 178 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestBaseFormatNotification) { |
| 179 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); |
| 180 |
| 181 // Create a new notification with the minimum required properties. |
| 182 { |
| 183 scoped_refptr<extensions::NotificationsCreateFunction> |
| 184 notification_create_function( |
| 185 new extensions::NotificationsCreateFunction()); |
| 186 notification_create_function->set_extension(empty_extension.get()); |
| 187 notification_create_function->set_has_callback(true); |
| 188 |
| 189 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 190 notification_create_function.get(), |
| 191 "[\"\", " |
| 192 "{" |
| 193 "\"type\": \"basic\"," |
| 194 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 195 "\"title\": \"Attention!\"," |
| 196 "\"message\": \"Check out Cirque du Soleil\"" |
| 197 "}]", |
| 198 browser(), |
| 199 utils::NONE)); |
| 200 |
| 201 std::string notification_id; |
| 202 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); |
| 203 ASSERT_TRUE(result->GetAsString(¬ification_id)); |
| 204 ASSERT_TRUE(notification_id.length() > 0); |
| 205 } |
| 206 |
| 207 // Create another new notification with more than the required properties. |
| 208 { |
| 209 scoped_refptr<extensions::NotificationsCreateFunction> |
| 210 notification_create_function( |
| 211 new extensions::NotificationsCreateFunction()); |
| 212 notification_create_function->set_extension(empty_extension.get()); |
| 213 notification_create_function->set_has_callback(true); |
| 214 |
| 215 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 216 notification_create_function.get(), |
| 217 "[\"\", " |
| 218 "{" |
| 219 "\"type\": \"basic\"," |
| 220 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 221 "\"title\": \"Attention!\"," |
| 222 "\"message\": \"Check out Cirque du Soleil\"," |
| 223 "\"priority\": 1," |
| 224 "\"eventTime\": 1234567890.12345678," |
| 225 "\"buttons\": [" |
| 226 " {" |
| 227 " \"title\": \"Up\"," |
| 228 " \"iconUrl\":\"http://www.google.com/logos/2012/\"" |
| 229 " }," |
| 230 " {" |
| 231 " \"title\": \"Down\"" // note: no iconUrl |
| 232 " }" |
| 233 "]," |
| 234 "\"expandedMessage\": \"This is a longer expanded message.\"," |
| 235 "\"imageUrl\": \"http://www.google.com/logos/2012/election12-hp.jpg\"" |
| 236 "}]", |
| 237 browser(), |
| 238 utils::NONE)); |
| 239 |
| 240 std::string notification_id; |
| 241 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); |
| 242 ASSERT_TRUE(result->GetAsString(¬ification_id)); |
| 243 ASSERT_TRUE(notification_id.length() > 0); |
| 244 } |
| 245 |
| 246 // Error case: missing type property. |
| 247 { |
| 248 scoped_refptr<extensions::NotificationsCreateFunction> |
| 249 notification_create_function( |
| 250 new extensions::NotificationsCreateFunction()); |
| 251 notification_create_function->set_extension(empty_extension.get()); |
| 252 notification_create_function->set_has_callback(true); |
| 253 |
| 254 utils::RunFunction( |
| 255 notification_create_function.get(), |
| 256 "[\"\", " |
| 257 "{" |
| 258 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 259 "\"title\": \"Attention!\"," |
| 260 "\"message\": \"Check out Cirque du Soleil\"" |
| 261 "}]", |
| 262 browser(), |
| 263 utils::NONE); |
| 264 |
| 265 EXPECT_FALSE(notification_create_function->GetError().empty()); |
| 266 } |
| 267 |
| 268 // Error case: missing iconUrl property. |
| 269 { |
| 270 scoped_refptr<extensions::NotificationsCreateFunction> |
| 271 notification_create_function( |
| 272 new extensions::NotificationsCreateFunction()); |
| 273 notification_create_function->set_extension(empty_extension.get()); |
| 274 notification_create_function->set_has_callback(true); |
| 275 |
| 276 utils::RunFunction( |
| 277 notification_create_function.get(), |
| 278 "[\"\", " |
| 279 "{" |
| 280 "\"type\": \"basic\"," |
| 281 "\"title\": \"Attention!\"," |
| 282 "\"message\": \"Check out Cirque du Soleil\"" |
| 283 "}]", |
| 284 browser(), |
| 285 utils::NONE); |
| 286 |
| 287 EXPECT_FALSE(notification_create_function->GetError().empty()); |
| 288 } |
| 289 |
| 290 // Error case: missing title property. |
| 291 { |
| 292 scoped_refptr<extensions::NotificationsCreateFunction> |
| 293 notification_create_function( |
| 294 new extensions::NotificationsCreateFunction()); |
| 295 notification_create_function->set_extension(empty_extension.get()); |
| 296 notification_create_function->set_has_callback(true); |
| 297 |
| 298 utils::RunFunction( |
| 299 notification_create_function.get(), |
| 300 "[\"\", " |
| 301 "{" |
| 302 "\"type\": \"basic\"," |
| 303 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 304 "\"message\": \"Check out Cirque du Soleil\"" |
| 305 "}]", |
| 306 browser(), |
| 307 utils::NONE); |
| 308 |
| 309 EXPECT_FALSE(notification_create_function->GetError().empty()); |
| 310 } |
| 311 |
| 312 // Error case: missing message property. |
| 313 { |
| 314 scoped_refptr<extensions::NotificationsCreateFunction> |
| 315 notification_create_function( |
| 316 new extensions::NotificationsCreateFunction()); |
| 317 notification_create_function->set_extension(empty_extension.get()); |
| 318 notification_create_function->set_has_callback(true); |
| 319 |
| 320 utils::RunFunction( |
| 321 notification_create_function.get(), |
| 322 "[\"\", " |
| 323 "{" |
| 324 "\"type\": \"basic\"," |
| 325 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 326 "\"title\": \"Attention!\"" |
| 327 "}]", |
| 328 browser(), |
| 329 utils::NONE); |
| 330 |
| 331 EXPECT_FALSE(notification_create_function->GetError().empty()); |
| 332 } |
| 333 } |
| 334 |
| 335 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestMultipleItemNotification) { |
| 336 scoped_refptr<extensions::NotificationsCreateFunction> |
| 337 notification_create_function( |
| 338 new extensions::NotificationsCreateFunction()); |
| 339 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); |
| 340 |
| 341 notification_create_function->set_extension(empty_extension.get()); |
| 342 notification_create_function->set_has_callback(true); |
| 343 |
| 344 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 345 notification_create_function.get(), |
| 346 "[\"\", " |
| 347 "{" |
| 348 "\"type\": \"list\"," |
| 349 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 350 "\"title\": \"Multiple Item Notification Title\"," |
| 351 "\"message\": \"Multiple item notification message.\"," |
| 352 "\"items\": [" |
| 353 " {\"title\": \"Brett Boe\"," |
| 354 " \"message\": \"This is an important message!\"}," |
| 355 " {\"title\": \"Carla Coe\"," |
| 356 " \"message\": \"Just took a look at the proposal\"}," |
| 357 " {\"title\": \"Donna Doe\"," |
| 358 " \"message\": \"I see that you went to the conference\"}," |
| 359 " {\"title\": \"Frank Foe\"," |
| 360 " \"message\": \"I ate Harry's sandwich!\"}," |
| 361 " {\"title\": \"Grace Goe\"," |
| 362 " \"message\": \"I saw Frank steal a sandwich :-)\"}" |
| 363 "]," |
| 364 "\"priority\": 1," |
| 365 "\"eventTime\": 1361488019.9999999" |
| 366 "}]", |
| 367 browser(), |
| 368 utils::NONE)); |
| 369 // TODO(dharcourt): [...], items = [{title: foo, message: bar}, ...], [...] |
| 370 |
| 371 std::string notification_id; |
| 372 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); |
| 373 ASSERT_TRUE(result->GetAsString(¬ification_id)); |
| 374 ASSERT_TRUE(notification_id.length() > 0); |
| 375 } |
| 376 |
| 377 #if defined(OS_LINUX) |
| 378 #define MAYBE_TestGetAll DISABLED_TestGetAll |
| 379 #else |
| 380 #define MAYBE_TestGetAll TestGetAll |
| 381 #endif |
| 382 |
| 383 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestGetAll) { |
| 384 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); |
| 385 |
| 386 { |
| 387 scoped_refptr<extensions::NotificationsGetAllFunction> |
| 388 notification_get_all_function( |
| 389 new extensions::NotificationsGetAllFunction()); |
| 390 notification_get_all_function->set_extension(empty_extension.get()); |
| 391 notification_get_all_function->set_has_callback(true); |
| 392 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 393 notification_get_all_function.get(), "[]", browser(), utils::NONE)); |
| 394 |
| 395 base::DictionaryValue* return_value; |
| 396 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); |
| 397 ASSERT_TRUE(result->GetAsDictionary(&return_value)); |
| 398 ASSERT_TRUE(return_value->size() == 0); |
| 399 } |
| 400 |
| 401 const unsigned int kNotificationsToCreate = 4; |
| 402 |
| 403 for (unsigned int i = 0; i < kNotificationsToCreate; i++) { |
| 404 scoped_refptr<extensions::NotificationsCreateFunction> |
| 405 notification_create_function( |
| 406 new extensions::NotificationsCreateFunction()); |
| 407 |
| 408 notification_create_function->set_extension(empty_extension.get()); |
| 409 notification_create_function->set_has_callback(true); |
| 410 |
| 411 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 412 notification_create_function.get(), |
| 413 base::StringPrintf("[\"identifier-%u\", " |
| 414 "{" |
| 415 "\"type\": \"basic\"," |
| 416 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 417 "\"title\": \"Title\"," |
| 418 "\"message\": \"Message.\"," |
| 419 "\"priority\": 1," |
| 420 "\"eventTime\": 1361488019.9999999" |
| 421 "}]", |
| 422 i), |
| 423 browser(), |
| 424 utils::NONE)); |
| 425 } |
| 426 |
| 427 { |
| 428 scoped_refptr<extensions::NotificationsGetAllFunction> |
| 429 notification_get_all_function( |
| 430 new extensions::NotificationsGetAllFunction()); |
| 431 notification_get_all_function->set_extension(empty_extension.get()); |
| 432 notification_get_all_function->set_has_callback(true); |
| 433 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 434 notification_get_all_function.get(), "[]", browser(), utils::NONE)); |
| 435 |
| 436 base::DictionaryValue* return_value; |
| 437 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); |
| 438 ASSERT_TRUE(result->GetAsDictionary(&return_value)); |
| 439 ASSERT_EQ(return_value->size(), kNotificationsToCreate); |
| 440 bool dictionary_bool = false; |
| 441 for (unsigned int i = 0; i < kNotificationsToCreate; i++) { |
| 442 std::string id = base::StringPrintf("identifier-%u", i); |
| 443 ASSERT_TRUE(return_value->GetBoolean(id, &dictionary_bool)); |
| 444 ASSERT_TRUE(dictionary_bool); |
| 445 } |
| 446 } |
48 } | 447 } |
49 | 448 |
50 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) { | 449 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) { |
51 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_; | 450 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_; |
52 } | 451 } |
53 | 452 |
54 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestCSP) { | 453 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestCSP) { |
55 ASSERT_TRUE(RunExtensionTest("notifications/api/csp")) << message_; | 454 ASSERT_TRUE(RunExtensionTest("notifications/api/csp")) << message_; |
56 } | 455 } |
57 | 456 |
(...skipping 10 matching lines...) Expand all Loading... |
68 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 467 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
69 } | 468 } |
70 | 469 |
71 { | 470 { |
72 ResultCatcher catcher; | 471 ResultCatcher catcher; |
73 g_browser_process->message_center()->RemoveNotification( | 472 g_browser_process->message_center()->RemoveNotification( |
74 extension->id() + "-BAR", | 473 extension->id() + "-BAR", |
75 true); | 474 true); |
76 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 475 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
77 } | 476 } |
78 | |
79 { | |
80 ResultCatcher catcher; | |
81 g_browser_process->message_center()->RemoveAllNotifications(false); | |
82 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | |
83 } | |
84 { | |
85 ResultCatcher catcher; | |
86 g_browser_process->message_center()->RemoveAllNotifications(true); | |
87 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | |
88 } | |
89 } | 477 } |
90 | 478 |
| 479 |
| 480 #if defined(OS_LINUX) |
| 481 #define MAYBE_TestProgressNotification DISABLED_TestProgressNotification |
| 482 #else |
| 483 #define MAYBE_TestProgressNotification TestProgressNotification |
| 484 #endif |
| 485 |
| 486 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestProgressNotification) { |
| 487 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); |
| 488 |
| 489 // Create a new progress notification. |
| 490 std::string notification_id; |
| 491 { |
| 492 scoped_refptr<extensions::NotificationsCreateFunction> |
| 493 notification_create_function( |
| 494 new extensions::NotificationsCreateFunction()); |
| 495 notification_create_function->set_extension(empty_extension.get()); |
| 496 notification_create_function->set_has_callback(true); |
| 497 |
| 498 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 499 notification_create_function.get(), |
| 500 "[\"\", " |
| 501 "{" |
| 502 "\"type\": \"progress\"," |
| 503 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 504 "\"title\": \"Test!\"," |
| 505 "\"message\": \"This is a progress notification.\"," |
| 506 "\"priority\": 1," |
| 507 "\"eventTime\": 1234567890.12345678," |
| 508 "\"progress\": 30" |
| 509 "}]", |
| 510 browser(), |
| 511 utils::NONE)); |
| 512 |
| 513 EXPECT_EQ(base::Value::TYPE_STRING, result->GetType()); |
| 514 EXPECT_TRUE(result->GetAsString(¬ification_id)); |
| 515 EXPECT_TRUE(notification_id.length() > 0); |
| 516 } |
| 517 |
| 518 // Update the progress property only. |
| 519 { |
| 520 scoped_refptr<extensions::NotificationsUpdateFunction> |
| 521 notification_function( |
| 522 new extensions::NotificationsUpdateFunction()); |
| 523 notification_function->set_extension(empty_extension.get()); |
| 524 notification_function->set_has_callback(true); |
| 525 |
| 526 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 527 notification_function.get(), |
| 528 "[\"" + notification_id + |
| 529 "\", " |
| 530 "{" |
| 531 "\"progress\": 60" |
| 532 "}]", |
| 533 browser(), |
| 534 utils::NONE)); |
| 535 |
| 536 EXPECT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); |
| 537 bool copy_bool_value = false; |
| 538 EXPECT_TRUE(result->GetAsBoolean(©_bool_value)); |
| 539 EXPECT_TRUE(copy_bool_value); |
| 540 } |
| 541 |
| 542 // Error case: progress value provided for non-progress type. |
| 543 { |
| 544 scoped_refptr<extensions::NotificationsCreateFunction> |
| 545 notification_create_function( |
| 546 new extensions::NotificationsCreateFunction()); |
| 547 notification_create_function->set_extension(empty_extension.get()); |
| 548 notification_create_function->set_has_callback(true); |
| 549 |
| 550 utils::RunFunction( |
| 551 notification_create_function.get(), |
| 552 "[\"\", " |
| 553 "{" |
| 554 "\"type\": \"basic\"," |
| 555 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 556 "\"title\": \"Test!\"," |
| 557 "\"message\": \"This is a progress notification.\"," |
| 558 "\"priority\": 1," |
| 559 "\"eventTime\": 1234567890.12345678," |
| 560 "\"progress\": 10" |
| 561 "}]", |
| 562 browser(), |
| 563 utils::NONE); |
| 564 EXPECT_FALSE(notification_create_function->GetError().empty()); |
| 565 } |
| 566 |
| 567 // Error case: progress value less than lower bound. |
| 568 { |
| 569 scoped_refptr<extensions::NotificationsCreateFunction> |
| 570 notification_create_function( |
| 571 new extensions::NotificationsCreateFunction()); |
| 572 notification_create_function->set_extension(empty_extension.get()); |
| 573 notification_create_function->set_has_callback(true); |
| 574 |
| 575 utils::RunFunction( |
| 576 notification_create_function.get(), |
| 577 "[\"\", " |
| 578 "{" |
| 579 "\"type\": \"progress\"," |
| 580 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 581 "\"title\": \"Test!\"," |
| 582 "\"message\": \"This is a progress notification.\"," |
| 583 "\"priority\": 1," |
| 584 "\"eventTime\": 1234567890.12345678," |
| 585 "\"progress\": -10" |
| 586 "}]", |
| 587 browser(), |
| 588 utils::NONE); |
| 589 EXPECT_FALSE(notification_create_function->GetError().empty()); |
| 590 } |
| 591 |
| 592 // Error case: progress value greater than upper bound. |
| 593 { |
| 594 scoped_refptr<extensions::NotificationsCreateFunction> |
| 595 notification_create_function( |
| 596 new extensions::NotificationsCreateFunction()); |
| 597 notification_create_function->set_extension(empty_extension.get()); |
| 598 notification_create_function->set_has_callback(true); |
| 599 |
| 600 utils::RunFunction( |
| 601 notification_create_function.get(), |
| 602 "[\"\", " |
| 603 "{" |
| 604 "\"type\": \"progress\"," |
| 605 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 606 "\"title\": \"Test!\"," |
| 607 "\"message\": \"This is a progress notification.\"," |
| 608 "\"priority\": 1," |
| 609 "\"eventTime\": 1234567890.12345678," |
| 610 "\"progress\": 101" |
| 611 "}]", |
| 612 browser(), |
| 613 utils::NONE); |
| 614 EXPECT_FALSE(notification_create_function->GetError().empty()); |
| 615 } |
| 616 } |
| 617 |
91 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestPartialUpdate) { | 618 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestPartialUpdate) { |
92 ASSERT_TRUE(RunExtensionTest("notifications/api/partial_update")) << message_; | 619 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); |
93 const extensions::Extension* extension = GetSingleLoadedExtension(); | 620 |
94 ASSERT_TRUE(extension) << message_; | 621 // Create a new notification. |
95 | 622 std::string notification_id; |
| 623 { |
| 624 scoped_refptr<extensions::NotificationsCreateFunction> |
| 625 notification_function( |
| 626 new extensions::NotificationsCreateFunction()); |
| 627 notification_function->set_extension(empty_extension.get()); |
| 628 notification_function->set_has_callback(true); |
| 629 |
| 630 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 631 notification_function.get(), |
| 632 "[\"\", " // Empty string: ask API to generate ID |
| 633 "{" |
| 634 "\"type\": \"basic\"," |
| 635 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 636 "\"title\": \"Attention!\"," |
| 637 "\"message\": \"Check out Cirque du Soleil\"," |
| 638 "\"buttons\": [{\"title\": \"Button\"}]" |
| 639 "}]", |
| 640 browser(), |
| 641 utils::NONE)); |
| 642 |
| 643 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); |
| 644 ASSERT_TRUE(result->GetAsString(¬ification_id)); |
| 645 ASSERT_TRUE(notification_id.length() > 0); |
| 646 } |
| 647 |
| 648 // Update a few properties in the existing notification. |
96 const char kNewTitle[] = "Changed!"; | 649 const char kNewTitle[] = "Changed!"; |
97 const char kNewMessage[] = "Too late! The show ended yesterday"; | 650 const char kNewMessage[] = "Too late! The show ended yesterday"; |
| 651 { |
| 652 scoped_refptr<extensions::NotificationsUpdateFunction> |
| 653 notification_function( |
| 654 new extensions::NotificationsUpdateFunction()); |
| 655 notification_function->set_extension(empty_extension.get()); |
| 656 notification_function->set_has_callback(true); |
| 657 |
| 658 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 659 notification_function.get(), |
| 660 "[\"" + notification_id + |
| 661 "\", " |
| 662 "{" |
| 663 "\"title\": \"" + kNewTitle + "\"," |
| 664 "\"message\": \"" + kNewMessage + "\"" |
| 665 "}]", |
| 666 browser(), |
| 667 utils::NONE)); |
| 668 |
| 669 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); |
| 670 bool copy_bool_value = false; |
| 671 ASSERT_TRUE(result->GetAsBoolean(©_bool_value)); |
| 672 ASSERT_TRUE(copy_bool_value); |
| 673 } |
| 674 |
| 675 // Update some other properties in the existing notification. |
98 int kNewPriority = 2; | 676 int kNewPriority = 2; |
99 | 677 { |
| 678 scoped_refptr<extensions::NotificationsUpdateFunction> |
| 679 notification_function( |
| 680 new extensions::NotificationsUpdateFunction()); |
| 681 notification_function->set_extension(empty_extension.get()); |
| 682 notification_function->set_has_callback(true); |
| 683 |
| 684 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 685 notification_function.get(), |
| 686 "[\"" + notification_id + |
| 687 "\", " |
| 688 "{" |
| 689 "\"priority\": " + base::IntToString(kNewPriority) + "," |
| 690 "\"buttons\": []" |
| 691 "}]", |
| 692 browser(), |
| 693 utils::NONE)); |
| 694 |
| 695 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); |
| 696 bool copy_bool_value = false; |
| 697 ASSERT_TRUE(result->GetAsBoolean(©_bool_value)); |
| 698 ASSERT_TRUE(copy_bool_value); |
| 699 } |
| 700 |
| 701 // Get the updated notification and verify its data. |
100 const message_center::NotificationList::Notifications& notifications = | 702 const message_center::NotificationList::Notifications& notifications = |
101 g_browser_process->message_center()->GetVisibleNotifications(); | 703 g_browser_process->message_center()->GetVisibleNotifications(); |
102 ASSERT_EQ(1u, notifications.size()); | 704 ASSERT_EQ(1u, notifications.size()); |
103 message_center::Notification* notification = *(notifications.begin()); | 705 message_center::Notification* notification = *(notifications.begin()); |
104 LOG(INFO) << "Notification ID: " << notification->id(); | |
105 | |
106 EXPECT_EQ(base::ASCIIToUTF16(kNewTitle), notification->title()); | 706 EXPECT_EQ(base::ASCIIToUTF16(kNewTitle), notification->title()); |
107 EXPECT_EQ(base::ASCIIToUTF16(kNewMessage), notification->message()); | 707 EXPECT_EQ(base::ASCIIToUTF16(kNewMessage), notification->message()); |
108 EXPECT_EQ(kNewPriority, notification->priority()); | 708 EXPECT_EQ(kNewPriority, notification->priority()); |
109 EXPECT_EQ(0u, notification->buttons().size()); | 709 EXPECT_EQ(0u, notification->buttons().size()); |
110 } | 710 } |
111 | 711 |
112 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestGetPermissionLevel) { | 712 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestGetPermissionLevel) { |
113 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | 713 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); |
114 | 714 |
115 // Get permission level for the extension whose notifications are enabled. | 715 // Get permission level for the extension whose notifications are enabled. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 message_center::NotifierId notifier_id( | 788 message_center::NotifierId notifier_id( |
189 message_center::NotifierId::APPLICATION, | 789 message_center::NotifierId::APPLICATION, |
190 extension->id()); | 790 extension->id()); |
191 message_center::Notifier notifier(notifier_id, base::string16(), false); | 791 message_center::Notifier notifier(notifier_id, base::string16(), false); |
192 g_browser_process->message_center()->GetNotifierSettingsProvider()-> | 792 g_browser_process->message_center()->GetNotifierSettingsProvider()-> |
193 SetNotifierEnabled(notifier, true); | 793 SetNotifierEnabled(notifier, true); |
194 | 794 |
195 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 795 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
196 } | 796 } |
197 } | 797 } |
OLD | NEW |