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_delegate_aura.h" | 7 #include "ash/accelerators/accelerator_controller_delegate_aura.h" |
8 #include "ash/common/test/test_session_state_delegate.h" | 8 #include "ash/common/test/test_session_state_delegate.h" |
9 #include "ash/common/test/test_system_tray_delegate.h" | 9 #include "ash/common/test/test_system_tray_delegate.h" |
10 #include "ash/common/test/wm_shell_test_api.h" | 10 #include "ash/common/test/wm_shell_test_api.h" |
11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
| 12 #include "ash/common/wm_window.h" |
| 13 #include "ash/mus/screen_mus.h" |
| 14 #include "ash/mus/window_manager.h" |
| 15 #include "ash/mus/window_manager_application.h" |
12 #include "ash/shell.h" | 16 #include "ash/shell.h" |
13 #include "ash/shell_init_params.h" | 17 #include "ash/shell_init_params.h" |
14 #include "ash/system/chromeos/screen_layout_observer.h" | 18 #include "ash/system/chromeos/screen_layout_observer.h" |
15 #include "ash/test/ash_test_environment.h" | 19 #include "ash/test/ash_test_environment.h" |
16 #include "ash/test/ash_test_views_delegate.h" | 20 #include "ash/test/ash_test_views_delegate.h" |
17 #include "ash/test/shell_test_api.h" | 21 #include "ash/test/shell_test_api.h" |
18 #include "ash/test/test_screenshot_delegate.h" | 22 #include "ash/test/test_screenshot_delegate.h" |
19 #include "ash/test/test_shell_delegate.h" | 23 #include "ash/test/test_shell_delegate.h" |
20 #include "base/memory/ptr_util.h" | 24 #include "base/memory/ptr_util.h" |
21 #include "base/run_loop.h" | 25 #include "base/run_loop.h" |
| 26 #include "base/strings/string_split.h" |
| 27 #include "base/test/sequenced_worker_pool_owner.h" |
22 #include "chromeos/audio/cras_audio_handler.h" | 28 #include "chromeos/audio/cras_audio_handler.h" |
23 #include "chromeos/dbus/dbus_thread_manager.h" | 29 #include "chromeos/dbus/dbus_thread_manager.h" |
24 #include "device/bluetooth/bluetooth_adapter_factory.h" | 30 #include "device/bluetooth/bluetooth_adapter_factory.h" |
25 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 31 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
26 #include "ui/aura/env.h" | 32 #include "ui/aura/env.h" |
27 #include "ui/aura/input_state_lookup.h" | 33 #include "ui/aura/input_state_lookup.h" |
| 34 #include "ui/aura/mus/window_tree_client.h" |
28 #include "ui/aura/test/env_test_helper.h" | 35 #include "ui/aura/test/env_test_helper.h" |
29 #include "ui/aura/test/event_generator_delegate_aura.h" | 36 #include "ui/aura/test/event_generator_delegate_aura.h" |
| 37 #include "ui/aura/test/mus/window_tree_client_private.h" |
30 #include "ui/base/ime/input_method_initializer.h" | 38 #include "ui/base/ime/input_method_initializer.h" |
31 #include "ui/base/material_design/material_design_controller.h" | 39 #include "ui/base/material_design/material_design_controller.h" |
32 #include "ui/base/platform_window_defaults.h" | 40 #include "ui/base/platform_window_defaults.h" |
33 #include "ui/base/test/material_design_controller_test_api.h" | 41 #include "ui/base/test/material_design_controller_test_api.h" |
34 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 42 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
35 #include "ui/compositor/test/context_factories_for_test.h" | 43 #include "ui/compositor/test/context_factories_for_test.h" |
| 44 #include "ui/display/manager/display_manager.h" |
36 #include "ui/display/manager/managed_display_info.h" | 45 #include "ui/display/manager/managed_display_info.h" |
37 #include "ui/display/test/display_manager_test_api.h" | 46 #include "ui/display/test/display_manager_test_api.h" |
38 #include "ui/message_center/message_center.h" | 47 #include "ui/message_center/message_center.h" |
39 #include "ui/wm/core/capture_controller.h" | 48 #include "ui/wm/core/capture_controller.h" |
40 #include "ui/wm/core/cursor_manager.h" | 49 #include "ui/wm/core/cursor_manager.h" |
41 #include "ui/wm/core/wm_state.h" | 50 #include "ui/wm/core/wm_state.h" |
42 | 51 |
| 52 using display::ManagedDisplayInfo; |
| 53 |
43 namespace ash { | 54 namespace ash { |
44 namespace test { | 55 namespace test { |
| 56 namespace { |
| 57 |
| 58 bool IsMash() { |
| 59 return aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS; |
| 60 } |
| 61 |
| 62 bool CompareByDisplayId(RootWindowController* root1, |
| 63 RootWindowController* root2) { |
| 64 return root1->GetWindow()->GetDisplayNearestWindow().id() < |
| 65 root2->GetWindow()->GetDisplayNearestWindow().id(); |
| 66 } |
| 67 |
| 68 } // namespace |
45 | 69 |
46 AshTestHelper::AshTestHelper(AshTestEnvironment* ash_test_environment) | 70 AshTestHelper::AshTestHelper(AshTestEnvironment* ash_test_environment) |
47 : ash_test_environment_(ash_test_environment), | 71 : ash_test_environment_(ash_test_environment), |
48 test_shell_delegate_(nullptr), | 72 test_shell_delegate_(nullptr), |
49 test_screenshot_delegate_(nullptr), | 73 test_screenshot_delegate_(nullptr), |
50 dbus_thread_manager_initialized_(false), | 74 dbus_thread_manager_initialized_(false), |
51 bluez_dbus_manager_initialized_(false) { | 75 bluez_dbus_manager_initialized_(false) { |
52 ui::test::EnableTestConfigForPlatformWindows(); | 76 ui::test::EnableTestConfigForPlatformWindows(); |
53 aura::test::InitializeAuraEventGeneratorDelegate(); | 77 aura::test::InitializeAuraEventGeneratorDelegate(); |
54 } | 78 } |
55 | 79 |
56 AshTestHelper::~AshTestHelper() {} | 80 AshTestHelper::~AshTestHelper() {} |
57 | 81 |
58 void AshTestHelper::SetUp(bool start_session) { | 82 void AshTestHelper::SetUp(bool start_session) { |
59 display::ResetDisplayIdForTest(); | 83 display::ResetDisplayIdForTest(); |
60 wm_state_ = base::MakeUnique<::wm::WMState>(); | 84 const bool is_mash = IsMash(); |
| 85 if (is_mash) |
| 86 aura::test::EnvTestHelper().SetAlwaysUseLastMouseLocation(true); |
| 87 // WindowManager creates WMState for mash. |
| 88 if (!is_mash) |
| 89 wm_state_ = base::MakeUnique<::wm::WMState>(); |
61 views_delegate_ = ash_test_environment_->CreateViewsDelegate(); | 90 views_delegate_ = ash_test_environment_->CreateViewsDelegate(); |
62 | 91 |
63 // Disable animations during tests. | 92 // Disable animations during tests. |
64 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( | 93 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
65 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); | 94 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); |
66 ui::InitializeInputMethodForTesting(); | 95 ui::InitializeInputMethodForTesting(); |
67 | 96 |
68 bool enable_pixel_output = false; | |
69 ui::ContextFactory* context_factory = nullptr; | |
70 ui::ContextFactoryPrivate* context_factory_private = nullptr; | |
71 ui::InitializeContextFactoryForTests(enable_pixel_output, &context_factory, | |
72 &context_factory_private); | |
73 | |
74 // Creates Shell and hook with Desktop. | 97 // Creates Shell and hook with Desktop. |
75 if (!test_shell_delegate_) | 98 if (!test_shell_delegate_) |
76 test_shell_delegate_ = new TestShellDelegate; | 99 test_shell_delegate_ = new TestShellDelegate; |
77 | 100 |
78 // Creates MessageCenter since g_browser_process is not created in AshTestBase | 101 if (!is_mash) { |
79 // tests. | 102 // All of this initialization is done in WindowManagerApplication for mash. |
80 message_center::MessageCenter::Initialize(); | |
81 | 103 |
82 // Create DBusThreadManager for testing. | 104 // Creates MessageCenter since g_browser_process is not created in |
83 if (!chromeos::DBusThreadManager::IsInitialized()) { | 105 // AshTestBase tests. |
84 chromeos::DBusThreadManager::Initialize( | 106 message_center::MessageCenter::Initialize(); |
85 chromeos::DBusThreadManager::PROCESS_ASH); | 107 |
86 dbus_thread_manager_initialized_ = true; | 108 if (!chromeos::DBusThreadManager::IsInitialized()) { |
| 109 chromeos::DBusThreadManager::Initialize( |
| 110 chromeos::DBusThreadManager::PROCESS_ASH); |
| 111 dbus_thread_manager_initialized_ = true; |
| 112 } |
| 113 |
| 114 if (!bluez::BluezDBusManager::IsInitialized()) { |
| 115 bluez::BluezDBusManager::Initialize( |
| 116 chromeos::DBusThreadManager::Get()->GetSystemBus(), |
| 117 chromeos::DBusThreadManager::Get()->IsUsingFakes()); |
| 118 bluez_dbus_manager_initialized_ = true; |
| 119 } |
| 120 |
| 121 // Create CrasAudioHandler for testing since g_browser_process is not |
| 122 // created in AshTestBase tests. |
| 123 chromeos::CrasAudioHandler::InitializeForTesting(); |
87 } | 124 } |
88 | 125 |
89 if (!bluez::BluezDBusManager::IsInitialized()) { | |
90 bluez::BluezDBusManager::Initialize( | |
91 chromeos::DBusThreadManager::Get()->GetSystemBus(), | |
92 chromeos::DBusThreadManager::Get()->IsUsingFakes()); | |
93 bluez_dbus_manager_initialized_ = true; | |
94 } | |
95 | |
96 // Create CrasAudioHandler for testing since g_browser_process is not | |
97 // created in AshTestBase tests. | |
98 chromeos::CrasAudioHandler::InitializeForTesting(); | |
99 | |
100 ash_test_environment_->SetUp(); | 126 ash_test_environment_->SetUp(); |
101 // Reset the global state for the cursor manager. This includes the | 127 // Reset the global state for the cursor manager. This includes the |
102 // last cursor visibility state, etc. | 128 // last cursor visibility state, etc. |
103 ::wm::CursorManager::ResetCursorVisibilityStateForTest(); | 129 ::wm::CursorManager::ResetCursorVisibilityStateForTest(); |
104 | 130 |
105 // ContentTestSuiteBase might have already initialized | 131 // ContentTestSuiteBase might have already initialized |
106 // MaterialDesignController in unit_tests suite. | 132 // MaterialDesignController in unit_tests suite. |
107 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); | 133 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); |
108 ui::MaterialDesignController::Initialize(); | 134 ui::MaterialDesignController::Initialize(); |
109 | 135 |
110 ShellInitParams init_params; | 136 if (is_mash) |
111 init_params.delegate = test_shell_delegate_; | 137 CreateMashWindowManager(); |
112 init_params.context_factory = context_factory; | 138 else |
113 init_params.context_factory_private = context_factory_private; | 139 CreateShell(); |
114 init_params.blocking_pool = ash_test_environment_->GetBlockingPool(); | 140 |
115 Shell::CreateInstance(init_params); | 141 aura::test::EnvTestHelper().SetInputStateLookup( |
116 aura::test::EnvTestHelper(aura::Env::GetInstance()) | 142 std::unique_ptr<aura::InputStateLookup>()); |
117 .SetInputStateLookup(std::unique_ptr<aura::InputStateLookup>()); | |
118 | 143 |
119 Shell* shell = Shell::GetInstance(); | 144 Shell* shell = Shell::GetInstance(); |
120 if (start_session) { | 145 if (start_session) { |
121 GetTestSessionStateDelegate()->SetActiveUserSessionStarted(true); | 146 GetTestSessionStateDelegate()->SetActiveUserSessionStarted(true); |
122 GetTestSessionStateDelegate()->SetHasActiveUser(true); | 147 GetTestSessionStateDelegate()->SetHasActiveUser(true); |
123 } | 148 } |
124 | 149 |
125 // Tests that change the display configuration generally don't care about the | 150 if (!is_mash) { |
126 // notifications and the popup UI can interfere with things like cursors. | 151 // ScreenLayoutObserver is specific to classic-ash. |
127 shell->screen_layout_observer()->set_show_notifications_for_testing(false); | 152 // Tests that change the display configuration generally don't care about |
| 153 // the notifications and the popup UI can interfere with things like |
| 154 // cursors. |
| 155 shell->screen_layout_observer()->set_show_notifications_for_testing(false); |
128 | 156 |
129 display::test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()) | 157 // DisplayManager is specific to classic-ash. |
130 .DisableChangeDisplayUponHostResize(); | 158 display::test::DisplayManagerTestApi( |
131 ShellTestApi(shell).DisableDisplayAnimator(); | 159 Shell::GetInstance()->display_manager()) |
| 160 .DisableChangeDisplayUponHostResize(); |
| 161 ShellTestApi(shell).DisableDisplayAnimator(); |
132 | 162 |
133 test_screenshot_delegate_ = new TestScreenshotDelegate(); | 163 // TODO: disabled for mash as AcceleratorControllerDelegateAura isn't |
134 shell->accelerator_controller_delegate()->SetScreenshotDelegate( | 164 // created in mash http://crbug.com/632111. |
135 std::unique_ptr<ScreenshotDelegate>(test_screenshot_delegate_)); | 165 test_screenshot_delegate_ = new TestScreenshotDelegate(); |
| 166 shell->accelerator_controller_delegate()->SetScreenshotDelegate( |
| 167 std::unique_ptr<ScreenshotDelegate>(test_screenshot_delegate_)); |
| 168 } |
136 } | 169 } |
137 | 170 |
138 void AshTestHelper::TearDown() { | 171 void AshTestHelper::TearDown() { |
139 // Tear down the shell. | 172 window_manager_app_.reset(); |
140 Shell::DeleteInstance(); | 173 |
| 174 const bool is_mash = IsMash(); |
| 175 |
| 176 // WindowManger owns the Shell in mash. |
| 177 if (!is_mash) |
| 178 Shell::DeleteInstance(); |
141 | 179 |
142 // Suspend the tear down until all resources are returned via | 180 // Suspend the tear down until all resources are returned via |
143 // MojoCompositorFrameSinkClient::ReclaimResources() | 181 // MojoCompositorFrameSinkClient::ReclaimResources() |
144 RunAllPendingInMessageLoop(); | 182 RunAllPendingInMessageLoop(); |
145 ash_test_environment_->TearDown(); | 183 ash_test_environment_->TearDown(); |
146 | 184 |
147 test_screenshot_delegate_ = NULL; | 185 test_screenshot_delegate_ = NULL; |
148 | 186 |
149 // Remove global message center state. | 187 if (!is_mash) { |
150 message_center::MessageCenter::Shutdown(); | 188 // Remove global message center state. |
| 189 message_center::MessageCenter::Shutdown(); |
151 | 190 |
152 chromeos::CrasAudioHandler::Shutdown(); | 191 chromeos::CrasAudioHandler::Shutdown(); |
| 192 } |
| 193 |
153 if (bluez_dbus_manager_initialized_) { | 194 if (bluez_dbus_manager_initialized_) { |
154 device::BluetoothAdapterFactory::Shutdown(); | 195 device::BluetoothAdapterFactory::Shutdown(); |
155 bluez::BluezDBusManager::Shutdown(); | 196 bluez::BluezDBusManager::Shutdown(); |
156 bluez_dbus_manager_initialized_ = false; | 197 bluez_dbus_manager_initialized_ = false; |
157 } | 198 } |
| 199 |
158 if (dbus_thread_manager_initialized_) { | 200 if (dbus_thread_manager_initialized_) { |
159 chromeos::DBusThreadManager::Shutdown(); | 201 chromeos::DBusThreadManager::Shutdown(); |
160 dbus_thread_manager_initialized_ = false; | 202 dbus_thread_manager_initialized_ = false; |
161 } | 203 } |
162 | 204 |
163 ui::TerminateContextFactoryForTests(); | 205 ui::TerminateContextFactoryForTests(); |
164 | 206 |
165 ui::ShutdownInputMethodForTesting(); | 207 ui::ShutdownInputMethodForTesting(); |
166 zero_duration_mode_.reset(); | 208 zero_duration_mode_.reset(); |
167 | 209 |
168 views_delegate_.reset(); | 210 views_delegate_.reset(); |
169 wm_state_.reset(); | 211 wm_state_.reset(); |
170 | 212 |
171 CHECK(!::wm::CaptureController::Get()); | 213 // WindowManager owns the CaptureController for mash. |
| 214 CHECK(is_mash || !::wm::CaptureController::Get()); |
172 } | 215 } |
173 | 216 |
174 void AshTestHelper::RunAllPendingInMessageLoop() { | 217 void AshTestHelper::RunAllPendingInMessageLoop() { |
175 base::RunLoop run_loop; | 218 base::RunLoop run_loop; |
176 run_loop.RunUntilIdle(); | 219 run_loop.RunUntilIdle(); |
177 } | 220 } |
178 | 221 |
179 // static | 222 // static |
180 TestSessionStateDelegate* AshTestHelper::GetTestSessionStateDelegate() { | 223 TestSessionStateDelegate* AshTestHelper::GetTestSessionStateDelegate() { |
181 CHECK(WmShell::HasInstance()); | 224 CHECK(WmShell::HasInstance()); |
182 return static_cast<TestSessionStateDelegate*>( | 225 return static_cast<TestSessionStateDelegate*>( |
183 WmShell::Get()->GetSessionStateDelegate()); | 226 WmShell::Get()->GetSessionStateDelegate()); |
184 } | 227 } |
185 | 228 |
186 aura::Window* AshTestHelper::CurrentContext() { | 229 aura::Window* AshTestHelper::CurrentContext() { |
187 aura::Window* root_window = Shell::GetTargetRootWindow(); | 230 aura::Window* root_window = Shell::GetTargetRootWindow(); |
188 if (!root_window) | 231 if (!root_window) |
189 root_window = Shell::GetPrimaryRootWindow(); | 232 root_window = Shell::GetPrimaryRootWindow(); |
190 DCHECK(root_window); | 233 DCHECK(root_window); |
191 return root_window; | 234 return root_window; |
192 } | 235 } |
193 | 236 |
| 237 void AshTestHelper::UpdateDisplayForMash(const std::string& display_spec) { |
| 238 CHECK(IsMash()); |
| 239 const std::vector<std::string> parts = base::SplitString( |
| 240 display_spec, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 241 std::vector<RootWindowController*> root_window_controllers = |
| 242 GetRootsOrderedByDisplayId(); |
| 243 int next_x = 0; |
| 244 for (size_t i = 0, |
| 245 end = std::min(parts.size(), root_window_controllers.size()); |
| 246 i < end; ++i) { |
| 247 UpdateDisplay(root_window_controllers[i], parts[i], &next_x); |
| 248 } |
| 249 for (size_t i = root_window_controllers.size(); i < parts.size(); ++i) { |
| 250 root_window_controllers.push_back( |
| 251 CreateRootWindowController(parts[i], &next_x)); |
| 252 } |
| 253 const bool in_shutdown = false; |
| 254 while (root_window_controllers.size() > parts.size()) { |
| 255 window_manager_app_->window_manager()->DestroyRootWindowController( |
| 256 root_window_controllers.back(), in_shutdown); |
| 257 root_window_controllers.pop_back(); |
| 258 } |
| 259 } |
| 260 |
| 261 display::Display AshTestHelper::GetSecondaryDisplay() { |
| 262 if (!IsMash()) |
| 263 return Shell::GetInstance()->display_manager()->GetSecondaryDisplay(); |
| 264 |
| 265 std::vector<RootWindowController*> roots = GetRootsOrderedByDisplayId(); |
| 266 CHECK_LE(2U, roots.size()); |
| 267 return roots.size() < 2 ? display::Display() |
| 268 : roots[1]->GetWindow()->GetDisplayNearestWindow(); |
| 269 } |
| 270 |
| 271 void AshTestHelper::CreateMashWindowManager() { |
| 272 CHECK(IsMash()); |
| 273 window_manager_app_ = base::MakeUnique<mus::WindowManagerApplication>(); |
| 274 |
| 275 window_manager_app_->window_manager_.reset(new mus::WindowManager(nullptr)); |
| 276 window_manager_app_->window_manager()->shell_delegate_for_test_.reset( |
| 277 test_shell_delegate_); |
| 278 window_manager_app_->window_manager() |
| 279 ->create_session_state_delegate_stub_for_test_ = false; |
| 280 |
| 281 window_tree_client_setup_.InitForWindowManager( |
| 282 window_manager_app_->window_manager_.get(), |
| 283 window_manager_app_->window_manager_.get()); |
| 284 aura::test::EnvTestHelper().SetWindowTreeClient( |
| 285 window_tree_client_setup_.window_tree_client()); |
| 286 window_manager_app_->InitWindowManager( |
| 287 window_tree_client_setup_.OwnWindowTreeClient(), |
| 288 ash_test_environment_->GetBlockingPool()); |
| 289 |
| 290 aura::WindowTreeClient* window_tree_client = |
| 291 window_manager_app_->window_manager()->window_tree_client(); |
| 292 window_tree_client_private_ = |
| 293 base::MakeUnique<aura::WindowTreeClientPrivate>(window_tree_client); |
| 294 int next_x = 0; |
| 295 CreateRootWindowController("800x600", &next_x); |
| 296 } |
| 297 |
| 298 void AshTestHelper::CreateShell() { |
| 299 CHECK(!IsMash()); |
| 300 ui::ContextFactory* context_factory = nullptr; |
| 301 ui::ContextFactoryPrivate* context_factory_private = nullptr; |
| 302 bool enable_pixel_output = false; |
| 303 ui::InitializeContextFactoryForTests(enable_pixel_output, &context_factory, |
| 304 &context_factory_private); |
| 305 ShellInitParams init_params; |
| 306 init_params.delegate = test_shell_delegate_; |
| 307 init_params.context_factory = context_factory; |
| 308 init_params.context_factory_private = context_factory_private; |
| 309 init_params.blocking_pool = ash_test_environment_->GetBlockingPool(); |
| 310 Shell::CreateInstance(init_params); |
| 311 } |
| 312 |
| 313 RootWindowController* AshTestHelper::CreateRootWindowController( |
| 314 const std::string& display_spec, |
| 315 int* next_x) { |
| 316 ManagedDisplayInfo display_info = |
| 317 ManagedDisplayInfo::CreateFromSpec(display_spec); |
| 318 gfx::Rect bounds = display_info.bounds_in_native(); |
| 319 bounds.set_x(*next_x); |
| 320 *next_x += bounds.size().width(); |
| 321 display::Display display(next_display_id_++, bounds); |
| 322 display.set_device_scale_factor(display_info.device_scale_factor()); |
| 323 gfx::Rect work_area(bounds.size()); |
| 324 // Offset the height slightly to give a different work area. -20 is arbitrary, |
| 325 // it could be anything. |
| 326 work_area.set_height(std::max(0, work_area.height() - 20)); |
| 327 display.set_work_area(work_area); |
| 328 window_tree_client_private_->CallWmNewDisplayAdded(display); |
| 329 return GetRootsOrderedByDisplayId().back(); |
| 330 } |
| 331 |
| 332 void AshTestHelper::UpdateDisplay(RootWindowController* root_window_controller, |
| 333 const std::string& display_spec, |
| 334 int* next_x) { |
| 335 ManagedDisplayInfo display_info = |
| 336 ManagedDisplayInfo::CreateFromSpec(display_spec); |
| 337 gfx::Rect bounds = display_info.bounds_in_native(); |
| 338 bounds.set_x(*next_x); |
| 339 *next_x += bounds.size().width(); |
| 340 display::Display updated_display = |
| 341 root_window_controller->GetWindow()->GetDisplayNearestWindow(); |
| 342 gfx::Insets work_area_insets = updated_display.GetWorkAreaInsets(); |
| 343 updated_display.set_bounds(bounds); |
| 344 updated_display.UpdateWorkAreaFromInsets(work_area_insets); |
| 345 updated_display.set_device_scale_factor(display_info.device_scale_factor()); |
| 346 root_window_controller->GetWindow()->SetBounds(gfx::Rect(bounds.size())); |
| 347 ScreenMus* screen = window_manager_app_->window_manager()->screen_.get(); |
| 348 const bool is_primary = |
| 349 screen->display_list().FindDisplayById(updated_display.id()) == |
| 350 screen->display_list().GetPrimaryDisplayIterator(); |
| 351 screen->display_list().UpdateDisplay( |
| 352 updated_display, is_primary ? display::DisplayList::Type::PRIMARY |
| 353 : display::DisplayList::Type::NOT_PRIMARY); |
| 354 } |
| 355 |
| 356 std::vector<RootWindowController*> AshTestHelper::GetRootsOrderedByDisplayId() { |
| 357 std::set<RootWindowController*> roots = |
| 358 window_manager_app_->window_manager()->GetRootWindowControllers(); |
| 359 std::vector<RootWindowController*> ordered_roots; |
| 360 ordered_roots.insert(ordered_roots.begin(), roots.begin(), roots.end()); |
| 361 std::sort(ordered_roots.begin(), ordered_roots.end(), &CompareByDisplayId); |
| 362 return ordered_roots; |
| 363 } |
| 364 |
194 } // namespace test | 365 } // namespace test |
195 } // namespace ash | 366 } // namespace ash |
OLD | NEW |