Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc

Issue 2448943002: Refactor SecurityStateModel/Clients for simplicity and reusability. (Closed)
Patch Set: update comments. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 EXPECT_EQ(expected_parent, resource.url()); 574 EXPECT_EQ(expected_parent, resource.url());
575 break; 575 break;
576 } 576 }
577 } 577 }
578 EXPECT_EQ(expected_child_size, actual_resource.child_ids_size()); 578 EXPECT_EQ(expected_child_size, actual_resource.child_ids_size());
579 EXPECT_EQ(expected_tag_name, actual_resource.tag_name()); 579 EXPECT_EQ(expected_tag_name, actual_resource.tag_name());
580 } 580 }
581 581
582 void ExpectSecurityIndicatorDowngrade(content::WebContents* tab, 582 void ExpectSecurityIndicatorDowngrade(content::WebContents* tab,
583 net::CertStatus cert_status) { 583 net::CertStatus cert_status) {
584 ChromeSecurityStateModelClient* model_client = 584 SecurityStateTabHelper* helper =
585 ChromeSecurityStateModelClient::FromWebContents(tab); 585 SecurityStateTabHelper::FromWebContents(tab);
586 ASSERT_TRUE(model_client); 586 ASSERT_TRUE(helper);
587 security_state::SecurityStateModel::SecurityInfo security_info; 587 security_state::SecurityStateModel::SecurityInfo security_info;
588 model_client->GetSecurityInfo(&security_info); 588 helper->GetSecurityInfo(&security_info);
589 EXPECT_EQ(security_state::SecurityStateModel::DANGEROUS, 589 EXPECT_EQ(security_state::SecurityStateModel::DANGEROUS,
590 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::SecurityStateModel::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::SecurityStateModel::NONE,
603 security_info.security_level); 603 security_info.security_level);
604 EXPECT_FALSE(security_info.fails_malware_check); 604 EXPECT_FALSE(security_info.fails_malware_check);
605 } 605 }
606 606
607 protected: 607 protected:
608 TestThreatDetailsFactory details_factory_; 608 TestThreatDetailsFactory details_factory_;
609 609
610 private: 610 private:
611 // Adds a safebrowsing result of the current test threat to the fake 611 // Adds a safebrowsing result of the current test threat to the fake
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 1307
1308 INSTANTIATE_TEST_CASE_P( 1308 INSTANTIATE_TEST_CASE_P(
1309 SafeBrowsingBlockingPageIDNTestWithThreatType, 1309 SafeBrowsingBlockingPageIDNTestWithThreatType,
1310 SafeBrowsingBlockingPageIDNTest, 1310 SafeBrowsingBlockingPageIDNTest,
1311 testing::Combine(testing::Values(false, true), 1311 testing::Combine(testing::Values(false, true),
1312 testing::Values(SB_THREAT_TYPE_URL_MALWARE, 1312 testing::Values(SB_THREAT_TYPE_URL_MALWARE,
1313 SB_THREAT_TYPE_URL_PHISHING, 1313 SB_THREAT_TYPE_URL_PHISHING,
1314 SB_THREAT_TYPE_URL_UNWANTED))); 1314 SB_THREAT_TYPE_URL_UNWANTED)));
1315 1315
1316 } // namespace safe_browsing 1316 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698