OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/test/ash_test_helper.h" | 5 #include "ash/test/ash_test_helper.h" |
6 | 6 |
7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
8 #include "ash/ash_switches.h" | 8 #include "ash/ash_switches.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/test/display_manager_test_api.h" | 10 #include "ash/test/display_manager_test_api.h" |
11 #include "ash/test/shell_test_api.h" | 11 #include "ash/test/shell_test_api.h" |
12 #include "ash/test/test_screenshot_delegate.h" | 12 #include "ash/test/test_screenshot_delegate.h" |
13 #include "ash/test/test_session_state_delegate.h" | 13 #include "ash/test/test_session_state_delegate.h" |
14 #include "ash/test/test_shell_delegate.h" | 14 #include "ash/test/test_shell_delegate.h" |
15 #include "ash/test/test_system_tray_delegate.h" | 15 #include "ash/test/test_system_tray_delegate.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
18 #include "ui/aura/input_state_lookup.h" | 18 #include "ui/aura/input_state_lookup.h" |
19 #include "ui/aura/test/env_test_helper.h" | 19 #include "ui/aura/test/env_test_helper.h" |
20 #include "ui/base/ime/input_method_initializer.h" | 20 #include "ui/base/ime/input_method_initializer.h" |
21 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 21 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 22 #include "ui/compositor/test/context_factories_for_test.h" |
22 #include "ui/message_center/message_center.h" | 23 #include "ui/message_center/message_center.h" |
23 #include "ui/views/corewm/capture_controller.h" | 24 #include "ui/views/corewm/capture_controller.h" |
24 | 25 |
25 #if defined(OS_CHROMEOS) | 26 #if defined(OS_CHROMEOS) |
26 #include "chromeos/audio/cras_audio_handler.h" | 27 #include "chromeos/audio/cras_audio_handler.h" |
27 #include "chromeos/network/network_handler.h" | 28 #include "chromeos/network/network_handler.h" |
28 #endif | 29 #endif |
29 | 30 |
30 #if defined(USE_X11) | 31 #if defined(USE_X11) |
31 #include "ui/aura/root_window_host_x11.h" | 32 #include "ui/aura/root_window_host_x11.h" |
(...skipping 15 matching lines...) Expand all Loading... |
47 | 48 |
48 AshTestHelper::~AshTestHelper() { | 49 AshTestHelper::~AshTestHelper() { |
49 } | 50 } |
50 | 51 |
51 void AshTestHelper::SetUp(bool start_session) { | 52 void AshTestHelper::SetUp(bool start_session) { |
52 // Disable animations during tests. | 53 // Disable animations during tests. |
53 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( | 54 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
54 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); | 55 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); |
55 ui::InitializeInputMethodForTesting(); | 56 ui::InitializeInputMethodForTesting(); |
56 | 57 |
| 58 bool allow_test_contexts = true; |
| 59 ui::InitializeContextFactoryForTests(allow_test_contexts); |
| 60 |
57 // Creates Shell and hook with Desktop. | 61 // Creates Shell and hook with Desktop. |
58 test_shell_delegate_ = new TestShellDelegate; | 62 test_shell_delegate_ = new TestShellDelegate; |
59 | 63 |
60 // Creates MessageCenter since g_browser_process is not created in AshTestBase | 64 // Creates MessageCenter since g_browser_process is not created in AshTestBase |
61 // tests. | 65 // tests. |
62 message_center::MessageCenter::Initialize(); | 66 message_center::MessageCenter::Initialize(); |
63 | 67 |
64 #if defined(OS_CHROMEOS) | 68 #if defined(OS_CHROMEOS) |
65 // Create CrasAudioHandler for testing since g_browser_process is not | 69 // Create CrasAudioHandler for testing since g_browser_process is not |
66 // created in AshTestBase tests. | 70 // created in AshTestBase tests. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // Remove global message center state. | 108 // Remove global message center state. |
105 message_center::MessageCenter::Shutdown(); | 109 message_center::MessageCenter::Shutdown(); |
106 | 110 |
107 #if defined(OS_CHROMEOS) | 111 #if defined(OS_CHROMEOS) |
108 if (tear_down_network_handler_ && chromeos::NetworkHandler::IsInitialized()) | 112 if (tear_down_network_handler_ && chromeos::NetworkHandler::IsInitialized()) |
109 chromeos::NetworkHandler::Shutdown(); | 113 chromeos::NetworkHandler::Shutdown(); |
110 chromeos::CrasAudioHandler::Shutdown(); | 114 chromeos::CrasAudioHandler::Shutdown(); |
111 #endif | 115 #endif |
112 | 116 |
113 aura::Env::DeleteInstance(); | 117 aura::Env::DeleteInstance(); |
| 118 ui::TerminateContextFactoryForTests(); |
114 | 119 |
115 // Need to reset the initial login status. | 120 // Need to reset the initial login status. |
116 TestSystemTrayDelegate::SetInitialLoginStatus(user::LOGGED_IN_USER); | 121 TestSystemTrayDelegate::SetInitialLoginStatus(user::LOGGED_IN_USER); |
117 | 122 |
118 ui::ShutdownInputMethodForTesting(); | 123 ui::ShutdownInputMethodForTesting(); |
119 zero_duration_mode_.reset(); | 124 zero_duration_mode_.reset(); |
120 | 125 |
121 CHECK(!views::corewm::ScopedCaptureClient::IsActive()); | 126 CHECK(!views::corewm::ScopedCaptureClient::IsActive()); |
122 } | 127 } |
123 | 128 |
124 void AshTestHelper::RunAllPendingInMessageLoop() { | 129 void AshTestHelper::RunAllPendingInMessageLoop() { |
125 DCHECK(base::MessageLoopForUI::current() == message_loop_); | 130 DCHECK(base::MessageLoopForUI::current() == message_loop_); |
126 aura::Env::CreateInstance(); | 131 aura::Env::CreateInstance(); |
127 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher()); | 132 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher()); |
128 run_loop.RunUntilIdle(); | 133 run_loop.RunUntilIdle(); |
129 } | 134 } |
130 | 135 |
131 aura::Window* AshTestHelper::CurrentContext() { | 136 aura::Window* AshTestHelper::CurrentContext() { |
132 aura::Window* root_window = Shell::GetTargetRootWindow(); | 137 aura::Window* root_window = Shell::GetTargetRootWindow(); |
133 if (!root_window) | 138 if (!root_window) |
134 root_window = Shell::GetPrimaryRootWindow(); | 139 root_window = Shell::GetPrimaryRootWindow(); |
135 DCHECK(root_window); | 140 DCHECK(root_window); |
136 return root_window; | 141 return root_window; |
137 } | 142 } |
138 | 143 |
139 } // namespace test | 144 } // namespace test |
140 } // namespace ash | 145 } // namespace ash |
OLD | NEW |