Chromium Code Reviews| 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 file defines a unit test for the profile's token service. | 5 // This file defines a unit test for the profile's token service. |
| 6 | 6 |
| 7 #include "chrome/browser/signin/token_service_unittest.h" | 7 #include "chrome/browser/signin/token_service_unittest.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 14 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
| 15 #include "chrome/browser/signin/fake_signin_manager.h" | 15 #include "chrome/browser/signin/fake_signin_manager.h" |
| 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 17 #include "chrome/browser/signin/signin_manager_factory.h" | 17 #include "chrome/browser/signin/signin_manager_factory.h" |
| 18 #include "chrome/browser/signin/token_service_factory.h" | 18 #include "chrome/browser/signin/token_service_factory.h" |
| 19 #include "chrome/browser/webdata/token_web_data.h" | 19 #include "chrome/browser/webdata/token_web_data.h" |
| 20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 21 #include "components/webdata/encryptor/encryptor.h" | 21 #include "components/webdata/encryptor/encryptor.h" |
| 22 #include "google_apis/gaia/gaia_constants.h" | 22 #include "google_apis/gaia/gaia_constants.h" |
| 23 #include "google_apis/gaia/mock_url_fetcher_factory.h" | 23 #include "google_apis/gaia/mock_url_fetcher_factory.h" |
| 24 #include "net/url_request/test_url_fetcher_factory.h" | 24 #include "net/url_request/test_url_fetcher_factory.h" |
| 25 | 25 |
| 26 TokenAvailableTracker::TokenAvailableTracker() {} | 26 TokenServiceTestHarness::TokenServiceTestHarness() {} |
|
fgorski
2013/11/13 20:36:48
: signin_manager_(NULL), service_(NULL) {
Unless
Roger Tawa OOO till Jul 10th
2013/11/13 20:56:12
Good catch. Done.
| |
| 27 | |
| 28 TokenAvailableTracker::~TokenAvailableTracker() {} | |
| 29 | |
| 30 void TokenAvailableTracker::Observe( | |
| 31 int type, | |
| 32 const content::NotificationSource& source, | |
| 33 const content::NotificationDetails& details) { | |
| 34 TestNotificationTracker::Observe(type, source, details); | |
| 35 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { | |
| 36 content::Details<const TokenService::TokenAvailableDetails> full = details; | |
| 37 details_ = *full.ptr(); | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 TokenFailedTracker::TokenFailedTracker() {} | |
| 42 | |
| 43 TokenFailedTracker::~TokenFailedTracker() {} | |
| 44 | |
| 45 void TokenFailedTracker::Observe(int type, | |
| 46 const content::NotificationSource& source, | |
| 47 const content::NotificationDetails& details) { | |
| 48 TestNotificationTracker::Observe(type, source, details); | |
| 49 if (type == chrome::NOTIFICATION_TOKEN_REQUEST_FAILED) { | |
| 50 content::Details<const TokenService::TokenRequestFailedDetails> full = | |
| 51 details; | |
| 52 details_ = *full.ptr(); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 TokenServiceTestHarness::TokenServiceTestHarness() | |
| 57 : signin_manager_(NULL), service_(NULL) { | |
| 58 } | |
| 59 | 27 |
| 60 TokenServiceTestHarness::~TokenServiceTestHarness() {} | 28 TokenServiceTestHarness::~TokenServiceTestHarness() {} |
| 61 | 29 |
| 62 void TokenServiceTestHarness::SetUp() { | 30 void TokenServiceTestHarness::SetUp() { |
| 63 #if defined(OS_MACOSX) | 31 #if defined(OS_MACOSX) |
| 64 Encryptor::UseMockKeychain(true); | 32 Encryptor::UseMockKeychain(true); |
| 65 #endif | 33 #endif |
| 66 credentials_.sid = "sid"; | 34 credentials_.sid = "sid"; |
| 67 credentials_.lsid = "lsid"; | 35 credentials_.lsid = "lsid"; |
| 68 credentials_.token = "token"; | 36 credentials_.token = "token"; |
| 69 credentials_.data = "data"; | 37 credentials_.data = "data"; |
| 70 oauth_token_ = "oauth"; | 38 oauth_token_ = "oauth"; |
| 71 oauth_secret_ = "secret"; | 39 oauth_secret_ = "secret"; |
| 72 | 40 |
| 73 profile_ = CreateProfile().Pass(); | 41 profile_ = CreateProfile().Pass(); |
| 74 | 42 |
| 75 profile_->CreateWebDataService(); | 43 profile_->CreateWebDataService(); |
| 76 | 44 |
| 77 // Force the loading of the WebDataService. | 45 // Force the loading of the WebDataService. |
| 78 TokenWebData::FromBrowserContext(profile_.get()); | 46 TokenWebData::FromBrowserContext(profile_.get()); |
| 79 base::RunLoop().RunUntilIdle(); | 47 base::RunLoop().RunUntilIdle(); |
| 80 | 48 |
| 81 service_ = TokenServiceFactory::GetForProfile(profile_.get()); | 49 service_ = TokenServiceFactory::GetForProfile(profile_.get()); |
| 82 | 50 |
| 83 success_tracker_.ListenFor(chrome::NOTIFICATION_TOKEN_AVAILABLE, | |
| 84 content::Source<TokenService>(service_)); | |
| 85 failure_tracker_.ListenFor(chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, | |
| 86 content::Source<TokenService>(service_)); | |
| 87 | |
| 88 service()->Initialize("test", profile_.get()); | 51 service()->Initialize("test", profile_.get()); |
| 89 } | 52 } |
| 90 | 53 |
| 91 scoped_ptr<TestingProfile> TokenServiceTestHarness::CreateProfile() { | 54 scoped_ptr<TestingProfile> TokenServiceTestHarness::CreateProfile() { |
| 92 TestingProfile::Builder builder; | 55 TestingProfile::Builder builder; |
| 93 builder.AddTestingFactory( | 56 builder.AddTestingFactory( |
| 94 ProfileOAuth2TokenServiceFactory::GetInstance(), | 57 ProfileOAuth2TokenServiceFactory::GetInstance(), |
| 95 FakeProfileOAuth2TokenService::Build); | 58 FakeProfileOAuth2TokenService::Build); |
| 96 return builder.Build(); | 59 return builder.Build(); |
| 97 } | 60 } |
| 98 | 61 |
| 99 void TokenServiceTestHarness::CreateSigninManager(const std::string& username) { | 62 void TokenServiceTestHarness::CreateSigninManager(const std::string& username) { |
| 100 signin_manager_ = | 63 signin_manager_ = |
| 101 static_cast<FakeSigninManagerBase*>( | 64 static_cast<FakeSigninManagerBase*>( |
| 102 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 65 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
| 103 profile(), FakeSigninManagerBase::Build)); | 66 profile(), FakeSigninManagerBase::Build)); |
| 104 signin_manager_->Initialize(profile(), NULL); | 67 signin_manager_->Initialize(profile(), NULL); |
| 105 signin_manager_->SetAuthenticatedUsername(username); | 68 signin_manager_->SetAuthenticatedUsername(username); |
| 106 } | 69 } |
| 107 | 70 |
| 108 void TokenServiceTestHarness::TearDown() { | 71 void TokenServiceTestHarness::TearDown() { |
| 109 // You have to destroy the profile before the threads are shut down. | 72 // You have to destroy the profile before the threads are shut down. |
| 110 profile_.reset(); | 73 profile_.reset(); |
| 111 } | 74 } |
| 112 | 75 |
| 113 void TokenServiceTestHarness::UpdateCredentialsOnService() { | 76 void TokenServiceTestHarness::UpdateCredentialsOnService() { |
| 114 service()->UpdateCredentials(credentials_); | 77 service()->UpdateCredentials(credentials_); |
| 115 } | 78 } |
| 79 | |
|
fgorski
2013/11/13 20:36:48
nit: delete the new line.
Roger Tawa OOO till Jul 10th
2013/11/13 20:56:12
Done.
| |
| OLD | NEW |