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 // This test creates a fake safebrowsing service, where we can inject known- | 5 // This test creates a fake safebrowsing service, where we can inject known- |
6 // threat urls. It then uses a real browser to go to these urls, and sends | 6 // threat urls. It then uses a real browser to go to these urls, and sends |
7 // "goback" or "proceed" commands and verifies they work. | 7 // "goback" or "proceed" commands and verifies they work. |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... | |
35 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
36 #include "chrome/test/base/in_process_browser_test.h" | 36 #include "chrome/test/base/in_process_browser_test.h" |
37 #include "chrome/test/base/ui_test_utils.h" | 37 #include "chrome/test/base/ui_test_utils.h" |
38 #include "components/google/core/browser/google_util.h" | 38 #include "components/google/core/browser/google_util.h" |
39 #include "components/prefs/pref_service.h" | 39 #include "components/prefs/pref_service.h" |
40 #include "components/safe_browsing/browser/threat_details.h" | 40 #include "components/safe_browsing/browser/threat_details.h" |
41 #include "components/safe_browsing/common/safe_browsing_prefs.h" | 41 #include "components/safe_browsing/common/safe_browsing_prefs.h" |
42 #include "components/safe_browsing_db/database_manager.h" | 42 #include "components/safe_browsing_db/database_manager.h" |
43 #include "components/safe_browsing_db/test_database_manager.h" | 43 #include "components/safe_browsing_db/test_database_manager.h" |
44 #include "components/safe_browsing_db/util.h" | 44 #include "components/safe_browsing_db/util.h" |
45 #include "components/security_interstitials/content/security_interstitial_contro ller_client.h" | |
45 #include "components/security_interstitials/core/controller_client.h" | 46 #include "components/security_interstitials/core/controller_client.h" |
46 #include "components/security_interstitials/core/metrics_helper.h" | 47 #include "components/security_interstitials/core/metrics_helper.h" |
47 #include "components/security_interstitials/core/urls.h" | 48 #include "components/security_interstitials/core/urls.h" |
48 #include "components/security_state/core/security_state.h" | 49 #include "components/security_state/core/security_state.h" |
49 #include "components/strings/grit/components_strings.h" | 50 #include "components/strings/grit/components_strings.h" |
50 #include "content/public/browser/interstitial_page.h" | 51 #include "content/public/browser/interstitial_page.h" |
51 #include "content/public/browser/navigation_controller.h" | 52 #include "content/public/browser/navigation_controller.h" |
52 #include "content/public/browser/navigation_entry.h" | 53 #include "content/public/browser/navigation_entry.h" |
53 #include "content/public/browser/notification_types.h" | 54 #include "content/public/browser/notification_types.h" |
54 #include "content/public/browser/render_frame_host.h" | 55 #include "content/public/browser/render_frame_host.h" |
55 #include "content/public/browser/render_process_host.h" | 56 #include "content/public/browser/render_process_host.h" |
56 #include "content/public/browser/security_style_explanations.h" | 57 #include "content/public/browser/security_style_explanations.h" |
57 #include "content/public/browser/web_contents.h" | 58 #include "content/public/browser/web_contents.h" |
58 #include "content/public/test/browser_test_utils.h" | 59 #include "content/public/test/browser_test_utils.h" |
59 #include "content/public/test/test_browser_thread.h" | 60 #include "content/public/test/test_browser_thread.h" |
61 #include "content/public/test/test_navigation_observer.h" | |
60 #include "content/public/test/test_utils.h" | 62 #include "content/public/test/test_utils.h" |
61 #include "net/cert/cert_verify_result.h" | 63 #include "net/cert/cert_verify_result.h" |
62 #include "net/cert/mock_cert_verifier.h" | 64 #include "net/cert/mock_cert_verifier.h" |
63 #include "net/test/embedded_test_server/embedded_test_server.h" | 65 #include "net/test/embedded_test_server/embedded_test_server.h" |
64 #include "net/test/url_request/url_request_mock_http_job.h" | 66 #include "net/test/url_request/url_request_mock_http_job.h" |
65 #include "testing/gmock/include/gmock/gmock-matchers.h" | 67 #include "testing/gmock/include/gmock/gmock-matchers.h" |
66 #include "ui/base/l10n/l10n_util.h" | 68 #include "ui/base/l10n/l10n_util.h" |
67 | 69 |
68 using chrome_browser_interstitials::SecurityInterstitialIDNTest; | 70 using chrome_browser_interstitials::SecurityInterstitialIDNTest; |
69 using content::BrowserThread; | 71 using content::BrowserThread; |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 EXPECT_EQ(security_state::MALICIOUS_CONTENT_STATUS_NONE, | 724 EXPECT_EQ(security_state::MALICIOUS_CONTENT_STATUS_NONE, |
723 security_info.malicious_content_status); | 725 security_info.malicious_content_status); |
724 } | 726 } |
725 | 727 |
726 bool hit_report_sent() { | 728 bool hit_report_sent() { |
727 return static_cast<FakeSafeBrowsingUIManager*>( | 729 return static_cast<FakeSafeBrowsingUIManager*>( |
728 factory_.test_safe_browsing_service()->ui_manager().get()) | 730 factory_.test_safe_browsing_service()->ui_manager().get()) |
729 ->hit_report_sent(); | 731 ->hit_report_sent(); |
730 } | 732 } |
731 | 733 |
734 // Helper method for LearnMore test below. Implelemnted as a test fixture | |
estark
2017/06/27 17:48:32
nit: typo, Implemented
| |
735 // method instead of in the test below because the whole test fixture class | |
736 // is friended by SafeBrowsingBlockingPage. | |
737 void MockHelpCenterUrl(InterstitialPage* interstitial_page) { | |
738 ASSERT_TRUE(https_server_.Start()); | |
739 scoped_refptr<net::X509Certificate> cert(https_server_.GetCertificate()); | |
740 net::CertVerifyResult verify_result; | |
741 verify_result.is_issued_by_known_root = true; | |
742 verify_result.verified_cert = cert; | |
743 verify_result.cert_status = 0; | |
744 mock_cert_verifier()->AddResultForCert(cert.get(), verify_result, net::OK); | |
745 | |
746 SafeBrowsingBlockingPage* sb_interstitial = | |
747 static_cast<SafeBrowsingBlockingPage*>( | |
748 interstitial_page->GetDelegateForTesting()); | |
749 security_interstitials::SecurityInterstitialControllerClient* client = | |
750 sb_interstitial->controller(); | |
751 | |
752 client->SetBaseHelpCenterUrlForTesting( | |
753 https_server_.GetURL("/title1.html")); | |
754 } | |
755 | |
732 protected: | 756 protected: |
733 TestThreatDetailsFactory details_factory_; | 757 TestThreatDetailsFactory details_factory_; |
734 | 758 |
735 private: | 759 private: |
736 // Adds a safebrowsing result of the current test threat to the fake | 760 // Adds a safebrowsing result of the current test threat to the fake |
737 // safebrowsing service, navigates to that page, and returns the url. | 761 // safebrowsing service, navigates to that page, and returns the url. |
738 // The various wrappers supply different URLs. | 762 // The various wrappers supply different URLs. |
739 GURL SetupWarningAndNavigateToURL(GURL url, Browser* browser) { | 763 GURL SetupWarningAndNavigateToURL(GURL url, Browser* browser) { |
740 SetURLThreatType(url, testing::get<0>(GetParam())); | 764 SetURLThreatType(url, testing::get<0>(GetParam())); |
741 ui_test_utils::NavigateToURL(browser, url); | 765 ui_test_utils::NavigateToURL(browser, url); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
788 EXPECT_TRUE(ClickAndWaitForDetach("primary-button")); | 812 EXPECT_TRUE(ClickAndWaitForDetach("primary-button")); |
789 | 813 |
790 AssertNoInterstitial(false); // Assert the interstitial is gone | 814 AssertNoInterstitial(false); // Assert the interstitial is gone |
791 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank" | 815 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank" |
792 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); | 816 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); |
793 } | 817 } |
794 | 818 |
795 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, VisitWhitePaper) { | 819 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, VisitWhitePaper) { |
796 SetupWarningAndNavigate(browser()); | 820 SetupWarningAndNavigate(browser()); |
797 | 821 |
822 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
823 WebContents* interstitial_tab = | |
824 browser()->tab_strip_model()->GetActiveWebContents(); | |
825 ASSERT_TRUE(interstial_tab); | |
826 | |
798 EXPECT_EQ(VISIBLE, GetVisibility("whitepaper-link")); | 827 EXPECT_EQ(VISIBLE, GetVisibility("whitepaper-link")); |
799 EXPECT_TRUE(ClickAndWaitForDetach("whitepaper-link")); | 828 content::TestNavigationObserver nav_observer(nullptr); |
829 nav_observer.StartWatchingNewWebContents(); | |
830 EXPECT_TRUE(Click("whitepaper-link")); | |
800 | 831 |
801 AssertNoInterstitial(false); // Assert the interstitial is gone | 832 nav_observer.Wait(); |
802 EXPECT_EQ(GetWhitePaperUrl(), | 833 |
803 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); | 834 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
835 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); | |
836 | |
837 // Assert the interstitial is not present in the foreground tab. | |
838 AssertNoInterstitial(false); | |
839 | |
840 // Foreground tab displays the help center. | |
841 WebContents* new_tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
842 ASSERT_TRUE(new_tab); | |
843 EXPECT_EQ(GetWhitePaperUrl(), new_tab->GetURL()); | |
844 | |
845 // Interstitial should still display in the background tab. | |
846 browser()->tab_strip_model()->ActivateTabAt(0, true); | |
847 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | |
848 EXPECT_EQ(interstitial_tab, | |
849 browser()->tab_strip_model()->GetActiveWebContents()); | |
850 EXPECT_TRUE(YesInterstitial()); | |
804 } | 851 } |
805 | 852 |
806 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, Proceed) { | 853 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, Proceed) { |
807 GURL url = SetupWarningAndNavigate(browser()); | 854 GURL url = SetupWarningAndNavigate(browser()); |
808 | 855 |
809 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); | 856 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); |
810 AssertNoInterstitial(true); // Assert the interstitial is gone. | 857 AssertNoInterstitial(true); // Assert the interstitial is gone. |
811 EXPECT_EQ(url, | 858 EXPECT_EQ(url, |
812 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); | 859 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); |
813 } | 860 } |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1102 | 1149 |
1103 // Check navigation entry state. | 1150 // Check navigation entry state. |
1104 ASSERT_TRUE(controller.GetVisibleEntry()); | 1151 ASSERT_TRUE(controller.GetVisibleEntry()); |
1105 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 1152 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
1106 ASSERT_TRUE(controller.GetPendingEntry()); | 1153 ASSERT_TRUE(controller.GetPendingEntry()); |
1107 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); | 1154 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); |
1108 } | 1155 } |
1109 | 1156 |
1110 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, LearnMore) { | 1157 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, LearnMore) { |
1111 SetupWarningAndNavigate(browser()); | 1158 SetupWarningAndNavigate(browser()); |
1112 EXPECT_TRUE(ClickAndWaitForDetach("learn-more-link")); | |
1113 AssertNoInterstitial(false); // Assert the interstitial is gone | |
1114 | 1159 |
1115 // We are in the help page. | 1160 WebContents* interstitial_tab = |
1116 EXPECT_EQ( | 1161 browser()->tab_strip_model()->GetActiveWebContents(); |
1117 GURL("https://support.google.com/chrome/answer/99020").GetWithEmptyPath(), | 1162 ASSERT_TRUE(interstitial_tab); |
1118 browser() | 1163 |
1119 ->tab_strip_model() | 1164 MockHelpCenterUrl(interstitial_tab->GetInterstitialPage()); |
1120 ->GetActiveWebContents() | 1165 |
1121 ->GetURL() | 1166 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
1122 .GetWithEmptyPath()); | 1167 |
1168 content::TestNavigationObserver nav_observer(nullptr); | |
1169 nav_observer.StartWatchingNewWebContents(); | |
1170 SendCommand(security_interstitials::CMD_OPEN_HELP_CENTER); | |
1171 nav_observer.Wait(); | |
1172 | |
1173 // A new tab has been opened. | |
1174 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | |
1175 | |
1176 // Interstitial does not display in the foreground tab. | |
1177 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); | |
1178 WebContents* new_tab = browser()->tab_strip_model()->GetWebContentsAt(1); | |
1179 ASSERT_TRUE(new_tab); | |
1180 EXPECT_FALSE(new_tab->ShowingInterstitialPage()); | |
1181 | |
1182 // Interstitial still displays in the background tab. | |
1183 browser()->tab_strip_model()->ActivateTabAt(0, true); | |
1184 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | |
1185 EXPECT_EQ(interstitial_tab, | |
1186 browser()->tab_strip_model()->GetActiveWebContents()); | |
1187 EXPECT_TRUE(YesInterstitial()); | |
1123 } | 1188 } |
1124 | 1189 |
1125 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, | 1190 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, |
1126 Histograms_DontProceed) { | 1191 Histograms_DontProceed) { |
1127 base::HistogramTester histograms; | 1192 base::HistogramTester histograms; |
1128 std::string prefix; | 1193 std::string prefix; |
1129 SBThreatType threat_type = testing::get<0>(GetParam()); | 1194 SBThreatType threat_type = testing::get<0>(GetParam()); |
1130 if (threat_type == SB_THREAT_TYPE_URL_MALWARE) | 1195 if (threat_type == SB_THREAT_TYPE_URL_MALWARE) |
1131 prefix = "malware"; | 1196 prefix = "malware"; |
1132 else if (threat_type == SB_THREAT_TYPE_URL_PHISHING) | 1197 else if (threat_type == SB_THREAT_TYPE_URL_PHISHING) |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1591 | 1656 |
1592 INSTANTIATE_TEST_CASE_P( | 1657 INSTANTIATE_TEST_CASE_P( |
1593 SafeBrowsingBlockingPageIDNTestWithThreatType, | 1658 SafeBrowsingBlockingPageIDNTestWithThreatType, |
1594 SafeBrowsingBlockingPageIDNTest, | 1659 SafeBrowsingBlockingPageIDNTest, |
1595 testing::Combine(testing::Values(false, true), | 1660 testing::Combine(testing::Values(false, true), |
1596 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 1661 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
1597 SB_THREAT_TYPE_URL_PHISHING, | 1662 SB_THREAT_TYPE_URL_PHISHING, |
1598 SB_THREAT_TYPE_URL_UNWANTED))); | 1663 SB_THREAT_TYPE_URL_UNWANTED))); |
1599 | 1664 |
1600 } // namespace safe_browsing | 1665 } // namespace safe_browsing |
OLD | NEW |