Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / components / signin / core / browser / test_signin_client.cc
blob68b32df46e6f663616bd672d4b2dbbbd48911e88
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() {
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());
75 database_->Init();
78 bool TestSigninClient::ShouldMergeSigninCredentialsIntoCookieJar() {
79 return true;
82 scoped_ptr<SigninClient::CookieChangedSubscription>
83 TestSigninClient::AddCookieChangedCallback(
84 const GURL& url,
85 const std::string& name,
86 const net::CookieStore::CookieChangedCallback& callback) {
87 return scoped_ptr<SigninClient::CookieChangedSubscription>(
88 new SigninClient::CookieChangedSubscription);
91 #if defined(OS_IOS)
92 ios::ProfileOAuth2TokenServiceIOSProvider* TestSigninClient::GetIOSProvider() {
93 return GetIOSProviderAsFake();
96 ios::FakeProfileOAuth2TokenServiceIOSProvider*
97 TestSigninClient::GetIOSProviderAsFake() {
98 if (!iosProvider_) {
99 iosProvider_.reset(new ios::FakeProfileOAuth2TokenServiceIOSProvider());
101 return iosProvider_.get();
103 #endif
105 void TestSigninClient::SetSigninProcess(int process_id) {
106 if (process_id == signin_host_id_)
107 return;
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 {
126 return false;
129 base::Time TestSigninClient::GetInstallDate() {
130 return base::Time::Now();