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" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/string_number_conversions.h" | |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/safe_browsing/database_manager.h" | 17 #include "chrome/browser/safe_browsing/database_manager.h" |
17 #include "chrome/browser/safe_browsing/malware_details.h" | 18 #include "chrome/browser/safe_browsing/malware_details.h" |
18 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 19 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
20 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 21 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
21 #include "chrome/browser/safe_browsing/ui_manager.h" | 22 #include "chrome/browser/safe_browsing/ui_manager.h" |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 GURL SetupThreatIframeWarningAndNavigate() { | 394 GURL SetupThreatIframeWarningAndNavigate() { |
394 GURL url = test_server()->GetURL(kMalwarePage); | 395 GURL url = test_server()->GetURL(kMalwarePage); |
395 GURL iframe_url = test_server()->GetURL(kMalwareIframe); | 396 GURL iframe_url = test_server()->GetURL(kMalwareIframe); |
396 SetURLThreatType(iframe_url, GetParam()); | 397 SetURLThreatType(iframe_url, GetParam()); |
397 | 398 |
398 ui_test_utils::NavigateToURL(browser(), url); | 399 ui_test_utils::NavigateToURL(browser(), url); |
399 EXPECT_TRUE(WaitForReady()); | 400 EXPECT_TRUE(WaitForReady()); |
400 return url; | 401 return url; |
401 } | 402 } |
402 | 403 |
403 void SendCommand(const std::string& command) { | 404 void SendCommand(int command) { |
Bernhard Bauer
2015/03/11 08:42:14
You could use the enum type here, and then maybe t
felt
2015/03/11 15:25:09
Done.
| |
404 WebContents* contents = | 405 WebContents* contents = |
405 browser()->tab_strip_model()->GetActiveWebContents(); | 406 browser()->tab_strip_model()->GetActiveWebContents(); |
406 // We use InterstitialPage::GetInterstitialPage(tab) instead of | 407 // We use InterstitialPage::GetInterstitialPage(tab) instead of |
407 // tab->GetInterstitialPage() because the tab doesn't have a pointer | 408 // tab->GetInterstitialPage() because the tab doesn't have a pointer |
408 // to its interstital page until it gets a command from the renderer | 409 // to its interstital page until it gets a command from the renderer |
409 // that it has indeed displayed it -- and this sometimes happens after | 410 // that it has indeed displayed it -- and this sometimes happens after |
410 // NavigateToURL returns. | 411 // NavigateToURL returns. |
411 SafeBrowsingBlockingPage* interstitial_page = | 412 SafeBrowsingBlockingPage* interstitial_page = |
412 static_cast<SafeBrowsingBlockingPage*>( | 413 static_cast<SafeBrowsingBlockingPage*>( |
413 InterstitialPage::GetInterstitialPage(contents)-> | 414 InterstitialPage::GetInterstitialPage(contents)-> |
414 GetDelegateForTesting()); | 415 GetDelegateForTesting()); |
415 ASSERT_TRUE(interstitial_page); | 416 ASSERT_TRUE(interstitial_page); |
416 ASSERT_EQ(SafeBrowsingBlockingPage::kTypeForTesting, | 417 ASSERT_EQ(SafeBrowsingBlockingPage::kTypeForTesting, |
417 interstitial_page->GetTypeForTesting()); | 418 interstitial_page->GetTypeForTesting()); |
418 interstitial_page->CommandReceived(command); | 419 interstitial_page->CommandReceived(base::IntToString(command)); |
419 } | 420 } |
420 | 421 |
421 void DontProceedThroughInterstitial() { | 422 void DontProceedThroughInterstitial() { |
422 WebContents* contents = | 423 WebContents* contents = |
423 browser()->tab_strip_model()->GetActiveWebContents(); | 424 browser()->tab_strip_model()->GetActiveWebContents(); |
424 InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage( | 425 InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage( |
425 contents); | 426 contents); |
426 ASSERT_TRUE(interstitial_page); | 427 ASSERT_TRUE(interstitial_page); |
427 interstitial_page->DontProceed(); | 428 interstitial_page->DontProceed(); |
428 } | 429 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 content::WaitForInterstitialAttach(contents); | 494 content::WaitForInterstitialAttach(contents); |
494 // Cancel the redirect request while interstitial page is open. | 495 // Cancel the redirect request while interstitial page is open. |
495 browser()->tab_strip_model()->ActivateTabAt(0, true); | 496 browser()->tab_strip_model()->ActivateTabAt(0, true); |
496 ui_test_utils::NavigateToURL(browser(), GURL("javascript:stopWin()")); | 497 ui_test_utils::NavigateToURL(browser(), GURL("javascript:stopWin()")); |
497 browser()->tab_strip_model()->ActivateTabAt(1, true); | 498 browser()->tab_strip_model()->ActivateTabAt(1, true); |
498 // Simulate the user clicking "proceed", there should be no crash. Since | 499 // Simulate the user clicking "proceed", there should be no crash. Since |
499 // clicking proceed may do nothing (see comment in RedirectCanceled | 500 // clicking proceed may do nothing (see comment in RedirectCanceled |
500 // below, and crbug.com/76460), we use SendCommand to trigger the callback | 501 // below, and crbug.com/76460), we use SendCommand to trigger the callback |
501 // directly rather than using ClickAndWaitForDetach since there might not | 502 // directly rather than using ClickAndWaitForDetach since there might not |
502 // be a notification to wait for. | 503 // be a notification to wait for. |
503 SendCommand("\"proceed\""); | 504 SendCommand(SecurityInterstitialPage::CMD_PROCEED); |
504 } | 505 } |
505 | 506 |
506 content::RenderViewHost* GetRenderViewHost() { | 507 content::RenderViewHost* GetRenderViewHost() { |
507 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage( | 508 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage( |
508 browser()->tab_strip_model()->GetActiveWebContents()); | 509 browser()->tab_strip_model()->GetActiveWebContents()); |
509 if (!interstitial) | 510 if (!interstitial) |
510 return NULL; | 511 return NULL; |
511 return interstitial->GetMainFrame()->GetRenderViewHost(); | 512 return interstitial->GetMainFrame()->GetRenderViewHost(); |
512 } | 513 } |
513 | 514 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
725 | 726 |
726 SetupWarningAndNavigate(); | 727 SetupWarningAndNavigate(); |
727 | 728 |
728 EXPECT_EQ(VISIBLE, GetVisibility("primary-button")); | 729 EXPECT_EQ(VISIBLE, GetVisibility("primary-button")); |
729 EXPECT_EQ(HIDDEN, GetVisibility("details")); | 730 EXPECT_EQ(HIDDEN, GetVisibility("details")); |
730 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); | 731 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); |
731 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph")); | 732 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph")); |
732 EXPECT_TRUE(Click("details-button")); | 733 EXPECT_TRUE(Click("details-button")); |
733 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); | 734 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); |
734 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph")); | 735 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph")); |
735 SendCommand("proceed"); | 736 SendCommand(SecurityInterstitialPage::CMD_PROCEED); |
736 | 737 |
737 // The "proceed" command should go back instead, if proceeding is disabled. | 738 // The "proceed" command should go back instead, if proceeding is disabled. |
738 AssertNoInterstitial(true); | 739 AssertNoInterstitial(true); |
739 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank" | 740 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank" |
740 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); | 741 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); |
741 } | 742 } |
742 | 743 |
743 // Verifies that the reporting checkbox is hidden on non-HTTP pages. | 744 // Verifies that the reporting checkbox is hidden on non-HTTP pages. |
744 // TODO(mattm): Should also verify that no report is sent, but there isn't a | 745 // TODO(mattm): Should also verify that no report is sent, but there isn't a |
745 // good way to do that in the current design. | 746 // good way to do that in the current design. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
787 ? "/transparencyreport/safebrowsing/" | 788 ? "/transparencyreport/safebrowsing/" |
788 : "/safebrowsing/diagnostic", | 789 : "/safebrowsing/diagnostic", |
789 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); | 790 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); |
790 } | 791 } |
791 | 792 |
792 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageBrowserTestWithThreatType, | 793 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageBrowserTestWithThreatType, |
793 SafeBrowsingBlockingPageBrowserTest, | 794 SafeBrowsingBlockingPageBrowserTest, |
794 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 795 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
795 SB_THREAT_TYPE_URL_PHISHING, | 796 SB_THREAT_TYPE_URL_PHISHING, |
796 SB_THREAT_TYPE_URL_UNWANTED)); | 797 SB_THREAT_TYPE_URL_UNWANTED)); |
OLD | NEW |