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

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

Issue 1943993006: Create test fixture for SafeBrowsingService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h"
6
7 #include "base/strings/string_util.h"
8 #include "chrome/browser/safe_browsing/download_protection_service.h"
9 #include "chrome/browser/safe_browsing/ping_manager.h"
10 #include "chrome/browser/safe_browsing/ui_manager.h"
11 #include "components/safe_browsing_db/database_manager.h"
12 #include "components/safe_browsing_db/test_database_manager.h"
13
14 namespace safe_browsing {
15
16 TestSafeBrowsingUIManager::TestSafeBrowsingUIManager()
Nathan Parker 2016/05/07 00:05:32 nit: Can you add a comment/header between the diff
Jialiu Lin 2016/05/12 21:53:58 Comments added. Also moved TestSafeBrowsingUIManag
17 : SafeBrowsingUIManager(nullptr) {}
18
19 TestSafeBrowsingUIManager::TestSafeBrowsingUIManager(
20 const scoped_refptr<SafeBrowsingService>& service)
21 : SafeBrowsingUIManager(service) {}
22
23 void TestSafeBrowsingUIManager::SetSafeBrowsingService(
24 SafeBrowsingService* sb_service) {
25 sb_service_ = sb_service;
26 }
27
28 void TestSafeBrowsingUIManager::SendSerializedThreatDetails(
29 const std::string& serialized) {
30 details_.push_back(serialized);
31 }
32
33 std::list<std::string>* TestSafeBrowsingUIManager::GetThreatDetails() {
34 return &details_;
35 }
36
37 TestSafeBrowsingUIManager::~TestSafeBrowsingUIManager() {}
38
39 TestSafeBrowsingService::TestSafeBrowsingService()
40 : protocol_manager_delegate_disabled_(false),
41 serialized_download_report_(base::EmptyString()) {}
42
43 TestSafeBrowsingService::~TestSafeBrowsingService() {}
44
45 SafeBrowsingProtocolConfig TestSafeBrowsingService::GetProtocolConfig() const {
46 if (protocol_config_)
47 return *protocol_config_;
48 return SafeBrowsingService::GetProtocolConfig();
49 }
50
51 V4ProtocolConfig TestSafeBrowsingService::GetV4ProtocolConfig() const {
52 if (v4_protocol_config_)
53 return *v4_protocol_config_;
54 return SafeBrowsingService::GetV4ProtocolConfig();
55 }
56
57 std::string TestSafeBrowsingService::serilized_download_report() {
58 return serialized_download_report_;
59 }
60
61 void TestSafeBrowsingService::SetDatabaseManager(
62 TestSafeBrowsingDatabaseManager* database_manager) {
63 database_manager_ = database_manager;
64 // Since TestSafeBrowsingDatabaseManager does not implement
65 // SafeBrowsingProtocolManagerDelegate, when it is used we need to disable
66 // protocol_manager_delegate.
67 protocol_manager_delegate_disabled_ = true;
68 }
69
70 void TestSafeBrowsingService::SetUIManager(
71 TestSafeBrowsingUIManager* ui_manager) {
72 ui_manager->SetSafeBrowsingService(this);
73 ui_manager_ = ui_manager;
74 }
75
76 SafeBrowsingDatabaseManager* TestSafeBrowsingService::CreateDatabaseManager() {
77 if (database_manager_)
78 return database_manager_.get();
79 return SafeBrowsingService::CreateDatabaseManager();
Nathan Parker 2016/05/07 00:05:32 Should this store the created object? The functio
Jialiu Lin 2016/05/12 21:53:58 Since the only place CreateDatabaseManager() calle
80 }
81
82 SafeBrowsingUIManager* TestSafeBrowsingService::CreateUIManager() {
83 if (!ui_manager_)
84 ui_manager_ = new TestSafeBrowsingUIManager(this);
85 return ui_manager_.get();
86 }
87
88 SafeBrowsingProtocolManagerDelegate*
89 TestSafeBrowsingService::GetProtocolManagerDelegate() {
90 if (protocol_manager_delegate_disabled_)
91 return nullptr;
92 return SafeBrowsingService::GetProtocolManagerDelegate();
93 }
94
95 void TestSafeBrowsingService::SendSerializedDownloadReport(
96 const std::string& report) {
97 serialized_download_report_ = report;
98 }
99
100 void TestSafeBrowsingService::SetProtocolConfig(
101 SafeBrowsingProtocolConfig* protocol_config) {
Nathan Parker 2016/05/07 00:05:32 Would this be simpler as a pass- and store-by-valu
Jialiu Lin 2016/05/12 21:53:58 Currently, TestSafeBrowsingService relies on if(pr
Nathan Parker 2016/05/16 19:56:39 Makes sense. I'm not advocating it, but I've been
102 protocol_config_.reset(protocol_config);
103 }
104
105 void TestSafeBrowsingService::SetV4ProtocolConfig(
106 V4ProtocolConfig* v4_protocol_config) {
107 v4_protocol_config_.reset(v4_protocol_config);
108 }
109
110 TestSafeBrowsingServiceFactory::TestSafeBrowsingServiceFactory()
111 : test_safe_browsing_service_(nullptr), test_protocol_config_(nullptr) {}
112
113 TestSafeBrowsingServiceFactory::~TestSafeBrowsingServiceFactory() {}
114
115 SafeBrowsingService*
116 TestSafeBrowsingServiceFactory::CreateSafeBrowsingService() {
117 // Instantiate TestSafeBrowsingService.
118 test_safe_browsing_service_ = new TestSafeBrowsingService();
119 // Plug-in test member clases accordingly.
120 if (test_ui_manager_)
121 test_safe_browsing_service_->SetUIManager(test_ui_manager_.get());
122 if (test_database_manager_)
123 test_safe_browsing_service_->SetDatabaseManager(
124 test_database_manager_.get());
125 if (test_protocol_config_)
126 test_safe_browsing_service_->SetProtocolConfig(test_protocol_config_);
127 return test_safe_browsing_service_;
Nathan Parker 2016/05/07 00:05:32 Does the factory need to retain a copy of this ptr
Jialiu Lin 2016/05/12 21:53:58 hmm, it actually makes things more complicated. Si
128 }
129
130 TestSafeBrowsingService*
131 TestSafeBrowsingServiceFactory::test_safe_browsing_service() {
132 return test_safe_browsing_service_;
133 }
134
135 void TestSafeBrowsingServiceFactory::SetTestUIManager(
136 TestSafeBrowsingUIManager* ui_manager) {
137 test_ui_manager_ = ui_manager;
138 if (test_safe_browsing_service_)
139 test_ui_manager_->SetSafeBrowsingService(test_safe_browsing_service_);
140 }
141
142 void TestSafeBrowsingServiceFactory::SetTestDatabaseManager(
143 TestSafeBrowsingDatabaseManager* database_manager) {
144 test_database_manager_ = database_manager;
145 }
146
147 void TestSafeBrowsingServiceFactory::SetTestProtocolConfig(
148 const SafeBrowsingProtocolConfig& protocol_config) {
149 test_protocol_config_ = new SafeBrowsingProtocolConfig(protocol_config);
150 }
151
152 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698