| 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_NE(security_state::MALICIOUS_CONTENT_STATUS_NONE, |
| 591 EXPECT_NE(security_state::SecurityStateModel::MALICIOUS_CONTENT_STATUS_NONE, | |
| 592 security_info.malicious_content_status); | 592 security_info.malicious_content_status); |
| 593 // TODO(felt): Restore this check when https://crbug.com/641187 is fixed. | 593 // TODO(felt): Restore this check when https://crbug.com/641187 is fixed. |
| 594 // EXPECT_EQ(cert_status, model_client->GetSecurityInfo().cert_status); | 594 // EXPECT_EQ(cert_status, helper->GetSecurityInfo().cert_status); |
| 595 } | 595 } |
| 596 | 596 |
| 597 void ExpectNoSecurityIndicatorDowngrade(content::WebContents* tab) { | 597 void ExpectNoSecurityIndicatorDowngrade(content::WebContents* tab) { |
| 598 ChromeSecurityStateModelClient* model_client = | 598 SecurityStateTabHelper* helper = |
| 599 ChromeSecurityStateModelClient::FromWebContents(tab); | 599 SecurityStateTabHelper::FromWebContents(tab); |
| 600 ASSERT_TRUE(model_client); | 600 ASSERT_TRUE(helper); |
| 601 security_state::SecurityStateModel::SecurityInfo security_info; | 601 security_state::SecurityInfo security_info; |
| 602 model_client->GetSecurityInfo(&security_info); | 602 helper->GetSecurityInfo(&security_info); |
| 603 EXPECT_EQ(security_state::SecurityStateModel::NONE, | 603 EXPECT_EQ(security_state::NONE, security_info.security_level); |
| 604 security_info.security_level); | 604 EXPECT_EQ(security_state::MALICIOUS_CONTENT_STATUS_NONE, |
| 605 EXPECT_EQ(security_state::SecurityStateModel::MALICIOUS_CONTENT_STATUS_NONE, | |
| 606 security_info.malicious_content_status); | 605 security_info.malicious_content_status); |
| 607 } | 606 } |
| 608 | 607 |
| 609 protected: | 608 protected: |
| 610 TestThreatDetailsFactory details_factory_; | 609 TestThreatDetailsFactory details_factory_; |
| 611 | 610 |
| 612 private: | 611 private: |
| 613 // Adds a safebrowsing result of the current test threat to the fake | 612 // Adds a safebrowsing result of the current test threat to the fake |
| 614 // safebrowsing service, navigates to that page, and returns the url. | 613 // safebrowsing service, navigates to that page, and returns the url. |
| 615 // The various wrappers supply different URLs. | 614 // The various wrappers supply different URLs. |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1309 | 1308 |
| 1310 INSTANTIATE_TEST_CASE_P( | 1309 INSTANTIATE_TEST_CASE_P( |
| 1311 SafeBrowsingBlockingPageIDNTestWithThreatType, | 1310 SafeBrowsingBlockingPageIDNTestWithThreatType, |
| 1312 SafeBrowsingBlockingPageIDNTest, | 1311 SafeBrowsingBlockingPageIDNTest, |
| 1313 testing::Combine(testing::Values(false, true), | 1312 testing::Combine(testing::Values(false, true), |
| 1314 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 1313 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
| 1315 SB_THREAT_TYPE_URL_PHISHING, | 1314 SB_THREAT_TYPE_URL_PHISHING, |
| 1316 SB_THREAT_TYPE_URL_UNWANTED))); | 1315 SB_THREAT_TYPE_URL_UNWANTED))); |
| 1317 | 1316 |
| 1318 } // namespace safe_browsing | 1317 } // namespace safe_browsing |
| OLD | NEW |