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 "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "content/public/test/test_browser_thread.h" | 45 #include "content/public/test/test_browser_thread.h" |
46 #include "content/public/test/test_utils.h" | 46 #include "content/public/test/test_utils.h" |
47 #include "net/test/url_request/url_request_mock_http_job.h" | 47 #include "net/test/url_request/url_request_mock_http_job.h" |
48 | 48 |
49 using chrome_browser_interstitials::SecurityInterstitialIDNTest; | 49 using chrome_browser_interstitials::SecurityInterstitialIDNTest; |
50 using content::BrowserThread; | 50 using content::BrowserThread; |
51 using content::InterstitialPage; | 51 using content::InterstitialPage; |
52 using content::NavigationController; | 52 using content::NavigationController; |
53 using content::WebContents; | 53 using content::WebContents; |
54 | 54 |
| 55 namespace safe_browsing { |
| 56 |
55 namespace { | 57 namespace { |
56 | 58 |
57 const char kEmptyPage[] = "empty.html"; | 59 const char kEmptyPage[] = "empty.html"; |
58 const char kMalwarePage[] = "safe_browsing/malware.html"; | 60 const char kMalwarePage[] = "safe_browsing/malware.html"; |
59 const char kMalwareIframe[] = "safe_browsing/malware_iframe.html"; | 61 const char kMalwareIframe[] = "safe_browsing/malware_iframe.html"; |
60 const char kUnrelatedUrl[] = "https://www.google.com"; | 62 const char kUnrelatedUrl[] = "https://www.google.com"; |
61 | 63 |
62 // A SafeBrowsingDatabaseManager class that allows us to inject the malicious | 64 // A SafeBrowsingDatabaseManager class that allows us to inject the malicious |
63 // URLs. | 65 // URLs. |
64 class FakeSafeBrowsingDatabaseManager : public TestSafeBrowsingDatabaseManager { | 66 class FakeSafeBrowsingDatabaseManager : public TestSafeBrowsingDatabaseManager { |
(...skipping 20 matching lines...) Expand all Loading... |
85 std::vector<SBThreatType> expected_threats; | 87 std::vector<SBThreatType> expected_threats; |
86 // TODO(nparker): Remove ref to LocalSafeBrowsingDatabase by calling | 88 // TODO(nparker): Remove ref to LocalSafeBrowsingDatabase by calling |
87 // client->OnCheckBrowseUrlResult(..) directly. | 89 // client->OnCheckBrowseUrlResult(..) directly. |
88 expected_threats.push_back(SB_THREAT_TYPE_URL_MALWARE); | 90 expected_threats.push_back(SB_THREAT_TYPE_URL_MALWARE); |
89 expected_threats.push_back(SB_THREAT_TYPE_URL_PHISHING); | 91 expected_threats.push_back(SB_THREAT_TYPE_URL_PHISHING); |
90 expected_threats.push_back(SB_THREAT_TYPE_URL_UNWANTED); | 92 expected_threats.push_back(SB_THREAT_TYPE_URL_UNWANTED); |
91 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck sb_check( | 93 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck sb_check( |
92 std::vector<GURL>(1, gurl), | 94 std::vector<GURL>(1, gurl), |
93 std::vector<SBFullHash>(), | 95 std::vector<SBFullHash>(), |
94 client, | 96 client, |
95 safe_browsing::MALWARE, | 97 MALWARE, |
96 expected_threats); | 98 expected_threats); |
97 sb_check.url_results[0] = badurls[gurl.spec()]; | 99 sb_check.url_results[0] = badurls[gurl.spec()]; |
98 sb_check.OnSafeBrowsingResult(); | 100 sb_check.OnSafeBrowsingResult(); |
99 } | 101 } |
100 | 102 |
101 void SetURLThreatType(const GURL& url, SBThreatType threat_type) { | 103 void SetURLThreatType(const GURL& url, SBThreatType threat_type) { |
102 badurls[url.spec()] = threat_type; | 104 badurls[url.spec()] = threat_type; |
103 } | 105 } |
104 | 106 |
105 // These are called when checking URLs, so we implement them. | 107 // These are called when checking URLs, so we implement them. |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 AssertNoInterstitial(true); // Assert the interstitial is gone | 740 AssertNoInterstitial(true); // Assert the interstitial is gone |
739 | 741 |
740 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( | 742 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( |
741 prefs::kSafeBrowsingExtendedReportingEnabled)); | 743 prefs::kSafeBrowsingExtendedReportingEnabled)); |
742 EXPECT_EQ(url, | 744 EXPECT_EQ(url, |
743 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); | 745 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); |
744 | 746 |
745 if (expect_threat_details) { | 747 if (expect_threat_details) { |
746 threat_report_sent_runner->Run(); | 748 threat_report_sent_runner->Run(); |
747 std::string serialized = GetReportSent(); | 749 std::string serialized = GetReportSent(); |
748 safe_browsing::ClientSafeBrowsingReportRequest report; | 750 ClientSafeBrowsingReportRequest report; |
749 ASSERT_TRUE(report.ParseFromString(serialized)); | 751 ASSERT_TRUE(report.ParseFromString(serialized)); |
750 // Verify the report is complete. | 752 // Verify the report is complete. |
751 EXPECT_TRUE(report.complete()); | 753 EXPECT_TRUE(report.complete()); |
752 } | 754 } |
753 } | 755 } |
754 | 756 |
755 // Verifies that the "proceed anyway" link isn't available when it is disabled | 757 // Verifies that the "proceed anyway" link isn't available when it is disabled |
756 // by the corresponding policy. Also verifies that sending the "proceed" | 758 // by the corresponding policy. Also verifies that sending the "proceed" |
757 // command anyway doesn't advance to the unsafe site. | 759 // command anyway doesn't advance to the unsafe site. |
758 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, ProceedDisabled) { | 760 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, ProceedDisabled) { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageIDNTest, | 1019 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageIDNTest, |
1018 SafeBrowsingBlockingPageDecodesIDN) { | 1020 SafeBrowsingBlockingPageDecodesIDN) { |
1019 EXPECT_TRUE(VerifyIDNDecoded()); | 1021 EXPECT_TRUE(VerifyIDNDecoded()); |
1020 } | 1022 } |
1021 | 1023 |
1022 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageIDNTestWithThreatType, | 1024 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageIDNTestWithThreatType, |
1023 SafeBrowsingBlockingPageIDNTest, | 1025 SafeBrowsingBlockingPageIDNTest, |
1024 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 1026 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
1025 SB_THREAT_TYPE_URL_PHISHING, | 1027 SB_THREAT_TYPE_URL_PHISHING, |
1026 SB_THREAT_TYPE_URL_UNWANTED)); | 1028 SB_THREAT_TYPE_URL_UNWANTED)); |
| 1029 |
| 1030 } // namespace safe_browsing |
OLD | NEW |