| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
| 16 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 17 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
| 18 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
| 19 #include "base/test/thread_test_helper.h" | 20 #include "base/test/thread_test_helper.h" |
| 20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/chrome_notification_types.h" | 23 #include "chrome/browser/chrome_notification_types.h" |
| 23 #include "chrome/browser/prerender/prerender_manager.h" | 24 #include "chrome/browser/prerender/prerender_manager.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/browser/profiles/startup_task_runner_service.h" | 27 #include "chrome/browser/profiles/startup_task_runner_service.h" |
| 27 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" | 28 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" |
| 28 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 29 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
| 29 #include "chrome/browser/safe_browsing/database_manager.h" | 30 #include "chrome/browser/safe_browsing/database_manager.h" |
| 30 #include "chrome/browser/safe_browsing/protocol_manager.h" | 31 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 31 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 32 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
| 32 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 33 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 33 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 34 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 34 #include "chrome/browser/safe_browsing/ui_manager.h" | 35 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 35 #include "chrome/browser/ui/browser.h" | 36 #include "chrome/browser/ui/browser.h" |
| 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 37 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 37 #include "chrome/common/chrome_paths.h" | 38 #include "chrome/common/chrome_paths.h" |
| 39 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
| 39 #include "chrome/test/base/in_process_browser_test.h" | 41 #include "chrome/test/base/in_process_browser_test.h" |
| 40 #include "chrome/test/base/ui_test_utils.h" | 42 #include "chrome/test/base/ui_test_utils.h" |
| 41 #include "content/public/browser/web_contents.h" | 43 #include "content/public/browser/web_contents.h" |
| 42 #include "net/cookies/cookie_store.h" | 44 #include "net/cookies/cookie_store.h" |
| 43 #include "sql/connection.h" | 45 #include "sql/connection.h" |
| 44 #include "sql/statement.h" | 46 #include "sql/statement.h" |
| 45 #include "testing/gmock/include/gmock/gmock.h" | 47 #include "testing/gmock/include/gmock/gmock.h" |
| 46 | 48 |
| 49 #if defined(OS_CHROMEOS) |
| 50 #include "chromeos/chromeos_switches.h" |
| 51 #endif |
| 52 |
| 47 using content::BrowserThread; | 53 using content::BrowserThread; |
| 48 using content::InterstitialPage; | 54 using content::InterstitialPage; |
| 49 using content::WebContents; | 55 using content::WebContents; |
| 50 using ::testing::_; | 56 using ::testing::_; |
| 51 using ::testing::Mock; | 57 using ::testing::Mock; |
| 52 using ::testing::StrictMock; | 58 using ::testing::StrictMock; |
| 53 | 59 |
| 54 namespace { | 60 namespace { |
| 55 | 61 |
| 56 void InvokeFullHashCallback( | 62 void InvokeFullHashCallback( |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 virtual void TearDown() { | 393 virtual void TearDown() { |
| 388 InProcessBrowserTest::TearDown(); | 394 InProcessBrowserTest::TearDown(); |
| 389 | 395 |
| 390 // Unregister test factories after InProcessBrowserTest::TearDown | 396 // Unregister test factories after InProcessBrowserTest::TearDown |
| 391 // (which destructs SafeBrowsingService). | 397 // (which destructs SafeBrowsingService). |
| 392 SafeBrowsingDatabase::RegisterFactory(NULL); | 398 SafeBrowsingDatabase::RegisterFactory(NULL); |
| 393 SafeBrowsingProtocolManager::RegisterFactory(NULL); | 399 SafeBrowsingProtocolManager::RegisterFactory(NULL); |
| 394 SafeBrowsingService::RegisterFactory(NULL); | 400 SafeBrowsingService::RegisterFactory(NULL); |
| 395 } | 401 } |
| 396 | 402 |
| 403 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 404 // Makes sure the auto update is not triggered during the test. |
| 405 // This test will fill up the database using testing prefixes |
| 406 // and urls. |
| 407 command_line->AppendSwitch(switches::kSbDisableAutoUpdate); |
| 408 #if defined(OS_CHROMEOS) |
| 409 command_line->AppendSwitch( |
| 410 chromeos::switches::kIgnoreUserProfileMappingForTests); |
| 411 #endif |
| 412 } |
| 413 |
| 397 virtual void SetUpInProcessBrowserTestFixture() { | 414 virtual void SetUpInProcessBrowserTestFixture() { |
| 398 ASSERT_TRUE(test_server()->Start()); | 415 ASSERT_TRUE(test_server()->Start()); |
| 399 } | 416 } |
| 400 | 417 |
| 401 // This will setup the "url" prefix in database and prepare protocol manager | 418 // This will setup the "url" prefix in database and prepare protocol manager |
| 402 // to response with |full_hash| for get full hash request. | 419 // to response with |full_hash| for get full hash request. |
| 403 void SetupResponseForUrl(const GURL& url, const SBFullHashResult& full_hash) { | 420 void SetupResponseForUrl(const GURL& url, const SBFullHashResult& full_hash) { |
| 404 std::vector<SBPrefix> prefix_hits; | 421 std::vector<SBPrefix> prefix_hits; |
| 405 prefix_hits.push_back(full_hash.hash.prefix); | 422 prefix_hits.push_back(full_hash.hash.prefix); |
| 406 | 423 |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 content::WindowedNotificationObserver observer( | 993 content::WindowedNotificationObserver observer( |
| 977 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, | 994 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, |
| 978 content::Source<SafeBrowsingDatabaseManager>( | 995 content::Source<SafeBrowsingDatabaseManager>( |
| 979 sb_service_->database_manager().get())); | 996 sb_service_->database_manager().get())); |
| 980 BrowserThread::PostTask( | 997 BrowserThread::PostTask( |
| 981 BrowserThread::IO, | 998 BrowserThread::IO, |
| 982 FROM_HERE, | 999 FROM_HERE, |
| 983 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); | 1000 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); |
| 984 observer.Wait(); | 1001 observer.Wait(); |
| 985 } | 1002 } |
| OLD | NEW |