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/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
6 #include "chrome/browser/browser_process.h" | 6 #include "chrome/browser/browser_process.h" |
7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/extensions/api/notifications/notifications_api.h" | 8 #include "chrome/browser/extensions/api/notifications/notifications_api.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/extensions/extension_function_test_utils.h" | 10 #include "chrome/browser/extensions/extension_function_test_utils.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 utils::NONE)); | 184 utils::NONE)); |
185 | 185 |
186 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); | 186 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); |
187 bool copy_bool_value = false; | 187 bool copy_bool_value = false; |
188 ASSERT_TRUE(result->GetAsBoolean(©_bool_value)); | 188 ASSERT_TRUE(result->GetAsBoolean(©_bool_value)); |
189 ASSERT_TRUE(copy_bool_value); | 189 ASSERT_TRUE(copy_bool_value); |
190 } | 190 } |
191 } | 191 } |
192 | 192 |
193 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestBaseFormatNotification) { | 193 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestBaseFormatNotification) { |
194 scoped_refptr<extensions::NotificationsCreateFunction> | |
195 notification_create_function( | |
196 new extensions::NotificationsCreateFunction()); | |
197 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | 194 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); |
198 | 195 |
199 notification_create_function->set_extension(empty_extension.get()); | 196 // Create a new notification with the minimum required properties. |
200 notification_create_function->set_has_callback(true); | 197 { |
| 198 scoped_refptr<extensions::NotificationsCreateFunction> |
| 199 notification_create_function( |
| 200 new extensions::NotificationsCreateFunction()); |
| 201 notification_create_function->set_extension(empty_extension.get()); |
| 202 notification_create_function->set_has_callback(true); |
201 | 203 |
202 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | 204 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
203 notification_create_function.get(), | 205 notification_create_function.get(), |
204 "[\"\", " | 206 "[\"\", " |
205 "{" | 207 "{" |
206 "\"type\": \"basic\"," | 208 "\"type\": \"basic\"," |
207 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," | 209 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
208 "\"title\": \"Attention!\"," | 210 "\"title\": \"Attention!\"," |
209 "\"message\": \"Check out Cirque du Soleil\"," | 211 "\"message\": \"Check out Cirque du Soleil\"" |
210 "\"priority\": 1," | 212 "}]", |
211 "\"eventTime\": 1234567890.12345678," | 213 browser(), |
212 "\"buttons\": [" | 214 utils::NONE)); |
213 " {" | |
214 " \"title\": \"Up\"," | |
215 " \"iconUrl\":\"http://www.google.com/logos/2012/\"" | |
216 " }," | |
217 " {" | |
218 " \"title\": \"Down\"" // note: no iconUrl | |
219 " }" | |
220 "]," | |
221 "\"expandedMessage\": \"This is a longer expanded message.\"," | |
222 "\"imageUrl\": \"http://www.google.com/logos/2012/election12-hp.jpg\"" | |
223 "}]", | |
224 browser(), | |
225 utils::NONE)); | |
226 | 215 |
227 std::string notification_id; | 216 std::string notification_id; |
228 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); | 217 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); |
229 ASSERT_TRUE(result->GetAsString(¬ification_id)); | 218 ASSERT_TRUE(result->GetAsString(¬ification_id)); |
230 ASSERT_TRUE(notification_id.length() > 0); | 219 ASSERT_TRUE(notification_id.length() > 0); |
| 220 } |
| 221 |
| 222 // Create another new notification with more than the required properties. |
| 223 { |
| 224 scoped_refptr<extensions::NotificationsCreateFunction> |
| 225 notification_create_function( |
| 226 new extensions::NotificationsCreateFunction()); |
| 227 notification_create_function->set_extension(empty_extension.get()); |
| 228 notification_create_function->set_has_callback(true); |
| 229 |
| 230 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 231 notification_create_function.get(), |
| 232 "[\"\", " |
| 233 "{" |
| 234 "\"type\": \"basic\"," |
| 235 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 236 "\"title\": \"Attention!\"," |
| 237 "\"message\": \"Check out Cirque du Soleil\"," |
| 238 "\"priority\": 1," |
| 239 "\"eventTime\": 1234567890.12345678," |
| 240 "\"buttons\": [" |
| 241 " {" |
| 242 " \"title\": \"Up\"," |
| 243 " \"iconUrl\":\"http://www.google.com/logos/2012/\"" |
| 244 " }," |
| 245 " {" |
| 246 " \"title\": \"Down\"" // note: no iconUrl |
| 247 " }" |
| 248 "]," |
| 249 "\"expandedMessage\": \"This is a longer expanded message.\"," |
| 250 "\"imageUrl\": \"http://www.google.com/logos/2012/election12-hp.jpg\"" |
| 251 "}]", |
| 252 browser(), |
| 253 utils::NONE)); |
| 254 |
| 255 std::string notification_id; |
| 256 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); |
| 257 ASSERT_TRUE(result->GetAsString(¬ification_id)); |
| 258 ASSERT_TRUE(notification_id.length() > 0); |
| 259 } |
| 260 |
| 261 // Error case: try to create a new notification with some required properties |
| 262 // missing. |
| 263 { |
| 264 scoped_refptr<extensions::NotificationsCreateFunction> |
| 265 notification_create_function( |
| 266 new extensions::NotificationsCreateFunction()); |
| 267 notification_create_function->set_extension(empty_extension.get()); |
| 268 notification_create_function->set_has_callback(true); |
| 269 |
| 270 utils::RunFunction( |
| 271 notification_create_function.get(), |
| 272 "[\"\", " |
| 273 "{" |
| 274 "\"type\": \"basic\"," |
| 275 "\"iconUrl\": \"an/image/that/does/not/exist.png\"" |
| 276 "}]", |
| 277 browser(), |
| 278 utils::NONE); |
| 279 |
| 280 EXPECT_FALSE(notification_create_function->GetError().empty()); |
| 281 } |
231 } | 282 } |
232 | 283 |
233 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestMultipleItemNotification) { | 284 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestMultipleItemNotification) { |
234 scoped_refptr<extensions::NotificationsCreateFunction> | 285 scoped_refptr<extensions::NotificationsCreateFunction> |
235 notification_create_function( | 286 notification_create_function( |
236 new extensions::NotificationsCreateFunction()); | 287 new extensions::NotificationsCreateFunction()); |
237 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | 288 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); |
238 | 289 |
239 notification_create_function->set_extension(empty_extension.get()); | 290 notification_create_function->set_extension(empty_extension.get()); |
240 notification_create_function->set_has_callback(true); | 291 notification_create_function->set_has_callback(true); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 | 443 |
393 #if defined(OS_LINUX) | 444 #if defined(OS_LINUX) |
394 #define MAYBE_TestProgressNotification DISABLED_TestProgressNotification | 445 #define MAYBE_TestProgressNotification DISABLED_TestProgressNotification |
395 #else | 446 #else |
396 #define MAYBE_TestProgressNotification TestProgressNotification | 447 #define MAYBE_TestProgressNotification TestProgressNotification |
397 #endif | 448 #endif |
398 | 449 |
399 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestProgressNotification) { | 450 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestProgressNotification) { |
400 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | 451 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); |
401 | 452 |
| 453 // Create a new progress notification. |
| 454 std::string notification_id; |
402 { | 455 { |
403 scoped_refptr<extensions::NotificationsCreateFunction> | 456 scoped_refptr<extensions::NotificationsCreateFunction> |
404 notification_create_function( | 457 notification_create_function( |
405 new extensions::NotificationsCreateFunction()); | 458 new extensions::NotificationsCreateFunction()); |
406 notification_create_function->set_extension(empty_extension.get()); | 459 notification_create_function->set_extension(empty_extension.get()); |
407 notification_create_function->set_has_callback(true); | 460 notification_create_function->set_has_callback(true); |
408 | 461 |
409 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | 462 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
410 notification_create_function.get(), | 463 notification_create_function.get(), |
411 "[\"\", " | 464 "[\"\", " |
412 "{" | 465 "{" |
413 "\"type\": \"progress\"," | 466 "\"type\": \"progress\"," |
414 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," | 467 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
415 "\"title\": \"Test!\"," | 468 "\"title\": \"Test!\"," |
416 "\"message\": \"This is a progress notification.\"," | 469 "\"message\": \"This is a progress notification.\"," |
417 "\"priority\": 1," | 470 "\"priority\": 1," |
418 "\"eventTime\": 1234567890.12345678," | 471 "\"eventTime\": 1234567890.12345678," |
419 "\"progress\": 30" | 472 "\"progress\": 30" |
420 "}]", | 473 "}]", |
421 browser(), | 474 browser(), |
422 utils::NONE)); | 475 utils::NONE)); |
423 | 476 |
424 std::string notification_id; | |
425 EXPECT_EQ(base::Value::TYPE_STRING, result->GetType()); | 477 EXPECT_EQ(base::Value::TYPE_STRING, result->GetType()); |
426 EXPECT_TRUE(result->GetAsString(¬ification_id)); | 478 EXPECT_TRUE(result->GetAsString(¬ification_id)); |
427 EXPECT_TRUE(notification_id.length() > 0); | 479 EXPECT_TRUE(notification_id.length() > 0); |
428 } | 480 } |
429 | 481 |
| 482 // Update the progress property only. |
| 483 { |
| 484 scoped_refptr<extensions::NotificationsUpdateFunction> |
| 485 notification_function( |
| 486 new extensions::NotificationsUpdateFunction()); |
| 487 notification_function->set_extension(empty_extension.get()); |
| 488 notification_function->set_has_callback(true); |
| 489 |
| 490 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 491 notification_function.get(), |
| 492 "[\"" + notification_id + |
| 493 "\", " |
| 494 "{" |
| 495 "\"progress\": 60" |
| 496 "}]", |
| 497 browser(), |
| 498 utils::NONE)); |
| 499 |
| 500 EXPECT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); |
| 501 bool copy_bool_value = false; |
| 502 EXPECT_TRUE(result->GetAsBoolean(©_bool_value)); |
| 503 EXPECT_TRUE(copy_bool_value); |
| 504 } |
| 505 |
430 // Error case: progress value provided for non-progress type. | 506 // Error case: progress value provided for non-progress type. |
431 { | 507 { |
432 scoped_refptr<extensions::NotificationsCreateFunction> | 508 scoped_refptr<extensions::NotificationsCreateFunction> |
433 notification_create_function( | 509 notification_create_function( |
434 new extensions::NotificationsCreateFunction()); | 510 new extensions::NotificationsCreateFunction()); |
435 notification_create_function->set_extension(empty_extension.get()); | 511 notification_create_function->set_extension(empty_extension.get()); |
436 notification_create_function->set_has_callback(true); | 512 notification_create_function->set_has_callback(true); |
437 | 513 |
438 utils::RunFunction( | 514 utils::RunFunction( |
439 notification_create_function.get(), | 515 notification_create_function.get(), |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 "\"message\": \"This is a progress notification.\"," | 571 "\"message\": \"This is a progress notification.\"," |
496 "\"priority\": 1," | 572 "\"priority\": 1," |
497 "\"eventTime\": 1234567890.12345678," | 573 "\"eventTime\": 1234567890.12345678," |
498 "\"progress\": 101" | 574 "\"progress\": 101" |
499 "}]", | 575 "}]", |
500 browser(), | 576 browser(), |
501 utils::NONE); | 577 utils::NONE); |
502 EXPECT_FALSE(notification_create_function->GetError().empty()); | 578 EXPECT_FALSE(notification_create_function->GetError().empty()); |
503 } | 579 } |
504 } | 580 } |
| 581 |
| 582 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestPartialUpdate) { |
| 583 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); |
| 584 |
| 585 // Create a new notification. |
| 586 std::string notification_id; |
| 587 { |
| 588 scoped_refptr<extensions::NotificationsCreateFunction> |
| 589 notification_function( |
| 590 new extensions::NotificationsCreateFunction()); |
| 591 notification_function->set_extension(empty_extension.get()); |
| 592 notification_function->set_has_callback(true); |
| 593 |
| 594 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 595 notification_function.get(), |
| 596 "[\"\", " // Empty string: ask API to generate ID |
| 597 "{" |
| 598 "\"type\": \"basic\"," |
| 599 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," |
| 600 "\"title\": \"Attention!\"," |
| 601 "\"message\": \"Check out Cirque du Soleil\"" |
| 602 "}]", |
| 603 browser(), |
| 604 utils::NONE)); |
| 605 |
| 606 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); |
| 607 ASSERT_TRUE(result->GetAsString(¬ification_id)); |
| 608 ASSERT_TRUE(notification_id.length() > 0); |
| 609 } |
| 610 |
| 611 // Update a few properties in the existing notification. |
| 612 { |
| 613 scoped_refptr<extensions::NotificationsUpdateFunction> |
| 614 notification_function( |
| 615 new extensions::NotificationsUpdateFunction()); |
| 616 notification_function->set_extension(empty_extension.get()); |
| 617 notification_function->set_has_callback(true); |
| 618 |
| 619 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 620 notification_function.get(), |
| 621 "[\"" + notification_id + |
| 622 "\", " |
| 623 "{" |
| 624 "\"title\": \"Changed!\"," |
| 625 "\"message\": \"Too late! The show ended yesterday\"" |
| 626 "}]", |
| 627 browser(), |
| 628 utils::NONE)); |
| 629 |
| 630 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); |
| 631 bool copy_bool_value = false; |
| 632 ASSERT_TRUE(result->GetAsBoolean(©_bool_value)); |
| 633 ASSERT_TRUE(copy_bool_value); |
| 634 } |
| 635 |
| 636 // Update another property in the existing notification. |
| 637 { |
| 638 scoped_refptr<extensions::NotificationsUpdateFunction> |
| 639 notification_function( |
| 640 new extensions::NotificationsUpdateFunction()); |
| 641 notification_function->set_extension(empty_extension.get()); |
| 642 notification_function->set_has_callback(true); |
| 643 |
| 644 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 645 notification_function.get(), |
| 646 "[\"" + notification_id + |
| 647 "\", " |
| 648 "{" |
| 649 "\"priority\": 2" |
| 650 "}]", |
| 651 browser(), |
| 652 utils::NONE)); |
| 653 |
| 654 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); |
| 655 bool copy_bool_value = false; |
| 656 ASSERT_TRUE(result->GetAsBoolean(©_bool_value)); |
| 657 ASSERT_TRUE(copy_bool_value); |
| 658 } |
| 659 } |
OLD | NEW |