diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-11 20:44:42 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-11 20:44:42 +0000 |
commit | 5322a7f16a374a15fe69b3bb2621678aede48bca (patch) | |
tree | 56c8ee955ed32cd69f8b3395cb609dcdd504e58c /chrome/browser/net | |
parent | 192a05f2e4d8f66d095227439d4dce7bb14b16b5 (diff) | |
download | chromium_src-5322a7f16a374a15fe69b3bb2621678aede48bca.zip chromium_src-5322a7f16a374a15fe69b3bb2621678aede48bca.tar.gz chromium_src-5322a7f16a374a15fe69b3bb2621678aede48bca.tar.bz2 |
Continuing with the out-of-lining of test code.
BUG=none
TEST=compiles
Review URL: http://codereview.chromium.org/6485015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74660 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net')
-rw-r--r-- | chrome/browser/net/gaia/token_service_unittest.cc | 57 | ||||
-rw-r--r-- | chrome/browser/net/gaia/token_service_unittest.h | 56 |
2 files changed, 62 insertions, 51 deletions
diff --git a/chrome/browser/net/gaia/token_service_unittest.cc b/chrome/browser/net/gaia/token_service_unittest.cc index d06956f..8650442 100644 --- a/chrome/browser/net/gaia/token_service_unittest.cc +++ b/chrome/browser/net/gaia/token_service_unittest.cc @@ -7,11 +7,68 @@ #include "chrome/browser/net/gaia/token_service_unittest.h" #include "base/command_line.h" +#include "chrome/browser/password_manager/encryptor.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/net/gaia/gaia_auth_fetcher_unittest.h" #include "chrome/common/net/gaia/gaia_constants.h" #include "chrome/common/net/test_url_fetcher_factory.h" +TokenServiceTestHarness::TokenServiceTestHarness() + : ui_thread_(BrowserThread::UI, &message_loop_), + db_thread_(BrowserThread::DB) { +} + +TokenServiceTestHarness::~TokenServiceTestHarness() {} + +void TokenServiceTestHarness::SetUp() { +#if defined(OS_MACOSX) + Encryptor::UseMockKeychain(true); +#endif + credentials_.sid = "sid"; + credentials_.lsid = "lsid"; + credentials_.token = "token"; + credentials_.data = "data"; + + ASSERT_TRUE(db_thread_.Start()); + + profile_.reset(new TestingProfile()); + profile_->CreateWebDataService(false); + WaitForDBLoadCompletion(); + + success_tracker_.ListenFor(NotificationType::TOKEN_AVAILABLE, + Source<TokenService>(&service_)); + failure_tracker_.ListenFor(NotificationType::TOKEN_REQUEST_FAILED, + Source<TokenService>(&service_)); + + service_.Initialize("test", profile_.get()); + + URLFetcher::set_factory(NULL); +} + +void TokenServiceTestHarness::TearDown() { + // You have to destroy the profile before the db_thread_ stops. + if (profile_.get()) { + profile_.reset(NULL); + } + + db_thread_.Stop(); + MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); + MessageLoop::current()->Run(); +} + +void TokenServiceTestHarness::WaitForDBLoadCompletion() { + // The WebDB does all work on the DB thread. This will add an event + // to the end of the DB thread, so when we reach this task, all DB + // operations should be complete. + WaitableEvent done(false, false); + BrowserThread::PostTask( + BrowserThread::DB, FROM_HERE, new SignalingTask(&done)); + done.Wait(); + + // Notifications should be returned from the DB thread onto the UI thread. + message_loop_.RunAllPending(); +} + class TokenServiceTest : public TokenServiceTestHarness { public: virtual void SetUp() { diff --git a/chrome/browser/net/gaia/token_service_unittest.h b/chrome/browser/net/gaia/token_service_unittest.h index 46cffb0c..9481d22 100644 --- a/chrome/browser/net/gaia/token_service_unittest.h +++ b/chrome/browser/net/gaia/token_service_unittest.h @@ -9,7 +9,6 @@ #pragma once #include "chrome/browser/net/gaia/token_service.h" -#include "chrome/browser/password_manager/encryptor.h" #include "chrome/browser/webdata/web_data_service.h" #include "chrome/common/net/gaia/gaia_auth_consumer.h" #include "chrome/common/notification_details.h" @@ -64,59 +63,14 @@ class TokenFailedTracker : public TestNotificationTracker { class TokenServiceTestHarness : public testing::Test { public: - TokenServiceTestHarness() - : ui_thread_(BrowserThread::UI, &message_loop_), - db_thread_(BrowserThread::DB) { - } - - virtual void SetUp() { -#if defined(OS_MACOSX) - Encryptor::UseMockKeychain(true); -#endif - credentials_.sid = "sid"; - credentials_.lsid = "lsid"; - credentials_.token = "token"; - credentials_.data = "data"; - - ASSERT_TRUE(db_thread_.Start()); - - profile_.reset(new TestingProfile()); - profile_->CreateWebDataService(false); - WaitForDBLoadCompletion(); - - success_tracker_.ListenFor(NotificationType::TOKEN_AVAILABLE, - Source<TokenService>(&service_)); - failure_tracker_.ListenFor(NotificationType::TOKEN_REQUEST_FAILED, - Source<TokenService>(&service_)); - - service_.Initialize("test", profile_.get()); + TokenServiceTestHarness(); + virtual ~TokenServiceTestHarness(); - URLFetcher::set_factory(NULL); - } - - virtual void TearDown() { - // You have to destroy the profile before the db_thread_ stops. - if (profile_.get()) { - profile_.reset(NULL); - } + virtual void SetUp(); - db_thread_.Stop(); - MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); - MessageLoop::current()->Run(); - } - - void WaitForDBLoadCompletion() { - // The WebDB does all work on the DB thread. This will add an event - // to the end of the DB thread, so when we reach this task, all DB - // operations should be complete. - WaitableEvent done(false, false); - BrowserThread::PostTask( - BrowserThread::DB, FROM_HERE, new SignalingTask(&done)); - done.Wait(); + virtual void TearDown(); - // Notifications should be returned from the DB thread onto the UI thread. - message_loop_.RunAllPending(); - } + void WaitForDBLoadCompletion(); MessageLoopForUI message_loop_; BrowserThread ui_thread_; // Mostly so DCHECKS pass. |