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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 #include "net/test/embedded_test_server/embedded_test_server.h" | 60 #include "net/test/embedded_test_server/embedded_test_server.h" |
61 #include "net/test/url_request/url_request_mock_http_job.h" | 61 #include "net/test/url_request/url_request_mock_http_job.h" |
62 #include "ui/base/l10n/l10n_util.h" | 62 #include "ui/base/l10n/l10n_util.h" |
63 | 63 |
64 using chrome_browser_interstitials::SecurityInterstitialIDNTest; | 64 using chrome_browser_interstitials::SecurityInterstitialIDNTest; |
65 using content::BrowserThread; | 65 using content::BrowserThread; |
66 using content::InterstitialPage; | 66 using content::InterstitialPage; |
67 using content::NavigationController; | 67 using content::NavigationController; |
68 using content::RenderFrameHost; | 68 using content::RenderFrameHost; |
69 using content::WebContents; | 69 using content::WebContents; |
| 70 using security_interstitials::SafeBrowsingErrorUI; |
70 | 71 |
71 namespace safe_browsing { | 72 namespace safe_browsing { |
72 | 73 |
73 namespace { | 74 namespace { |
74 | 75 |
75 const char kEmptyPage[] = "empty.html"; | 76 const char kEmptyPage[] = "empty.html"; |
76 const char kHTTPSPage[] = "/ssl/google.html"; | 77 const char kHTTPSPage[] = "/ssl/google.html"; |
77 const char kMaliciousPage[] = "safe_browsing/malware.html"; | 78 const char kMaliciousPage[] = "safe_browsing/malware.html"; |
78 const char kCrossSiteMaliciousPage[] = "safe_browsing/malware2.html"; | 79 const char kCrossSiteMaliciousPage[] = "safe_browsing/malware2.html"; |
79 const char kMaliciousIframe[] = "safe_browsing/malware_iframe.html"; | 80 const char kMaliciousIframe[] = "safe_browsing/malware_iframe.html"; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 }; | 206 }; |
206 | 207 |
207 } // namespace | 208 } // namespace |
208 | 209 |
209 class TestThreatDetailsFactory : public ThreatDetailsFactory { | 210 class TestThreatDetailsFactory : public ThreatDetailsFactory { |
210 public: | 211 public: |
211 TestThreatDetailsFactory() : details_() {} | 212 TestThreatDetailsFactory() : details_() {} |
212 ~TestThreatDetailsFactory() override {} | 213 ~TestThreatDetailsFactory() override {} |
213 | 214 |
214 ThreatDetails* CreateThreatDetails( | 215 ThreatDetails* CreateThreatDetails( |
215 SafeBrowsingUIManager* delegate, | 216 BaseUIManager* delegate, |
216 WebContents* web_contents, | 217 WebContents* web_contents, |
217 const security_interstitials::UnsafeResource& unsafe_resource) override { | 218 const security_interstitials::UnsafeResource& unsafe_resource) override { |
218 details_ = new ThreatDetails(delegate, web_contents, unsafe_resource); | 219 details_ = new ThreatDetails(delegate, web_contents, unsafe_resource); |
219 return details_; | 220 return details_; |
220 } | 221 } |
221 | 222 |
222 ThreatDetails* get_details() { return details_; } | 223 ThreatDetails* get_details() { return details_; } |
223 | 224 |
224 private: | 225 private: |
225 ThreatDetails* details_; | 226 ThreatDetails* details_; |
226 }; | 227 }; |
227 | 228 |
228 // A SafeBrowingBlockingPage class that lets us wait until it's hidden. | 229 // A SafeBrowingBlockingPage class that lets us wait until it's hidden. |
229 class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPage { | 230 class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPage { |
230 public: | 231 public: |
231 TestSafeBrowsingBlockingPage(SafeBrowsingUIManager* manager, | 232 TestSafeBrowsingBlockingPage( |
232 WebContents* web_contents, | 233 BaseUIManager* manager, |
233 const GURL& main_frame_url, | 234 WebContents* web_contents, |
234 const UnsafeResourceList& unsafe_resources) | 235 const GURL& main_frame_url, |
| 236 const UnsafeResourceList& unsafe_resources, |
| 237 const SafeBrowsingErrorUI::SBErrorDisplayOptions& display_options) |
235 : SafeBrowsingBlockingPage(manager, | 238 : SafeBrowsingBlockingPage(manager, |
236 web_contents, | 239 web_contents, |
237 main_frame_url, | 240 main_frame_url, |
238 unsafe_resources), | 241 unsafe_resources, |
| 242 display_options), |
239 wait_for_delete_(false) { | 243 wait_for_delete_(false) { |
240 // Don't wait the whole 3 seconds for the browser test. | 244 // Don't wait the whole 3 seconds for the browser test. |
241 threat_details_proceed_delay_ms_ = 100; | 245 threat_details_proceed_delay_ms_ = 100; |
242 } | 246 } |
243 | 247 |
244 ~TestSafeBrowsingBlockingPage() override { | 248 ~TestSafeBrowsingBlockingPage() override { |
245 if (!wait_for_delete_) | 249 if (!wait_for_delete_) |
246 return; | 250 return; |
247 | 251 |
248 // Notify that we are gone | 252 // Notify that we are gone |
(...skipping 17 matching lines...) Expand all Loading... |
266 bool wait_for_delete_; | 270 bool wait_for_delete_; |
267 }; | 271 }; |
268 | 272 |
269 class TestSafeBrowsingBlockingPageFactory | 273 class TestSafeBrowsingBlockingPageFactory |
270 : public SafeBrowsingBlockingPageFactory { | 274 : public SafeBrowsingBlockingPageFactory { |
271 public: | 275 public: |
272 TestSafeBrowsingBlockingPageFactory() { } | 276 TestSafeBrowsingBlockingPageFactory() { } |
273 ~TestSafeBrowsingBlockingPageFactory() override {} | 277 ~TestSafeBrowsingBlockingPageFactory() override {} |
274 | 278 |
275 SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 279 SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
276 SafeBrowsingUIManager* delegate, | 280 BaseUIManager* delegate, |
277 WebContents* web_contents, | 281 WebContents* web_contents, |
278 const GURL& main_frame_url, | 282 const GURL& main_frame_url, |
279 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) | 283 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) |
280 override { | 284 override { |
| 285 PrefService* prefs = |
| 286 Profile::FromBrowserContext(web_contents->GetBrowserContext()) |
| 287 ->GetPrefs(); |
| 288 bool is_extended_reporting_opt_in_allowed = |
| 289 prefs->GetBoolean(prefs::kSafeBrowsingExtendedReportingOptInAllowed); |
| 290 bool is_proceed_anyway_disabled = |
| 291 prefs->GetBoolean(prefs::kSafeBrowsingProceedAnywayDisabled); |
| 292 SafeBrowsingErrorUI::SBErrorDisplayOptions display_options( |
| 293 BaseBlockingPage::IsMainPageLoadBlocked(unsafe_resources), |
| 294 is_extended_reporting_opt_in_allowed, |
| 295 web_contents->GetBrowserContext()->IsOffTheRecord(), |
| 296 IsExtendedReportingEnabled(*prefs), IsScout(*prefs), |
| 297 is_proceed_anyway_disabled); |
281 return new TestSafeBrowsingBlockingPage(delegate, web_contents, | 298 return new TestSafeBrowsingBlockingPage(delegate, web_contents, |
282 main_frame_url, unsafe_resources); | 299 main_frame_url, unsafe_resources, |
| 300 display_options); |
283 } | 301 } |
284 }; | 302 }; |
285 | 303 |
286 // Tests the safe browsing blocking page in a browser. | 304 // Tests the safe browsing blocking page in a browser. |
287 class SafeBrowsingBlockingPageBrowserTest | 305 class SafeBrowsingBlockingPageBrowserTest |
288 : public CertVerifierBrowserTest, | 306 : public CertVerifierBrowserTest, |
289 public testing::WithParamInterface<testing::tuple<SBThreatType, bool>> { | 307 public testing::WithParamInterface<testing::tuple<SBThreatType, bool>> { |
290 public: | 308 public: |
291 enum Visibility { | 309 enum Visibility { |
292 VISIBILITY_ERROR = -1, | 310 VISIBILITY_ERROR = -1, |
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 | 1379 |
1362 INSTANTIATE_TEST_CASE_P( | 1380 INSTANTIATE_TEST_CASE_P( |
1363 SafeBrowsingBlockingPageIDNTestWithThreatType, | 1381 SafeBrowsingBlockingPageIDNTestWithThreatType, |
1364 SafeBrowsingBlockingPageIDNTest, | 1382 SafeBrowsingBlockingPageIDNTest, |
1365 testing::Combine(testing::Values(false, true), | 1383 testing::Combine(testing::Values(false, true), |
1366 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 1384 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
1367 SB_THREAT_TYPE_URL_PHISHING, | 1385 SB_THREAT_TYPE_URL_PHISHING, |
1368 SB_THREAT_TYPE_URL_UNWANTED))); | 1386 SB_THREAT_TYPE_URL_UNWANTED))); |
1369 | 1387 |
1370 } // namespace safe_browsing | 1388 } // namespace safe_browsing |
OLD | NEW |