Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: ash/test/ash_test_helper.cc

Issue 2694623016: chromeos: Makes AshTestBase/Helper target mash when appropriate (Closed)
Patch Set: cleanup Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_number_conversions.h"
27 #include "base/strings/string_split.h"
28 #include "base/test/sequenced_worker_pool_owner.h"
22 #include "chromeos/audio/cras_audio_handler.h" 29 #include "chromeos/audio/cras_audio_handler.h"
23 #include "chromeos/dbus/dbus_thread_manager.h" 30 #include "chromeos/dbus/dbus_thread_manager.h"
24 #include "device/bluetooth/bluetooth_adapter_factory.h" 31 #include "device/bluetooth/bluetooth_adapter_factory.h"
25 #include "device/bluetooth/dbus/bluez_dbus_manager.h" 32 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
26 #include "ui/aura/env.h" 33 #include "ui/aura/env.h"
27 #include "ui/aura/input_state_lookup.h" 34 #include "ui/aura/input_state_lookup.h"
35 #include "ui/aura/mus/window_tree_client.h"
28 #include "ui/aura/test/env_test_helper.h" 36 #include "ui/aura/test/env_test_helper.h"
29 #include "ui/aura/test/event_generator_delegate_aura.h" 37 #include "ui/aura/test/event_generator_delegate_aura.h"
38 #include "ui/aura/test/mus/window_tree_client_private.h"
30 #include "ui/base/ime/input_method_initializer.h" 39 #include "ui/base/ime/input_method_initializer.h"
31 #include "ui/base/material_design/material_design_controller.h" 40 #include "ui/base/material_design/material_design_controller.h"
32 #include "ui/base/platform_window_defaults.h" 41 #include "ui/base/platform_window_defaults.h"
33 #include "ui/base/test/material_design_controller_test_api.h" 42 #include "ui/base/test/material_design_controller_test_api.h"
34 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 43 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
35 #include "ui/compositor/test/context_factories_for_test.h" 44 #include "ui/compositor/test/context_factories_for_test.h"
45 #include "ui/display/manager/display_manager.h"
36 #include "ui/display/manager/managed_display_info.h" 46 #include "ui/display/manager/managed_display_info.h"
37 #include "ui/display/test/display_manager_test_api.h" 47 #include "ui/display/test/display_manager_test_api.h"
48 #include "ui/gfx/geometry/dip_util.h"
38 #include "ui/message_center/message_center.h" 49 #include "ui/message_center/message_center.h"
39 #include "ui/wm/core/capture_controller.h" 50 #include "ui/wm/core/capture_controller.h"
40 #include "ui/wm/core/cursor_manager.h" 51 #include "ui/wm/core/cursor_manager.h"
41 #include "ui/wm/core/wm_state.h" 52 #include "ui/wm/core/wm_state.h"
42 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 struct DisplayInfo {
69 gfx::Rect bounds;
70 int scale_factor = 1;
71 };
72
73 // TODO(sky): at some point this needs to support everything in DisplayInfo,
74 // for now just the bare minimum, which is [x+y-]wxh[*scale_factor].
75 DisplayInfo ParseDisplayBounds(const std::string& spec) {
James Cook 2017/02/18 02:23:21 This seems like it should share code with ManagedD
sky 2017/02/18 18:00:57 Done.
76 DisplayInfo result;
77 const std::vector<std::string> parts =
78 base::SplitString(spec, "-", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
79 std::string size_spec;
80 if (parts.size() == 2u) {
81 size_spec = parts[1];
82 const std::vector<std::string> origin_parts = base::SplitString(
83 parts[0], "+", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
84 CHECK_EQ(2u, origin_parts.size());
85 int x, y;
86 CHECK(base::StringToInt(origin_parts[0], &x));
87 CHECK(base::StringToInt(origin_parts[1], &y));
88 result.bounds.set_origin(gfx::Point(x, y));
89 } else {
90 CHECK_EQ(1u, parts.size());
91 size_spec = spec;
92 }
93 const std::vector<std::string> size_parts = base::SplitString(
94 size_spec, "x", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
95 CHECK_EQ(2u, size_parts.size());
96 std::string height_string = size_parts[1];
97 const size_t scale_factor_index = height_string.find('*');
98 if (scale_factor_index != std::string::npos) {
99 CHECK(base::StringToInt(height_string.substr(scale_factor_index + 1),
100 &(result.scale_factor)));
101 height_string = height_string.substr(0, scale_factor_index);
102 }
103 int w = 0, h = 0;
104 CHECK(base::StringToInt(size_parts[0], &w));
105 CHECK(base::StringToInt(height_string, &h));
106 result.bounds.set_size(gfx::Size(w, h));
107 result.bounds = gfx::ConvertRectToDIP(result.scale_factor, result.bounds);
108 return result;
109 }
110
111 } // namespace
45 112
46 AshTestHelper::AshTestHelper(AshTestEnvironment* ash_test_environment) 113 AshTestHelper::AshTestHelper(AshTestEnvironment* ash_test_environment)
47 : ash_test_environment_(ash_test_environment), 114 : ash_test_environment_(ash_test_environment),
48 test_shell_delegate_(nullptr), 115 test_shell_delegate_(nullptr),
49 test_screenshot_delegate_(nullptr), 116 test_screenshot_delegate_(nullptr),
50 dbus_thread_manager_initialized_(false), 117 dbus_thread_manager_initialized_(false),
51 bluez_dbus_manager_initialized_(false) { 118 bluez_dbus_manager_initialized_(false) {
52 ui::test::EnableTestConfigForPlatformWindows(); 119 ui::test::EnableTestConfigForPlatformWindows();
53 aura::test::InitializeAuraEventGeneratorDelegate(); 120 aura::test::InitializeAuraEventGeneratorDelegate();
121 aura::test::EnvTestHelper().SetAlwaysUseLastMouseLocation(true);
54 } 122 }
55 123
56 AshTestHelper::~AshTestHelper() {} 124 AshTestHelper::~AshTestHelper() {}
57 125
58 void AshTestHelper::SetUp(bool start_session) { 126 void AshTestHelper::SetUp(bool start_session) {
59 display::ResetDisplayIdForTest(); 127 display::ResetDisplayIdForTest();
60 wm_state_ = base::MakeUnique<::wm::WMState>(); 128 const bool is_mash = IsMash();
129 // WindowManager creates WMState for mash.
130 if (!is_mash)
131 wm_state_ = base::MakeUnique<::wm::WMState>();
61 views_delegate_ = ash_test_environment_->CreateViewsDelegate(); 132 views_delegate_ = ash_test_environment_->CreateViewsDelegate();
62 133
63 // Disable animations during tests. 134 // Disable animations during tests.
64 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( 135 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
65 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); 136 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
66 ui::InitializeInputMethodForTesting(); 137 ui::InitializeInputMethodForTesting();
67 138
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. 139 // Creates Shell and hook with Desktop.
75 if (!test_shell_delegate_) 140 if (!test_shell_delegate_)
76 test_shell_delegate_ = new TestShellDelegate; 141 test_shell_delegate_ = new TestShellDelegate;
77 142
78 // Creates MessageCenter since g_browser_process is not created in AshTestBase 143 if (!is_mash) {
79 // tests. 144 // All of this initialization is done in WindowManagerApplication for mash.
80 message_center::MessageCenter::Initialize();
81 145
82 // Create DBusThreadManager for testing. 146 // Creates MessageCenter since g_browser_process is not created in
83 if (!chromeos::DBusThreadManager::IsInitialized()) { 147 // AshTestBase tests.
84 chromeos::DBusThreadManager::Initialize( 148 message_center::MessageCenter::Initialize();
85 chromeos::DBusThreadManager::PROCESS_ASH); 149
86 dbus_thread_manager_initialized_ = true; 150 if (!chromeos::DBusThreadManager::IsInitialized()) {
151 chromeos::DBusThreadManager::Initialize(
152 chromeos::DBusThreadManager::PROCESS_ASH);
153 dbus_thread_manager_initialized_ = true;
154 }
155
156 if (!bluez::BluezDBusManager::IsInitialized()) {
157 bluez::BluezDBusManager::Initialize(
158 chromeos::DBusThreadManager::Get()->GetSystemBus(),
159 chromeos::DBusThreadManager::Get()->IsUsingFakes());
160 bluez_dbus_manager_initialized_ = true;
161 }
162
163 // Create CrasAudioHandler for testing since g_browser_process is not
164 // created in AshTestBase tests.
165 chromeos::CrasAudioHandler::InitializeForTesting();
87 } 166 }
88 167
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(); 168 ash_test_environment_->SetUp();
101 // Reset the global state for the cursor manager. This includes the 169 // Reset the global state for the cursor manager. This includes the
102 // last cursor visibility state, etc. 170 // last cursor visibility state, etc.
103 ::wm::CursorManager::ResetCursorVisibilityStateForTest(); 171 ::wm::CursorManager::ResetCursorVisibilityStateForTest();
104 172
105 // ContentTestSuiteBase might have already initialized 173 // ContentTestSuiteBase might have already initialized
106 // MaterialDesignController in unit_tests suite. 174 // MaterialDesignController in unit_tests suite.
107 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); 175 ui::test::MaterialDesignControllerTestAPI::Uninitialize();
108 ui::MaterialDesignController::Initialize(); 176 ui::MaterialDesignController::Initialize();
109 177
110 ShellInitParams init_params; 178 if (is_mash) {
111 init_params.delegate = test_shell_delegate_; 179 window_manager_app_ = base::MakeUnique<mus::WindowManagerApplication>();
112 init_params.context_factory = context_factory; 180 const size_t kMaxNumberThreads = 3u; // Matches that of content.
113 init_params.context_factory_private = context_factory_private; 181 const char kThreadNamePrefix[] = "MashBlockingForTesting";
114 init_params.blocking_pool = ash_test_environment_->GetBlockingPool(); 182 blocking_pool_owner_ = base::MakeUnique<base::SequencedWorkerPoolOwner>(
James Cook 2017/02/18 02:23:21 Could WindowManagerApplication handle the creation
sky 2017/02/18 18:00:57 I think you may be right, but I would like to hold
115 Shell::CreateInstance(init_params); 183 kMaxNumberThreads, kThreadNamePrefix);
184
185 window_manager_app_->window_manager_.reset(new mus::WindowManager(nullptr));
186 window_manager_app_->window_manager()->shell_delegate_for_test_.reset(
187 test_shell_delegate_);
188 window_manager_app_->window_manager()
189 ->create_session_state_delegate_stub_for_test_ = false;
190
191 window_tree_client_setup_.InitForWindowManager(
192 window_manager_app_->window_manager_.get(),
193 window_manager_app_->window_manager_.get());
194 aura::test::EnvTestHelper().SetWindowTreeClient(
195 window_tree_client_setup_.window_tree_client());
196 window_manager_app_->InitWindowManager(
197 window_tree_client_setup_.OwnWindowTreeClient(),
198 blocking_pool_owner_->pool());
199
200 aura::WindowTreeClient* window_tree_client =
201 window_manager_app_->window_manager()->window_tree_client();
202 window_tree_client_private_ =
203 base::MakeUnique<aura::WindowTreeClientPrivate>(window_tree_client);
204 int next_x = 0;
205 CreateRootWindowController("800x600", &next_x);
James Cook 2017/02/18 02:23:21 This code and functions below are very similar to
sky 2017/02/18 18:00:57 Indeed. I would like to remove WmTestHelper and mo
206 } else {
207 ui::ContextFactory* context_factory = nullptr;
208 ui::ContextFactoryPrivate* context_factory_private = nullptr;
209 bool enable_pixel_output = false;
210 ui::InitializeContextFactoryForTests(enable_pixel_output, &context_factory,
211 &context_factory_private);
212 ShellInitParams init_params;
213 init_params.delegate = test_shell_delegate_;
214 init_params.context_factory = context_factory;
215 init_params.context_factory_private = context_factory_private;
216 init_params.blocking_pool = ash_test_environment_->GetBlockingPool();
217 Shell::CreateInstance(init_params);
218 }
James Cook 2017/02/18 02:23:21 This function is kind of long. Can you pull some o
sky 2017/02/18 18:00:57 Done.
116 aura::test::EnvTestHelper(aura::Env::GetInstance()) 219 aura::test::EnvTestHelper(aura::Env::GetInstance())
117 .SetInputStateLookup(std::unique_ptr<aura::InputStateLookup>()); 220 .SetInputStateLookup(std::unique_ptr<aura::InputStateLookup>());
118 221
119 Shell* shell = Shell::GetInstance(); 222 Shell* shell = Shell::GetInstance();
120 if (start_session) { 223 if (start_session) {
121 GetTestSessionStateDelegate()->SetActiveUserSessionStarted(true); 224 GetTestSessionStateDelegate()->SetActiveUserSessionStarted(true);
122 GetTestSessionStateDelegate()->SetHasActiveUser(true); 225 GetTestSessionStateDelegate()->SetHasActiveUser(true);
123 } 226 }
124 227
125 // Tests that change the display configuration generally don't care about the 228 if (!is_mash) {
126 // notifications and the popup UI can interfere with things like cursors. 229 // ScreenLayoutObserver is specific to cash.
127 shell->screen_layout_observer()->set_show_notifications_for_testing(false); 230 // Tests that change the display configuration generally don't care about
231 // the
James Cook 2017/02/18 02:23:21 nit: rewrap
sky 2017/02/18 18:00:57 Done.
232 // notifications and the popup UI can interfere with things like cursors.
233 shell->screen_layout_observer()->set_show_notifications_for_testing(false);
128 234
129 display::test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()) 235 // DisplayManager is specific to cash.
130 .DisableChangeDisplayUponHostResize(); 236 display::test::DisplayManagerTestApi(
131 ShellTestApi(shell).DisableDisplayAnimator(); 237 Shell::GetInstance()->display_manager())
238 .DisableChangeDisplayUponHostResize();
239 ShellTestApi(shell).DisableDisplayAnimator();
132 240
133 test_screenshot_delegate_ = new TestScreenshotDelegate(); 241 // TODO: disabled for mash as AcceleratorControllerDelegateAura isn't
134 shell->accelerator_controller_delegate()->SetScreenshotDelegate( 242 // created in mash http://crbug.com/632111.
135 std::unique_ptr<ScreenshotDelegate>(test_screenshot_delegate_)); 243 test_screenshot_delegate_ = new TestScreenshotDelegate();
244 shell->accelerator_controller_delegate()->SetScreenshotDelegate(
245 std::unique_ptr<ScreenshotDelegate>(test_screenshot_delegate_));
246 }
136 } 247 }
137 248
138 void AshTestHelper::TearDown() { 249 void AshTestHelper::TearDown() {
139 // Tear down the shell. 250 window_manager_app_.reset();
140 Shell::DeleteInstance(); 251
252 base::RunLoop().RunUntilIdle();
253 blocking_pool_owner_.reset();
254 base::RunLoop().RunUntilIdle();
255
256 const bool is_mash = IsMash();
257
258 // WindowManger owns the Shell in mash.
259 if (!is_mash)
260 Shell::DeleteInstance();
141 261
142 // Suspend the tear down until all resources are returned via 262 // Suspend the tear down until all resources are returned via
143 // MojoCompositorFrameSinkClient::ReclaimResources() 263 // MojoCompositorFrameSinkClient::ReclaimResources()
144 RunAllPendingInMessageLoop(); 264 RunAllPendingInMessageLoop();
145 ash_test_environment_->TearDown(); 265 ash_test_environment_->TearDown();
146 266
147 test_screenshot_delegate_ = NULL; 267 test_screenshot_delegate_ = NULL;
148 268
149 // Remove global message center state. 269 if (!is_mash) {
150 message_center::MessageCenter::Shutdown(); 270 // Remove global message center state.
271 message_center::MessageCenter::Shutdown();
151 272
152 chromeos::CrasAudioHandler::Shutdown(); 273 chromeos::CrasAudioHandler::Shutdown();
274 }
275
153 if (bluez_dbus_manager_initialized_) { 276 if (bluez_dbus_manager_initialized_) {
154 device::BluetoothAdapterFactory::Shutdown(); 277 device::BluetoothAdapterFactory::Shutdown();
155 bluez::BluezDBusManager::Shutdown(); 278 bluez::BluezDBusManager::Shutdown();
156 bluez_dbus_manager_initialized_ = false; 279 bluez_dbus_manager_initialized_ = false;
157 } 280 }
281
158 if (dbus_thread_manager_initialized_) { 282 if (dbus_thread_manager_initialized_) {
159 chromeos::DBusThreadManager::Shutdown(); 283 chromeos::DBusThreadManager::Shutdown();
160 dbus_thread_manager_initialized_ = false; 284 dbus_thread_manager_initialized_ = false;
161 } 285 }
162 286
163 ui::TerminateContextFactoryForTests(); 287 ui::TerminateContextFactoryForTests();
164 288
165 ui::ShutdownInputMethodForTesting(); 289 ui::ShutdownInputMethodForTesting();
166 zero_duration_mode_.reset(); 290 zero_duration_mode_.reset();
167 291
168 views_delegate_.reset(); 292 views_delegate_.reset();
169 wm_state_.reset(); 293 wm_state_.reset();
170 294
171 CHECK(!::wm::CaptureController::Get()); 295 // WindowManager owns the CaptureController for mash.
296 CHECK(is_mash || !::wm::CaptureController::Get());
172 } 297 }
173 298
174 void AshTestHelper::RunAllPendingInMessageLoop() { 299 void AshTestHelper::RunAllPendingInMessageLoop() {
175 base::RunLoop run_loop; 300 base::RunLoop run_loop;
176 run_loop.RunUntilIdle(); 301 run_loop.RunUntilIdle();
177 } 302 }
178 303
179 // static 304 // static
180 TestSessionStateDelegate* AshTestHelper::GetTestSessionStateDelegate() { 305 TestSessionStateDelegate* AshTestHelper::GetTestSessionStateDelegate() {
181 CHECK(WmShell::HasInstance()); 306 CHECK(WmShell::HasInstance());
182 return static_cast<TestSessionStateDelegate*>( 307 return static_cast<TestSessionStateDelegate*>(
183 WmShell::Get()->GetSessionStateDelegate()); 308 WmShell::Get()->GetSessionStateDelegate());
184 } 309 }
185 310
186 aura::Window* AshTestHelper::CurrentContext() { 311 aura::Window* AshTestHelper::CurrentContext() {
187 aura::Window* root_window = Shell::GetTargetRootWindow(); 312 aura::Window* root_window = Shell::GetTargetRootWindow();
188 if (!root_window) 313 if (!root_window)
189 root_window = Shell::GetPrimaryRootWindow(); 314 root_window = Shell::GetPrimaryRootWindow();
190 DCHECK(root_window); 315 DCHECK(root_window);
191 return root_window; 316 return root_window;
192 } 317 }
193 318
319 void AshTestHelper::UpdateDisplayForMash(const std::string& display_spec) {
320 CHECK(IsMash());
321 const std::vector<std::string> parts = base::SplitString(
322 display_spec, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
323 std::vector<RootWindowController*> root_window_controllers =
324 GetRootsOrderedByDisplayId();
325 int next_x = 0;
326 for (size_t i = 0,
327 end = std::min(parts.size(), root_window_controllers.size());
328 i < end; ++i) {
329 UpdateDisplay(root_window_controllers[i], parts[i], &next_x);
330 }
331 for (size_t i = root_window_controllers.size(); i < parts.size(); ++i) {
332 root_window_controllers.push_back(
333 CreateRootWindowController(parts[i], &next_x));
334 }
335 const bool in_shutdown = false;
James Cook 2017/02/18 02:23:21 Hooray for named constants instead of bare "false"
336 while (root_window_controllers.size() > parts.size()) {
337 window_manager_app_->window_manager()->DestroyRootWindowController(
338 root_window_controllers.back(), in_shutdown);
339 root_window_controllers.pop_back();
340 }
341 }
342
343 display::Display AshTestHelper::GetSecondaryDisplay() {
344 if (!IsMash())
345 return Shell::GetInstance()->display_manager()->GetSecondaryDisplay();
346
347 std::vector<RootWindowController*> roots = GetRootsOrderedByDisplayId();
348 return roots.size() < 2 ? display::Display()
James Cook 2017/02/18 02:23:21 Maybe it should be an error to try to get the seco
sky 2017/02/18 18:00:57 Done.
349 : roots[1]->GetWindow()->GetDisplayNearestWindow();
350 }
351
352 RootWindowController* AshTestHelper::CreateRootWindowController(
353 const std::string& display_spec,
354 int* next_x) {
355 DisplayInfo display_info = ParseDisplayBounds(display_spec);
356 display_info.bounds.set_x(*next_x);
357 *next_x += display_info.bounds.size().width();
358 display::Display display(next_display_id_++, display_info.bounds);
359 display.set_device_scale_factor(display_info.scale_factor);
360 gfx::Rect work_area(display.bounds());
361 // Offset the height slightly to give a different work area. -20 is arbitrary,
362 // it could be anything.
363 work_area.set_height(std::max(0, work_area.height() - 20));
364 display.set_work_area(work_area);
365 window_tree_client_private_->CallWmNewDisplayAdded(display);
366 return GetRootsOrderedByDisplayId().back();
367 }
368
369 void AshTestHelper::UpdateDisplay(RootWindowController* root_window_controller,
370 const std::string& display_spec,
371 int* next_x) {
372 DisplayInfo display_info = ParseDisplayBounds(display_spec);
373 display_info.bounds.set_x(*next_x);
374 *next_x += display_info.bounds.size().width();
375 display::Display updated_display =
376 root_window_controller->GetWindow()->GetDisplayNearestWindow();
377 gfx::Insets work_area_insets = updated_display.GetWorkAreaInsets();
378 updated_display.set_bounds(display_info.bounds);
379 updated_display.UpdateWorkAreaFromInsets(work_area_insets);
380 updated_display.set_device_scale_factor(display_info.scale_factor);
381 root_window_controller->GetWindow()->SetBounds(
382 gfx::Rect(display_info.bounds.size()));
383 ScreenMus* screen = window_manager_app_->window_manager()->screen_.get();
384 const bool is_primary =
385 screen->display_list().FindDisplayById(updated_display.id()) ==
386 screen->display_list().GetPrimaryDisplayIterator();
387 screen->display_list().UpdateDisplay(
388 updated_display, is_primary ? display::DisplayList::Type::PRIMARY
389 : display::DisplayList::Type::NOT_PRIMARY);
390 }
391
392 std::vector<RootWindowController*> AshTestHelper::GetRootsOrderedByDisplayId() {
393 std::set<RootWindowController*> roots =
394 window_manager_app_->window_manager()->GetRootWindowControllers();
395 std::vector<RootWindowController*> ordered_roots;
396 ordered_roots.insert(ordered_roots.begin(), roots.begin(), roots.end());
397 std::sort(ordered_roots.begin(), ordered_roots.end(), &CompareByDisplayId);
398 return ordered_roots;
399 }
400
194 } // namespace test 401 } // namespace test
195 } // namespace ash 402 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698