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 <deque> | 5 #include <deque> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #if defined(OS_MACOSX) |
| 12 #import "base/mac/mac_util.h" |
| 13 #endif |
11 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
12 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
13 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
14 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 19 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
17 #include "chrome/browser/infobars/infobar_service.h" | 20 #include "chrome/browser/infobars/infobar_service.h" |
18 #include "chrome/browser/notifications/balloon.h" | 21 #include "chrome/browser/notifications/balloon.h" |
19 #include "chrome/browser/notifications/balloon_collection.h" | 22 #include "chrome/browser/notifications/balloon_collection.h" |
20 #include "chrome/browser/notifications/balloon_host.h" | 23 #include "chrome/browser/notifications/balloon_host.h" |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 "files/notifications/notifications_request_inline.html")); | 496 "files/notifications/notifications_request_inline.html")); |
494 | 497 |
495 EXPECT_EQ(0U, InfoBarService::FromWebContents( | 498 EXPECT_EQ(0U, InfoBarService::FromWebContents( |
496 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount()); | 499 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount()); |
497 } | 500 } |
498 | 501 |
499 // Disable new testcases on Chrome OS due to failure on creating notification. | 502 // Disable new testcases on Chrome OS due to failure on creating notification. |
500 #if !defined(OS_CHROMEOS) | 503 #if !defined(OS_CHROMEOS) |
501 | 504 |
502 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { | 505 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { |
| 506 #if defined(OS_MACOSX) |
| 507 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 508 if (base::mac::IsOSMountainLionOrLater()) |
| 509 return; |
| 510 #endif |
| 511 |
503 // Creates a simple notification. | 512 // Creates a simple notification. |
504 AllowAllOrigins(); | 513 AllowAllOrigins(); |
505 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 514 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
506 | 515 |
507 std::string result = CreateSimpleNotification(browser(), true); | 516 std::string result = CreateSimpleNotification(browser(), true); |
508 EXPECT_NE("-1", result); | 517 EXPECT_NE("-1", result); |
509 | 518 |
510 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); | 519 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); |
511 ASSERT_EQ(1, GetNotificationCount()); | 520 ASSERT_EQ(1, GetNotificationCount()); |
512 #if ENABLE_MESSAGE_CENTER_TESTING | 521 #if ENABLE_MESSAGE_CENTER_TESTING |
513 message_center::NotificationList* notification_list = | 522 message_center::NotificationList* notification_list = |
514 message_center::MessageCenter::Get()->notification_list(); | 523 message_center::MessageCenter::Get()->notification_list(); |
515 message_center::NotificationList::Notifications notifications = | 524 message_center::NotificationList::Notifications notifications = |
516 notification_list->GetNotifications(); | 525 notification_list->GetNotifications(); |
517 EXPECT_EQ(ASCIIToUTF16("My Title"), (*notifications.rbegin())->title()); | 526 EXPECT_EQ(ASCIIToUTF16("My Title"), (*notifications.rbegin())->title()); |
518 EXPECT_EQ(ASCIIToUTF16("My Body"), (*notifications.rbegin())->message()); | 527 EXPECT_EQ(ASCIIToUTF16("My Body"), (*notifications.rbegin())->message()); |
519 #else | 528 #else |
520 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 529 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
521 ASSERT_EQ(1U, balloons.size()); | 530 ASSERT_EQ(1U, balloons.size()); |
522 Balloon* balloon = balloons[0]; | 531 Balloon* balloon = balloons[0]; |
523 const Notification& notification = balloon->notification(); | 532 const Notification& notification = balloon->notification(); |
524 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); | 533 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
525 EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title()); | 534 EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title()); |
526 EXPECT_EQ(ASCIIToUTF16("My Body"), notification.body()); | 535 EXPECT_EQ(ASCIIToUTF16("My Body"), notification.body()); |
527 #endif | 536 #endif |
528 } | 537 } |
529 | 538 |
530 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { | 539 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { |
| 540 #if defined(OS_MACOSX) |
| 541 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 542 if (base::mac::IsOSMountainLionOrLater()) |
| 543 return; |
| 544 #endif |
| 545 |
531 // Creates a notification and closes it. | 546 // Creates a notification and closes it. |
532 AllowAllOrigins(); | 547 AllowAllOrigins(); |
533 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 548 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
534 | 549 |
535 std::string result = CreateSimpleNotification(browser(), true); | 550 std::string result = CreateSimpleNotification(browser(), true); |
536 EXPECT_NE("-1", result); | 551 EXPECT_NE("-1", result); |
537 ASSERT_EQ(1, GetNotificationCount()); | 552 ASSERT_EQ(1, GetNotificationCount()); |
538 | 553 |
539 #if ENABLE_MESSAGE_CENTER_TESTING | 554 #if ENABLE_MESSAGE_CENTER_TESTING |
540 message_center::NotificationList* notification_list = | 555 message_center::NotificationList* notification_list = |
541 message_center::MessageCenter::Get()->notification_list(); | 556 message_center::MessageCenter::Get()->notification_list(); |
542 message_center::NotificationList::Notifications notifications = | 557 message_center::NotificationList::Notifications notifications = |
543 notification_list->GetNotifications(); | 558 notification_list->GetNotifications(); |
544 message_center::MessageCenter::Get()->SendRemoveNotification( | 559 message_center::MessageCenter::Get()->SendRemoveNotification( |
545 (*notifications.rbegin())->id(), | 560 (*notifications.rbegin())->id(), |
546 true); // by_user | 561 true); // by_user |
547 #else | 562 #else |
548 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 563 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
549 EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); | 564 EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); |
550 #endif // ENABLE_MESSAGE_CENTER_TESTING | 565 #endif // ENABLE_MESSAGE_CENTER_TESTING |
551 | 566 |
552 ASSERT_EQ(0, GetNotificationCount()); | 567 ASSERT_EQ(0, GetNotificationCount()); |
553 } | 568 } |
554 | 569 |
555 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCancelNotification) { | 570 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCancelNotification) { |
| 571 #if defined(OS_MACOSX) |
| 572 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 573 if (base::mac::IsOSMountainLionOrLater()) |
| 574 return; |
| 575 #endif |
| 576 |
556 // Creates a notification and cancels it in the origin page. | 577 // Creates a notification and cancels it in the origin page. |
557 AllowAllOrigins(); | 578 AllowAllOrigins(); |
558 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 579 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
559 | 580 |
560 std::string note_id = CreateSimpleNotification(browser(), true); | 581 std::string note_id = CreateSimpleNotification(browser(), true); |
561 EXPECT_NE(note_id, "-1"); | 582 EXPECT_NE(note_id, "-1"); |
562 | 583 |
563 ASSERT_EQ(1, GetNotificationCount()); | 584 ASSERT_EQ(1, GetNotificationCount()); |
564 ASSERT_TRUE(CancelNotification(note_id.c_str(), browser())); | 585 ASSERT_TRUE(CancelNotification(note_id.c_str(), browser())); |
565 ASSERT_EQ(0, GetNotificationCount()); | 586 ASSERT_EQ(0, GetNotificationCount()); |
566 } | 587 } |
567 | 588 |
568 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestPermissionInfobarAppears) { | 589 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestPermissionInfobarAppears) { |
569 // Requests notification privileges and verifies the infobar appears. | 590 // Requests notification privileges and verifies the infobar appears. |
570 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 591 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
571 ASSERT_TRUE(RequestPermissionAndWait(browser())); | 592 ASSERT_TRUE(RequestPermissionAndWait(browser())); |
572 | 593 |
573 ASSERT_EQ(0, GetNotificationCount()); | 594 ASSERT_EQ(0, GetNotificationCount()); |
574 VerifyInfobar(browser(), 0); | 595 VerifyInfobar(browser(), 0); |
575 } | 596 } |
576 | 597 |
577 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowOnPermissionInfobar) { | 598 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowOnPermissionInfobar) { |
| 599 #if defined(OS_MACOSX) |
| 600 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 601 if (base::mac::IsOSMountainLionOrLater()) |
| 602 return; |
| 603 #endif |
| 604 |
578 // Tries to create a notification and clicks allow on the infobar. | 605 // Tries to create a notification and clicks allow on the infobar. |
579 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 606 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
580 // This notification should not be shown because we do not have permission. | 607 // This notification should not be shown because we do not have permission. |
581 CreateSimpleNotification(browser(), false); | 608 CreateSimpleNotification(browser(), false); |
582 ASSERT_EQ(0, GetNotificationCount()); | 609 ASSERT_EQ(0, GetNotificationCount()); |
583 | 610 |
584 ASSERT_TRUE(RequestPermissionAndWait(browser())); | 611 ASSERT_TRUE(RequestPermissionAndWait(browser())); |
585 ASSERT_TRUE(PerformActionOnInfobar(browser(), ALLOW, 0, 0)); | 612 ASSERT_TRUE(PerformActionOnInfobar(browser(), ALLOW, 0, 0)); |
586 | 613 |
587 CreateSimpleNotification(browser(), true); | 614 CreateSimpleNotification(browser(), true); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 Balloon* balloon = balloons[0]; | 909 Balloon* balloon = balloons[0]; |
883 const Notification& notification = balloon->notification(); | 910 const Notification& notification = balloon->notification(); |
884 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); | 911 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); |
885 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); | 912 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
886 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); | 913 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); |
887 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body()); | 914 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body()); |
888 #endif | 915 #endif |
889 } | 916 } |
890 | 917 |
891 #endif // !defined(OS_CHROMEOS) | 918 #endif // !defined(OS_CHROMEOS) |
OLD | NEW |