OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 5 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
6 #include "chrome/browser/browser_process.h" | 6 #include "chrome/browser/browser_process.h" |
7 #include "chrome/browser/signin/account_tracker_service_factory.h" | 7 #include "chrome/browser/signin/account_tracker_service_factory.h" |
8 #include "chrome/browser/signin/chrome_signin_client_factory.h" | 8 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
9 #include "chrome/browser/signin/fake_signin_manager.h" | 9 #include "chrome/browser/signin/fake_signin_manager.h" |
10 #include "chrome/browser/signin/signin_manager_factory.h" | 10 #include "chrome/browser/signin/signin_manager_factory.h" |
11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
12 | 12 |
13 #if defined(USE_ASH) | 13 #if defined(USE_ASH) |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
15 #endif | 15 #endif |
16 | 16 |
17 #if defined(USE_AURA) | 17 #if defined(USE_AURA) |
18 #include "ui/aura/env.h" | 18 #include "ui/aura/env.h" |
19 #include "ui/aura/window_event_dispatcher.h" | 19 #include "ui/aura/window_event_dispatcher.h" |
20 #endif | 20 #endif |
21 | 21 |
22 using content::RenderViewHostTester; | 22 using content::RenderViewHostTester; |
23 using content::RenderViewHostTestHarness; | 23 using content::RenderViewHostTestHarness; |
24 | 24 |
| 25 namespace { |
| 26 |
| 27 scoped_ptr<KeyedService> BuildSigninManagerFake( |
| 28 content::BrowserContext* context) { |
| 29 Profile* profile = static_cast<Profile*>(context); |
| 30 #if defined (OS_CHROMEOS) |
| 31 scoped_ptr<SigninManagerBase> signin(new SigninManagerBase( |
| 32 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile), |
| 33 AccountTrackerServiceFactory::GetInstance()->GetForProfile(profile))); |
| 34 signin->Initialize(NULL); |
| 35 return signin.Pass(); |
| 36 #else |
| 37 scoped_ptr<FakeSigninManager> manager(new FakeSigninManager(profile)); |
| 38 manager->Initialize(g_browser_process->local_state()); |
| 39 return manager.Pass(); |
| 40 #endif |
| 41 } |
| 42 |
| 43 } // namespace |
| 44 |
25 ChromeRenderViewHostTestHarness::ChromeRenderViewHostTestHarness() { | 45 ChromeRenderViewHostTestHarness::ChromeRenderViewHostTestHarness() { |
26 } | 46 } |
27 | 47 |
28 ChromeRenderViewHostTestHarness::~ChromeRenderViewHostTestHarness() { | 48 ChromeRenderViewHostTestHarness::~ChromeRenderViewHostTestHarness() { |
29 } | 49 } |
30 | 50 |
31 TestingProfile* ChromeRenderViewHostTestHarness::profile() { | 51 TestingProfile* ChromeRenderViewHostTestHarness::profile() { |
32 return static_cast<TestingProfile*>(browser_context()); | 52 return static_cast<TestingProfile*>(browser_context()); |
33 } | 53 } |
34 | 54 |
35 static KeyedService* BuildSigninManagerFake(content::BrowserContext* context) { | |
36 Profile* profile = static_cast<Profile*>(context); | |
37 #if defined (OS_CHROMEOS) | |
38 SigninManagerBase* signin = new SigninManagerBase( | |
39 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile), | |
40 AccountTrackerServiceFactory::GetInstance()->GetForProfile(profile)); | |
41 signin->Initialize(NULL); | |
42 return signin; | |
43 #else | |
44 FakeSigninManager* manager = new FakeSigninManager(profile); | |
45 manager->Initialize(g_browser_process->local_state()); | |
46 return manager; | |
47 #endif | |
48 } | |
49 | |
50 void ChromeRenderViewHostTestHarness::TearDown() { | 55 void ChromeRenderViewHostTestHarness::TearDown() { |
51 RenderViewHostTestHarness::TearDown(); | 56 RenderViewHostTestHarness::TearDown(); |
52 #if defined(USE_ASH) | 57 #if defined(USE_ASH) |
53 ash::Shell::DeleteInstance(); | 58 ash::Shell::DeleteInstance(); |
54 #endif | 59 #endif |
55 #if defined(USE_AURA) | 60 #if defined(USE_AURA) |
56 aura::Env::DeleteInstance(); | 61 aura::Env::DeleteInstance(); |
57 #endif | 62 #endif |
58 } | 63 } |
59 | 64 |
60 content::BrowserContext* | 65 content::BrowserContext* |
61 ChromeRenderViewHostTestHarness::CreateBrowserContext() { | 66 ChromeRenderViewHostTestHarness::CreateBrowserContext() { |
62 TestingProfile::Builder builder; | 67 TestingProfile::Builder builder; |
63 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), | 68 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), |
64 BuildSigninManagerFake); | 69 BuildSigninManagerFake); |
65 return builder.Build().release(); | 70 return builder.Build().release(); |
66 } | 71 } |
OLD | NEW |