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/compositor/test/context_factories_for_test.h" |
23 #include "ui/message_center/message_center.h" | 23 #include "ui/message_center/message_center.h" |
24 #include "ui/views/corewm/capture_controller.h" | 24 #include "ui/views/corewm/capture_controller.h" |
25 #include "ui/views/corewm/transient_window_stacking_client.h" | 25 #include "ui/views/corewm/wm_state.h" |
26 | 26 |
27 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
28 #include "chromeos/audio/cras_audio_handler.h" | 28 #include "chromeos/audio/cras_audio_handler.h" |
29 #include "chromeos/dbus/dbus_thread_manager.h" | 29 #include "chromeos/dbus/dbus_thread_manager.h" |
30 #endif | 30 #endif |
31 | 31 |
32 #if defined(USE_X11) | 32 #if defined(USE_X11) |
33 #include "ui/aura/root_window_host_x11.h" | 33 #include "ui/aura/root_window_host_x11.h" |
34 #endif | 34 #endif |
35 | 35 |
36 namespace ash { | 36 namespace ash { |
37 namespace test { | 37 namespace test { |
38 | 38 |
39 AshTestHelper::AshTestHelper(base::MessageLoopForUI* message_loop) | 39 AshTestHelper::AshTestHelper(base::MessageLoopForUI* message_loop) |
40 : message_loop_(message_loop), | 40 : message_loop_(message_loop), |
41 test_shell_delegate_(NULL), | 41 test_shell_delegate_(NULL), |
42 test_screenshot_delegate_(NULL), | 42 test_screenshot_delegate_(NULL), |
43 dbus_thread_manager_initialized_(false) { | 43 dbus_thread_manager_initialized_(false) { |
44 CHECK(message_loop_); | 44 CHECK(message_loop_); |
45 #if defined(USE_X11) | 45 #if defined(USE_X11) |
46 aura::test::SetUseOverrideRedirectWindowByDefault(true); | 46 aura::test::SetUseOverrideRedirectWindowByDefault(true); |
47 #endif | 47 #endif |
48 } | 48 } |
49 | 49 |
50 AshTestHelper::~AshTestHelper() { | 50 AshTestHelper::~AshTestHelper() { |
51 } | 51 } |
52 | 52 |
53 void AshTestHelper::SetUp(bool start_session) { | 53 void AshTestHelper::SetUp(bool start_session) { |
| 54 wm_state_.reset(new views::corewm::WMState); |
| 55 |
54 // Disable animations during tests. | 56 // Disable animations during tests. |
55 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( | 57 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
56 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); | 58 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); |
57 ui::InitializeInputMethodForTesting(); | 59 ui::InitializeInputMethodForTesting(); |
58 | 60 |
59 bool allow_test_contexts = true; | 61 bool allow_test_contexts = true; |
60 ui::InitializeContextFactoryForTests(allow_test_contexts); | 62 ui::InitializeContextFactoryForTests(allow_test_contexts); |
61 | 63 |
62 // Creates Shell and hook with Desktop. | 64 // Creates Shell and hook with Desktop. |
63 test_shell_delegate_ = new TestShellDelegate; | 65 test_shell_delegate_ = new TestShellDelegate; |
(...skipping 24 matching lines...) Expand all Loading... |
88 SetHasActiveUser(true); | 90 SetHasActiveUser(true); |
89 } | 91 } |
90 | 92 |
91 test::DisplayManagerTestApi(shell->display_manager()). | 93 test::DisplayManagerTestApi(shell->display_manager()). |
92 DisableChangeDisplayUponHostResize(); | 94 DisableChangeDisplayUponHostResize(); |
93 ShellTestApi(shell).DisableOutputConfiguratorAnimation(); | 95 ShellTestApi(shell).DisableOutputConfiguratorAnimation(); |
94 | 96 |
95 test_screenshot_delegate_ = new TestScreenshotDelegate(); | 97 test_screenshot_delegate_ = new TestScreenshotDelegate(); |
96 shell->accelerator_controller()->SetScreenshotDelegate( | 98 shell->accelerator_controller()->SetScreenshotDelegate( |
97 scoped_ptr<ScreenshotDelegate>(test_screenshot_delegate_)); | 99 scoped_ptr<ScreenshotDelegate>(test_screenshot_delegate_)); |
98 | |
99 // SetWindowStackingClient() takes ownership of TransientWindowStackingClient. | |
100 aura::client::SetWindowStackingClient( | |
101 new views::corewm::TransientWindowStackingClient); | |
102 } | 100 } |
103 | 101 |
104 void AshTestHelper::TearDown() { | 102 void AshTestHelper::TearDown() { |
105 // Tear down the shell. | 103 // Tear down the shell. |
106 Shell::DeleteInstance(); | 104 Shell::DeleteInstance(); |
107 test_screenshot_delegate_ = NULL; | 105 test_screenshot_delegate_ = NULL; |
108 | 106 |
109 // Remove global message center state. | 107 // Remove global message center state. |
110 message_center::MessageCenter::Shutdown(); | 108 message_center::MessageCenter::Shutdown(); |
111 | 109 |
112 #if defined(OS_CHROMEOS) | 110 #if defined(OS_CHROMEOS) |
113 chromeos::CrasAudioHandler::Shutdown(); | 111 chromeos::CrasAudioHandler::Shutdown(); |
114 if (dbus_thread_manager_initialized_) { | 112 if (dbus_thread_manager_initialized_) { |
115 chromeos::DBusThreadManager::Shutdown(); | 113 chromeos::DBusThreadManager::Shutdown(); |
116 dbus_thread_manager_initialized_ = false; | 114 dbus_thread_manager_initialized_ = false; |
117 } | 115 } |
118 #endif | 116 #endif |
119 | 117 |
120 aura::Env::DeleteInstance(); | 118 aura::Env::DeleteInstance(); |
121 ui::TerminateContextFactoryForTests(); | 119 ui::TerminateContextFactoryForTests(); |
122 | 120 |
123 // Need to reset the initial login status. | 121 // Need to reset the initial login status. |
124 TestSystemTrayDelegate::SetInitialLoginStatus(user::LOGGED_IN_USER); | 122 TestSystemTrayDelegate::SetInitialLoginStatus(user::LOGGED_IN_USER); |
125 | 123 |
126 ui::ShutdownInputMethodForTesting(); | 124 ui::ShutdownInputMethodForTesting(); |
127 zero_duration_mode_.reset(); | 125 zero_duration_mode_.reset(); |
128 | 126 |
129 CHECK(!views::corewm::ScopedCaptureClient::IsActive()); | 127 CHECK(!views::corewm::ScopedCaptureClient::IsActive()); |
130 | 128 |
131 aura::client::SetWindowStackingClient(NULL); | 129 wm_state_.reset(); |
132 } | 130 } |
133 | 131 |
134 void AshTestHelper::RunAllPendingInMessageLoop() { | 132 void AshTestHelper::RunAllPendingInMessageLoop() { |
135 DCHECK(base::MessageLoopForUI::current() == message_loop_); | 133 DCHECK(base::MessageLoopForUI::current() == message_loop_); |
136 aura::Env::CreateInstance(); | 134 aura::Env::CreateInstance(); |
137 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher()); | 135 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher()); |
138 run_loop.RunUntilIdle(); | 136 run_loop.RunUntilIdle(); |
139 } | 137 } |
140 | 138 |
141 aura::Window* AshTestHelper::CurrentContext() { | 139 aura::Window* AshTestHelper::CurrentContext() { |
142 aura::Window* root_window = Shell::GetTargetRootWindow(); | 140 aura::Window* root_window = Shell::GetTargetRootWindow(); |
143 if (!root_window) | 141 if (!root_window) |
144 root_window = Shell::GetPrimaryRootWindow(); | 142 root_window = Shell::GetPrimaryRootWindow(); |
145 DCHECK(root_window); | 143 DCHECK(root_window); |
146 return root_window; | 144 return root_window; |
147 } | 145 } |
148 | 146 |
149 } // namespace test | 147 } // namespace test |
150 } // namespace ash | 148 } // namespace ash |
OLD | NEW |