| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/chrome_notification_types.h" | 23 #include "chrome/browser/chrome_notification_types.h" |
| 24 #include "chrome/browser/prerender/prerender_manager.h" | 24 #include "chrome/browser/prerender/prerender_manager.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/browser/profiles/startup_task_runner_service.h" | 27 #include "chrome/browser/profiles/startup_task_runner_service.h" |
| 28 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" | 28 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" |
| 29 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 29 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
| 30 #include "chrome/browser/safe_browsing/database_manager.h" | 30 #include "chrome/browser/safe_browsing/database_manager.h" |
| 31 #include "chrome/browser/safe_browsing/local_database_manager.h" |
| 31 #include "chrome/browser/safe_browsing/metadata.pb.h" | 32 #include "chrome/browser/safe_browsing/metadata.pb.h" |
| 32 #include "chrome/browser/safe_browsing/protocol_manager.h" | 33 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 33 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 34 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
| 34 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 35 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 35 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 36 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 36 #include "chrome/browser/safe_browsing/ui_manager.h" | 37 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 37 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
| 38 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 39 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 39 #include "chrome/common/chrome_paths.h" | 40 #include "chrome/common/chrome_paths.h" |
| 40 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
| 41 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
| 42 #include "chrome/test/base/in_process_browser_test.h" | 43 #include "chrome/test/base/in_process_browser_test.h" |
| 43 #include "chrome/test/base/ui_test_utils.h" | 44 #include "chrome/test/base/ui_test_utils.h" |
| 44 #include "content/public/browser/web_contents.h" | 45 #include "content/public/browser/web_contents.h" |
| 45 #include "net/cookies/cookie_store.h" | 46 #include "net/cookies/cookie_store.h" |
| 46 #include "sql/connection.h" | 47 #include "sql/connection.h" |
| 47 #include "sql/statement.h" | 48 #include "sql/statement.h" |
| 48 #include "testing/gmock/include/gmock/gmock.h" | 49 #include "testing/gmock/include/gmock/gmock.h" |
| 49 | 50 |
| 50 #if defined(OS_CHROMEOS) | 51 #if defined(OS_CHROMEOS) |
| 51 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 52 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 52 #include "chromeos/chromeos_switches.h" | 53 #include "chromeos/chromeos_switches.h" |
| 53 #endif | 54 #endif |
| 54 | 55 |
| 56 #if !defined(SAFE_BROWSING_DB_LOCAL) |
| 57 #error This test requires SAFE_BROWSING_DB_LOCAL. |
| 58 #endif |
| 59 |
| 55 using content::BrowserThread; | 60 using content::BrowserThread; |
| 56 using content::InterstitialPage; | 61 using content::InterstitialPage; |
| 57 using content::WebContents; | 62 using content::WebContents; |
| 58 using ::testing::_; | 63 using ::testing::_; |
| 59 using ::testing::Mock; | 64 using ::testing::Mock; |
| 60 using ::testing::StrictMock; | 65 using ::testing::StrictMock; |
| 61 | 66 |
| 62 namespace { | 67 namespace { |
| 63 | 68 |
| 64 void InvokeFullHashCallback( | 69 void InvokeFullHashCallback( |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 WebContents* contents = | 472 WebContents* contents = |
| 468 browser()->tab_strip_model()->GetActiveWebContents(); | 473 browser()->tab_strip_model()->GetActiveWebContents(); |
| 469 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); | 474 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); |
| 470 return interstitial_page != NULL; | 475 return interstitial_page != NULL; |
| 471 } | 476 } |
| 472 | 477 |
| 473 void IntroduceGetHashDelay(const base::TimeDelta& delay) { | 478 void IntroduceGetHashDelay(const base::TimeDelta& delay) { |
| 474 pm_factory_.GetProtocolManager()->IntroduceDelay(delay); | 479 pm_factory_.GetProtocolManager()->IntroduceDelay(delay); |
| 475 } | 480 } |
| 476 | 481 |
| 477 base::TimeDelta GetCheckTimeout(SafeBrowsingService* sb_service) { | 482 // TODO(nparker): Remove the need for this by wiring in our own |
| 478 return sb_service->database_manager()->check_timeout_; | 483 // SafeBrowsingDatabaseManager factory and keep a ptr to the subclass. |
| 484 // Or add a Get/SetTimeout to sbdbmgr. |
| 485 static LocalSafeBrowsingDatabaseManager* LocalDatabaseManagerForService( |
| 486 SafeBrowsingService* sb_service) { |
| 487 return static_cast<LocalSafeBrowsingDatabaseManager*>( |
| 488 sb_service->database_manager().get()); |
| 479 } | 489 } |
| 480 | 490 |
| 481 void SetCheckTimeout(SafeBrowsingService* sb_service, | 491 static base::TimeDelta GetCheckTimeout(SafeBrowsingService* sb_service) { |
| 482 const base::TimeDelta& delay) { | 492 return LocalDatabaseManagerForService(sb_service)->check_timeout_; |
| 483 sb_service->database_manager()->check_timeout_ = delay; | 493 } |
| 494 |
| 495 static void SetCheckTimeout(SafeBrowsingService* sb_service, |
| 496 const base::TimeDelta& delay) { |
| 497 LocalDatabaseManagerForService(sb_service)->check_timeout_ = delay; |
| 484 } | 498 } |
| 485 | 499 |
| 486 void CreateCSDService() { | 500 void CreateCSDService() { |
| 487 #if defined(SAFE_BROWSING_CSD) | 501 #if defined(SAFE_BROWSING_CSD) |
| 488 safe_browsing::ClientSideDetectionService* csd_service = | 502 safe_browsing::ClientSideDetectionService* csd_service = |
| 489 safe_browsing::ClientSideDetectionService::Create(NULL); | 503 safe_browsing::ClientSideDetectionService::Create(NULL); |
| 490 SafeBrowsingService* sb_service = | 504 SafeBrowsingService* sb_service = |
| 491 g_browser_process->safe_browsing_service(); | 505 g_browser_process->safe_browsing_service(); |
| 492 sb_service->csd_service_.reset(csd_service); | 506 sb_service->csd_service_.reset(csd_service); |
| 493 sb_service->RefreshState(); | 507 sb_service->RefreshState(); |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1249 } | 1263 } |
| 1250 | 1264 |
| 1251 scoped_refptr<SafeBrowsingService> sb_service_; | 1265 scoped_refptr<SafeBrowsingService> sb_service_; |
| 1252 | 1266 |
| 1253 private: | 1267 private: |
| 1254 scoped_ptr<TestSafeBrowsingServiceFactory> sb_factory_; | 1268 scoped_ptr<TestSafeBrowsingServiceFactory> sb_factory_; |
| 1255 | 1269 |
| 1256 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseManagerCookieTest); | 1270 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseManagerCookieTest); |
| 1257 }; | 1271 }; |
| 1258 | 1272 |
| 1259 // Test that a Safe Browsing database update request both sends cookies and can | 1273 // Test that a Local Safe Browsing database update request both sends cookies |
| 1260 // save cookies. | 1274 // and can save cookies. |
| 1261 IN_PROC_BROWSER_TEST_F(SafeBrowsingDatabaseManagerCookieTest, | 1275 IN_PROC_BROWSER_TEST_F(SafeBrowsingDatabaseManagerCookieTest, |
| 1262 TestSBUpdateCookies) { | 1276 TestSBUpdateCookies) { |
| 1263 content::WindowedNotificationObserver observer( | 1277 content::WindowedNotificationObserver observer( |
| 1264 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, | 1278 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, |
| 1265 content::Source<SafeBrowsingDatabaseManager>( | 1279 content::Source<SafeBrowsingDatabaseManager>( |
| 1266 sb_service_->database_manager().get())); | 1280 sb_service_->database_manager().get())); |
| 1267 BrowserThread::PostTask( | 1281 BrowserThread::PostTask( |
| 1268 BrowserThread::IO, | 1282 BrowserThread::IO, |
| 1269 FROM_HERE, | 1283 FROM_HERE, |
| 1270 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); | 1284 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); |
| 1271 observer.Wait(); | 1285 observer.Wait(); |
| 1272 } | 1286 } |
| OLD | NEW |