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 15 matching lines...) Expand all Loading... |
26 #include "chrome/browser/safe_browsing/threat_details.h" | 26 #include "chrome/browser/safe_browsing/threat_details.h" |
27 #include "chrome/browser/safe_browsing/ui_manager.h" | 27 #include "chrome/browser/safe_browsing/ui_manager.h" |
28 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
29 #include "chrome/browser/ui/browser_tabstrip.h" | 29 #include "chrome/browser/ui/browser_tabstrip.h" |
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 30 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
32 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
33 #include "chrome/test/base/in_process_browser_test.h" | 33 #include "chrome/test/base/in_process_browser_test.h" |
34 #include "chrome/test/base/test_switches.h" | 34 #include "chrome/test/base/test_switches.h" |
35 #include "chrome/test/base/ui_test_utils.h" | 35 #include "chrome/test/base/ui_test_utils.h" |
| 36 #include "components/security_interstitials/core/controller_client.h" |
36 #include "components/security_interstitials/core/metrics_helper.h" | 37 #include "components/security_interstitials/core/metrics_helper.h" |
37 #include "content/public/browser/interstitial_page.h" | 38 #include "content/public/browser/interstitial_page.h" |
38 #include "content/public/browser/navigation_controller.h" | 39 #include "content/public/browser/navigation_controller.h" |
39 #include "content/public/browser/notification_types.h" | 40 #include "content/public/browser/notification_types.h" |
40 #include "content/public/browser/render_frame_host.h" | 41 #include "content/public/browser/render_frame_host.h" |
41 #include "content/public/browser/render_process_host.h" | 42 #include "content/public/browser/render_process_host.h" |
42 #include "content/public/browser/render_view_host.h" | 43 #include "content/public/browser/render_view_host.h" |
43 #include "content/public/browser/web_contents.h" | 44 #include "content/public/browser/web_contents.h" |
44 #include "content/public/test/browser_test_utils.h" | 45 #include "content/public/test/browser_test_utils.h" |
45 #include "content/public/test/test_browser_thread.h" | 46 #include "content/public/test/test_browser_thread.h" |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 GURL url = net::URLRequestMockHTTPJob::GetMockUrl(kMalwarePage); | 423 GURL url = net::URLRequestMockHTTPJob::GetMockUrl(kMalwarePage); |
423 GURL iframe_url = net::URLRequestMockHTTPJob::GetMockUrl(kMalwareIframe); | 424 GURL iframe_url = net::URLRequestMockHTTPJob::GetMockUrl(kMalwareIframe); |
424 SetURLThreatType(iframe_url, GetParam()); | 425 SetURLThreatType(iframe_url, GetParam()); |
425 | 426 |
426 ui_test_utils::NavigateToURL(browser(), url); | 427 ui_test_utils::NavigateToURL(browser(), url); |
427 EXPECT_TRUE(WaitForReady()); | 428 EXPECT_TRUE(WaitForReady()); |
428 return url; | 429 return url; |
429 } | 430 } |
430 | 431 |
431 void SendCommand( | 432 void SendCommand( |
432 SecurityInterstitialPage::SecurityInterstitialCommands command) { | 433 security_interstitials::SecurityInterstitialCommands command) { |
433 WebContents* contents = | 434 WebContents* contents = |
434 browser()->tab_strip_model()->GetActiveWebContents(); | 435 browser()->tab_strip_model()->GetActiveWebContents(); |
435 // We use InterstitialPage::GetInterstitialPage(tab) instead of | 436 // We use InterstitialPage::GetInterstitialPage(tab) instead of |
436 // tab->GetInterstitialPage() because the tab doesn't have a pointer | 437 // tab->GetInterstitialPage() because the tab doesn't have a pointer |
437 // to its interstital page until it gets a command from the renderer | 438 // to its interstital page until it gets a command from the renderer |
438 // that it has indeed displayed it -- and this sometimes happens after | 439 // that it has indeed displayed it -- and this sometimes happens after |
439 // NavigateToURL returns. | 440 // NavigateToURL returns. |
440 SafeBrowsingBlockingPage* interstitial_page = | 441 SafeBrowsingBlockingPage* interstitial_page = |
441 static_cast<SafeBrowsingBlockingPage*>( | 442 static_cast<SafeBrowsingBlockingPage*>( |
442 InterstitialPage::GetInterstitialPage(contents)-> | 443 InterstitialPage::GetInterstitialPage(contents)-> |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 content::WaitForInterstitialAttach(contents); | 523 content::WaitForInterstitialAttach(contents); |
523 // Cancel the redirect request while interstitial page is open. | 524 // Cancel the redirect request while interstitial page is open. |
524 browser()->tab_strip_model()->ActivateTabAt(0, true); | 525 browser()->tab_strip_model()->ActivateTabAt(0, true); |
525 ui_test_utils::NavigateToURL(browser(), GURL("javascript:stopWin()")); | 526 ui_test_utils::NavigateToURL(browser(), GURL("javascript:stopWin()")); |
526 browser()->tab_strip_model()->ActivateTabAt(1, true); | 527 browser()->tab_strip_model()->ActivateTabAt(1, true); |
527 // Simulate the user clicking "proceed", there should be no crash. Since | 528 // Simulate the user clicking "proceed", there should be no crash. Since |
528 // clicking proceed may do nothing (see comment in RedirectCanceled | 529 // clicking proceed may do nothing (see comment in RedirectCanceled |
529 // below, and crbug.com/76460), we use SendCommand to trigger the callback | 530 // below, and crbug.com/76460), we use SendCommand to trigger the callback |
530 // directly rather than using ClickAndWaitForDetach since there might not | 531 // directly rather than using ClickAndWaitForDetach since there might not |
531 // be a notification to wait for. | 532 // be a notification to wait for. |
532 SendCommand(SecurityInterstitialPage::CMD_PROCEED); | 533 SendCommand(security_interstitials::CMD_PROCEED); |
533 } | 534 } |
534 | 535 |
535 content::RenderViewHost* GetRenderViewHost() { | 536 content::RenderViewHost* GetRenderViewHost() { |
536 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage( | 537 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage( |
537 browser()->tab_strip_model()->GetActiveWebContents()); | 538 browser()->tab_strip_model()->GetActiveWebContents()); |
538 if (!interstitial) | 539 if (!interstitial) |
539 return NULL; | 540 return NULL; |
540 return interstitial->GetMainFrame()->GetRenderViewHost(); | 541 return interstitial->GetMainFrame()->GetRenderViewHost(); |
541 } | 542 } |
542 | 543 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 | 777 |
777 SetupWarningAndNavigate(); | 778 SetupWarningAndNavigate(); |
778 | 779 |
779 EXPECT_EQ(VISIBLE, GetVisibility("primary-button")); | 780 EXPECT_EQ(VISIBLE, GetVisibility("primary-button")); |
780 EXPECT_EQ(HIDDEN, GetVisibility("details")); | 781 EXPECT_EQ(HIDDEN, GetVisibility("details")); |
781 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); | 782 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); |
782 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph")); | 783 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph")); |
783 EXPECT_TRUE(Click("details-button")); | 784 EXPECT_TRUE(Click("details-button")); |
784 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); | 785 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); |
785 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph")); | 786 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph")); |
786 SendCommand(SecurityInterstitialPage::CMD_PROCEED); | 787 SendCommand(security_interstitials::CMD_PROCEED); |
787 | 788 |
788 // The "proceed" command should go back instead, if proceeding is disabled. | 789 // The "proceed" command should go back instead, if proceeding is disabled. |
789 AssertNoInterstitial(true); | 790 AssertNoInterstitial(true); |
790 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank" | 791 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank" |
791 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); | 792 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); |
792 } | 793 } |
793 | 794 |
794 // Verifies that the reporting checkbox is hidden on non-HTTP pages. | 795 // Verifies that the reporting checkbox is hidden on non-HTTP pages. |
795 // TODO(mattm): Should also verify that no report is sent, but there isn't a | 796 // TODO(mattm): Should also verify that no report is sent, but there isn't a |
796 // good way to do that in the current design. | 797 // good way to do that in the current design. |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 EXPECT_TRUE(VerifyIDNDecoded()); | 1026 EXPECT_TRUE(VerifyIDNDecoded()); |
1026 } | 1027 } |
1027 | 1028 |
1028 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageIDNTestWithThreatType, | 1029 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageIDNTestWithThreatType, |
1029 SafeBrowsingBlockingPageIDNTest, | 1030 SafeBrowsingBlockingPageIDNTest, |
1030 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 1031 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
1031 SB_THREAT_TYPE_URL_PHISHING, | 1032 SB_THREAT_TYPE_URL_PHISHING, |
1032 SB_THREAT_TYPE_URL_UNWANTED)); | 1033 SB_THREAT_TYPE_URL_UNWANTED)); |
1033 | 1034 |
1034 } // namespace safe_browsing | 1035 } // namespace safe_browsing |
OLD | NEW |