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

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

Issue 11347005: Change SafeBrowsingProtocolManager::GetFullHash signature. (Closed) Base URL: http://git.chromium.org/chromium/src.git@in_progress
Patch Set: Fix rebase with browser_test Created 8 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 safebrowsing service using test safebrowsing database 5 // This test creates a safebrowsing service using test safebrowsing database
6 // and a test protocol manager. It is used to test logics in safebrowsing 6 // and a test protocol manager. It is used to test logics in safebrowsing
7 // service. 7 // service.
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "sql/statement.h" 42 #include "sql/statement.h"
43 #include "testing/gmock/include/gmock/gmock.h" 43 #include "testing/gmock/include/gmock/gmock.h"
44 44
45 using content::BrowserThread; 45 using content::BrowserThread;
46 using content::InterstitialPage; 46 using content::InterstitialPage;
47 using content::WebContents; 47 using content::WebContents;
48 using ::testing::_; 48 using ::testing::_;
49 using ::testing::Mock; 49 using ::testing::Mock;
50 using ::testing::StrictMock; 50 using ::testing::StrictMock;
51 51
52 namespace {
53
54 void InvokeFullHashCallback(
55 SafeBrowsingProtocolManager::FullHashCallback callback,
56 const std::vector<SBFullHashResult>& result) {
57 callback.Run(result, true);
58 }
59
60 } // namespace
61
52 // A SafeBrowingDatabase class that allows us to inject the malicious URLs. 62 // A SafeBrowingDatabase class that allows us to inject the malicious URLs.
53 class TestSafeBrowsingDatabase : public SafeBrowsingDatabase { 63 class TestSafeBrowsingDatabase : public SafeBrowsingDatabase {
54 public: 64 public:
55 TestSafeBrowsingDatabase() {} 65 TestSafeBrowsingDatabase() {}
56 66
57 virtual ~TestSafeBrowsingDatabase() {} 67 virtual ~TestSafeBrowsingDatabase() {}
58 68
59 // Initializes the database with the given filename. 69 // Initializes the database with the given filename.
60 virtual void Init(const FilePath& filename) {} 70 virtual void Init(const FilePath& filename) {}
61 71
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 class TestProtocolManager : public SafeBrowsingProtocolManager { 212 class TestProtocolManager : public SafeBrowsingProtocolManager {
203 public: 213 public:
204 TestProtocolManager(SafeBrowsingService* sb_service, 214 TestProtocolManager(SafeBrowsingService* sb_service,
205 const std::string& client_name, 215 const std::string& client_name,
206 net::URLRequestContextGetter* request_context_getter, 216 net::URLRequestContextGetter* request_context_getter,
207 const std::string& url_prefix, 217 const std::string& url_prefix,
208 bool disable_auto_update) 218 bool disable_auto_update)
209 : SafeBrowsingProtocolManager(sb_service, client_name, 219 : SafeBrowsingProtocolManager(sb_service, client_name,
210 request_context_getter, url_prefix, 220 request_context_getter, url_prefix,
211 disable_auto_update), 221 disable_auto_update),
212 sb_service_(sb_service),
213 delay_ms_(0) { 222 delay_ms_(0) {
214 create_count_++; 223 create_count_++;
215 } 224 }
216 225
217 ~TestProtocolManager() { 226 ~TestProtocolManager() {
218 delete_count_++; 227 delete_count_++;
219 } 228 }
220 229
221 // This function is called when there is a prefix hit in local safebrowsing 230 // This function is called when there is a prefix hit in local safebrowsing
222 // database and safebrowsing service issues a get hash request to backends. 231 // database and safebrowsing service issues a get hash request to backends.
223 // We return a result from the prefilled full_hashes_ hash_map to simulate 232 // We return a result from the prefilled full_hashes_ hash_map to simulate
224 // server's response. At the same time, latency is added to simulate real 233 // server's response. At the same time, latency is added to simulate real
225 // life network issues. 234 // life network issues.
226 virtual void GetFullHash(SafeBrowsingService::SafeBrowsingCheck* check, 235 virtual void GetFullHash(
227 const std::vector<SBPrefix>& prefixes) { 236 const std::vector<SBPrefix>& prefixes,
228 // When we get a valid response, always cache the result. 237 SafeBrowsingProtocolManager::FullHashCallback callback,
229 bool cancache = true; 238 bool is_download) OVERRIDE {
230 BrowserThread::PostDelayedTask( 239 BrowserThread::PostDelayedTask(
231 BrowserThread::IO, FROM_HERE, 240 BrowserThread::IO, FROM_HERE,
232 base::Bind(&SafeBrowsingService::HandleGetHashResults, 241 base::Bind(InvokeFullHashCallback, callback, full_hashes_),
233 sb_service_, check, full_hashes_, cancache),
234 base::TimeDelta::FromMilliseconds(delay_ms_)); 242 base::TimeDelta::FromMilliseconds(delay_ms_));
235 } 243 }
236 244
237 // Prepare the GetFullHash results for the next request. 245 // Prepare the GetFullHash results for the next request.
238 void SetGetFullHashResponse(const SBFullHashResult& full_hash_result) { 246 void SetGetFullHashResponse(const SBFullHashResult& full_hash_result) {
239 full_hashes_.clear(); 247 full_hashes_.clear();
240 full_hashes_.push_back(full_hash_result); 248 full_hashes_.push_back(full_hash_result);
241 } 249 }
242 250
243 void IntroduceDelay(int64 ms) { 251 void IntroduceDelay(int64 ms) {
244 delay_ms_ = ms; 252 delay_ms_ = ms;
245 } 253 }
246 254
247 static int create_count() { 255 static int create_count() {
248 return create_count_; 256 return create_count_;
249 } 257 }
250 258
251 static int delete_count() { 259 static int delete_count() {
252 return delete_count_; 260 return delete_count_;
253 } 261 }
254 262
255 private: 263 private:
256 std::vector<SBFullHashResult> full_hashes_; 264 std::vector<SBFullHashResult> full_hashes_;
257 SafeBrowsingService* sb_service_;
258 int64 delay_ms_; 265 int64 delay_ms_;
259 static int create_count_; 266 static int create_count_;
260 static int delete_count_; 267 static int delete_count_;
261 }; 268 };
262 269
263 // static 270 // static
264 int TestProtocolManager::create_count_ = 0; 271 int TestProtocolManager::create_count_ = 0;
265 // static 272 // static
266 int TestProtocolManager::delete_count_ = 0; 273 int TestProtocolManager::delete_count_ = 0;
267 274
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 // save cookies. 976 // save cookies.
970 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceCookieTest, TestSBUpdateCookies) { 977 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceCookieTest, TestSBUpdateCookies) {
971 content::WindowedNotificationObserver observer( 978 content::WindowedNotificationObserver observer(
972 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, 979 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE,
973 content::Source<SafeBrowsingService>(sb_service_.get())); 980 content::Source<SafeBrowsingService>(sb_service_.get()));
974 BrowserThread::PostTask( 981 BrowserThread::PostTask(
975 BrowserThread::IO, FROM_HERE, 982 BrowserThread::IO, FROM_HERE,
976 base::Bind(&SafeBrowsingServiceCookieTest::ForceUpdate, this)); 983 base::Bind(&SafeBrowsingServiceCookieTest::ForceUpdate, this));
977 observer.Wait(); 984 observer.Wait();
978 } 985 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698