Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / test / base / chrome_render_view_host_test_harness.cc
blobb32b8e62fcd50c67107492aa86374d74b7c466d5
1 // Copyright (c) 2012 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 "chrome/browser/browser_process.h"
6 #include "chrome/browser/signin/account_tracker_service_factory.h"
7 #include "chrome/browser/signin/chrome_signin_client_factory.h"
8 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
9 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
10 #include "chrome/browser/signin/signin_manager_factory.h"
11 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "components/signin/core/browser/fake_signin_manager.h"
15 #if defined(USE_ASH)
16 #include "ash/shell.h"
17 #endif
19 using content::RenderViewHostTester;
20 using content::RenderViewHostTestHarness;
22 namespace {
24 scoped_ptr<KeyedService> BuildSigninManagerFake(
25 content::BrowserContext* context) {
26 Profile* profile = static_cast<Profile*>(context);
27 SigninClient* signin_client =
28 ChromeSigninClientFactory::GetForProfile(profile);
29 AccountTrackerService* account_tracker_service =
30 AccountTrackerServiceFactory::GetForProfile(profile);
31 #if defined (OS_CHROMEOS)
32 scoped_ptr<SigninManagerBase> signin(
33 new SigninManagerBase(signin_client, account_tracker_service));
34 signin->Initialize(NULL);
35 return signin.Pass();
36 #else
37 scoped_ptr<FakeSigninManager> manager(new FakeSigninManager(
38 signin_client, ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
39 account_tracker_service,
40 GaiaCookieManagerServiceFactory::GetForProfile(profile)));
41 manager->Initialize(g_browser_process->local_state());
42 return manager.Pass();
43 #endif
46 } // namespace
48 ChromeRenderViewHostTestHarness::ChromeRenderViewHostTestHarness() {
51 ChromeRenderViewHostTestHarness::~ChromeRenderViewHostTestHarness() {
54 TestingProfile* ChromeRenderViewHostTestHarness::profile() {
55 return static_cast<TestingProfile*>(browser_context());
58 void ChromeRenderViewHostTestHarness::TearDown() {
59 RenderViewHostTestHarness::TearDown();
60 #if defined(USE_ASH)
61 ash::Shell::DeleteInstance();
62 #endif
65 content::BrowserContext*
66 ChromeRenderViewHostTestHarness::CreateBrowserContext() {
67 TestingProfile::Builder builder;
68 builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
69 BuildSigninManagerFake);
70 return builder.Build().release();