1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/logging.h" 6 #include "components/signin/core/browser/test_signin_client.h" 7 #include "components/signin/core/browser/webdata/token_service_table.h" 8 #include "components/webdata/common/web_data_service_base.h" 9 #include "components/webdata/common/web_database_service.h" 10 #include "testing/gtest/include/gtest/gtest.h" 11 12 #if defined(OS_IOS) 13 #include "ios/public/test/fake_profile_oauth2_token_service_ios_provider.h" 14 #endif 15 16 namespace { 17 18 // Helper for testing. 19 const int kInvalidProcessId = -1; 20 } 21 TestSigninClient()22TestSigninClient::TestSigninClient() 23 : request_context_(new net::TestURLRequestContextGetter( 24 base::MessageLoopProxy::current())), 25 pref_service_(NULL) { 26 LoadDatabase(); 27 } 28 TestSigninClient(PrefService * pref_service)29TestSigninClient::TestSigninClient(PrefService* pref_service) 30 : pref_service_(pref_service) {} 31 ~TestSigninClient()32TestSigninClient::~TestSigninClient() {} 33 GetPrefs()34PrefService* TestSigninClient::GetPrefs() { 35 return pref_service_; 36 } 37 GetDatabase()38scoped_refptr<TokenWebData> TestSigninClient::GetDatabase() { 39 return database_; 40 } 41 CanRevokeCredentials()42bool TestSigninClient::CanRevokeCredentials() { return true; } 43 GetSigninScopedDeviceId()44std::string TestSigninClient::GetSigninScopedDeviceId() { 45 return std::string(); 46 } 47 ClearSigninScopedDeviceId()48void TestSigninClient::ClearSigninScopedDeviceId() { 49 } 50 GetURLRequestContext()51net::URLRequestContextGetter* TestSigninClient::GetURLRequestContext() { 52 return request_context_.get(); 53 } 54 SetURLRequestContext(net::URLRequestContextGetter * request_context)55void TestSigninClient::SetURLRequestContext( 56 net::URLRequestContextGetter* request_context) { 57 request_context_ = request_context; 58 } 59 GetProductVersion()60std::string TestSigninClient::GetProductVersion() { return ""; } 61 LoadDatabase()62void TestSigninClient::LoadDatabase() { 63 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 64 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); 65 scoped_refptr<WebDatabaseService> web_database = 66 new WebDatabaseService(path, 67 base::MessageLoopProxy::current(), 68 base::MessageLoopProxy::current()); 69 web_database->AddTable(scoped_ptr<WebDatabaseTable>(new TokenServiceTable())); 70 web_database->LoadDatabase(); 71 database_ = new TokenWebData(web_database, 72 base::MessageLoopProxy::current(), 73 base::MessageLoopProxy::current(), 74 WebDataServiceBase::ProfileErrorCallback()); 75 database_->Init(); 76 } 77 ShouldMergeSigninCredentialsIntoCookieJar()78bool TestSigninClient::ShouldMergeSigninCredentialsIntoCookieJar() { 79 return true; 80 } 81 82 scoped_ptr<SigninClient::CookieChangedCallbackList::Subscription> AddCookieChangedCallback(const SigninClient::CookieChangedCallback & callback)83TestSigninClient::AddCookieChangedCallback( 84 const SigninClient::CookieChangedCallback& callback) { 85 return cookie_callbacks_.Add(callback); 86 } 87 88 #if defined(OS_IOS) GetIOSProvider()89ios::ProfileOAuth2TokenServiceIOSProvider* TestSigninClient::GetIOSProvider() { 90 return GetIOSProviderAsFake(); 91 } 92 93 ios::FakeProfileOAuth2TokenServiceIOSProvider* GetIOSProviderAsFake()94TestSigninClient::GetIOSProviderAsFake() { 95 if (!iosProvider_) { 96 iosProvider_.reset(new ios::FakeProfileOAuth2TokenServiceIOSProvider()); 97 } 98 return iosProvider_.get(); 99 } 100 #endif 101 SetSigninProcess(int process_id)102void TestSigninClient::SetSigninProcess(int process_id) { 103 if (process_id == signin_host_id_) 104 return; 105 DLOG_IF(WARNING, signin_host_id_ != kInvalidProcessId) 106 << "Replacing in-use signin process."; 107 signin_host_id_ = process_id; 108 } 109 ClearSigninProcess()110void TestSigninClient::ClearSigninProcess() { 111 signin_host_id_ = kInvalidProcessId; 112 } 113 IsSigninProcess(int process_id) const114bool TestSigninClient::IsSigninProcess(int process_id) const { 115 return process_id == signin_host_id_; 116 } 117 HasSigninProcess() const118bool TestSigninClient::HasSigninProcess() const { 119 return signin_host_id_ != kInvalidProcessId; 120 } 121 IsFirstRun() const122bool TestSigninClient::IsFirstRun() const { 123 return false; 124 } 125 GetInstallDate()126base::Time TestSigninClient::GetInstallDate() { 127 return base::Time::Now(); 128 } 129