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

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

Issue 2831583006: Fix incorrect |main_frame_url_| parameter to BaseBlockingPage (Closed)
Patch Set: Created 3 years, 8 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 using security_interstitials::SafeBrowsingErrorUI; 71 using security_interstitials::SafeBrowsingErrorUI;
72 72
73 namespace safe_browsing { 73 namespace safe_browsing {
74 74
75 namespace { 75 namespace {
76 76
77 const char kEmptyPage[] = "empty.html"; 77 const char kEmptyPage[] = "empty.html";
78 const char kHTTPSPage[] = "/ssl/google.html"; 78 const char kHTTPSPage[] = "/ssl/google.html";
79 const char kMaliciousPage[] = "safe_browsing/malware.html"; 79 const char kMaliciousPage[] = "safe_browsing/malware.html";
80 const char kCrossSiteMaliciousPage[] = "safe_browsing/malware2.html"; 80 const char kCrossSiteMaliciousPage[] = "safe_browsing/malware2.html";
81 const char kPageWithCrossOriginMaliciousIframe[] =
82 "safe_browsing/malware3.html";
83 const char kCrossOriginMaliciousIframeHost[] = "malware.test";
81 const char kMaliciousIframe[] = "safe_browsing/malware_iframe.html"; 84 const char kMaliciousIframe[] = "safe_browsing/malware_iframe.html";
82 const char kUnrelatedUrl[] = "https://www.google.com"; 85 const char kUnrelatedUrl[] = "https://www.google.com";
83 86
84 // A SafeBrowsingDatabaseManager class that allows us to inject the malicious 87 // A SafeBrowsingDatabaseManager class that allows us to inject the malicious
85 // URLs. 88 // URLs.
86 class FakeSafeBrowsingDatabaseManager : public TestSafeBrowsingDatabaseManager { 89 class FakeSafeBrowsingDatabaseManager : public TestSafeBrowsingDatabaseManager {
87 public: 90 public:
88 FakeSafeBrowsingDatabaseManager() {} 91 FakeSafeBrowsingDatabaseManager() {}
89 92
90 // Called on the IO thread to check if the given url is safe or not. If we 93 // Called on the IO thread to check if the given url is safe or not. If we
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 GURL SetupThreatIframeWarningAndNavigate() { 426 GURL SetupThreatIframeWarningAndNavigate() {
424 GURL url = net::URLRequestMockHTTPJob::GetMockUrl(kCrossSiteMaliciousPage); 427 GURL url = net::URLRequestMockHTTPJob::GetMockUrl(kCrossSiteMaliciousPage);
425 GURL iframe_url = net::URLRequestMockHTTPJob::GetMockUrl(kMaliciousIframe); 428 GURL iframe_url = net::URLRequestMockHTTPJob::GetMockUrl(kMaliciousIframe);
426 SetURLThreatType(iframe_url, testing::get<0>(GetParam())); 429 SetURLThreatType(iframe_url, testing::get<0>(GetParam()));
427 430
428 ui_test_utils::NavigateToURL(browser(), url); 431 ui_test_utils::NavigateToURL(browser(), url);
429 EXPECT_TRUE(WaitForReady()); 432 EXPECT_TRUE(WaitForReady());
430 return url; 433 return url;
431 } 434 }
432 435
436 // Adds a safebrowsing threat results to the fake safebrowsing service, and
437 // navigates to a page with a cross-origin iframe containing the threat site.
438 // Returns the url of the parent page and sets |iframe_url| to the malicious
439 // cross-origin iframe.
440 GURL SetupCrossOriginThreatIframeWarningAndNavigate(GURL* iframe_url) {
441 content::SetupCrossSiteRedirector(embedded_test_server());
442 EXPECT_TRUE(embedded_test_server()->Start());
443 GURL url = embedded_test_server()->GetURL(
444 std::string("/") + kPageWithCrossOriginMaliciousIframe);
445 *iframe_url =
446 embedded_test_server()->GetURL(std::string("/") + kMaliciousIframe);
447 GURL::Replacements replace_host;
448 replace_host.SetHostStr(kCrossOriginMaliciousIframeHost);
449 *iframe_url = iframe_url->ReplaceComponents(replace_host);
450 SetURLThreatType(*iframe_url, testing::get<0>(GetParam()));
451
452 ui_test_utils::NavigateToURL(browser(), url);
453 EXPECT_TRUE(WaitForReady());
454 return url;
455 }
456
433 void SendCommand( 457 void SendCommand(
434 security_interstitials::SecurityInterstitialCommands command) { 458 security_interstitials::SecurityInterstitialCommands command) {
435 WebContents* contents = 459 WebContents* contents =
436 browser()->tab_strip_model()->GetActiveWebContents(); 460 browser()->tab_strip_model()->GetActiveWebContents();
437 // We use InterstitialPage::GetInterstitialPage(tab) instead of 461 // We use InterstitialPage::GetInterstitialPage(tab) instead of
438 // tab->GetInterstitialPage() because the tab doesn't have a pointer 462 // tab->GetInterstitialPage() because the tab doesn't have a pointer
439 // to its interstital page until it gets a command from the renderer 463 // to its interstital page until it gets a command from the renderer
440 // that it has indeed displayed it -- and this sometimes happens after 464 // that it has indeed displayed it -- and this sometimes happens after
441 // NavigateToURL returns. 465 // NavigateToURL returns.
442 SafeBrowsingBlockingPage* interstitial_page = 466 SafeBrowsingBlockingPage* interstitial_page =
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 // Test that the security indicator does not stay downgraded after 1312 // Test that the security indicator does not stay downgraded after
1289 // clicking back from a Safe Browsing interstitial triggered by a 1313 // clicking back from a Safe Browsing interstitial triggered by a
1290 // subresource. Regression test for https://crbug.com/659709. 1314 // subresource. Regression test for https://crbug.com/659709.
1291 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, 1315 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
1292 SecurityStateGoBackOnSubresourceInterstitial) { 1316 SecurityStateGoBackOnSubresourceInterstitial) {
1293 // Navigate to a page so that there is somewhere to go back to. 1317 // Navigate to a page so that there is somewhere to go back to.
1294 GURL start_url = 1318 GURL start_url =
1295 net::URLRequestMockHTTPJob::GetMockUrl("http://example.test"); 1319 net::URLRequestMockHTTPJob::GetMockUrl("http://example.test");
1296 ui_test_utils::NavigateToURL(browser(), start_url); 1320 ui_test_utils::NavigateToURL(browser(), start_url);
1297 1321
1298 // The security indicator should be downgraded while the interstitial shows. 1322 // The security indicator should be downgraded while the interstitial
1299 SetupThreatIframeWarningAndNavigate(); 1323 // shows. Load a cross-origin iframe to be sure that the main frame origin
1324 // (rather than the subresource origin) is being added and removed from the
1325 // whitelist; this is a regression test for https://crbug.com/710955.
1326 GURL bad_iframe_url;
1327 GURL main_url =
1328 SetupCrossOriginThreatIframeWarningAndNavigate(&bad_iframe_url);
1300 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); 1329 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents();
1301 ASSERT_TRUE(error_tab); 1330 ASSERT_TRUE(error_tab);
1302 ExpectSecurityIndicatorDowngrade(error_tab, 0u); 1331 ExpectSecurityIndicatorDowngrade(error_tab, 0u);
1303 1332
1304 // Go back. 1333 // Go back.
1305 EXPECT_EQ(VISIBLE, GetVisibility("primary-button")); 1334 EXPECT_EQ(VISIBLE, GetVisibility("primary-button"));
1306 EXPECT_EQ(HIDDEN, GetVisibility("details")); 1335 EXPECT_EQ(HIDDEN, GetVisibility("details"));
1307 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); 1336 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link"));
1308 EXPECT_EQ(HIDDEN, GetVisibility("error-code")); 1337 EXPECT_EQ(HIDDEN, GetVisibility("error-code"));
1309 EXPECT_TRUE(Click("details-button")); 1338 EXPECT_TRUE(Click("details-button"));
1310 EXPECT_EQ(VISIBLE, GetVisibility("details")); 1339 EXPECT_EQ(VISIBLE, GetVisibility("details"));
1311 EXPECT_EQ(VISIBLE, GetVisibility("proceed-link")); 1340 EXPECT_EQ(VISIBLE, GetVisibility("proceed-link"));
1312 EXPECT_EQ(HIDDEN, GetVisibility("error-code")); 1341 EXPECT_EQ(HIDDEN, GetVisibility("error-code"));
1313 EXPECT_TRUE(ClickAndWaitForDetach("primary-button")); 1342 EXPECT_TRUE(ClickAndWaitForDetach("primary-button"));
1314 1343
1315 // The security indicator should *not* still be downgraded after going back. 1344 // The security indicator should *not* still be downgraded after going back.
1316 AssertNoInterstitial(true); 1345 AssertNoInterstitial(true);
1317 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); 1346 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents();
1318 ASSERT_TRUE(post_tab); 1347 ASSERT_TRUE(post_tab);
1319 content::NavigationEntry* entry = post_tab->GetController().GetVisibleEntry(); 1348 content::NavigationEntry* entry = post_tab->GetController().GetVisibleEntry();
1320 ASSERT_TRUE(entry); 1349 ASSERT_TRUE(entry);
1321 EXPECT_EQ(start_url, entry->GetURL()); 1350 EXPECT_EQ(start_url, entry->GetURL());
1322 ExpectNoSecurityIndicatorDowngrade(post_tab); 1351 ExpectNoSecurityIndicatorDowngrade(post_tab);
1352
1353 // Clear the malicious subresource URL, and check that the hostname of the
1354 // interstitial is no longer marked as Dangerous.
1355 ClearBadURL(bad_iframe_url);
1356 ui_test_utils::NavigateToURL(browser(), main_url);
1357 ExpectNoSecurityIndicatorDowngrade(
1358 browser()->tab_strip_model()->GetActiveWebContents());
1323 } 1359 }
1324 1360
1325 // Test that the security indicator is downgraded after clicking through a 1361 // Test that the security indicator is downgraded after clicking through a
1326 // Safe Browsing interstitial. 1362 // Safe Browsing interstitial.
1327 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, 1363 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
1328 SecurityState_HTTP) { 1364 SecurityState_HTTP) {
1329 // The security indicator should be downgraded while the interstitial shows. 1365 // The security indicator should be downgraded while the interstitial shows.
1330 SetupWarningAndNavigate(); 1366 SetupWarningAndNavigate();
1331 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); 1367 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents();
1332 ASSERT_TRUE(error_tab); 1368 ASSERT_TRUE(error_tab);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 1473
1438 INSTANTIATE_TEST_CASE_P( 1474 INSTANTIATE_TEST_CASE_P(
1439 SafeBrowsingBlockingPageIDNTestWithThreatType, 1475 SafeBrowsingBlockingPageIDNTestWithThreatType,
1440 SafeBrowsingBlockingPageIDNTest, 1476 SafeBrowsingBlockingPageIDNTest,
1441 testing::Combine(testing::Values(false, true), 1477 testing::Combine(testing::Values(false, true),
1442 testing::Values(SB_THREAT_TYPE_URL_MALWARE, 1478 testing::Values(SB_THREAT_TYPE_URL_MALWARE,
1443 SB_THREAT_TYPE_URL_PHISHING, 1479 SB_THREAT_TYPE_URL_PHISHING,
1444 SB_THREAT_TYPE_URL_UNWANTED))); 1480 SB_THREAT_TYPE_URL_UNWANTED)));
1445 1481
1446 } // namespace safe_browsing 1482 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page.cc ('k') | chrome/test/data/safe_browsing/malware3.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698