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.
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"
13 #include "ios/public/test/fake_profile_oauth2_token_service_ios_provider.h"
18 // Helper for testing.
19 const int kInvalidProcessId
= -1;
22 TestSigninClient::TestSigninClient()
23 : request_context_(new net::TestURLRequestContextGetter(
24 base::MessageLoopProxy::current())),
29 TestSigninClient::TestSigninClient(PrefService
* pref_service
)
30 : pref_service_(pref_service
) {}
32 TestSigninClient::~TestSigninClient() {}
34 PrefService
* TestSigninClient::GetPrefs() {
38 scoped_refptr
<TokenWebData
> TestSigninClient::GetDatabase() {
42 bool TestSigninClient::CanRevokeCredentials() { return true; }
44 std::string
TestSigninClient::GetSigninScopedDeviceId() {
48 void TestSigninClient::OnSignedOut() {
51 net::URLRequestContextGetter
* TestSigninClient::GetURLRequestContext() {
52 return request_context_
.get();
55 void TestSigninClient::SetURLRequestContext(
56 net::URLRequestContextGetter
* request_context
) {
57 request_context_
= request_context
;
60 std::string
TestSigninClient::GetProductVersion() { return ""; }
62 void 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());
78 bool TestSigninClient::ShouldMergeSigninCredentialsIntoCookieJar() {
82 scoped_ptr
<SigninClient::CookieChangedSubscription
>
83 TestSigninClient::AddCookieChangedCallback(
85 const std::string
& name
,
86 const net::CookieStore::CookieChangedCallback
& callback
) {
87 return scoped_ptr
<SigninClient::CookieChangedSubscription
>(
88 new SigninClient::CookieChangedSubscription
);
92 ios::ProfileOAuth2TokenServiceIOSProvider
* TestSigninClient::GetIOSProvider() {
93 return GetIOSProviderAsFake();
96 ios::FakeProfileOAuth2TokenServiceIOSProvider
*
97 TestSigninClient::GetIOSProviderAsFake() {
99 iosProvider_
.reset(new ios::FakeProfileOAuth2TokenServiceIOSProvider());
101 return iosProvider_
.get();
105 void TestSigninClient::SetSigninProcess(int process_id
) {
106 if (process_id
== signin_host_id_
)
108 DLOG_IF(WARNING
, signin_host_id_
!= kInvalidProcessId
)
109 << "Replacing in-use signin process.";
110 signin_host_id_
= process_id
;
113 void TestSigninClient::ClearSigninProcess() {
114 signin_host_id_
= kInvalidProcessId
;
117 bool TestSigninClient::IsSigninProcess(int process_id
) const {
118 return process_id
== signin_host_id_
;
121 bool TestSigninClient::HasSigninProcess() const {
122 return signin_host_id_
!= kInvalidProcessId
;
125 bool TestSigninClient::IsFirstRun() const {
129 base::Time
TestSigninClient::GetInstallDate() {
130 return base::Time::Now();