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/string_number_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" | |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/safe_browsing/database_manager.h" | 18 #include "chrome/browser/safe_browsing/database_manager.h" |
18 #include "chrome/browser/safe_browsing/malware_details.h" | 19 #include "chrome/browser/safe_browsing/malware_details.h" |
19 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 20 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 21 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
21 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 22 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
22 #include "chrome/browser/safe_browsing/ui_manager.h" | 23 #include "chrome/browser/safe_browsing/ui_manager.h" |
23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/browser_tabstrip.h" | 25 #include "chrome/browser/ui/browser_tabstrip.h" |
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
28 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
29 #include "chrome/test/base/in_process_browser_test.h" | 30 #include "chrome/test/base/in_process_browser_test.h" |
30 #include "chrome/test/base/test_switches.h" | 31 #include "chrome/test/base/test_switches.h" |
31 #include "chrome/test/base/ui_test_utils.h" | 32 #include "chrome/test/base/ui_test_utils.h" |
32 #include "content/public/browser/interstitial_page.h" | 33 #include "content/public/browser/interstitial_page.h" |
33 #include "content/public/browser/navigation_controller.h" | 34 #include "content/public/browser/navigation_controller.h" |
34 #include "content/public/browser/notification_types.h" | 35 #include "content/public/browser/notification_types.h" |
35 #include "content/public/browser/render_frame_host.h" | 36 #include "content/public/browser/render_frame_host.h" |
37 #include "content/public/browser/render_process_host.h" | |
36 #include "content/public/browser/render_view_host.h" | 38 #include "content/public/browser/render_view_host.h" |
37 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
38 #include "content/public/test/browser_test_utils.h" | 40 #include "content/public/test/browser_test_utils.h" |
39 #include "content/public/test/test_browser_thread.h" | 41 #include "content/public/test/test_browser_thread.h" |
40 #include "content/public/test/test_utils.h" | 42 #include "content/public/test/test_utils.h" |
41 | 43 |
44 using chrome_browser_interstitials::SecurityInterstitialIDNTest; | |
42 using content::BrowserThread; | 45 using content::BrowserThread; |
43 using content::InterstitialPage; | 46 using content::InterstitialPage; |
44 using content::NavigationController; | 47 using content::NavigationController; |
45 using content::WebContents; | 48 using content::WebContents; |
46 | 49 |
47 namespace { | 50 namespace { |
48 | 51 |
49 const char kEmptyPage[] = "files/empty.html"; | 52 const char kEmptyPage[] = "files/empty.html"; |
50 const char kMalwarePage[] = "files/safe_browsing/malware.html"; | 53 const char kMalwarePage[] = "files/safe_browsing/malware.html"; |
51 const char kMalwareIframe[] = "files/safe_browsing/malware_iframe.html"; | 54 const char kMalwareIframe[] = "files/safe_browsing/malware_iframe.html"; |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
784 AssertNoInterstitial(false); // Assert the interstitial is gone | 787 AssertNoInterstitial(false); // Assert the interstitial is gone |
785 | 788 |
786 // We are in the help page. | 789 // We are in the help page. |
787 EXPECT_EQ( | 790 EXPECT_EQ( |
788 GetParam() == SB_THREAT_TYPE_URL_PHISHING | 791 GetParam() == SB_THREAT_TYPE_URL_PHISHING |
789 ? "/transparencyreport/safebrowsing/" | 792 ? "/transparencyreport/safebrowsing/" |
790 : "/safebrowsing/diagnostic", | 793 : "/safebrowsing/diagnostic", |
791 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); | 794 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); |
792 } | 795 } |
793 | 796 |
797 // Test that SafeBrowsingBlockingPage properly decodes IDN URLs that are | |
798 // displayed. | |
799 class SafeBrowsingBlockingPageIDNTest : public SecurityInterstitialIDNTest { | |
800 protected: | |
801 // SecurityInterstitialIDNTest implementation | |
802 SecurityInterstitialPage* CreateInterstitial( | |
803 content::WebContents* contents, | |
804 const GURL& request_url) const override { | |
805 SafeBrowsingService* sb_service = | |
806 g_browser_process->safe_browsing_service(); | |
807 SafeBrowsingBlockingPage::UnsafeResourceList resource_list; | |
808 SafeBrowsingBlockingPage::UnsafeResource resource; | |
809 | |
810 resource.url = request_url; | |
811 resource.is_subresource = false; | |
812 resource.threat_type = SB_THREAT_TYPE_URL_MALWARE; | |
813 resource.render_process_host_id = contents->GetRenderProcessHost()->GetID(); | |
814 resource.render_view_id = contents->GetRenderViewHost()->GetRoutingID(); | |
815 resource_list.push_back(resource); | |
816 | |
817 // Use a TestSafeBrowsingBlockingPage because it has a public | |
818 // constructor, unlike the real thing. | |
mattm
2015/03/27 22:47:25
Does that matter for this test? woudn't SafeBrowsi
estark
2015/03/27 22:51:49
Done.
| |
819 return new TestSafeBrowsingBlockingPage(sb_service->ui_manager().get(), | |
820 contents, resource_list); | |
821 } | |
822 }; | |
823 | |
824 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageIDNTest, | |
825 SafeBrowsingBlockingPageDecodesIDN) { | |
826 EXPECT_TRUE(VerifyIDNDecoded()); | |
827 } | |
828 | |
794 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageBrowserTestWithThreatType, | 829 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageBrowserTestWithThreatType, |
795 SafeBrowsingBlockingPageBrowserTest, | 830 SafeBrowsingBlockingPageBrowserTest, |
796 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 831 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
797 SB_THREAT_TYPE_URL_PHISHING, | 832 SB_THREAT_TYPE_URL_PHISHING, |
798 SB_THREAT_TYPE_URL_UNWANTED)); | 833 SB_THREAT_TYPE_URL_UNWANTED)); |
OLD | NEW |