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

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 browser_tests after rebase 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
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 }; 208 };
199 209
200 // A TestProtocolManager that could return fixed responses from 210 // A TestProtocolManager that could return fixed responses from
201 // safebrowsing server for testing purpose. 211 // safebrowsing server for testing purpose.
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 net::URLRequestContextGetter* request_context_getter, 215 net::URLRequestContextGetter* request_context_getter,
206 const SafeBrowsingProtocolConfig& config) 216 const SafeBrowsingProtocolConfig& config)
207 : SafeBrowsingProtocolManager(sb_service, request_context_getter, config), 217 : SafeBrowsingProtocolManager(sb_service, request_context_getter, config),
208 sb_service_(sb_service),
209 delay_ms_(0) { 218 delay_ms_(0) {
210 create_count_++; 219 create_count_++;
211 } 220 }
212 221
213 ~TestProtocolManager() { 222 ~TestProtocolManager() {
214 delete_count_++; 223 delete_count_++;
215 } 224 }
216 225
217 // This function is called when there is a prefix hit in local safebrowsing 226 // This function is called when there is a prefix hit in local safebrowsing
218 // database and safebrowsing service issues a get hash request to backends. 227 // database and safebrowsing service issues a get hash request to backends.
219 // We return a result from the prefilled full_hashes_ hash_map to simulate 228 // We return a result from the prefilled full_hashes_ hash_map to simulate
220 // server's response. At the same time, latency is added to simulate real 229 // server's response. At the same time, latency is added to simulate real
221 // life network issues. 230 // life network issues.
222 virtual void GetFullHash(SafeBrowsingService::SafeBrowsingCheck* check, 231 virtual void GetFullHash(
223 const std::vector<SBPrefix>& prefixes) OVERRIDE { 232 const std::vector<SBPrefix>& prefixes,
224 // When we get a valid response, always cache the result. 233 SafeBrowsingProtocolManager::FullHashCallback callback,
225 bool cancache = true; 234 bool is_download) OVERRIDE {
226 BrowserThread::PostDelayedTask( 235 BrowserThread::PostDelayedTask(
227 BrowserThread::IO, FROM_HERE, 236 BrowserThread::IO, FROM_HERE,
228 base::Bind(&SafeBrowsingService::HandleGetHashResults, 237 base::Bind(InvokeFullHashCallback, callback, full_hashes_),
229 sb_service_, check, full_hashes_, cancache),
230 base::TimeDelta::FromMilliseconds(delay_ms_)); 238 base::TimeDelta::FromMilliseconds(delay_ms_));
231 } 239 }
232 240
233 // Prepare the GetFullHash results for the next request. 241 // Prepare the GetFullHash results for the next request.
234 void SetGetFullHashResponse(const SBFullHashResult& full_hash_result) { 242 void SetGetFullHashResponse(const SBFullHashResult& full_hash_result) {
235 full_hashes_.clear(); 243 full_hashes_.clear();
236 full_hashes_.push_back(full_hash_result); 244 full_hashes_.push_back(full_hash_result);
237 } 245 }
238 246
239 void IntroduceDelay(int64 ms) { 247 void IntroduceDelay(int64 ms) {
240 delay_ms_ = ms; 248 delay_ms_ = ms;
241 } 249 }
242 250
243 static int create_count() { 251 static int create_count() {
244 return create_count_; 252 return create_count_;
245 } 253 }
246 254
247 static int delete_count() { 255 static int delete_count() {
248 return delete_count_; 256 return delete_count_;
249 } 257 }
250 258
251 private: 259 private:
252 std::vector<SBFullHashResult> full_hashes_; 260 std::vector<SBFullHashResult> full_hashes_;
253 SafeBrowsingService* sb_service_;
254 int64 delay_ms_; 261 int64 delay_ms_;
255 static int create_count_; 262 static int create_count_;
256 static int delete_count_; 263 static int delete_count_;
257 }; 264 };
258 265
259 // static 266 // static
260 int TestProtocolManager::create_count_ = 0; 267 int TestProtocolManager::create_count_ = 0;
261 // static 268 // static
262 int TestProtocolManager::delete_count_ = 0; 269 int TestProtocolManager::delete_count_ = 0;
263 270
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 // save cookies. 971 // save cookies.
965 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceCookieTest, TestSBUpdateCookies) { 972 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceCookieTest, TestSBUpdateCookies) {
966 content::WindowedNotificationObserver observer( 973 content::WindowedNotificationObserver observer(
967 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, 974 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE,
968 content::Source<SafeBrowsingService>(sb_service_.get())); 975 content::Source<SafeBrowsingService>(sb_service_.get()));
969 BrowserThread::PostTask( 976 BrowserThread::PostTask(
970 BrowserThread::IO, FROM_HERE, 977 BrowserThread::IO, FROM_HERE,
971 base::Bind(&SafeBrowsingServiceCookieTest::ForceUpdate, this)); 978 base::Bind(&SafeBrowsingServiceCookieTest::ForceUpdate, this));
972 observer.Wait(); 979 observer.Wait();
973 } 980 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698