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

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: extend test db manager to fix browser tests 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 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 handle(handle) { 694 handle(handle) {
693 } 695 }
694 696
695 FinalStatus final_status; 697 FinalStatus final_status;
696 base::WeakPtr<TestPrerender> handle; 698 base::WeakPtr<TestPrerender> handle;
697 }; 699 };
698 700
699 std::deque<ExpectedContents> expected_contents_queue_; 701 std::deque<ExpectedContents> expected_contents_queue_;
700 }; 702 };
701 703
704 // TODO(nparker): Switch this to use TestSafeBrowsingDatabaseManager and run
705 // with SAFE_BROWSING_DB_LOCAL || SAFE_BROWSING_DB_REMOTE once fixing
706 // SafeBrowsingService::StartOnIOThread()'s requirement for a
707 // SafeBrowsingProtocolManagerDelegate*.
702 #if defined(FULL_SAFE_BROWSING) 708 #if defined(FULL_SAFE_BROWSING)
703 // A SafeBrowsingDatabaseManager implementation that returns a fixed result for 709 // A SafeBrowsingDatabaseManager implementation that returns a fixed result for
704 // a given URL. 710 // a given URL. The SafeBrowsingProtocolManagerDelegate is there to emulate
705 class FakeSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager { 711 class FakeSafeBrowsingDatabaseManager
712 : public LocalSafeBrowsingDatabaseManager {
706 public: 713 public:
707 explicit FakeSafeBrowsingDatabaseManager(SafeBrowsingService* service) 714 explicit FakeSafeBrowsingDatabaseManager(SafeBrowsingService* service)
708 : SafeBrowsingDatabaseManager(service), 715 : LocalSafeBrowsingDatabaseManager(service),
709 threat_type_(SB_THREAT_TYPE_SAFE) { } 716 threat_type_(SB_THREAT_TYPE_SAFE) {}
710 717
711 // Called on the IO thread to check if the given url is safe or not. If we 718 // Called on the IO thread to check if the given url is safe or not. If we
712 // can synchronously determine that the url is safe, CheckUrl returns true. 719 // can synchronously determine that the url is safe, CheckUrl returns true.
713 // Otherwise it returns false, and "client" is called asynchronously with the 720 // Otherwise it returns false, and "client" is called asynchronously with the
714 // result when it is ready. 721 // result when it is ready.
715 // Returns true, indicating a SAFE result, unless the URL is the fixed URL 722 // Returns true, indicating a SAFE result, unless the URL is the fixed URL
716 // specified by the user, and the user-specified result is not SAFE 723 // specified by the user, and the user-specified result is not SAFE
717 // (in which that result will be communicated back via a call into the 724 // (in which that result will be communicated back via a call into the
718 // client, and false will be returned). 725 // client, and false will be returned).
719 // Overrides SafeBrowsingService::CheckBrowseUrl. 726 // Overrides SafeBrowsingDatabaseManager::CheckBrowseUrl.
720 bool CheckBrowseUrl(const GURL& gurl, Client* client) override { 727 bool CheckBrowseUrl(const GURL& gurl, Client* client) override {
721 if (gurl != url_ || threat_type_ == SB_THREAT_TYPE_SAFE) 728 if (gurl != url_ || threat_type_ == SB_THREAT_TYPE_SAFE)
722 return true; 729 return true;
723 730
724 BrowserThread::PostTask( 731 BrowserThread::PostTask(
725 BrowserThread::IO, FROM_HERE, 732 BrowserThread::IO, FROM_HERE,
726 base::Bind(&FakeSafeBrowsingDatabaseManager::OnCheckBrowseURLDone, 733 base::Bind(&FakeSafeBrowsingDatabaseManager::OnCheckBrowseURLDone,
727 this, gurl, client)); 734 this, gurl, client));
728 return false; 735 return false;
729 } 736 }
730 737
731 void SetThreatTypeForUrl(const GURL& url, SBThreatType threat_type) { 738 void SetThreatTypeForUrl(const GURL& url, SBThreatType threat_type) {
732 url_ = url; 739 url_ = url;
733 threat_type_ = threat_type; 740 threat_type_ = threat_type;
734 } 741 }
735 742
736 private: 743 private:
737 ~FakeSafeBrowsingDatabaseManager() override {} 744 ~FakeSafeBrowsingDatabaseManager() override {}
738 745
739 void OnCheckBrowseURLDone(const GURL& gurl, Client* client) { 746 void OnCheckBrowseURLDone(const GURL& gurl, Client* client) {
740 std::vector<SBThreatType> expected_threats; 747 std::vector<SBThreatType> expected_threats;
741 expected_threats.push_back(SB_THREAT_TYPE_URL_MALWARE); 748 expected_threats.push_back(SB_THREAT_TYPE_URL_MALWARE);
742 expected_threats.push_back(SB_THREAT_TYPE_URL_PHISHING); 749 expected_threats.push_back(SB_THREAT_TYPE_URL_PHISHING);
743 SafeBrowsingDatabaseManager::SafeBrowsingCheck sb_check( 750 // TODO(nparker): Replace SafeBrowsingCheck w/ a call to
751 // client->OnCheckBrowseUrlResult()
752 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck sb_check(
744 std::vector<GURL>(1, gurl), 753 std::vector<GURL>(1, gurl),
745 std::vector<SBFullHash>(), 754 std::vector<SBFullHash>(),
746 client, 755 client,
747 safe_browsing_util::MALWARE, 756 safe_browsing_util::MALWARE,
748 expected_threats); 757 expected_threats);
749 sb_check.url_results[0] = threat_type_; 758 sb_check.url_results[0] = threat_type_;
750 client->OnSafeBrowsingResult(sb_check); 759 sb_check.OnSafeBrowsingResult();
751 } 760 }
752 761
753 GURL url_; 762 GURL url_;
754 SBThreatType threat_type_; 763 SBThreatType threat_type_;
755 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingDatabaseManager); 764 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingDatabaseManager);
756 }; 765 };
757 766
758 class FakeSafeBrowsingService : public SafeBrowsingService { 767 class FakeSafeBrowsingService : public SafeBrowsingService {
759 public: 768 public:
760 FakeSafeBrowsingService() { } 769 FakeSafeBrowsingService() { }
(...skipping 3292 matching lines...) Expand 10 before | Expand all | Expand 10 after
4053 browser()->tab_strip_model()->GetActiveWebContents(); 4062 browser()->tab_strip_model()->GetActiveWebContents();
4054 bool display_test_result = false; 4063 bool display_test_result = false;
4055 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(web_contents, 4064 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(web_contents,
4056 "DidDisplayReallyPass()", 4065 "DidDisplayReallyPass()",
4057 &display_test_result)); 4066 &display_test_result));
4058 ASSERT_TRUE(display_test_result); 4067 ASSERT_TRUE(display_test_result);
4059 } 4068 }
4060 #endif // !defined(DISABLE_NACL) 4069 #endif // !defined(DISABLE_NACL)
4061 4070
4062 } // namespace prerender 4071 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698