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

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

Issue 2418813002: [Reland] Refactoring of SBER preference usage (Closed)
Patch Set: Sync Created 4 years, 2 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 19 matching lines...) Expand all
30 #include "chrome/browser/ssl/ssl_blocking_page.h" 30 #include "chrome/browser/ssl/ssl_blocking_page.h"
31 #include "chrome/browser/ui/browser.h" 31 #include "chrome/browser/ui/browser.h"
32 #include "chrome/browser/ui/browser_tabstrip.h" 32 #include "chrome/browser/ui/browser_tabstrip.h"
33 #include "chrome/browser/ui/tabs/tab_strip_model.h" 33 #include "chrome/browser/ui/tabs/tab_strip_model.h"
34 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
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/prefs/pref_service.h" 38 #include "components/prefs/pref_service.h"
39 #include "components/safe_browsing_db/database_manager.h" 39 #include "components/safe_browsing_db/database_manager.h"
40 #include "components/safe_browsing_db/safe_browsing_prefs.h"
40 #include "components/safe_browsing_db/test_database_manager.h" 41 #include "components/safe_browsing_db/test_database_manager.h"
41 #include "components/safe_browsing_db/util.h" 42 #include "components/safe_browsing_db/util.h"
42 #include "components/security_interstitials/core/controller_client.h" 43 #include "components/security_interstitials/core/controller_client.h"
43 #include "components/security_interstitials/core/metrics_helper.h" 44 #include "components/security_interstitials/core/metrics_helper.h"
44 #include "content/public/browser/interstitial_page.h" 45 #include "content/public/browser/interstitial_page.h"
45 #include "content/public/browser/navigation_controller.h" 46 #include "content/public/browser/navigation_controller.h"
46 #include "content/public/browser/notification_types.h" 47 #include "content/public/browser/notification_types.h"
47 #include "content/public/browser/render_frame_host.h" 48 #include "content/public/browser/render_frame_host.h"
48 #include "content/public/browser/render_process_host.h" 49 #include "content/public/browser/render_process_host.h"
49 #include "content/public/browser/web_contents.h" 50 #include "content/public/browser/web_contents.h"
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 // Set up testing url containing iframe and cross site iframe. 698 // Set up testing url containing iframe and cross site iframe.
698 GURL url = SetupThreatIframeWarningAndNavigate(); 699 GURL url = SetupThreatIframeWarningAndNavigate();
699 700
700 ThreatDetails* threat_details = details_factory_.get_details(); 701 ThreatDetails* threat_details = details_factory_.get_details();
701 EXPECT_EQ(expect_threat_details, threat_details != nullptr); 702 EXPECT_EQ(expect_threat_details, threat_details != nullptr);
702 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in")); 703 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in"));
703 EXPECT_TRUE(Click("opt-in-checkbox")); 704 EXPECT_TRUE(Click("opt-in-checkbox"));
704 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); 705 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link"));
705 AssertNoInterstitial(true); // Assert the interstitial is gone 706 AssertNoInterstitial(true); // Assert the interstitial is gone
706 707
707 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( 708 EXPECT_TRUE(IsExtendedReportingEnabled(*browser()->profile()->GetPrefs()));
708 prefs::kSafeBrowsingExtendedReportingEnabled));
709 EXPECT_EQ(url, 709 EXPECT_EQ(url,
710 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 710 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
711 711
712 if (expect_threat_details) { 712 if (expect_threat_details) {
713 threat_report_sent_runner->Run(); 713 threat_report_sent_runner->Run();
714 std::string serialized = GetReportSent(); 714 std::string serialized = GetReportSent();
715 ClientSafeBrowsingReportRequest report; 715 ClientSafeBrowsingReportRequest report;
716 ASSERT_TRUE(report.ParseFromString(serialized)); 716 ASSERT_TRUE(report.ParseFromString(serialized));
717 // Verify the report is complete. 717 // Verify the report is complete.
718 EXPECT_TRUE(report.complete()); 718 EXPECT_TRUE(report.complete());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 769
770 ThreatDetails* threat_details = details_factory_.get_details(); 770 ThreatDetails* threat_details = details_factory_.get_details();
771 EXPECT_EQ(expect_threat_details, threat_details != nullptr); 771 EXPECT_EQ(expect_threat_details, threat_details != nullptr);
772 772
773 // Go back. 773 // Go back.
774 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in")); 774 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in"));
775 EXPECT_TRUE(Click("opt-in-checkbox")); 775 EXPECT_TRUE(Click("opt-in-checkbox"));
776 EXPECT_TRUE(ClickAndWaitForDetach("primary-button")); 776 EXPECT_TRUE(ClickAndWaitForDetach("primary-button"));
777 AssertNoInterstitial(true); // Assert the interstitial is gone 777 AssertNoInterstitial(true); // Assert the interstitial is gone
778 778
779 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( 779 EXPECT_TRUE(IsExtendedReportingEnabled(*browser()->profile()->GetPrefs()));
780 prefs::kSafeBrowsingExtendedReportingEnabled));
781 EXPECT_EQ(safe_url, 780 EXPECT_EQ(safe_url,
782 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 781 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
783 782
784 if (expect_threat_details) { 783 if (expect_threat_details) {
785 threat_report_sent_runner->Run(); 784 threat_report_sent_runner->Run();
786 std::string serialized = GetReportSent(); 785 std::string serialized = GetReportSent();
787 ClientSafeBrowsingReportRequest report; 786 ClientSafeBrowsingReportRequest report;
788 ASSERT_TRUE(report.ParseFromString(serialized)); 787 ASSERT_TRUE(report.ParseFromString(serialized));
789 // Verify the report is complete. 788 // Verify the report is complete.
790 EXPECT_TRUE(report.complete()); 789 EXPECT_TRUE(report.complete());
(...skipping 30 matching lines...) Expand all
821 820
822 ThreatDetails* threat_details = details_factory_.get_details(); 821 ThreatDetails* threat_details = details_factory_.get_details();
823 EXPECT_EQ(expect_threat_details, threat_details != nullptr); 822 EXPECT_EQ(expect_threat_details, threat_details != nullptr);
824 823
825 // Proceed through the warning. 824 // Proceed through the warning.
826 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in")); 825 EXPECT_EQ(VISIBLE, GetVisibility("extended-reporting-opt-in"));
827 EXPECT_TRUE(Click("opt-in-checkbox")); 826 EXPECT_TRUE(Click("opt-in-checkbox"));
828 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); 827 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link"));
829 AssertNoInterstitial(true); // Assert the interstitial is gone 828 AssertNoInterstitial(true); // Assert the interstitial is gone
830 829
831 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( 830 EXPECT_TRUE(IsExtendedReportingEnabled(*browser()->profile()->GetPrefs()));
832 prefs::kSafeBrowsingExtendedReportingEnabled));
833 EXPECT_EQ(url, 831 EXPECT_EQ(url,
834 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 832 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
835 833
836 if (expect_threat_details) { 834 if (expect_threat_details) {
837 threat_report_sent_runner->Run(); 835 threat_report_sent_runner->Run();
838 std::string serialized = GetReportSent(); 836 std::string serialized = GetReportSent();
839 ClientSafeBrowsingReportRequest report; 837 ClientSafeBrowsingReportRequest report;
840 ASSERT_TRUE(report.ParseFromString(serialized)); 838 ASSERT_TRUE(report.ParseFromString(serialized));
841 // Verify the report is complete. 839 // Verify the report is complete.
842 EXPECT_TRUE(report.complete()); 840 EXPECT_TRUE(report.complete());
(...skipping 26 matching lines...) Expand all
869 // The "proceed" command should go back instead, if proceeding is disabled. 867 // The "proceed" command should go back instead, if proceeding is disabled.
870 AssertNoInterstitial(true); 868 AssertNoInterstitial(true);
871 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank" 869 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank"
872 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 870 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
873 } 871 }
874 872
875 // Verifies that the reporting checkbox is hidden on non-HTTP pages. 873 // Verifies that the reporting checkbox is hidden on non-HTTP pages.
876 // TODO(mattm): Should also verify that no report is sent, but there isn't a 874 // TODO(mattm): Should also verify that no report is sent, but there isn't a
877 // good way to do that in the current design. 875 // good way to do that in the current design.
878 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, ReportingDisabled) { 876 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, ReportingDisabled) {
879 browser()->profile()->GetPrefs()->SetBoolean( 877 browser()->profile()->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(),
880 prefs::kSafeBrowsingExtendedReportingEnabled, true); 878 true);
881 879
882 TestReportingDisabledAndDontProceed( 880 TestReportingDisabledAndDontProceed(
883 net::URLRequestMockHTTPJob::GetMockHttpsUrl(kEmptyPage)); 881 net::URLRequestMockHTTPJob::GetMockHttpsUrl(kEmptyPage));
884 } 882 }
885 883
886 // Verifies that the reporting checkbox is hidden when opt-in is 884 // Verifies that the reporting checkbox is hidden when opt-in is
887 // disabled by policy. 885 // disabled by policy.
888 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, 886 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
889 ReportingDisabledByPolicy) { 887 ReportingDisabledByPolicy) {
890 browser()->profile()->GetPrefs()->SetBoolean( 888 browser()->profile()->GetPrefs()->SetBoolean(GetExtendedReportingPrefName(),
891 prefs::kSafeBrowsingExtendedReportingEnabled, true); 889 true);
892 browser()->profile()->GetPrefs()->SetBoolean( 890 browser()->profile()->GetPrefs()->SetBoolean(
893 prefs::kSafeBrowsingExtendedReportingOptInAllowed, false); 891 prefs::kSafeBrowsingExtendedReportingOptInAllowed, false);
894 892
895 TestReportingDisabledAndDontProceed( 893 TestReportingDisabledAndDontProceed(
896 net::URLRequestMockHTTPJob::GetMockUrl(kEmptyPage)); 894 net::URLRequestMockHTTPJob::GetMockUrl(kEmptyPage));
897 } 895 }
898 896
899 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, LearnMore) { 897 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, LearnMore) {
900 SetupWarningAndNavigate(); 898 SetupWarningAndNavigate();
901 EXPECT_TRUE(ClickAndWaitForDetach("learn-more-link")); 899 EXPECT_TRUE(ClickAndWaitForDetach("learn-more-link"));
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 1151
1154 INSTANTIATE_TEST_CASE_P( 1152 INSTANTIATE_TEST_CASE_P(
1155 SafeBrowsingBlockingPageIDNTestWithThreatType, 1153 SafeBrowsingBlockingPageIDNTestWithThreatType,
1156 SafeBrowsingBlockingPageIDNTest, 1154 SafeBrowsingBlockingPageIDNTest,
1157 testing::Combine(testing::Values(false, true), 1155 testing::Combine(testing::Values(false, true),
1158 testing::Values(SB_THREAT_TYPE_URL_MALWARE, 1156 testing::Values(SB_THREAT_TYPE_URL_MALWARE,
1159 SB_THREAT_TYPE_URL_PHISHING, 1157 SB_THREAT_TYPE_URL_PHISHING,
1160 SB_THREAT_TYPE_URL_UNWANTED))); 1158 SB_THREAT_TYPE_URL_UNWANTED)));
1161 1159
1162 } // namespace safe_browsing 1160 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698