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" |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "content/public/browser/render_view_host.h" | 38 #include "content/public/browser/render_view_host.h" |
39 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
40 #include "content/public/test/browser_test_utils.h" | 40 #include "content/public/test/browser_test_utils.h" |
41 #include "content/public/test/test_utils.h" | 41 #include "content/public/test/test_utils.h" |
42 #include "googleurl/src/gurl.h" | 42 #include "googleurl/src/gurl.h" |
43 #include "net/base/net_util.h" | 43 #include "net/base/net_util.h" |
44 #include "net/test/test_server.h" | 44 #include "net/test/test_server.h" |
45 #include "testing/gtest/include/gtest/gtest.h" | 45 #include "testing/gtest/include/gtest/gtest.h" |
46 #include "ui/base/window_open_disposition.h" | 46 #include "ui/base/window_open_disposition.h" |
47 | 47 |
| 48 // TODO(kbr): remove: http://crbug.com/222296 |
| 49 #if defined(OS_MACOSX) |
| 50 #import "base/mac/mac_util.h" |
| 51 #endif |
| 52 |
48 #if defined(ENABLE_MESSAGE_CENTER) | 53 #if defined(ENABLE_MESSAGE_CENTER) |
49 #include "ui/message_center/message_center.h" | 54 #include "ui/message_center/message_center.h" |
50 #endif | 55 #endif |
51 | 56 |
52 // Mac implementation of message_center is incomplete. The code builds, but | 57 // Mac implementation of message_center is incomplete. The code builds, but |
53 // the tests do not pass <http://crbug.com/179904>. | 58 // the tests do not pass <http://crbug.com/179904>. |
54 #if defined(ENABLE_MESSAGE_CENTER) && !defined(OS_MACOSX) | 59 #if defined(ENABLE_MESSAGE_CENTER) && !defined(OS_MACOSX) |
55 #define ENABLE_MESSAGE_CENTER_TESTING 1 | 60 #define ENABLE_MESSAGE_CENTER_TESTING 1 |
56 #else | 61 #else |
57 #define ENABLE_MESSAGE_CENTER_TESTING 0 | 62 #define ENABLE_MESSAGE_CENTER_TESTING 0 |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 "files/notifications/notifications_request_inline.html")); | 498 "files/notifications/notifications_request_inline.html")); |
494 | 499 |
495 EXPECT_EQ(0U, InfoBarService::FromWebContents( | 500 EXPECT_EQ(0U, InfoBarService::FromWebContents( |
496 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount()); | 501 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount()); |
497 } | 502 } |
498 | 503 |
499 // Disable new testcases on Chrome OS due to failure on creating notification. | 504 // Disable new testcases on Chrome OS due to failure on creating notification. |
500 #if !defined(OS_CHROMEOS) | 505 #if !defined(OS_CHROMEOS) |
501 | 506 |
502 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { | 507 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { |
| 508 #if defined(OS_MACOSX) |
| 509 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 510 if (base::mac::IsOSMountainLionOrLater()) |
| 511 return; |
| 512 #endif |
| 513 |
503 // Creates a simple notification. | 514 // Creates a simple notification. |
504 AllowAllOrigins(); | 515 AllowAllOrigins(); |
505 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 516 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
506 | 517 |
507 std::string result = CreateSimpleNotification(browser(), true); | 518 std::string result = CreateSimpleNotification(browser(), true); |
508 EXPECT_NE("-1", result); | 519 EXPECT_NE("-1", result); |
509 | 520 |
510 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); | 521 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); |
511 ASSERT_EQ(1, GetNotificationCount()); | 522 ASSERT_EQ(1, GetNotificationCount()); |
512 #if ENABLE_MESSAGE_CENTER_TESTING | 523 #if ENABLE_MESSAGE_CENTER_TESTING |
513 message_center::NotificationList* notification_list = | 524 message_center::NotificationList* notification_list = |
514 message_center::MessageCenter::Get()->notification_list(); | 525 message_center::MessageCenter::Get()->notification_list(); |
515 message_center::NotificationList::Notifications notifications = | 526 message_center::NotificationList::Notifications notifications = |
516 notification_list->GetNotifications(); | 527 notification_list->GetNotifications(); |
517 EXPECT_EQ(ASCIIToUTF16("My Title"), (*notifications.rbegin())->title()); | 528 EXPECT_EQ(ASCIIToUTF16("My Title"), (*notifications.rbegin())->title()); |
518 EXPECT_EQ(ASCIIToUTF16("My Body"), (*notifications.rbegin())->message()); | 529 EXPECT_EQ(ASCIIToUTF16("My Body"), (*notifications.rbegin())->message()); |
519 #else | 530 #else |
520 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 531 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
521 ASSERT_EQ(1U, balloons.size()); | 532 ASSERT_EQ(1U, balloons.size()); |
522 Balloon* balloon = balloons[0]; | 533 Balloon* balloon = balloons[0]; |
523 const Notification& notification = balloon->notification(); | 534 const Notification& notification = balloon->notification(); |
524 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); | 535 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
525 EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title()); | 536 EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title()); |
526 EXPECT_EQ(ASCIIToUTF16("My Body"), notification.body()); | 537 EXPECT_EQ(ASCIIToUTF16("My Body"), notification.body()); |
527 #endif | 538 #endif |
528 } | 539 } |
529 | 540 |
530 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { | 541 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { |
| 542 #if defined(OS_MACOSX) |
| 543 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 544 if (base::mac::IsOSMountainLionOrLater()) |
| 545 return; |
| 546 #endif |
| 547 |
531 // Creates a notification and closes it. | 548 // Creates a notification and closes it. |
532 AllowAllOrigins(); | 549 AllowAllOrigins(); |
533 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 550 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
534 | 551 |
535 std::string result = CreateSimpleNotification(browser(), true); | 552 std::string result = CreateSimpleNotification(browser(), true); |
536 EXPECT_NE("-1", result); | 553 EXPECT_NE("-1", result); |
537 ASSERT_EQ(1, GetNotificationCount()); | 554 ASSERT_EQ(1, GetNotificationCount()); |
538 | 555 |
539 #if ENABLE_MESSAGE_CENTER_TESTING | 556 #if ENABLE_MESSAGE_CENTER_TESTING |
540 message_center::NotificationList* notification_list = | 557 message_center::NotificationList* notification_list = |
541 message_center::MessageCenter::Get()->notification_list(); | 558 message_center::MessageCenter::Get()->notification_list(); |
542 message_center::NotificationList::Notifications notifications = | 559 message_center::NotificationList::Notifications notifications = |
543 notification_list->GetNotifications(); | 560 notification_list->GetNotifications(); |
544 message_center::MessageCenter::Get()->SendRemoveNotification( | 561 message_center::MessageCenter::Get()->SendRemoveNotification( |
545 (*notifications.rbegin())->id(), | 562 (*notifications.rbegin())->id(), |
546 true); // by_user | 563 true); // by_user |
547 #else | 564 #else |
548 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 565 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
549 EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); | 566 EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); |
550 #endif // ENABLE_MESSAGE_CENTER_TESTING | 567 #endif // ENABLE_MESSAGE_CENTER_TESTING |
551 | 568 |
552 ASSERT_EQ(0, GetNotificationCount()); | 569 ASSERT_EQ(0, GetNotificationCount()); |
553 } | 570 } |
554 | 571 |
555 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCancelNotification) { | 572 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCancelNotification) { |
| 573 #if defined(OS_MACOSX) |
| 574 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 575 if (base::mac::IsOSMountainLionOrLater()) |
| 576 return; |
| 577 #endif |
| 578 |
556 // Creates a notification and cancels it in the origin page. | 579 // Creates a notification and cancels it in the origin page. |
557 AllowAllOrigins(); | 580 AllowAllOrigins(); |
558 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 581 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
559 | 582 |
560 std::string note_id = CreateSimpleNotification(browser(), true); | 583 std::string note_id = CreateSimpleNotification(browser(), true); |
561 EXPECT_NE(note_id, "-1"); | 584 EXPECT_NE(note_id, "-1"); |
562 | 585 |
563 ASSERT_EQ(1, GetNotificationCount()); | 586 ASSERT_EQ(1, GetNotificationCount()); |
564 ASSERT_TRUE(CancelNotification(note_id.c_str(), browser())); | 587 ASSERT_TRUE(CancelNotification(note_id.c_str(), browser())); |
565 ASSERT_EQ(0, GetNotificationCount()); | 588 ASSERT_EQ(0, GetNotificationCount()); |
566 } | 589 } |
567 | 590 |
568 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestPermissionInfobarAppears) { | 591 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestPermissionInfobarAppears) { |
569 // Requests notification privileges and verifies the infobar appears. | 592 // Requests notification privileges and verifies the infobar appears. |
570 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 593 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
571 ASSERT_TRUE(RequestPermissionAndWait(browser())); | 594 ASSERT_TRUE(RequestPermissionAndWait(browser())); |
572 | 595 |
573 ASSERT_EQ(0, GetNotificationCount()); | 596 ASSERT_EQ(0, GetNotificationCount()); |
574 VerifyInfobar(browser(), 0); | 597 VerifyInfobar(browser(), 0); |
575 } | 598 } |
576 | 599 |
577 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowOnPermissionInfobar) { | 600 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowOnPermissionInfobar) { |
| 601 #if defined(OS_MACOSX) |
| 602 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 603 if (base::mac::IsOSMountainLionOrLater()) |
| 604 return; |
| 605 #endif |
| 606 |
578 // Tries to create a notification and clicks allow on the infobar. | 607 // Tries to create a notification and clicks allow on the infobar. |
579 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 608 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
580 // This notification should not be shown because we do not have permission. | 609 // This notification should not be shown because we do not have permission. |
581 CreateSimpleNotification(browser(), false); | 610 CreateSimpleNotification(browser(), false); |
582 ASSERT_EQ(0, GetNotificationCount()); | 611 ASSERT_EQ(0, GetNotificationCount()); |
583 | 612 |
584 ASSERT_TRUE(RequestPermissionAndWait(browser())); | 613 ASSERT_TRUE(RequestPermissionAndWait(browser())); |
585 ASSERT_TRUE(PerformActionOnInfobar(browser(), ALLOW, 0, 0)); | 614 ASSERT_TRUE(PerformActionOnInfobar(browser(), ALLOW, 0, 0)); |
586 | 615 |
587 CreateSimpleNotification(browser(), true); | 616 CreateSimpleNotification(browser(), true); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 Balloon* balloon = balloons[0]; | 911 Balloon* balloon = balloons[0]; |
883 const Notification& notification = balloon->notification(); | 912 const Notification& notification = balloon->notification(); |
884 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); | 913 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); |
885 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); | 914 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
886 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); | 915 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); |
887 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body()); | 916 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body()); |
888 #endif | 917 #endif |
889 } | 918 } |
890 | 919 |
891 #endif // !defined(OS_CHROMEOS) | 920 #endif // !defined(OS_CHROMEOS) |
OLD | NEW |