Update JNI generator for javap version 1.8.
[chromium-blink-merge.git] / ash / test / ash_test_helper.cc
blobc9f6c7d56b0acdb60d36f56a42d1851eca36ac97
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
3 // found in the LICENSE file.
5 #include "ash/test/ash_test_helper.h"
7 #include "ash/accelerators/accelerator_controller.h"
8 #include "ash/ash_switches.h"
9 #include "ash/shell.h"
10 #include "ash/shell_init_params.h"
11 #include "ash/test/ash_test_views_delegate.h"
12 #include "ash/test/display_manager_test_api.h"
13 #include "ash/test/shell_test_api.h"
14 #include "ash/test/test_screenshot_delegate.h"
15 #include "ash/test/test_session_state_delegate.h"
16 #include "ash/test/test_shell_delegate.h"
17 #include "ash/test/test_system_tray_delegate.h"
18 #include "base/run_loop.h"
19 #include "ui/aura/env.h"
20 #include "ui/aura/input_state_lookup.h"
21 #include "ui/aura/test/env_test_helper.h"
22 #include "ui/aura/test/event_generator_delegate_aura.h"
23 #include "ui/base/ime/input_method_initializer.h"
24 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
25 #include "ui/compositor/test/context_factories_for_test.h"
26 #include "ui/message_center/message_center.h"
27 #include "ui/wm/core/capture_controller.h"
29 #if defined(OS_CHROMEOS)
30 #include "chromeos/audio/cras_audio_handler.h"
31 #include "chromeos/dbus/dbus_thread_manager.h"
32 #include "ui/keyboard/keyboard.h"
33 #endif
35 #if defined(OS_WIN)
36 #include "base/win/windows_version.h"
37 #endif
39 #if defined(USE_X11)
40 #include "ui/aura/window_tree_host_x11.h"
41 #endif
43 namespace ash {
44 namespace test {
46 AshTestHelper::AshTestHelper(base::MessageLoopForUI* message_loop)
47 : message_loop_(message_loop),
48 test_shell_delegate_(NULL),
49 test_screenshot_delegate_(NULL) {
50 CHECK(message_loop_);
51 #if defined(OS_CHROMEOS)
52 dbus_thread_manager_initialized_ = false;
53 #endif
54 #if defined(USE_X11)
55 aura::test::SetUseOverrideRedirectWindowByDefault(true);
56 #endif
57 aura::test::InitializeAuraEventGeneratorDelegate();
60 AshTestHelper::~AshTestHelper() {
63 void AshTestHelper::SetUp(bool start_session) {
64 views_delegate_.reset(new AshTestViewsDelegate);
66 // Disable animations during tests.
67 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
68 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
69 ui::InitializeInputMethodForTesting();
71 bool enable_pixel_output = false;
72 ui::ContextFactory* context_factory =
73 ui::InitializeContextFactoryForTests(enable_pixel_output);
75 // Creates Shell and hook with Desktop.
76 if (!test_shell_delegate_)
77 test_shell_delegate_ = new TestShellDelegate;
79 // Creates MessageCenter since g_browser_process is not created in AshTestBase
80 // tests.
81 message_center::MessageCenter::Initialize();
83 #if defined(OS_CHROMEOS)
84 // Create DBusThreadManager for testing.
85 if (!chromeos::DBusThreadManager::IsInitialized()) {
86 chromeos::DBusThreadManager::Initialize();
87 dbus_thread_manager_initialized_ = true;
89 // Create CrasAudioHandler for testing since g_browser_process is not
90 // created in AshTestBase tests.
91 chromeos::CrasAudioHandler::InitializeForTesting();
92 #endif
93 ShellInitParams init_params;
94 init_params.delegate = test_shell_delegate_;
95 init_params.context_factory = context_factory;
96 ash::Shell::CreateInstance(init_params);
97 aura::test::EnvTestHelper(aura::Env::GetInstance()).SetInputStateLookup(
98 scoped_ptr<aura::InputStateLookup>());
100 Shell* shell = Shell::GetInstance();
101 if (start_session) {
102 test_shell_delegate_->test_session_state_delegate()->
103 SetActiveUserSessionStarted(true);
104 test_shell_delegate_->test_session_state_delegate()->
105 SetHasActiveUser(true);
108 test::DisplayManagerTestApi(shell->display_manager()).
109 DisableChangeDisplayUponHostResize();
110 ShellTestApi(shell).DisableDisplayConfiguratorAnimation();
112 test_screenshot_delegate_ = new TestScreenshotDelegate();
113 shell->accelerator_controller()->SetScreenshotDelegate(
114 scoped_ptr<ScreenshotDelegate>(test_screenshot_delegate_));
117 void AshTestHelper::TearDown() {
118 // Tear down the shell.
119 Shell::DeleteInstance();
120 test_screenshot_delegate_ = NULL;
122 // Remove global message center state.
123 message_center::MessageCenter::Shutdown();
125 #if defined(OS_CHROMEOS)
126 chromeos::CrasAudioHandler::Shutdown();
127 if (dbus_thread_manager_initialized_) {
128 chromeos::DBusThreadManager::Shutdown();
129 dbus_thread_manager_initialized_ = false;
131 keyboard::ResetKeyboardForTesting();
132 #endif
134 aura::Env::DeleteInstance();
135 ui::TerminateContextFactoryForTests();
137 // Need to reset the initial login status.
138 TestSystemTrayDelegate::SetInitialLoginStatus(user::LOGGED_IN_USER);
140 ui::ShutdownInputMethodForTesting();
141 zero_duration_mode_.reset();
143 CHECK(!wm::ScopedCaptureClient::IsActive());
145 views_delegate_.reset();
148 void AshTestHelper::RunAllPendingInMessageLoop() {
149 DCHECK(base::MessageLoopForUI::current() == message_loop_);
150 aura::Env::CreateInstance(true);
151 base::RunLoop run_loop;
152 run_loop.RunUntilIdle();
155 aura::Window* AshTestHelper::CurrentContext() {
156 aura::Window* root_window = Shell::GetTargetRootWindow();
157 if (!root_window)
158 root_window = Shell::GetPrimaryRootWindow();
159 DCHECK(root_window);
160 return root_window;
163 // static
164 bool AshTestHelper::SupportsMultipleDisplays() {
165 #if defined(OS_WIN)
166 return false;
167 #else
168 return true;
169 #endif
172 // static
173 bool AshTestHelper::SupportsHostWindowResize() {
174 #if defined(OS_WIN)
175 return false;
176 #else
177 return true;
178 #endif
181 } // namespace test
182 } // namespace ash