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

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

Issue 1110723002: Split to SafeBrowsingDatabaseManager into Local* and Remote*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to review. Tweak comments and list initializer. 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 // This test uses the safebrowsing test server published at 5 // This test uses the safebrowsing test server published at
6 // http://code.google.com/p/google-safe-browsing/ to test the safebrowsing 6 // http://code.google.com/p/google-safe-browsing/ to test the safebrowsing
7 // protocol implemetation. Details of the safebrowsing testing flow is 7 // protocol implemetation. Details of the safebrowsing testing flow is
8 // documented at 8 // documented at
9 // http://code.google.com/p/google-safe-browsing/wiki/ProtocolTesting 9 // http://code.google.com/p/google-safe-browsing/wiki/ProtocolTesting
10 // 10 //
(...skipping 15 matching lines...) Expand all
26 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
27 #include "base/synchronization/lock.h" 27 #include "base/synchronization/lock.h"
28 #include "base/test/test_timeouts.h" 28 #include "base/test/test_timeouts.h"
29 #include "base/threading/platform_thread.h" 29 #include "base/threading/platform_thread.h"
30 #include "base/threading/thread.h" 30 #include "base/threading/thread.h"
31 #include "base/time/time.h" 31 #include "base/time/time.h"
32 #include "chrome/browser/browser_process.h" 32 #include "chrome/browser/browser_process.h"
33 #include "chrome/browser/chrome_notification_types.h" 33 #include "chrome/browser/chrome_notification_types.h"
34 #include "chrome/browser/profiles/profile.h" 34 #include "chrome/browser/profiles/profile.h"
35 #include "chrome/browser/safe_browsing/database_manager.h" 35 #include "chrome/browser/safe_browsing/database_manager.h"
36 #include "chrome/browser/safe_browsing/local_database_manager.h"
36 #include "chrome/browser/safe_browsing/local_safebrowsing_test_server.h" 37 #include "chrome/browser/safe_browsing/local_safebrowsing_test_server.h"
37 #include "chrome/browser/safe_browsing/protocol_manager.h" 38 #include "chrome/browser/safe_browsing/protocol_manager.h"
38 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 39 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
39 #include "chrome/browser/ui/browser.h" 40 #include "chrome/browser/ui/browser.h"
40 #include "chrome/common/chrome_switches.h" 41 #include "chrome/common/chrome_switches.h"
41 #include "chrome/common/url_constants.h" 42 #include "chrome/common/url_constants.h"
42 #include "chrome/test/base/in_process_browser_test.h" 43 #include "chrome/test/base/in_process_browser_test.h"
43 #include "content/public/browser/browser_context.h" 44 #include "content/public/browser/browser_context.h"
44 #include "content/public/test/test_browser_thread.h" 45 #include "content/public/test/test_browser_thread.h"
45 #include "content/public/test/test_utils.h" 46 #include "content/public/test/test_utils.h"
46 #include "net/base/load_flags.h" 47 #include "net/base/load_flags.h"
47 #include "net/dns/host_resolver.h" 48 #include "net/dns/host_resolver.h"
48 #include "net/log/net_log.h" 49 #include "net/log/net_log.h"
49 #include "net/test/python_utils.h" 50 #include "net/test/python_utils.h"
50 #include "net/url_request/url_fetcher.h" 51 #include "net/url_request/url_fetcher.h"
51 #include "net/url_request/url_fetcher_delegate.h" 52 #include "net/url_request/url_fetcher_delegate.h"
52 #include "net/url_request/url_request_status.h" 53 #include "net/url_request/url_request_status.h"
53 #include "testing/gtest/include/gtest/gtest.h" 54 #include "testing/gtest/include/gtest/gtest.h"
54 55
55 using content::BrowserThread; 56 using content::BrowserThread;
56 57
58 #ifndef SAFE_BROWSING_DB_LOCAL
59 #error This test requires the SAFE_BROWSING_DB_LOCAL implementation.
60 #endif
61
57 namespace { 62 namespace {
58 63
59 const base::FilePath::CharType kDataFile[] = 64 const base::FilePath::CharType kDataFile[] =
60 FILE_PATH_LITERAL("testing_input_nomac.dat"); 65 FILE_PATH_LITERAL("testing_input_nomac.dat");
61 const char kUrlVerifyPath[] = "safebrowsing/verify_urls"; 66 const char kUrlVerifyPath[] = "safebrowsing/verify_urls";
62 const char kDBVerifyPath[] = "safebrowsing/verify_database"; 67 const char kDBVerifyPath[] = "safebrowsing/verify_database";
63 const char kTestCompletePath[] = "test_complete"; 68 const char kTestCompletePath[] = "test_complete";
64 69
65 struct PhishingUrl { 70 struct PhishingUrl {
66 std::string url; 71 std::string url;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 observer.Wait(); 185 observer.Wait();
181 } 186 }
182 187
183 void ForceUpdateOnIOThread() { 188 void ForceUpdateOnIOThread() {
184 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 189 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
185 ASSERT_TRUE(safe_browsing_service_); 190 ASSERT_TRUE(safe_browsing_service_);
186 safe_browsing_service_->protocol_manager_->ForceScheduleNextUpdate( 191 safe_browsing_service_->protocol_manager_->ForceScheduleNextUpdate(
187 base::TimeDelta::FromSeconds(0)); 192 base::TimeDelta::FromSeconds(0));
188 } 193 }
189 194
195
190 void CheckIsDatabaseReady() { 196 void CheckIsDatabaseReady() {
191 base::AutoLock lock(update_status_mutex_); 197 base::AutoLock lock(update_status_mutex_);
192 is_database_ready_ = !database_manager()->database_update_in_progress_; 198 is_database_ready_ =
199 !local_database_manager()->database_update_in_progress_;
193 } 200 }
194 201
195 void CheckUrl(SafeBrowsingDatabaseManager::Client* helper, const GURL& url) { 202 void CheckUrl(SafeBrowsingDatabaseManager::Client* helper, const GURL& url) {
196 ASSERT_TRUE(safe_browsing_service_); 203 ASSERT_TRUE(safe_browsing_service_);
197 base::AutoLock lock(update_status_mutex_); 204 base::AutoLock lock(update_status_mutex_);
198 if (database_manager()->CheckBrowseUrl(url, helper)) { 205 if (database_manager()->CheckBrowseUrl(url, helper)) {
199 is_checked_url_in_db_ = false; 206 is_checked_url_in_db_ = false;
200 is_checked_url_safe_ = true; 207 is_checked_url_safe_ = true;
201 } else { 208 } else {
202 // In this case, Safebrowsing service will fetch the full hash 209 // In this case, Safebrowsing service will fetch the full hash
203 // from the server and examine that. Once it is done, 210 // from the server and examine that. Once it is done,
204 // set_is_checked_url_safe() will be called via callback. 211 // set_is_checked_url_safe() will be called via callback.
205 is_checked_url_in_db_ = true; 212 is_checked_url_in_db_ = true;
206 } 213 }
207 } 214 }
208 215
209 SafeBrowsingDatabaseManager* database_manager() { 216 SafeBrowsingDatabaseManager* database_manager() {
210 return safe_browsing_service_->database_manager().get(); 217 return safe_browsing_service_->database_manager().get();
211 } 218 }
212 219
220 // TODO(nparker): Remove the need for this by wiring in our own
221 // SafeBrowsingDatabaseManager factory and keep a ptr to the subclass.
222 LocalSafeBrowsingDatabaseManager* local_database_manager() {
223 return static_cast<LocalSafeBrowsingDatabaseManager*>(database_manager());
224 }
225
226
213 bool is_checked_url_in_db() { 227 bool is_checked_url_in_db() {
214 base::AutoLock l(update_status_mutex_); 228 base::AutoLock l(update_status_mutex_);
215 return is_checked_url_in_db_; 229 return is_checked_url_in_db_;
216 } 230 }
217 231
218 void set_is_checked_url_safe(bool safe) { 232 void set_is_checked_url_safe(bool safe) {
219 base::AutoLock l(update_status_mutex_); 233 base::AutoLock l(update_status_mutex_);
220 is_checked_url_safe_ = safe; 234 is_checked_url_safe_ = safe;
221 } 235 }
222 236
(...skipping 11 matching lines...) Expand all
234 base::AutoLock l(update_status_mutex_); 248 base::AutoLock l(update_status_mutex_);
235 return last_update_; 249 return last_update_;
236 } 250 }
237 251
238 bool is_update_scheduled() { 252 bool is_update_scheduled() {
239 base::AutoLock l(update_status_mutex_); 253 base::AutoLock l(update_status_mutex_);
240 return is_update_scheduled_; 254 return is_update_scheduled_;
241 } 255 }
242 256
243 scoped_refptr<base::SequencedTaskRunner> SafeBrowsingTaskRunner() { 257 scoped_refptr<base::SequencedTaskRunner> SafeBrowsingTaskRunner() {
244 return database_manager()->safe_browsing_task_runner_; 258 return local_database_manager()->safe_browsing_task_runner_;
245 } 259 }
246 260
247 const net::SpawnedTestServer& test_server() const { 261 const net::SpawnedTestServer& test_server() const {
248 return *test_server_; 262 return *test_server_;
249 } 263 }
250 264
251 protected: 265 protected:
252 bool InitSafeBrowsingService() { 266 bool InitSafeBrowsingService() {
253 safe_browsing_service_ = g_browser_process->safe_browsing_service(); 267 safe_browsing_service_ = g_browser_process->safe_browsing_service();
254 return safe_browsing_service_ != NULL; 268 return safe_browsing_service_ != NULL;
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 safe_browsing_helper->FetchDBToVerify(test_server(), step)); 582 safe_browsing_helper->FetchDBToVerify(test_server(), step));
569 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); 583 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U);
570 last_step = step; 584 last_step = step;
571 } 585 }
572 586
573 // Verifies with server if test is done and waits till server responses. 587 // Verifies with server if test is done and waits till server responses.
574 EXPECT_EQ(net::URLRequestStatus::SUCCESS, 588 EXPECT_EQ(net::URLRequestStatus::SUCCESS,
575 safe_browsing_helper->VerifyTestComplete(test_server(), last_step)); 589 safe_browsing_helper->VerifyTestComplete(test_server(), last_step));
576 EXPECT_EQ("yes", safe_browsing_helper->response_data()); 590 EXPECT_EQ("yes", safe_browsing_helper->response_data());
577 } 591 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698