test_signin_client.cc revision 116680a4aac90f2aa7413d9095a592090648e557
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 16namespace { 17 18// Helper for testing. 19const int kInvalidProcessId = -1; 20} 21 22TestSigninClient::TestSigninClient() 23 : request_context_(new net::TestURLRequestContextGetter( 24 base::MessageLoopProxy::current())), 25 pref_service_(NULL) { 26 LoadDatabase(); 27} 28 29TestSigninClient::TestSigninClient(PrefService* pref_service) 30 : pref_service_(pref_service) {} 31 32TestSigninClient::~TestSigninClient() {} 33 34PrefService* TestSigninClient::GetPrefs() { 35 return pref_service_; 36} 37 38scoped_refptr<TokenWebData> TestSigninClient::GetDatabase() { 39 return database_; 40} 41 42bool TestSigninClient::CanRevokeCredentials() { return true; } 43 44std::string TestSigninClient::GetSigninScopedDeviceId() { 45 return std::string(); 46} 47 48void TestSigninClient::ClearSigninScopedDeviceId() { 49} 50 51net::URLRequestContextGetter* TestSigninClient::GetURLRequestContext() { 52 return request_context_; 53} 54 55std::string TestSigninClient::GetProductVersion() { return ""; } 56 57void TestSigninClient::LoadDatabase() { 58 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 59 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); 60 scoped_refptr<WebDatabaseService> web_database = 61 new WebDatabaseService(path, 62 base::MessageLoopProxy::current(), 63 base::MessageLoopProxy::current()); 64 web_database->AddTable(scoped_ptr<WebDatabaseTable>(new TokenServiceTable())); 65 web_database->LoadDatabase(); 66 database_ = new TokenWebData(web_database, 67 base::MessageLoopProxy::current(), 68 base::MessageLoopProxy::current(), 69 WebDataServiceBase::ProfileErrorCallback()); 70 database_->Init(); 71} 72 73bool TestSigninClient::ShouldMergeSigninCredentialsIntoCookieJar() { 74 return true; 75} 76 77void TestSigninClient::SetCookieChangedCallback( 78 const CookieChangedCallback& callback) {} 79 80#if defined(OS_IOS) 81ios::ProfileOAuth2TokenServiceIOSProvider* TestSigninClient::GetIOSProvider() { 82 return GetIOSProviderAsFake(); 83} 84 85ios::FakeProfileOAuth2TokenServiceIOSProvider* 86TestSigninClient::GetIOSProviderAsFake() { 87 if (!iosProvider_) { 88 iosProvider_.reset(new ios::FakeProfileOAuth2TokenServiceIOSProvider()); 89 } 90 return iosProvider_.get(); 91} 92#endif 93 94void TestSigninClient::SetSigninProcess(int process_id) { 95 if (process_id == signin_host_id_) 96 return; 97 DLOG_IF(WARNING, signin_host_id_ != kInvalidProcessId) 98 << "Replacing in-use signin process."; 99 signin_host_id_ = process_id; 100} 101 102void TestSigninClient::ClearSigninProcess() { 103 signin_host_id_ = kInvalidProcessId; 104} 105 106bool TestSigninClient::IsSigninProcess(int process_id) const { 107 return process_id == signin_host_id_; 108} 109 110bool TestSigninClient::HasSigninProcess() const { 111 return signin_host_id_ != kInvalidProcessId; 112} 113