Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc

Issue 2955503002: Make interstitial links open in a new tab (Closed)
Patch Set: Fix compilation error Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 25 matching lines...) Expand all
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/safe_browsing_db/v4_protocol_manager_util.h" 45 #include "components/safe_browsing_db/v4_protocol_manager_util.h"
46 #include "components/security_interstitials/content/security_interstitial_contro ller_client.h"
46 #include "components/security_interstitials/core/controller_client.h" 47 #include "components/security_interstitials/core/controller_client.h"
47 #include "components/security_interstitials/core/metrics_helper.h" 48 #include "components/security_interstitials/core/metrics_helper.h"
48 #include "components/security_interstitials/core/urls.h" 49 #include "components/security_interstitials/core/urls.h"
49 #include "components/security_state/core/security_state.h" 50 #include "components/security_state/core/security_state.h"
50 #include "components/strings/grit/components_strings.h" 51 #include "components/strings/grit/components_strings.h"
51 #include "content/public/browser/interstitial_page.h" 52 #include "content/public/browser/interstitial_page.h"
52 #include "content/public/browser/navigation_controller.h" 53 #include "content/public/browser/navigation_controller.h"
53 #include "content/public/browser/navigation_entry.h" 54 #include "content/public/browser/navigation_entry.h"
54 #include "content/public/browser/notification_types.h" 55 #include "content/public/browser/notification_types.h"
55 #include "content/public/browser/render_frame_host.h" 56 #include "content/public/browser/render_frame_host.h"
56 #include "content/public/browser/render_process_host.h" 57 #include "content/public/browser/render_process_host.h"
57 #include "content/public/browser/security_style_explanations.h" 58 #include "content/public/browser/security_style_explanations.h"
58 #include "content/public/browser/web_contents.h" 59 #include "content/public/browser/web_contents.h"
59 #include "content/public/test/browser_test_utils.h" 60 #include "content/public/test/browser_test_utils.h"
60 #include "content/public/test/test_browser_thread.h" 61 #include "content/public/test/test_browser_thread.h"
62 #include "content/public/test/test_navigation_observer.h"
61 #include "content/public/test/test_utils.h" 63 #include "content/public/test/test_utils.h"
62 #include "net/cert/cert_verify_result.h" 64 #include "net/cert/cert_verify_result.h"
63 #include "net/cert/mock_cert_verifier.h" 65 #include "net/cert/mock_cert_verifier.h"
64 #include "net/test/embedded_test_server/embedded_test_server.h" 66 #include "net/test/embedded_test_server/embedded_test_server.h"
65 #include "net/test/url_request/url_request_mock_http_job.h" 67 #include "net/test/url_request/url_request_mock_http_job.h"
66 #include "testing/gmock/include/gmock/gmock-matchers.h" 68 #include "testing/gmock/include/gmock/gmock-matchers.h"
67 #include "ui/base/l10n/l10n_util.h" 69 #include "ui/base/l10n/l10n_util.h"
68 70
69 using chrome_browser_interstitials::SecurityInterstitialIDNTest; 71 using chrome_browser_interstitials::SecurityInterstitialIDNTest;
70 using content::BrowserThread; 72 using content::BrowserThread;
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 EXPECT_EQ(security_state::MALICIOUS_CONTENT_STATUS_NONE, 727 EXPECT_EQ(security_state::MALICIOUS_CONTENT_STATUS_NONE,
726 security_info.malicious_content_status); 728 security_info.malicious_content_status);
727 } 729 }
728 730
729 bool hit_report_sent() { 731 bool hit_report_sent() {
730 return static_cast<FakeSafeBrowsingUIManager*>( 732 return static_cast<FakeSafeBrowsingUIManager*>(
731 factory_.test_safe_browsing_service()->ui_manager().get()) 733 factory_.test_safe_browsing_service()->ui_manager().get())
732 ->hit_report_sent(); 734 ->hit_report_sent();
733 } 735 }
734 736
737 // Helper method for LearnMore test below. Implemented as a test fixture
738 // method instead of in the test below because the whole test fixture class
739 // is friended by SafeBrowsingBlockingPage.
740 void MockHelpCenterUrl(InterstitialPage* interstitial_page) {
741 ASSERT_TRUE(https_server_.Start());
742 scoped_refptr<net::X509Certificate> cert(https_server_.GetCertificate());
743 net::CertVerifyResult verify_result;
744 verify_result.is_issued_by_known_root = true;
745 verify_result.verified_cert = cert;
746 verify_result.cert_status = 0;
747 mock_cert_verifier()->AddResultForCert(cert.get(), verify_result, net::OK);
748
749 SafeBrowsingBlockingPage* sb_interstitial =
750 static_cast<SafeBrowsingBlockingPage*>(
751 interstitial_page->GetDelegateForTesting());
752 security_interstitials::SecurityInterstitialControllerClient* client =
753 sb_interstitial->controller();
754
755 client->SetBaseHelpCenterUrlForTesting(
756 https_server_.GetURL("/title1.html"));
757 }
758
735 protected: 759 protected:
736 TestThreatDetailsFactory details_factory_; 760 TestThreatDetailsFactory details_factory_;
737 761
738 private: 762 private:
739 // Adds a safebrowsing result of the current test threat to the fake 763 // Adds a safebrowsing result of the current test threat to the fake
740 // safebrowsing service, navigates to that page, and returns the url. 764 // safebrowsing service, navigates to that page, and returns the url.
741 // The various wrappers supply different URLs. 765 // The various wrappers supply different URLs.
742 GURL SetupWarningAndNavigateToURL(GURL url, Browser* browser) { 766 GURL SetupWarningAndNavigateToURL(GURL url, Browser* browser) {
743 SetURLThreatType(url, testing::get<0>(GetParam())); 767 SetURLThreatType(url, testing::get<0>(GetParam()));
744 ui_test_utils::NavigateToURL(browser, url); 768 ui_test_utils::NavigateToURL(browser, url);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 EXPECT_TRUE(ClickAndWaitForDetach("primary-button")); 815 EXPECT_TRUE(ClickAndWaitForDetach("primary-button"));
792 816
793 AssertNoInterstitial(false); // Assert the interstitial is gone 817 AssertNoInterstitial(false); // Assert the interstitial is gone
794 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank" 818 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank"
795 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 819 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
796 } 820 }
797 821
798 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, VisitWhitePaper) { 822 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, VisitWhitePaper) {
799 SetupWarningAndNavigate(browser()); 823 SetupWarningAndNavigate(browser());
800 824
825 EXPECT_EQ(1, browser()->tab_strip_model()->count());
826 WebContents* interstitial_tab =
827 browser()->tab_strip_model()->GetActiveWebContents();
828 ASSERT_TRUE(interstitial_tab);
829
801 EXPECT_EQ(VISIBLE, GetVisibility("whitepaper-link")); 830 EXPECT_EQ(VISIBLE, GetVisibility("whitepaper-link"));
802 EXPECT_TRUE(ClickAndWaitForDetach("whitepaper-link")); 831 content::TestNavigationObserver nav_observer(nullptr);
832 nav_observer.StartWatchingNewWebContents();
833 EXPECT_TRUE(Click("whitepaper-link"));
803 834
804 AssertNoInterstitial(false); // Assert the interstitial is gone 835 nav_observer.Wait();
805 EXPECT_EQ(GetWhitePaperUrl(), 836
806 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 837 EXPECT_EQ(2, browser()->tab_strip_model()->count());
838 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
839
840 // Assert the interstitial is not present in the foreground tab.
841 AssertNoInterstitial(false);
842
843 // Foreground tab displays the help center.
844 WebContents* new_tab = browser()->tab_strip_model()->GetActiveWebContents();
845 ASSERT_TRUE(new_tab);
846 EXPECT_EQ(GetWhitePaperUrl(), new_tab->GetURL());
847
848 // Interstitial should still display in the background tab.
849 browser()->tab_strip_model()->ActivateTabAt(0, true);
850 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
851 EXPECT_EQ(interstitial_tab,
852 browser()->tab_strip_model()->GetActiveWebContents());
853 EXPECT_TRUE(YesInterstitial());
807 } 854 }
808 855
809 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, Proceed) { 856 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, Proceed) {
810 GURL url = SetupWarningAndNavigate(browser()); 857 GURL url = SetupWarningAndNavigate(browser());
811 858
812 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); 859 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link"));
813 AssertNoInterstitial(true); // Assert the interstitial is gone. 860 AssertNoInterstitial(true); // Assert the interstitial is gone.
814 EXPECT_EQ(url, 861 EXPECT_EQ(url,
815 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 862 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
816 } 863 }
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 1152
1106 // Check navigation entry state. 1153 // Check navigation entry state.
1107 ASSERT_TRUE(controller.GetVisibleEntry()); 1154 ASSERT_TRUE(controller.GetVisibleEntry());
1108 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); 1155 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL());
1109 ASSERT_TRUE(controller.GetPendingEntry()); 1156 ASSERT_TRUE(controller.GetPendingEntry());
1110 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); 1157 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL());
1111 } 1158 }
1112 1159
1113 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, LearnMore) { 1160 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, LearnMore) {
1114 SetupWarningAndNavigate(browser()); 1161 SetupWarningAndNavigate(browser());
1115 EXPECT_TRUE(ClickAndWaitForDetach("learn-more-link"));
1116 AssertNoInterstitial(false); // Assert the interstitial is gone
1117 1162
1118 // We are in the help page. 1163 WebContents* interstitial_tab =
1119 EXPECT_EQ( 1164 browser()->tab_strip_model()->GetActiveWebContents();
1120 GURL("https://support.google.com/chrome/answer/99020").GetWithEmptyPath(), 1165 ASSERT_TRUE(interstitial_tab);
1121 browser() 1166
1122 ->tab_strip_model() 1167 MockHelpCenterUrl(interstitial_tab->GetInterstitialPage());
1123 ->GetActiveWebContents() 1168
1124 ->GetURL() 1169 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1125 .GetWithEmptyPath()); 1170
1171 content::TestNavigationObserver nav_observer(nullptr);
1172 nav_observer.StartWatchingNewWebContents();
1173 SendCommand(security_interstitials::CMD_OPEN_HELP_CENTER);
1174 nav_observer.Wait();
1175
1176 // A new tab has been opened.
1177 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1178
1179 // Interstitial does not display in the foreground tab.
1180 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
1181 WebContents* new_tab = browser()->tab_strip_model()->GetWebContentsAt(1);
1182 ASSERT_TRUE(new_tab);
1183 EXPECT_FALSE(new_tab->ShowingInterstitialPage());
1184
1185 // Interstitial still displays in the background tab.
1186 browser()->tab_strip_model()->ActivateTabAt(0, true);
1187 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1188 EXPECT_EQ(interstitial_tab,
1189 browser()->tab_strip_model()->GetActiveWebContents());
1190 EXPECT_TRUE(YesInterstitial());
1126 } 1191 }
1127 1192
1128 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, 1193 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
1129 Histograms_DontProceed) { 1194 Histograms_DontProceed) {
1130 base::HistogramTester histograms; 1195 base::HistogramTester histograms;
1131 std::string prefix; 1196 std::string prefix;
1132 SBThreatType threat_type = testing::get<0>(GetParam()); 1197 SBThreatType threat_type = testing::get<0>(GetParam());
1133 if (threat_type == SB_THREAT_TYPE_URL_MALWARE) 1198 if (threat_type == SB_THREAT_TYPE_URL_MALWARE)
1134 prefix = "malware"; 1199 prefix = "malware";
1135 else if (threat_type == SB_THREAT_TYPE_URL_PHISHING) 1200 else if (threat_type == SB_THREAT_TYPE_URL_PHISHING)
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 1659
1595 INSTANTIATE_TEST_CASE_P( 1660 INSTANTIATE_TEST_CASE_P(
1596 SafeBrowsingBlockingPageIDNTestWithThreatType, 1661 SafeBrowsingBlockingPageIDNTestWithThreatType,
1597 SafeBrowsingBlockingPageIDNTest, 1662 SafeBrowsingBlockingPageIDNTest,
1598 testing::Combine(testing::Values(false, true), 1663 testing::Combine(testing::Values(false, true),
1599 testing::Values(SB_THREAT_TYPE_URL_MALWARE, 1664 testing::Values(SB_THREAT_TYPE_URL_MALWARE,
1600 SB_THREAT_TYPE_URL_PHISHING, 1665 SB_THREAT_TYPE_URL_PHISHING,
1601 SB_THREAT_TYPE_URL_UNWANTED))); 1666 SB_THREAT_TYPE_URL_UNWANTED)));
1602 1667
1603 } // namespace safe_browsing 1668 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page.h ('k') | chrome/browser/ssl/ssl_browser_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698