GN + Android: extract android_standalone_library rule.
[chromium-blink-merge.git] / components / signin / core / browser / test_signin_client.cc
blob6c16931f39c87acfcef4b91b99e0cb8bb330914b
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"
12 #if defined(OS_IOS)
13 #include "ios/public/test/fake_profile_oauth2_token_service_ios_provider.h"
14 #endif
16 namespace {
18 // Helper for testing.
19 const int kInvalidProcessId = -1;
22 TestSigninClient::TestSigninClient()
23 : request_context_(new net::TestURLRequestContextGetter(
24 base::MessageLoopProxy::current())),
25 pref_service_(NULL) {
26 LoadDatabase();
29 TestSigninClient::TestSigninClient(PrefService* pref_service)
30 : pref_service_(pref_service) {}
32 TestSigninClient::~TestSigninClient() {}
34 PrefService* TestSigninClient::GetPrefs() {
35 return pref_service_;
38 scoped_refptr<TokenWebData> TestSigninClient::GetDatabase() {
39 return database_;
42 bool TestSigninClient::CanRevokeCredentials() { return true; }
44 std::string TestSigninClient::GetSigninScopedDeviceId() {
45 return std::string();
48 void TestSigninClient::OnSignedOut() {}
50 void TestSigninClient::PostSignedIn(const std::string& account_id,
51 const std::string& username,
52 const std::string& password) {
53 signed_in_password_ = password;
56 net::URLRequestContextGetter* TestSigninClient::GetURLRequestContext() {
57 return request_context_.get();
60 void TestSigninClient::SetURLRequestContext(
61 net::URLRequestContextGetter* request_context) {
62 request_context_ = request_context;
65 std::string TestSigninClient::GetProductVersion() { return ""; }
67 void TestSigninClient::LoadDatabase() {
68 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
69 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB");
70 scoped_refptr<WebDatabaseService> web_database =
71 new WebDatabaseService(path,
72 base::MessageLoopProxy::current(),
73 base::MessageLoopProxy::current());
74 web_database->AddTable(scoped_ptr<WebDatabaseTable>(new TokenServiceTable()));
75 web_database->LoadDatabase();
76 database_ = new TokenWebData(web_database,
77 base::MessageLoopProxy::current(),
78 base::MessageLoopProxy::current(),
79 WebDataServiceBase::ProfileErrorCallback());
80 database_->Init();
83 bool TestSigninClient::ShouldMergeSigninCredentialsIntoCookieJar() {
84 return true;
87 scoped_ptr<SigninClient::CookieChangedSubscription>
88 TestSigninClient::AddCookieChangedCallback(
89 const GURL& url,
90 const std::string& name,
91 const net::CookieStore::CookieChangedCallback& callback) {
92 return scoped_ptr<SigninClient::CookieChangedSubscription>(
93 new SigninClient::CookieChangedSubscription);
96 #if defined(OS_IOS)
97 ios::ProfileOAuth2TokenServiceIOSProvider* TestSigninClient::GetIOSProvider() {
98 return GetIOSProviderAsFake();
101 ios::FakeProfileOAuth2TokenServiceIOSProvider*
102 TestSigninClient::GetIOSProviderAsFake() {
103 if (!iosProvider_) {
104 iosProvider_.reset(new ios::FakeProfileOAuth2TokenServiceIOSProvider());
106 return iosProvider_.get();
108 #endif
110 void TestSigninClient::SetSigninProcess(int process_id) {
111 if (process_id == signin_host_id_)
112 return;
113 DLOG_IF(WARNING, signin_host_id_ != kInvalidProcessId)
114 << "Replacing in-use signin process.";
115 signin_host_id_ = process_id;
118 void TestSigninClient::ClearSigninProcess() {
119 signin_host_id_ = kInvalidProcessId;
122 bool TestSigninClient::IsSigninProcess(int process_id) const {
123 return process_id == signin_host_id_;
126 bool TestSigninClient::HasSigninProcess() const {
127 return signin_host_id_ != kInvalidProcessId;
130 bool TestSigninClient::IsFirstRun() const {
131 return false;
134 base::Time TestSigninClient::GetInstallDate() {
135 return base::Time::Now();