| 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/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 18 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 18 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 19 #include "chrome/browser/infobars/infobar.h" | 19 #include "chrome/browser/infobars/infobar.h" |
| 20 #include "chrome/browser/infobars/infobar_manager.h" |
| 20 #include "chrome/browser/infobars/infobar_service.h" | 21 #include "chrome/browser/infobars/infobar_service.h" |
| 21 #include "chrome/browser/notifications/balloon.h" | 22 #include "chrome/browser/notifications/balloon.h" |
| 22 #include "chrome/browser/notifications/balloon_collection.h" | 23 #include "chrome/browser/notifications/balloon_collection.h" |
| 23 #include "chrome/browser/notifications/balloon_host.h" | 24 #include "chrome/browser/notifications/balloon_host.h" |
| 24 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" | 25 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" |
| 25 #include "chrome/browser/notifications/desktop_notification_service.h" | 26 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 26 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 27 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 27 #include "chrome/browser/notifications/notification.h" | 28 #include "chrome/browser/notifications/notification.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 | 312 |
| 312 void NotificationsTest::AllowAllOrigins() { | 313 void NotificationsTest::AllowAllOrigins() { |
| 313 GetDesktopNotificationService()->ResetAllOrigins(); | 314 GetDesktopNotificationService()->ResetAllOrigins(); |
| 314 GetDesktopNotificationService()->SetDefaultContentSetting( | 315 GetDesktopNotificationService()->SetDefaultContentSetting( |
| 315 CONTENT_SETTING_ALLOW); | 316 CONTENT_SETTING_ALLOW); |
| 316 } | 317 } |
| 317 | 318 |
| 318 void NotificationsTest::VerifyInfoBar(const Browser* browser, int index) { | 319 void NotificationsTest::VerifyInfoBar(const Browser* browser, int index) { |
| 319 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 320 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 320 browser->tab_strip_model()->GetWebContentsAt(index)); | 321 browser->tab_strip_model()->GetWebContentsAt(index)); |
| 322 InfoBarManager* infobar_manager = infobar_service->infobar_manager(); |
| 321 | 323 |
| 322 ASSERT_EQ(1U, infobar_service->infobar_count()); | 324 ASSERT_EQ(1U, infobar_manager->infobar_count()); |
| 323 ConfirmInfoBarDelegate* confirm_infobar = | 325 ConfirmInfoBarDelegate* confirm_infobar = |
| 324 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 326 infobar_manager->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| 325 ASSERT_TRUE(confirm_infobar); | 327 ASSERT_TRUE(confirm_infobar); |
| 326 int buttons = confirm_infobar->GetButtons(); | 328 int buttons = confirm_infobar->GetButtons(); |
| 327 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK); | 329 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK); |
| 328 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL); | 330 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL); |
| 329 } | 331 } |
| 330 | 332 |
| 331 std::string NotificationsTest::CreateNotification( | 333 std::string NotificationsTest::CreateNotification( |
| 332 Browser* browser, | 334 Browser* browser, |
| 333 bool wait_for_new_balloon, | 335 bool wait_for_new_balloon, |
| 334 const char* icon, | 336 const char* icon, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 return observer->Wait(); | 397 return observer->Wait(); |
| 396 } | 398 } |
| 397 | 399 |
| 398 bool NotificationsTest::PerformActionOnInfoBar( | 400 bool NotificationsTest::PerformActionOnInfoBar( |
| 399 Browser* browser, | 401 Browser* browser, |
| 400 InfobarAction action, | 402 InfobarAction action, |
| 401 size_t infobar_index, | 403 size_t infobar_index, |
| 402 int tab_index) { | 404 int tab_index) { |
| 403 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 405 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 404 browser->tab_strip_model()->GetWebContentsAt(tab_index)); | 406 browser->tab_strip_model()->GetWebContentsAt(tab_index)); |
| 405 if (infobar_index >= infobar_service->infobar_count()) { | 407 InfoBarManager* infobar_manager = infobar_service->infobar_manager(); |
| 408 if (infobar_index >= infobar_manager->infobar_count()) { |
| 406 ADD_FAILURE(); | 409 ADD_FAILURE(); |
| 407 return false; | 410 return false; |
| 408 } | 411 } |
| 409 | 412 |
| 410 InfoBar* infobar = infobar_service->infobar_at(infobar_index); | 413 InfoBar* infobar = infobar_manager->infobar_at(infobar_index); |
| 411 InfoBarDelegate* infobar_delegate = infobar->delegate(); | 414 InfoBarDelegate* infobar_delegate = infobar->delegate(); |
| 412 switch (action) { | 415 switch (action) { |
| 413 case DISMISS: | 416 case DISMISS: |
| 414 infobar_delegate->InfoBarDismissed(); | 417 infobar_delegate->InfoBarDismissed(); |
| 415 infobar_service->RemoveInfoBar(infobar); | 418 infobar_manager->RemoveInfoBar(infobar); |
| 416 return true; | 419 return true; |
| 417 | 420 |
| 418 case ALLOW: { | 421 case ALLOW: { |
| 419 ConfirmInfoBarDelegate* confirm_infobar_delegate = | 422 ConfirmInfoBarDelegate* confirm_infobar_delegate = |
| 420 infobar_delegate->AsConfirmInfoBarDelegate(); | 423 infobar_delegate->AsConfirmInfoBarDelegate(); |
| 421 if (!confirm_infobar_delegate) { | 424 if (!confirm_infobar_delegate) { |
| 422 ADD_FAILURE(); | 425 ADD_FAILURE(); |
| 423 } else if (confirm_infobar_delegate->Accept()) { | 426 } else if (confirm_infobar_delegate->Accept()) { |
| 424 infobar_service->RemoveInfoBar(infobar); | 427 infobar_manager->RemoveInfoBar(infobar); |
| 425 return true; | 428 return true; |
| 426 } | 429 } |
| 427 } | 430 } |
| 428 | 431 |
| 429 case DENY: { | 432 case DENY: { |
| 430 ConfirmInfoBarDelegate* confirm_infobar_delegate = | 433 ConfirmInfoBarDelegate* confirm_infobar_delegate = |
| 431 infobar_delegate->AsConfirmInfoBarDelegate(); | 434 infobar_delegate->AsConfirmInfoBarDelegate(); |
| 432 if (!confirm_infobar_delegate) { | 435 if (!confirm_infobar_delegate) { |
| 433 ADD_FAILURE(); | 436 ADD_FAILURE(); |
| 434 } else if (confirm_infobar_delegate->Cancel()) { | 437 } else if (confirm_infobar_delegate->Cancel()) { |
| 435 infobar_service->RemoveInfoBar(infobar); | 438 infobar_manager->RemoveInfoBar(infobar); |
| 436 return true; | 439 return true; |
| 437 } | 440 } |
| 438 } | 441 } |
| 439 } | 442 } |
| 440 | 443 |
| 441 return false; | 444 return false; |
| 442 } | 445 } |
| 443 | 446 |
| 444 void NotificationsTest::GetPrefsByContentSetting( | 447 void NotificationsTest::GetPrefsByContentSetting( |
| 445 ContentSetting setting, | 448 ContentSetting setting, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 | 492 |
| 490 // Request permission by calling request() while eval'ing an inline script; | 493 // Request permission by calling request() while eval'ing an inline script; |
| 491 // That's considered a user gesture to webkit, and should produce an infobar. | 494 // That's considered a user gesture to webkit, and should produce an infobar. |
| 492 bool result; | 495 bool result; |
| 493 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 496 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 494 browser()->tab_strip_model()->GetActiveWebContents(), | 497 browser()->tab_strip_model()->GetActiveWebContents(), |
| 495 "window.domAutomationController.send(request());", | 498 "window.domAutomationController.send(request());", |
| 496 &result)); | 499 &result)); |
| 497 EXPECT_TRUE(result); | 500 EXPECT_TRUE(result); |
| 498 | 501 |
| 499 EXPECT_EQ(1U, InfoBarService::FromWebContents( | 502 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 500 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); | 503 browser()->tab_strip_model()->GetWebContentsAt(0)); |
| 504 EXPECT_EQ(1U, infobar_service->infobar_manager()->infobar_count()); |
| 501 } | 505 } |
| 502 | 506 |
| 503 // If this flakes, use http://crbug.com/62311. | 507 // If this flakes, use http://crbug.com/62311. |
| 504 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) { | 508 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) { |
| 505 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 509 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 506 | 510 |
| 507 // Load a page which just does a request; no user gesture should result | 511 // Load a page which just does a request; no user gesture should result |
| 508 // in no infobar. | 512 // in no infobar. |
| 509 ui_test_utils::NavigateToURL( | 513 ui_test_utils::NavigateToURL( |
| 510 browser(), | 514 browser(), |
| 511 embedded_test_server()->GetURL( | 515 embedded_test_server()->GetURL( |
| 512 "/notifications/notifications_request_inline.html")); | 516 "/notifications/notifications_request_inline.html")); |
| 513 | 517 |
| 514 EXPECT_EQ(0U, InfoBarService::FromWebContents( | 518 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 515 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); | 519 browser()->tab_strip_model()->GetWebContentsAt(0)); |
| 520 EXPECT_EQ(0U, infobar_service->infobar_manager()->infobar_count()); |
| 516 } | 521 } |
| 517 | 522 |
| 518 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { | 523 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { |
| 519 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 524 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 520 | 525 |
| 521 // Creates a simple notification. | 526 // Creates a simple notification. |
| 522 AllowAllOrigins(); | 527 AllowAllOrigins(); |
| 523 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 528 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 524 | 529 |
| 525 std::string result = CreateSimpleNotification(browser(), true); | 530 std::string result = CreateSimpleNotification(browser(), true); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 650 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 646 | 651 |
| 647 // Verify that all domains can be allowed to show notifications. | 652 // Verify that all domains can be allowed to show notifications. |
| 648 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW); | 653 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW); |
| 649 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 654 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 650 | 655 |
| 651 std::string result = CreateSimpleNotification(browser(), true); | 656 std::string result = CreateSimpleNotification(browser(), true); |
| 652 EXPECT_NE("-1", result); | 657 EXPECT_NE("-1", result); |
| 653 | 658 |
| 654 ASSERT_EQ(1, GetNotificationCount()); | 659 ASSERT_EQ(1, GetNotificationCount()); |
| 655 EXPECT_EQ(0U, InfoBarService::FromWebContents( | 660 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 656 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); | 661 browser()->tab_strip_model()->GetWebContentsAt(0)); |
| 662 EXPECT_EQ(0U, infobar_service->infobar_manager()->infobar_count()); |
| 657 } | 663 } |
| 658 | 664 |
| 659 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) { | 665 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) { |
| 660 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 666 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 661 | 667 |
| 662 // Verify that no domain can show notifications. | 668 // Verify that no domain can show notifications. |
| 663 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK); | 669 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK); |
| 664 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 670 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 665 | 671 |
| 666 std::string result = CreateSimpleNotification(browser(), false); | 672 std::string result = CreateSimpleNotification(browser(), false); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 std::string result = CreateSimpleNotification(browser(), false); | 718 std::string result = CreateSimpleNotification(browser(), false); |
| 713 EXPECT_EQ("-1", result); | 719 EXPECT_EQ("-1", result); |
| 714 | 720 |
| 715 ASSERT_EQ(0, GetNotificationCount()); | 721 ASSERT_EQ(0, GetNotificationCount()); |
| 716 | 722 |
| 717 AllowOrigin(GetTestPageURL().GetOrigin()); | 723 AllowOrigin(GetTestPageURL().GetOrigin()); |
| 718 result = CreateSimpleNotification(browser(), true); | 724 result = CreateSimpleNotification(browser(), true); |
| 719 EXPECT_NE("-1", result); | 725 EXPECT_NE("-1", result); |
| 720 | 726 |
| 721 ASSERT_EQ(1, GetNotificationCount()); | 727 ASSERT_EQ(1, GetNotificationCount()); |
| 722 EXPECT_EQ(0U, InfoBarService::FromWebContents( | 728 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 723 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); | 729 browser()->tab_strip_model()->GetWebContentsAt(0)); |
| 730 EXPECT_EQ(0U, infobar_service->infobar_manager()->infobar_count()); |
| 724 } | 731 } |
| 725 | 732 |
| 726 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { | 733 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { |
| 727 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 734 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 728 | 735 |
| 729 // Verify able to create, deny, and close the notification. | 736 // Verify able to create, deny, and close the notification. |
| 730 AllowAllOrigins(); | 737 AllowAllOrigins(); |
| 731 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); | 738 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 732 CreateSimpleNotification(browser(), true); | 739 CreateSimpleNotification(browser(), true); |
| 733 ASSERT_EQ(1, GetNotificationCount()); | 740 ASSERT_EQ(1, GetNotificationCount()); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 952 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| 946 ASSERT_EQ(1U, balloons.size()); | 953 ASSERT_EQ(1U, balloons.size()); |
| 947 Balloon* balloon = balloons[0]; | 954 Balloon* balloon = balloons[0]; |
| 948 const Notification& notification = balloon->notification(); | 955 const Notification& notification = balloon->notification(); |
| 949 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); | 956 GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); |
| 950 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); | 957 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
| 951 EXPECT_EQ(base::ASCIIToUTF16("Title2"), notification.title()); | 958 EXPECT_EQ(base::ASCIIToUTF16("Title2"), notification.title()); |
| 952 EXPECT_EQ(base::ASCIIToUTF16("Body2"), notification.message()); | 959 EXPECT_EQ(base::ASCIIToUTF16("Body2"), notification.message()); |
| 953 } | 960 } |
| 954 } | 961 } |
| OLD | NEW |