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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 void NotificationsTest::AllowAllOrigins() { | 337 void NotificationsTest::AllowAllOrigins() { |
338 GetDesktopNotificationService()->ResetAllOrigins(); | 338 GetDesktopNotificationService()->ResetAllOrigins(); |
339 GetDesktopNotificationService()->SetDefaultContentSetting( | 339 GetDesktopNotificationService()->SetDefaultContentSetting( |
340 CONTENT_SETTING_ALLOW); | 340 CONTENT_SETTING_ALLOW); |
341 } | 341 } |
342 | 342 |
343 void NotificationsTest::VerifyInfobar(const Browser* browser, int index) { | 343 void NotificationsTest::VerifyInfobar(const Browser* browser, int index) { |
344 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 344 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
345 browser->tab_strip_model()->GetWebContentsAt(index)); | 345 browser->tab_strip_model()->GetWebContentsAt(index)); |
346 | 346 |
347 ASSERT_EQ(1U, infobar_service->GetInfoBarCount()); | 347 ASSERT_EQ(1U, infobar_service->infobar_count()); |
348 InfoBarDelegate* infobar = infobar_service->GetInfoBarDelegateAt(0); | 348 InfoBarDelegate* infobar = infobar_service->infobar_at(0); |
349 ConfirmInfoBarDelegate* confirm_infobar = infobar->AsConfirmInfoBarDelegate(); | 349 ConfirmInfoBarDelegate* confirm_infobar = infobar->AsConfirmInfoBarDelegate(); |
350 ASSERT_TRUE(confirm_infobar); | 350 ASSERT_TRUE(confirm_infobar); |
351 int buttons = confirm_infobar->GetButtons(); | 351 int buttons = confirm_infobar->GetButtons(); |
352 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK); | 352 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK); |
353 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL); | 353 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL); |
354 } | 354 } |
355 | 355 |
356 std::string NotificationsTest::CreateNotification( | 356 std::string NotificationsTest::CreateNotification( |
357 Browser* browser, | 357 Browser* browser, |
358 bool wait_for_new_balloon, | 358 bool wait_for_new_balloon, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 } | 421 } |
422 | 422 |
423 bool NotificationsTest::PerformActionOnInfobar( | 423 bool NotificationsTest::PerformActionOnInfobar( |
424 Browser* browser, | 424 Browser* browser, |
425 InfobarAction action, | 425 InfobarAction action, |
426 int infobar_index, | 426 int infobar_index, |
427 int tab_index) { | 427 int tab_index) { |
428 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 428 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
429 browser->tab_strip_model()->GetWebContentsAt(tab_index)); | 429 browser->tab_strip_model()->GetWebContentsAt(tab_index)); |
430 | 430 |
431 InfoBarDelegate* infobar = | 431 InfoBarDelegate* infobar = infobar_service->infobar_at(infobar_index); |
432 infobar_service->GetInfoBarDelegateAt(infobar_index); | |
433 switch (action) { | 432 switch (action) { |
434 case DISMISS: | 433 case DISMISS: |
435 infobar->InfoBarDismissed(); | 434 infobar->InfoBarDismissed(); |
436 infobar_service->RemoveInfoBar(infobar); | 435 infobar_service->RemoveInfoBar(infobar); |
437 return true; | 436 return true; |
438 | 437 |
439 case ALLOW: { | 438 case ALLOW: { |
440 ConfirmInfoBarDelegate* confirm_bar = infobar->AsConfirmInfoBarDelegate(); | 439 ConfirmInfoBarDelegate* confirm_bar = infobar->AsConfirmInfoBarDelegate(); |
441 if (confirm_bar->Accept()) { | 440 if (confirm_bar->Accept()) { |
442 infobar_service->RemoveInfoBar(infobar); | 441 infobar_service->RemoveInfoBar(infobar); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 // Request permission by calling request() while eval'ing an inline script; | 502 // Request permission by calling request() while eval'ing an inline script; |
504 // That's considered a user gesture to webkit, and should produce an infobar. | 503 // That's considered a user gesture to webkit, and should produce an infobar. |
505 bool result; | 504 bool result; |
506 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 505 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
507 browser()->tab_strip_model()->GetActiveWebContents(), | 506 browser()->tab_strip_model()->GetActiveWebContents(), |
508 "window.domAutomationController.send(request());", | 507 "window.domAutomationController.send(request());", |
509 &result)); | 508 &result)); |
510 EXPECT_TRUE(result); | 509 EXPECT_TRUE(result); |
511 | 510 |
512 EXPECT_EQ(1U, InfoBarService::FromWebContents( | 511 EXPECT_EQ(1U, InfoBarService::FromWebContents( |
513 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount()); | 512 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); |
514 } | 513 } |
515 | 514 |
516 // If this flakes, use http://crbug.com/62311. | 515 // If this flakes, use http://crbug.com/62311. |
517 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) { | 516 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) { |
518 // Load a page which just does a request; no user gesture should result | 517 // Load a page which just does a request; no user gesture should result |
519 // in no infobar. | 518 // in no infobar. |
520 ui_test_utils::NavigateToURL( | 519 ui_test_utils::NavigateToURL( |
521 browser(), | 520 browser(), |
522 test_server()->GetURL( | 521 test_server()->GetURL( |
523 "files/notifications/notifications_request_inline.html")); | 522 "files/notifications/notifications_request_inline.html")); |
524 | 523 |
525 EXPECT_EQ(0U, InfoBarService::FromWebContents( | 524 EXPECT_EQ(0U, InfoBarService::FromWebContents( |
526 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount()); | 525 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); |
527 } | 526 } |
528 | 527 |
529 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { | 528 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { |
530 #if defined(OS_MACOSX) | 529 #if defined(OS_MACOSX) |
531 // TODO(kbr): re-enable: http://crbug.com/222296 | 530 // TODO(kbr): re-enable: http://crbug.com/222296 |
532 if (base::mac::IsOSMountainLionOrLater()) | 531 if (base::mac::IsOSMountainLionOrLater()) |
533 return; | 532 return; |
534 #endif | 533 #endif |
535 | 534 |
536 // Creates a simple notification. | 535 // Creates a simple notification. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 #endif | 667 #endif |
669 // Verify that all domains can be allowed to show notifications. | 668 // Verify that all domains can be allowed to show notifications. |
670 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW); | 669 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW); |
671 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 670 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
672 | 671 |
673 std::string result = CreateSimpleNotification(browser(), true); | 672 std::string result = CreateSimpleNotification(browser(), true); |
674 EXPECT_NE("-1", result); | 673 EXPECT_NE("-1", result); |
675 | 674 |
676 ASSERT_EQ(1, GetNotificationCount()); | 675 ASSERT_EQ(1, GetNotificationCount()); |
677 EXPECT_EQ(0U, InfoBarService::FromWebContents( | 676 EXPECT_EQ(0U, InfoBarService::FromWebContents( |
678 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount()); | 677 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); |
679 } | 678 } |
680 | 679 |
681 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) { | 680 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) { |
682 // Verify that no domain can show notifications. | 681 // Verify that no domain can show notifications. |
683 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK); | 682 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK); |
684 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 683 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
685 | 684 |
686 std::string result = CreateSimpleNotification(browser(), false); | 685 std::string result = CreateSimpleNotification(browser(), false); |
687 EXPECT_EQ("-1", result); | 686 EXPECT_EQ("-1", result); |
688 | 687 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 EXPECT_EQ("-1", result); | 736 EXPECT_EQ("-1", result); |
738 | 737 |
739 ASSERT_EQ(0, GetNotificationCount()); | 738 ASSERT_EQ(0, GetNotificationCount()); |
740 | 739 |
741 AllowOrigin(test_page_url_.GetOrigin()); | 740 AllowOrigin(test_page_url_.GetOrigin()); |
742 result = CreateSimpleNotification(browser(), true); | 741 result = CreateSimpleNotification(browser(), true); |
743 EXPECT_NE("-1", result); | 742 EXPECT_NE("-1", result); |
744 | 743 |
745 ASSERT_EQ(1, GetNotificationCount()); | 744 ASSERT_EQ(1, GetNotificationCount()); |
746 EXPECT_EQ(0U, InfoBarService::FromWebContents( | 745 EXPECT_EQ(0U, InfoBarService::FromWebContents( |
747 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount()); | 746 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); |
748 } | 747 } |
749 | 748 |
750 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { | 749 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { |
751 #if defined(OS_MACOSX) | 750 #if defined(OS_MACOSX) |
752 // TODO(kbr): re-enable: http://crbug.com/222296 | 751 // TODO(kbr): re-enable: http://crbug.com/222296 |
753 if (base::mac::IsOSMountainLionOrLater()) | 752 if (base::mac::IsOSMountainLionOrLater()) |
754 return; | 753 return; |
755 #endif | 754 #endif |
756 // Verify able to create, deny, and close the notification. | 755 // Verify able to create, deny, and close the notification. |
757 AllowAllOrigins(); | 756 AllowAllOrigins(); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 967 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
969 ASSERT_EQ(1U, balloons.size()); | 968 ASSERT_EQ(1U, balloons.size()); |
970 Balloon* balloon = balloons[0]; | 969 Balloon* balloon = balloons[0]; |
971 const Notification& notification = balloon->notification(); | 970 const Notification& notification = balloon->notification(); |
972 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); | 971 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); |
973 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); | 972 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
974 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); | 973 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); |
975 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body()); | 974 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body()); |
976 #endif | 975 #endif |
977 } | 976 } |
OLD | NEW |