summaryrefslogtreecommitdiffstats
path: root/chrome/test/base/chrome_render_view_host_test_harness.cc
blob: 64d086798756c953db04278a6420650413ca76b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/test/base/chrome_render_view_host_test_harness.h"

#include <utility>

#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/test/base/testing_profile.h"
#include "components/signin/core/browser/fake_signin_manager.h"

#if defined(USE_ASH)
#include "ash/shell.h"
#endif

using content::RenderViewHostTester;
using content::RenderViewHostTestHarness;

namespace {

scoped_ptr<KeyedService> BuildSigninManagerFake(
    content::BrowserContext* context) {
  Profile* profile = static_cast<Profile*>(context);
  SigninClient* signin_client =
      ChromeSigninClientFactory::GetForProfile(profile);
  AccountTrackerService* account_tracker_service =
      AccountTrackerServiceFactory::GetForProfile(profile);
#if defined (OS_CHROMEOS)
  scoped_ptr<SigninManagerBase> signin(
      new SigninManagerBase(signin_client, account_tracker_service));
  signin->Initialize(NULL);
  return signin.Pass();
#else
  scoped_ptr<FakeSigninManager> manager(new FakeSigninManager(
      signin_client, ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
      account_tracker_service,
      GaiaCookieManagerServiceFactory::GetForProfile(profile)));
  manager->Initialize(g_browser_process->local_state());
  return std::move(manager);
#endif
}

}  // namespace

ChromeRenderViewHostTestHarness::ChromeRenderViewHostTestHarness() {
}

ChromeRenderViewHostTestHarness::~ChromeRenderViewHostTestHarness() {
}

TestingProfile* ChromeRenderViewHostTestHarness::profile() {
  return static_cast<TestingProfile*>(browser_context());
}

void ChromeRenderViewHostTestHarness::TearDown() {
  RenderViewHostTestHarness::TearDown();
#if defined(USE_ASH)
  ash::Shell::DeleteInstance();
#endif
}

content::BrowserContext*
ChromeRenderViewHostTestHarness::CreateBrowserContext() {
  TestingProfile::Builder builder;
  builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
                            BuildSigninManagerFake);
  return builder.Build().release();
}