| 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 <list> | 5 #include <list> |
| 6 | 6 |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "chrome/browser/interstitials/chrome_controller_client.h" | 8 #include "chrome/browser/interstitials/chrome_controller_client.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 10 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/test/web_contents_tester.h" | 23 #include "content/public/test/web_contents_tester.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| 27 using content::InterstitialPage; | 27 using content::InterstitialPage; |
| 28 using content::NavigationEntry; | 28 using content::NavigationEntry; |
| 29 using content::WebContents; | 29 using content::WebContents; |
| 30 using content::WebContentsTester; | 30 using content::WebContentsTester; |
| 31 using security_interstitials::SafeBrowsingErrorUI; |
| 31 | 32 |
| 32 static const char* kGoogleURL = "http://www.google.com/"; | 33 static const char* kGoogleURL = "http://www.google.com/"; |
| 33 static const char* kGoodURL = "http://www.goodguys.com/"; | 34 static const char* kGoodURL = "http://www.goodguys.com/"; |
| 34 static const char* kBadURL = "http://www.badguys.com/"; | 35 static const char* kBadURL = "http://www.badguys.com/"; |
| 35 static const char* kBadURL2 = "http://www.badguys2.com/"; | 36 static const char* kBadURL2 = "http://www.badguys2.com/"; |
| 36 static const char* kBadURL3 = "http://www.badguys3.com/"; | 37 static const char* kBadURL3 = "http://www.badguys3.com/"; |
| 37 | 38 |
| 38 namespace safe_browsing { | 39 namespace safe_browsing { |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 // A SafeBrowingBlockingPage class that does not create windows. | 43 // A SafeBrowingBlockingPage class that does not create windows. |
| 43 class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPage { | 44 class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPage { |
| 44 public: | 45 public: |
| 45 TestSafeBrowsingBlockingPage(SafeBrowsingUIManager* manager, | 46 TestSafeBrowsingBlockingPage( |
| 46 WebContents* web_contents, | 47 BaseUIManager* manager, |
| 47 const GURL& main_frame_url, | 48 WebContents* web_contents, |
| 48 const UnsafeResourceList& unsafe_resources) | 49 const GURL& main_frame_url, |
| 50 const UnsafeResourceList& unsafe_resources, |
| 51 const SafeBrowsingErrorUI::SBErrorDisplayOptions& display_options) |
| 49 : SafeBrowsingBlockingPage(manager, | 52 : SafeBrowsingBlockingPage(manager, |
| 50 web_contents, | 53 web_contents, |
| 51 main_frame_url, | 54 main_frame_url, |
| 52 unsafe_resources) { | 55 unsafe_resources, |
| 56 display_options) { |
| 53 // Don't delay details at all for the unittest. | 57 // Don't delay details at all for the unittest. |
| 54 threat_details_proceed_delay_ms_ = 0; | 58 threat_details_proceed_delay_ms_ = 0; |
| 55 DontCreateViewForTesting(); | 59 DontCreateViewForTesting(); |
| 56 } | 60 } |
| 57 }; | 61 }; |
| 58 | 62 |
| 59 class TestSafeBrowsingBlockingPageFactory | 63 class TestSafeBrowsingBlockingPageFactory |
| 60 : public SafeBrowsingBlockingPageFactory { | 64 : public SafeBrowsingBlockingPageFactory { |
| 61 public: | 65 public: |
| 62 TestSafeBrowsingBlockingPageFactory() { } | 66 TestSafeBrowsingBlockingPageFactory() { } |
| 63 ~TestSafeBrowsingBlockingPageFactory() override {} | 67 ~TestSafeBrowsingBlockingPageFactory() override {} |
| 64 | 68 |
| 65 SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 69 SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
| 66 SafeBrowsingUIManager* manager, | 70 BaseUIManager* manager, |
| 67 WebContents* web_contents, | 71 WebContents* web_contents, |
| 68 const GURL& main_frame_url, | 72 const GURL& main_frame_url, |
| 69 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) | 73 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) |
| 70 override { | 74 override { |
| 75 PrefService* prefs = |
| 76 Profile::FromBrowserContext(web_contents->GetBrowserContext()) |
| 77 ->GetPrefs(); |
| 78 bool is_extended_reporting_opt_in_allowed = |
| 79 prefs->GetBoolean(prefs::kSafeBrowsingExtendedReportingOptInAllowed); |
| 80 bool is_proceed_anyway_disabled = |
| 81 prefs->GetBoolean(prefs::kSafeBrowsingProceedAnywayDisabled); |
| 82 SafeBrowsingErrorUI::SBErrorDisplayOptions display_options( |
| 83 BaseBlockingPage::IsMainPageLoadBlocked(unsafe_resources), |
| 84 is_extended_reporting_opt_in_allowed, |
| 85 web_contents->GetBrowserContext()->IsOffTheRecord(), |
| 86 IsExtendedReportingEnabled(*prefs), IsScout(*prefs), |
| 87 is_proceed_anyway_disabled); |
| 71 return new TestSafeBrowsingBlockingPage(manager, web_contents, | 88 return new TestSafeBrowsingBlockingPage(manager, web_contents, |
| 72 main_frame_url, unsafe_resources); | 89 main_frame_url, unsafe_resources, |
| 90 display_options); |
| 73 } | 91 } |
| 74 }; | 92 }; |
| 75 | 93 |
| 76 class MockTestingProfile : public TestingProfile { | 94 class MockTestingProfile : public TestingProfile { |
| 77 public: | 95 public: |
| 78 MockTestingProfile() {} | 96 MockTestingProfile() {} |
| 79 virtual ~MockTestingProfile() {} | 97 virtual ~MockTestingProfile() {} |
| 80 | 98 |
| 81 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); | 99 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); |
| 82 }; | 100 }; |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 SetExtendedReportingPref(profile->GetPrefs(), false); | 648 SetExtendedReportingPref(profile->GetPrefs(), false); |
| 631 | 649 |
| 632 // Start a load. | 650 // Start a load. |
| 633 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 651 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 634 ui::PAGE_TRANSITION_TYPED, std::string()); | 652 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 635 | 653 |
| 636 // Simulate the load causing a safe browsing interstitial to be shown. | 654 // Simulate the load causing a safe browsing interstitial to be shown. |
| 637 ShowInterstitial(false, kBadURL); | 655 ShowInterstitial(false, kBadURL); |
| 638 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 656 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 639 ASSERT_TRUE(sb_interstitial); | 657 ASSERT_TRUE(sb_interstitial); |
| 640 EXPECT_TRUE(sb_interstitial->sb_error_ui_->CanShowExtendedReportingOption()); | 658 EXPECT_TRUE(sb_interstitial->sb_error_ui()->CanShowExtendedReportingOption()); |
| 641 | 659 |
| 642 base::RunLoop().RunUntilIdle(); | 660 base::RunLoop().RunUntilIdle(); |
| 643 | 661 |
| 644 // Simulate the user clicking "don't proceed". | 662 // Simulate the user clicking "don't proceed". |
| 645 DontProceedThroughInterstitial(sb_interstitial); | 663 DontProceedThroughInterstitial(sb_interstitial); |
| 646 | 664 |
| 647 // The interstitial should be gone. | 665 // The interstitial should be gone. |
| 648 EXPECT_EQ(CANCEL, user_response()); | 666 EXPECT_EQ(CANCEL, user_response()); |
| 649 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 667 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
| 650 | 668 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 664 SetExtendedReportingPref(profile->GetPrefs(), false); | 682 SetExtendedReportingPref(profile->GetPrefs(), false); |
| 665 | 683 |
| 666 // Start a load. | 684 // Start a load. |
| 667 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 685 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 668 ui::PAGE_TRANSITION_TYPED, std::string()); | 686 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 669 | 687 |
| 670 // Simulate the load causing a safe browsing interstitial to be shown. | 688 // Simulate the load causing a safe browsing interstitial to be shown. |
| 671 ShowInterstitial(false, kBadURL); | 689 ShowInterstitial(false, kBadURL); |
| 672 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 690 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 673 ASSERT_TRUE(sb_interstitial); | 691 ASSERT_TRUE(sb_interstitial); |
| 674 EXPECT_TRUE(sb_interstitial->sb_error_ui_->CanShowExtendedReportingOption()); | 692 EXPECT_TRUE(sb_interstitial->sb_error_ui()->CanShowExtendedReportingOption()); |
| 675 | 693 |
| 676 base::RunLoop().RunUntilIdle(); | 694 base::RunLoop().RunUntilIdle(); |
| 677 | 695 |
| 678 EXPECT_FALSE(IsExtendedReportingEnabled(*profile->GetPrefs())); | 696 EXPECT_FALSE(IsExtendedReportingEnabled(*profile->GetPrefs())); |
| 679 | 697 |
| 680 // Simulate the user check the report agreement checkbox. | 698 // Simulate the user check the report agreement checkbox. |
| 681 sb_interstitial->controller()->SetReportingPreference(true); | 699 sb_interstitial->controller()->SetReportingPreference(true); |
| 682 | 700 |
| 683 EXPECT_TRUE(IsExtendedReportingEnabled(*profile->GetPrefs())); | 701 EXPECT_TRUE(IsExtendedReportingEnabled(*profile->GetPrefs())); |
| 684 | 702 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 700 SetExtendedReportingPref(profile->GetPrefs(), true); | 718 SetExtendedReportingPref(profile->GetPrefs(), true); |
| 701 | 719 |
| 702 // Start a load. | 720 // Start a load. |
| 703 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 721 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 704 ui::PAGE_TRANSITION_TYPED, std::string()); | 722 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 705 | 723 |
| 706 // Simulate the load causing a safe browsing interstitial to be shown. | 724 // Simulate the load causing a safe browsing interstitial to be shown. |
| 707 ShowInterstitial(false, kBadURL); | 725 ShowInterstitial(false, kBadURL); |
| 708 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 726 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 709 ASSERT_TRUE(sb_interstitial); | 727 ASSERT_TRUE(sb_interstitial); |
| 710 EXPECT_FALSE(sb_interstitial->sb_error_ui_->CanShowExtendedReportingOption()); | 728 EXPECT_FALSE(sb_interstitial->sb_error_ui() |
| 729 ->CanShowExtendedReportingOption()); |
| 711 | 730 |
| 712 base::RunLoop().RunUntilIdle(); | 731 base::RunLoop().RunUntilIdle(); |
| 713 | 732 |
| 714 // Simulate the user clicking "don't proceed". | 733 // Simulate the user clicking "don't proceed". |
| 715 DontProceedThroughInterstitial(sb_interstitial); | 734 DontProceedThroughInterstitial(sb_interstitial); |
| 716 | 735 |
| 717 // The interstitial should be gone. | 736 // The interstitial should be gone. |
| 718 EXPECT_EQ(CANCEL, user_response()); | 737 EXPECT_EQ(CANCEL, user_response()); |
| 719 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 738 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
| 720 | 739 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 734 prefs::kSafeBrowsingExtendedReportingOptInAllowed, false); | 753 prefs::kSafeBrowsingExtendedReportingOptInAllowed, false); |
| 735 | 754 |
| 736 // Start a load. | 755 // Start a load. |
| 737 controller().LoadURL(GURL(kBadURL), content::Referrer(), | 756 controller().LoadURL(GURL(kBadURL), content::Referrer(), |
| 738 ui::PAGE_TRANSITION_TYPED, std::string()); | 757 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 739 | 758 |
| 740 // Simulate the load causing a safe browsing interstitial to be shown. | 759 // Simulate the load causing a safe browsing interstitial to be shown. |
| 741 ShowInterstitial(false, kBadURL); | 760 ShowInterstitial(false, kBadURL); |
| 742 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); | 761 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); |
| 743 ASSERT_TRUE(sb_interstitial); | 762 ASSERT_TRUE(sb_interstitial); |
| 744 EXPECT_FALSE(sb_interstitial->sb_error_ui_->CanShowExtendedReportingOption()); | 763 EXPECT_FALSE(sb_interstitial->sb_error_ui() |
| 764 ->CanShowExtendedReportingOption()); |
| 745 | 765 |
| 746 base::RunLoop().RunUntilIdle(); | 766 base::RunLoop().RunUntilIdle(); |
| 747 | 767 |
| 748 // Simulate the user clicking "don't proceed". | 768 // Simulate the user clicking "don't proceed". |
| 749 DontProceedThroughInterstitial(sb_interstitial); | 769 DontProceedThroughInterstitial(sb_interstitial); |
| 750 | 770 |
| 751 // The interstitial should be gone. | 771 // The interstitial should be gone. |
| 752 EXPECT_EQ(CANCEL, user_response()); | 772 EXPECT_EQ(CANCEL, user_response()); |
| 753 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); | 773 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); |
| 754 | 774 |
| 755 // No report should have been sent. | 775 // No report should have been sent. |
| 756 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); | 776 EXPECT_EQ(0u, ui_manager_->GetThreatDetails()->size()); |
| 757 ui_manager_->GetThreatDetails()->clear(); | 777 ui_manager_->GetThreatDetails()->clear(); |
| 758 } | 778 } |
| 759 | 779 |
| 760 } // namespace safe_browsing | 780 } // namespace safe_browsing |
| OLD | NEW |