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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/test/histogram_tester.h" | 16 #include "base/test/histogram_tester.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" | 20 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" |
21 #include "chrome/browser/net/url_request_mock_util.h" | 21 #include "chrome/browser/net/url_request_mock_util.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/safe_browsing/local_database_manager.h" | 23 #include "chrome/browser/safe_browsing/local_database_manager.h" |
24 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 24 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
25 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" | 25 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" |
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/ssl/cert_verifier_browser_test.h" | 28 #include "chrome/browser/ssl/cert_verifier_browser_test.h" |
29 #include "chrome/browser/ssl/chrome_security_state_model_client.h" | 29 #include "chrome/browser/ssl/security_state_tab_helper.h" |
30 #include "chrome/browser/ssl/ssl_blocking_page.h" | 30 #include "chrome/browser/ssl/ssl_blocking_page.h" |
31 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
32 #include "chrome/browser/ui/browser_tabstrip.h" | 32 #include "chrome/browser/ui/browser_tabstrip.h" |
33 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 33 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
34 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
35 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
36 #include "chrome/test/base/in_process_browser_test.h" | 36 #include "chrome/test/base/in_process_browser_test.h" |
37 #include "chrome/test/base/ui_test_utils.h" | 37 #include "chrome/test/base/ui_test_utils.h" |
38 #include "components/prefs/pref_service.h" | 38 #include "components/prefs/pref_service.h" |
39 #include "components/safe_browsing_db/database_manager.h" | 39 #include "components/safe_browsing_db/database_manager.h" |
40 #include "components/safe_browsing_db/safe_browsing_prefs.h" | 40 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
41 #include "components/safe_browsing_db/test_database_manager.h" | 41 #include "components/safe_browsing_db/test_database_manager.h" |
42 #include "components/safe_browsing_db/util.h" | 42 #include "components/safe_browsing_db/util.h" |
43 #include "components/security_interstitials/core/controller_client.h" | 43 #include "components/security_interstitials/core/controller_client.h" |
44 #include "components/security_interstitials/core/metrics_helper.h" | 44 #include "components/security_interstitials/core/metrics_helper.h" |
| 45 #include "components/security_state/core/security_state.h" |
45 #include "content/public/browser/interstitial_page.h" | 46 #include "content/public/browser/interstitial_page.h" |
46 #include "content/public/browser/navigation_controller.h" | 47 #include "content/public/browser/navigation_controller.h" |
47 #include "content/public/browser/navigation_entry.h" | 48 #include "content/public/browser/navigation_entry.h" |
48 #include "content/public/browser/notification_types.h" | 49 #include "content/public/browser/notification_types.h" |
49 #include "content/public/browser/render_frame_host.h" | 50 #include "content/public/browser/render_frame_host.h" |
50 #include "content/public/browser/render_process_host.h" | 51 #include "content/public/browser/render_process_host.h" |
51 #include "content/public/browser/web_contents.h" | 52 #include "content/public/browser/web_contents.h" |
52 #include "content/public/test/browser_test_utils.h" | 53 #include "content/public/test/browser_test_utils.h" |
53 #include "content/public/test/test_browser_thread.h" | 54 #include "content/public/test/test_browser_thread.h" |
54 #include "content/public/test/test_utils.h" | 55 #include "content/public/test/test_utils.h" |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 EXPECT_EQ(expected_parent, resource.url()); | 575 EXPECT_EQ(expected_parent, resource.url()); |
575 break; | 576 break; |
576 } | 577 } |
577 } | 578 } |
578 EXPECT_EQ(expected_child_size, actual_resource.child_ids_size()); | 579 EXPECT_EQ(expected_child_size, actual_resource.child_ids_size()); |
579 EXPECT_EQ(expected_tag_name, actual_resource.tag_name()); | 580 EXPECT_EQ(expected_tag_name, actual_resource.tag_name()); |
580 } | 581 } |
581 | 582 |
582 void ExpectSecurityIndicatorDowngrade(content::WebContents* tab, | 583 void ExpectSecurityIndicatorDowngrade(content::WebContents* tab, |
583 net::CertStatus cert_status) { | 584 net::CertStatus cert_status) { |
584 ChromeSecurityStateModelClient* model_client = | 585 SecurityStateTabHelper* helper = |
585 ChromeSecurityStateModelClient::FromWebContents(tab); | 586 SecurityStateTabHelper::FromWebContents(tab); |
586 ASSERT_TRUE(model_client); | 587 ASSERT_TRUE(helper); |
587 security_state::SecurityStateModel::SecurityInfo security_info; | 588 security_state::SecurityInfo security_info; |
588 model_client->GetSecurityInfo(&security_info); | 589 helper->GetSecurityInfo(&security_info); |
589 EXPECT_EQ(security_state::SecurityStateModel::DANGEROUS, | 590 EXPECT_EQ(security_state::DANGEROUS, security_info.security_level); |
590 security_info.security_level); | |
591 EXPECT_TRUE(security_info.fails_malware_check); | 591 EXPECT_TRUE(security_info.fails_malware_check); |
592 // TODO(felt): Restore this check when https://crbug.com/641187 is fixed. | 592 // TODO(felt): Restore this check when https://crbug.com/641187 is fixed. |
593 // EXPECT_EQ(cert_status, model_client->GetSecurityInfo().cert_status); | 593 // EXPECT_EQ(cert_status, helper->GetSecurityInfo().cert_status); |
594 } | 594 } |
595 | 595 |
596 void ExpectNoSecurityIndicatorDowngrade(content::WebContents* tab) { | 596 void ExpectNoSecurityIndicatorDowngrade(content::WebContents* tab) { |
597 ChromeSecurityStateModelClient* model_client = | 597 SecurityStateTabHelper* helper = |
598 ChromeSecurityStateModelClient::FromWebContents(tab); | 598 SecurityStateTabHelper::FromWebContents(tab); |
599 ASSERT_TRUE(model_client); | 599 ASSERT_TRUE(helper); |
600 security_state::SecurityStateModel::SecurityInfo security_info; | 600 security_state::SecurityInfo security_info; |
601 model_client->GetSecurityInfo(&security_info); | 601 helper->GetSecurityInfo(&security_info); |
602 EXPECT_EQ(security_state::SecurityStateModel::NONE, | 602 EXPECT_EQ(security_state::NONE, security_info.security_level); |
603 security_info.security_level); | |
604 EXPECT_FALSE(security_info.fails_malware_check); | 603 EXPECT_FALSE(security_info.fails_malware_check); |
605 } | 604 } |
606 | 605 |
607 protected: | 606 protected: |
608 TestThreatDetailsFactory details_factory_; | 607 TestThreatDetailsFactory details_factory_; |
609 | 608 |
610 private: | 609 private: |
611 // Adds a safebrowsing result of the current test threat to the fake | 610 // Adds a safebrowsing result of the current test threat to the fake |
612 // safebrowsing service, navigates to that page, and returns the url. | 611 // safebrowsing service, navigates to that page, and returns the url. |
613 // The various wrappers supply different URLs. | 612 // The various wrappers supply different URLs. |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1307 | 1306 |
1308 INSTANTIATE_TEST_CASE_P( | 1307 INSTANTIATE_TEST_CASE_P( |
1309 SafeBrowsingBlockingPageIDNTestWithThreatType, | 1308 SafeBrowsingBlockingPageIDNTestWithThreatType, |
1310 SafeBrowsingBlockingPageIDNTest, | 1309 SafeBrowsingBlockingPageIDNTest, |
1311 testing::Combine(testing::Values(false, true), | 1310 testing::Combine(testing::Values(false, true), |
1312 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 1311 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
1313 SB_THREAT_TYPE_URL_PHISHING, | 1312 SB_THREAT_TYPE_URL_PHISHING, |
1314 SB_THREAT_TYPE_URL_UNWANTED))); | 1313 SB_THREAT_TYPE_URL_UNWANTED))); |
1315 | 1314 |
1316 } // namespace safe_browsing | 1315 } // namespace safe_browsing |
OLD | NEW |