test_signin_client.cc revision a02191e04bc25c4935f804f2c080ae28663d096d
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
16TestSigninClient::TestSigninClient()
17    : request_context_(new net::TestURLRequestContextGetter(
18          base::MessageLoopProxy::current())) {
19  LoadDatabase();
20}
21
22TestSigninClient::~TestSigninClient() {}
23
24PrefService* TestSigninClient::GetPrefs() { return NULL; }
25
26scoped_refptr<TokenWebData> TestSigninClient::GetDatabase() {
27  return database_;
28}
29
30bool TestSigninClient::CanRevokeCredentials() { return true; }
31
32net::URLRequestContextGetter* TestSigninClient::GetURLRequestContext() {
33  return request_context_;
34}
35
36std::string TestSigninClient::GetProductVersion() { return ""; }
37
38void TestSigninClient::LoadDatabase() {
39  ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
40  base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB");
41  scoped_refptr<WebDatabaseService> web_database =
42      new WebDatabaseService(path,
43                             base::MessageLoopProxy::current(),
44                             base::MessageLoopProxy::current());
45  web_database->AddTable(scoped_ptr<WebDatabaseTable>(new TokenServiceTable()));
46  web_database->LoadDatabase();
47  database_ = new TokenWebData(web_database,
48                               base::MessageLoopProxy::current(),
49                               base::MessageLoopProxy::current(),
50                               WebDataServiceBase::ProfileErrorCallback());
51  database_->Init();
52}
53
54bool TestSigninClient::ShouldMergeSigninCredentialsIntoCookieJar() {
55  return true;
56}
57
58void TestSigninClient::SetCookieChangedCallback(
59    const CookieChangedCallback& callback) {}
60
61#if defined(OS_IOS)
62ios::ProfileOAuth2TokenServiceIOSProvider* TestSigninClient::GetIOSProvider() {
63  return GetIOSProviderAsFake();
64}
65
66ios::FakeProfileOAuth2TokenServiceIOSProvider*
67TestSigninClient::GetIOSProviderAsFake() {
68  if (!iosProvider_) {
69    iosProvider_.reset(new ios::FakeProfileOAuth2TokenServiceIOSProvider());
70  }
71  return iosProvider_.get();
72}
73#endif
74