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

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: Mock out help center URL in SafeBrowsingBlockingPageTest 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 24 matching lines...) Expand all
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
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 void MockHelpCenterUrl(InterstitialPage* interstitial_page) {
estark 2017/06/27 00:36:21 nit: maybe add a brief comment above this method t
sperigo 2017/06/27 17:31:58 Done.
735 ASSERT_TRUE(https_server_.Start());
736 scoped_refptr<net::X509Certificate> cert(https_server_.GetCertificate());
737 net::CertVerifyResult verify_result;
738 verify_result.is_issued_by_known_root = true;
739 verify_result.verified_cert = cert;
740 verify_result.cert_status = 0;
741 mock_cert_verifier()->AddResultForCert(cert.get(), verify_result, net::OK);
742
743 SafeBrowsingBlockingPage* sb_interstitial =
744 static_cast<SafeBrowsingBlockingPage*>(
745 interstitial_page->GetDelegateForTesting());
746 security_interstitials::SecurityInterstitialControllerClient* client =
747 sb_interstitial->controller();
748
749 const GURL mock_help_center_url = https_server_.GetURL("/title1.html");
estark 2017/06/27 00:36:21 nit: const GURL& or just inline it below: SetBaseH
sperigo 2017/06/27 17:31:58 Done.
750 client->SetBaseHelpCenterUrlForTesting(mock_help_center_url);
751 }
752
732 protected: 753 protected:
733 TestThreatDetailsFactory details_factory_; 754 TestThreatDetailsFactory details_factory_;
734 755
735 private: 756 private:
736 // Adds a safebrowsing result of the current test threat to the fake 757 // Adds a safebrowsing result of the current test threat to the fake
737 // safebrowsing service, navigates to that page, and returns the url. 758 // safebrowsing service, navigates to that page, and returns the url.
738 // The various wrappers supply different URLs. 759 // The various wrappers supply different URLs.
739 GURL SetupWarningAndNavigateToURL(GURL url, Browser* browser) { 760 GURL SetupWarningAndNavigateToURL(GURL url, Browser* browser) {
740 SetURLThreatType(url, testing::get<0>(GetParam())); 761 SetURLThreatType(url, testing::get<0>(GetParam()));
741 ui_test_utils::NavigateToURL(browser, url); 762 ui_test_utils::NavigateToURL(browser, url);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 EXPECT_TRUE(ClickAndWaitForDetach("primary-button")); 809 EXPECT_TRUE(ClickAndWaitForDetach("primary-button"));
789 810
790 AssertNoInterstitial(false); // Assert the interstitial is gone 811 AssertNoInterstitial(false); // Assert the interstitial is gone
791 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank" 812 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank"
792 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 813 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
793 } 814 }
794 815
795 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, VisitWhitePaper) { 816 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, VisitWhitePaper) {
796 SetupWarningAndNavigate(browser()); 817 SetupWarningAndNavigate(browser());
797 818
819 EXPECT_EQ(1, browser()->tab_strip_model()->count());
820 WebContents* interstitial_tab =
estark 2017/06/27 00:36:21 nit: ASSERT_TRUE(interstitial_tab) after this line
sperigo 2017/06/27 17:31:58 Done.
821 browser()->tab_strip_model()->GetActiveWebContents();
822
798 EXPECT_EQ(VISIBLE, GetVisibility("whitepaper-link")); 823 EXPECT_EQ(VISIBLE, GetVisibility("whitepaper-link"));
799 EXPECT_TRUE(ClickAndWaitForDetach("whitepaper-link")); 824 content::TestNavigationObserver nav_observer(nullptr);
825 nav_observer.StartWatchingNewWebContents();
826 EXPECT_TRUE(Click("whitepaper-link"));
800 827
801 AssertNoInterstitial(false); // Assert the interstitial is gone 828 nav_observer.Wait();
802 EXPECT_EQ(GetWhitePaperUrl(), 829
803 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 830 EXPECT_EQ(2, browser()->tab_strip_model()->count());
831 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
832
833 AssertNoInterstitial(false); // Assert the interstitial is not present in
estark 2017/06/27 00:36:21 nit: comment formatting is a little weird, you can
sperigo 2017/06/27 17:31:59 Done.
834 // the foreground tab.
835
836 // Foreground tab displays the help center.
837 WebContents* new_tab = browser()->tab_strip_model()->GetActiveWebContents();
estark 2017/06/27 00:36:21 nit: ASSERT_TRUE(new_tab) after this line to make
sperigo 2017/06/27 17:31:58 Done.
838 EXPECT_EQ(GetWhitePaperUrl(), new_tab->GetURL());
839
840 // Interstitial should still display in the background tab.
841 browser()->tab_strip_model()->ActivateTabAt(0, true);
842 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
843 EXPECT_EQ(interstitial_tab,
844 browser()->tab_strip_model()->GetActiveWebContents());
845 EXPECT_TRUE(YesInterstitial());
804 } 846 }
805 847
806 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, Proceed) { 848 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, Proceed) {
807 GURL url = SetupWarningAndNavigate(browser()); 849 GURL url = SetupWarningAndNavigate(browser());
808 850
809 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); 851 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link"));
810 AssertNoInterstitial(true); // Assert the interstitial is gone. 852 AssertNoInterstitial(true); // Assert the interstitial is gone.
811 EXPECT_EQ(url, 853 EXPECT_EQ(url,
812 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 854 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
813 } 855 }
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 1144
1103 // Check navigation entry state. 1145 // Check navigation entry state.
1104 ASSERT_TRUE(controller.GetVisibleEntry()); 1146 ASSERT_TRUE(controller.GetVisibleEntry());
1105 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); 1147 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL());
1106 ASSERT_TRUE(controller.GetPendingEntry()); 1148 ASSERT_TRUE(controller.GetPendingEntry());
1107 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); 1149 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL());
1108 } 1150 }
1109 1151
1110 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, LearnMore) { 1152 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, LearnMore) {
1111 SetupWarningAndNavigate(browser()); 1153 SetupWarningAndNavigate(browser());
1112 EXPECT_TRUE(ClickAndWaitForDetach("learn-more-link"));
1113 AssertNoInterstitial(false); // Assert the interstitial is gone
1114 1154
1115 // We are in the help page. 1155 WebContents* interstitial_tab =
1116 EXPECT_EQ( 1156 browser()->tab_strip_model()->GetActiveWebContents();
1117 GURL("https://support.google.com/chrome/answer/99020").GetWithEmptyPath(), 1157 ASSERT_TRUE(interstitial_tab);
1118 browser() 1158
1119 ->tab_strip_model() 1159 MockHelpCenterUrl(interstitial_tab->GetInterstitialPage());
1120 ->GetActiveWebContents() 1160
1121 ->GetURL() 1161 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1122 .GetWithEmptyPath()); 1162
1163 content::TestNavigationObserver nav_observer(nullptr);
1164 nav_observer.StartWatchingNewWebContents();
1165 SendCommand(security_interstitials::CMD_OPEN_HELP_CENTER);
1166 nav_observer.Wait();
1167
1168 // A new tab has been opened.
1169 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1170
1171 // Interstitial does not display in the foreground tab.
1172 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
1173 WebContents* new_tab = browser()->tab_strip_model()->GetWebContentsAt(1);
estark 2017/06/27 00:36:21 same nit about ASSERT_TRUE(new_tab)
sperigo 2017/06/27 17:31:58 Done.
1174 EXPECT_FALSE(new_tab->ShowingInterstitialPage());
1175
1176 // Interstitial still displays in the background tab.
1177 browser()->tab_strip_model()->ActivateTabAt(0, true);
1178 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1179 EXPECT_EQ(interstitial_tab,
1180 browser()->tab_strip_model()->GetActiveWebContents());
1181 EXPECT_TRUE(YesInterstitial());
1123 } 1182 }
1124 1183
1125 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, 1184 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
1126 Histograms_DontProceed) { 1185 Histograms_DontProceed) {
1127 base::HistogramTester histograms; 1186 base::HistogramTester histograms;
1128 std::string prefix; 1187 std::string prefix;
1129 SBThreatType threat_type = testing::get<0>(GetParam()); 1188 SBThreatType threat_type = testing::get<0>(GetParam());
1130 if (threat_type == SB_THREAT_TYPE_URL_MALWARE) 1189 if (threat_type == SB_THREAT_TYPE_URL_MALWARE)
1131 prefix = "malware"; 1190 prefix = "malware";
1132 else if (threat_type == SB_THREAT_TYPE_URL_PHISHING) 1191 else if (threat_type == SB_THREAT_TYPE_URL_PHISHING)
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1591 1650
1592 INSTANTIATE_TEST_CASE_P( 1651 INSTANTIATE_TEST_CASE_P(
1593 SafeBrowsingBlockingPageIDNTestWithThreatType, 1652 SafeBrowsingBlockingPageIDNTestWithThreatType,
1594 SafeBrowsingBlockingPageIDNTest, 1653 SafeBrowsingBlockingPageIDNTest,
1595 testing::Combine(testing::Values(false, true), 1654 testing::Combine(testing::Values(false, true),
1596 testing::Values(SB_THREAT_TYPE_URL_MALWARE, 1655 testing::Values(SB_THREAT_TYPE_URL_MALWARE,
1597 SB_THREAT_TYPE_URL_PHISHING, 1656 SB_THREAT_TYPE_URL_PHISHING,
1598 SB_THREAT_TYPE_URL_UNWANTED))); 1657 SB_THREAT_TYPE_URL_UNWANTED)));
1599 1658
1600 } // namespace safe_browsing 1659 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698