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

Side by Side Diff: chrome/browser/prerender/prerender_browsertest.cc

Issue 1110723002: Split to SafeBrowsingDatabaseManager into Local* and Remote*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move delegate mgmt to sb service. Use weak_ptr for ClientRequest Created 5 years, 7 months 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 #include <deque> 5 #include <deque>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 26 matching lines...) Expand all
37 #include "chrome/browser/prerender/prerender_field_trial.h" 37 #include "chrome/browser/prerender/prerender_field_trial.h"
38 #include "chrome/browser/prerender/prerender_handle.h" 38 #include "chrome/browser/prerender/prerender_handle.h"
39 #include "chrome/browser/prerender/prerender_link_manager.h" 39 #include "chrome/browser/prerender/prerender_link_manager.h"
40 #include "chrome/browser/prerender/prerender_link_manager_factory.h" 40 #include "chrome/browser/prerender/prerender_link_manager_factory.h"
41 #include "chrome/browser/prerender/prerender_manager.h" 41 #include "chrome/browser/prerender/prerender_manager.h"
42 #include "chrome/browser/prerender/prerender_manager_factory.h" 42 #include "chrome/browser/prerender/prerender_manager_factory.h"
43 #include "chrome/browser/profiles/profile.h" 43 #include "chrome/browser/profiles/profile.h"
44 #include "chrome/browser/profiles/profile_io_data.h" 44 #include "chrome/browser/profiles/profile_io_data.h"
45 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate. h" 45 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate. h"
46 #include "chrome/browser/safe_browsing/database_manager.h" 46 #include "chrome/browser/safe_browsing/database_manager.h"
47 #include "chrome/browser/safe_browsing/local_database_manager.h"
47 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 48 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
48 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 49 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
50 #include "chrome/browser/safe_browsing/test_database_manager.h"
49 #include "chrome/browser/task_manager/task_manager.h" 51 #include "chrome/browser/task_manager/task_manager.h"
50 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" 52 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
51 #include "chrome/browser/ui/browser.h" 53 #include "chrome/browser/ui/browser.h"
52 #include "chrome/browser/ui/browser_commands.h" 54 #include "chrome/browser/ui/browser_commands.h"
53 #include "chrome/browser/ui/browser_finder.h" 55 #include "chrome/browser/ui/browser_finder.h"
54 #include "chrome/browser/ui/browser_navigator.h" 56 #include "chrome/browser/ui/browser_navigator.h"
55 #include "chrome/browser/ui/browser_window.h" 57 #include "chrome/browser/ui/browser_window.h"
56 #include "chrome/browser/ui/location_bar/location_bar.h" 58 #include "chrome/browser/ui/location_bar/location_bar.h"
57 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" 59 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
58 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 60 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 handle(handle) { 695 handle(handle) {
694 } 696 }
695 697
696 FinalStatus final_status; 698 FinalStatus final_status;
697 base::WeakPtr<TestPrerender> handle; 699 base::WeakPtr<TestPrerender> handle;
698 }; 700 };
699 701
700 std::deque<ExpectedContents> expected_contents_queue_; 702 std::deque<ExpectedContents> expected_contents_queue_;
701 }; 703 };
702 704
705 // TODO(nparker): Switch this to use TestSafeBrowsingDatabaseManager and run
706 // with SAFE_BROWSING_DB_LOCAL || SAFE_BROWSING_DB_REMOTE once fixing
707 // SafeBrowsingService::StartOnIOThread()'s requirement for a
708 // SafeBrowsingProtocolManagerDelegate*.
703 #if defined(FULL_SAFE_BROWSING) 709 #if defined(FULL_SAFE_BROWSING)
704 // A SafeBrowsingDatabaseManager implementation that returns a fixed result for 710 // A SafeBrowsingDatabaseManager implementation that returns a fixed result for
705 // a given URL. 711 // a given URL. The SafeBrowsingProtocolManagerDelegate is there to emulate
706 class FakeSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager { 712 class FakeSafeBrowsingDatabaseManager
713 : public LocalSafeBrowsingDatabaseManager {
707 public: 714 public:
708 explicit FakeSafeBrowsingDatabaseManager(SafeBrowsingService* service) 715 explicit FakeSafeBrowsingDatabaseManager(SafeBrowsingService* service)
709 : SafeBrowsingDatabaseManager(service), 716 : LocalSafeBrowsingDatabaseManager(service),
710 threat_type_(SB_THREAT_TYPE_SAFE) { } 717 threat_type_(SB_THREAT_TYPE_SAFE) {}
711 718
712 // Called on the IO thread to check if the given url is safe or not. If we 719 // Called on the IO thread to check if the given url is safe or not. If we
713 // can synchronously determine that the url is safe, CheckUrl returns true. 720 // can synchronously determine that the url is safe, CheckUrl returns true.
714 // Otherwise it returns false, and "client" is called asynchronously with the 721 // Otherwise it returns false, and "client" is called asynchronously with the
715 // result when it is ready. 722 // result when it is ready.
716 // Returns true, indicating a SAFE result, unless the URL is the fixed URL 723 // Returns true, indicating a SAFE result, unless the URL is the fixed URL
717 // specified by the user, and the user-specified result is not SAFE 724 // specified by the user, and the user-specified result is not SAFE
718 // (in which that result will be communicated back via a call into the 725 // (in which that result will be communicated back via a call into the
719 // client, and false will be returned). 726 // client, and false will be returned).
720 // Overrides SafeBrowsingService::CheckBrowseUrl. 727 // Overrides SafeBrowsingDatabaseManager::CheckBrowseUrl.
721 bool CheckBrowseUrl(const GURL& gurl, Client* client) override { 728 bool CheckBrowseUrl(const GURL& gurl, Client* client) override {
722 if (gurl != url_ || threat_type_ == SB_THREAT_TYPE_SAFE) 729 if (gurl != url_ || threat_type_ == SB_THREAT_TYPE_SAFE)
723 return true; 730 return true;
724 731
725 BrowserThread::PostTask( 732 BrowserThread::PostTask(
726 BrowserThread::IO, FROM_HERE, 733 BrowserThread::IO, FROM_HERE,
727 base::Bind(&FakeSafeBrowsingDatabaseManager::OnCheckBrowseURLDone, 734 base::Bind(&FakeSafeBrowsingDatabaseManager::OnCheckBrowseURLDone,
728 this, gurl, client)); 735 this, gurl, client));
729 return false; 736 return false;
730 } 737 }
731 738
732 void SetThreatTypeForUrl(const GURL& url, SBThreatType threat_type) { 739 void SetThreatTypeForUrl(const GURL& url, SBThreatType threat_type) {
733 url_ = url; 740 url_ = url;
734 threat_type_ = threat_type; 741 threat_type_ = threat_type;
735 } 742 }
736 743
737 private: 744 private:
738 ~FakeSafeBrowsingDatabaseManager() override {} 745 ~FakeSafeBrowsingDatabaseManager() override {}
739 746
740 void OnCheckBrowseURLDone(const GURL& gurl, Client* client) { 747 void OnCheckBrowseURLDone(const GURL& gurl, Client* client) {
741 std::vector<SBThreatType> expected_threats; 748 std::vector<SBThreatType> expected_threats;
742 expected_threats.push_back(SB_THREAT_TYPE_URL_MALWARE); 749 expected_threats.push_back(SB_THREAT_TYPE_URL_MALWARE);
743 expected_threats.push_back(SB_THREAT_TYPE_URL_PHISHING); 750 expected_threats.push_back(SB_THREAT_TYPE_URL_PHISHING);
744 SafeBrowsingDatabaseManager::SafeBrowsingCheck sb_check( 751 // TODO(nparker): Replace SafeBrowsingCheck w/ a call to
752 // client->OnCheckBrowseUrlResult()
753 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck sb_check(
745 std::vector<GURL>(1, gurl), 754 std::vector<GURL>(1, gurl),
746 std::vector<SBFullHash>(), 755 std::vector<SBFullHash>(),
747 client, 756 client,
748 safe_browsing_util::MALWARE, 757 safe_browsing_util::MALWARE,
749 expected_threats); 758 expected_threats);
750 sb_check.url_results[0] = threat_type_; 759 sb_check.url_results[0] = threat_type_;
751 client->OnSafeBrowsingResult(sb_check); 760 sb_check.OnSafeBrowsingResult();
752 } 761 }
753 762
754 GURL url_; 763 GURL url_;
755 SBThreatType threat_type_; 764 SBThreatType threat_type_;
756 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingDatabaseManager); 765 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingDatabaseManager);
757 }; 766 };
758 767
759 class FakeSafeBrowsingService : public SafeBrowsingService { 768 class FakeSafeBrowsingService : public SafeBrowsingService {
760 public: 769 public:
761 FakeSafeBrowsingService() { } 770 FakeSafeBrowsingService() { }
(...skipping 3301 matching lines...) Expand 10 before | Expand all | Expand 10 after
4063 browser()->tab_strip_model()->GetActiveWebContents(); 4072 browser()->tab_strip_model()->GetActiveWebContents();
4064 bool display_test_result = false; 4073 bool display_test_result = false;
4065 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(web_contents, 4074 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(web_contents,
4066 "DidDisplayReallyPass()", 4075 "DidDisplayReallyPass()",
4067 &display_test_result)); 4076 &display_test_result));
4068 ASSERT_TRUE(display_test_result); 4077 ASSERT_TRUE(display_test_result);
4069 } 4078 }
4070 #endif // !defined(DISABLE_NACL) 4079 #endif // !defined(DISABLE_NACL)
4071 4080
4072 } // namespace prerender 4081 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698