1 // Copyright (c) 2012 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.
4
5 #include "ash/test/ash_test_base.h"
6
7 #include <map>
8 #include <memory>
9 #include <string>
10 #include <vector>
11
12 #include "ash/accessibility/accessibility_panel_layout_manager.h"
13 #include "ash/ambient/test/ambient_ash_test_helper.h"
14 #include "ash/app_list/test/app_list_test_helper.h"
15 #include "ash/display/extended_mouse_warp_controller.h"
16 #include "ash/display/mouse_cursor_event_filter.h"
17 #include "ash/display/screen_orientation_controller_test_api.h"
18 #include "ash/display/unified_mouse_warp_controller.h"
19 #include "ash/display/window_tree_host_manager.h"
20 #include "ash/keyboard/keyboard_controller_impl.h"
21 #include "ash/public/cpp/ash_prefs.h"
22 #include "ash/public/cpp/shell_window_ids.h"
23 #include "ash/public/cpp/window_properties.h"
24 #include "ash/root_window_controller.h"
25 #include "ash/session/session_controller_impl.h"
26 #include "ash/shelf/shelf.h"
27 #include "ash/shell.h"
28 #include "ash/system/status_area_widget.h"
29 #include "ash/test/ash_test_helper.h"
30 #include "ash/test_screenshot_delegate.h"
31 #include "ash/test_shell_delegate.h"
32 #include "ash/utility/screenshot_controller.h"
33 #include "ash/window_factory.h"
34 #include "ash/wm/tablet_mode/tablet_mode_controller.h"
35 #include "ash/wm/window_positioner.h"
36 #include "ash/wm/work_area_insets.h"
37 #include "base/memory/ptr_util.h"
38 #include "base/run_loop.h"
39 #include "base/task/thread_pool/thread_pool_instance.h"
40 #include "base/threading/thread_task_runner_handle.h"
41 #include "chromeos/dbus/power/fake_power_manager_client.h"
42 #include "components/account_id/account_id.h"
43 #include "components/user_manager/user_names.h"
44 #include "ui/aura/client/aura_constants.h"
45 #include "ui/aura/client/window_parenting_client.h"
46 #include "ui/aura/env.h"
47 #include "ui/aura/test/aura_test_utils.h"
48 #include "ui/aura/test/event_generator_delegate_aura.h"
49 #include "ui/aura/test/test_window_delegate.h"
50 #include "ui/aura/window.h"
51 #include "ui/aura/window_delegate.h"
52 #include "ui/aura/window_tree_host.h"
53 #include "ui/base/ime/init/input_method_initializer.h"
54 #include "ui/display/display.h"
55 #include "ui/display/screen.h"
56 #include "ui/display/test/display_manager_test_api.h"
57 #include "ui/display/types/display_constants.h"
58 #include "ui/events/devices/device_data_manager_test_api.h"
59 #include "ui/events/devices/touchscreen_device.h"
60 #include "ui/gfx/geometry/point.h"
61 #include "ui/gfx/geometry/rect.h"
62 #include "ui/views/view.h"
63 #include "ui/views/widget/widget.h"
64 #include "ui/views/widget/widget_delegate.h"
65 #include "ui/wm/core/coordinate_conversion.h"
66
67 using session_manager::SessionState;
68
69 namespace ash {
70 namespace {
71
72 class AshEventGeneratorDelegate
73 : public aura::test::EventGeneratorDelegateAura {
74 public:
75 AshEventGeneratorDelegate() = default;
76 ~AshEventGeneratorDelegate() override = default;
77
78 // aura::test::EventGeneratorDelegateAura overrides:
GetTargetAt(const gfx::Point & point_in_screen)79 ui::EventTarget* GetTargetAt(const gfx::Point& point_in_screen) override {
80 display::Screen* screen = display::Screen::GetScreen();
81 display::Display display = screen->GetDisplayNearestPoint(point_in_screen);
82 return Shell::GetRootWindowForDisplayId(display.id())->GetHost()->window();
83 }
84
DispatchKeyEventToIME(ui::EventTarget * target,ui::KeyEvent * event)85 ui::EventDispatchDetails DispatchKeyEventToIME(ui::EventTarget* target,
86 ui::KeyEvent* event) override {
87 // In Ash environment, the key event will be processed by event rewriters
88 // first.
89 return ui::EventDispatchDetails();
90 }
91
92 private:
93 DISALLOW_COPY_AND_ASSIGN(AshEventGeneratorDelegate);
94 };
95
96 // WidgetDelegate that is resizable and creates ash's NonClientFrameView
97 // implementation.
98 class TestWidgetDelegate : public views::WidgetDelegateView {
99 public:
TestWidgetDelegate()100 TestWidgetDelegate() {
101 SetCanMaximize(true);
102 SetCanMinimize(true);
103 SetCanResize(true);
104 }
105 ~TestWidgetDelegate() override = default;
106
107 // views::WidgetDelegateView:
CreateNonClientFrameView(views::Widget * widget)108 std::unique_ptr<views::NonClientFrameView> CreateNonClientFrameView(
109 views::Widget* widget) override {
110 return Shell::Get()->CreateDefaultNonClientFrameView(widget);
111 }
112
113 private:
114 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate);
115 };
116
117 } // namespace
118
119 /////////////////////////////////////////////////////////////////////////////
120
AshTestBase(std::unique_ptr<base::test::TaskEnvironment> task_environment)121 AshTestBase::AshTestBase(
122 std::unique_ptr<base::test::TaskEnvironment> task_environment)
123 : task_environment_(std::move(task_environment)) {
124 RegisterLocalStatePrefs(local_state_.registry(), true);
125 }
126
~AshTestBase()127 AshTestBase::~AshTestBase() {
128 CHECK(setup_called_)
129 << "You have overridden SetUp but never called AshTestBase::SetUp";
130 CHECK(teardown_called_)
131 << "You have overridden TearDown but never called AshTestBase::TearDown";
132 }
133
SetUp()134 void AshTestBase::SetUp() {
135 SetUp(nullptr);
136 }
137
SetUp(std::unique_ptr<TestShellDelegate> delegate)138 void AshTestBase::SetUp(std::unique_ptr<TestShellDelegate> delegate) {
139 // At this point, the task APIs should already be provided by
140 // |task_environment_|.
141 CHECK(base::ThreadTaskRunnerHandle::IsSet());
142 CHECK(base::ThreadPoolInstance::Get());
143
144 setup_called_ = true;
145
146 AshTestHelper::InitParams params;
147 params.start_session = start_session_;
148 params.delegate = std::move(delegate);
149 params.local_state = local_state();
150 ash_test_helper_ = std::make_unique<AshTestHelper>();
151 ash_test_helper_->SetUp(std::move(params));
152 }
153
TearDown()154 void AshTestBase::TearDown() {
155 teardown_called_ = true;
156 // Make sure that we can exit tablet mode before shutdown correctly.
157 Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
158 Shell::Get()->session_controller()->NotifyChromeTerminating();
159
160 // Flush the message loop to finish pending release tasks.
161 base::RunLoop().RunUntilIdle();
162
163 ash_test_helper_->TearDown();
164
165 event_generator_.reset();
166 // Some tests set an internal display id,
167 // reset it here, so other tests will continue in a clean environment.
168 display::Display::SetInternalDisplayId(display::kInvalidDisplayId);
169
170 // Tests can add devices, so reset the lists for future tests.
171 ui::DeviceDataManagerTestApi().SetTouchscreenDevices({});
172 ui::DeviceDataManagerTestApi().SetKeyboardDevices({});
173 }
174
175 // static
GetPrimaryShelf()176 Shelf* AshTestBase::GetPrimaryShelf() {
177 return Shell::GetPrimaryRootWindowController()->shelf();
178 }
179
180 // static
GetPrimaryUnifiedSystemTray()181 UnifiedSystemTray* AshTestBase::GetPrimaryUnifiedSystemTray() {
182 return GetPrimaryShelf()->GetStatusAreaWidget()->unified_system_tray();
183 }
184
185 // static
GetPrimaryWorkAreaInsets()186 WorkAreaInsets* AshTestBase::GetPrimaryWorkAreaInsets() {
187 return Shell::GetPrimaryRootWindowController()->work_area_insets();
188 }
189
GetEventGenerator()190 ui::test::EventGenerator* AshTestBase::GetEventGenerator() {
191 if (!event_generator_) {
192 event_generator_ = std::make_unique<ui::test::EventGenerator>(
193 std::make_unique<AshEventGeneratorDelegate>());
194 }
195 return event_generator_.get();
196 }
197
198 // static
GetActiveDisplayRotation(int64_t id)199 display::Display::Rotation AshTestBase::GetActiveDisplayRotation(int64_t id) {
200 return Shell::Get()
201 ->display_manager()
202 ->GetDisplayInfo(id)
203 .GetActiveRotation();
204 }
205
206 // static
GetCurrentInternalDisplayRotation()207 display::Display::Rotation AshTestBase::GetCurrentInternalDisplayRotation() {
208 return GetActiveDisplayRotation(display::Display::InternalDisplayId());
209 }
210
UpdateDisplay(const std::string & display_specs)211 void AshTestBase::UpdateDisplay(const std::string& display_specs) {
212 display::test::DisplayManagerTestApi(Shell::Get()->display_manager())
213 .UpdateDisplay(display_specs);
214 ScreenOrientationControllerTestApi(
215 Shell::Get()->screen_orientation_controller())
216 .UpdateNaturalOrientation();
217 }
218
GetContext()219 aura::Window* AshTestBase::GetContext() {
220 return ash_test_helper_->GetContext();
221 }
222
223 // static
CreateTestWidget(views::WidgetDelegate * delegate,int container_id,const gfx::Rect & bounds,bool show)224 std::unique_ptr<views::Widget> AshTestBase::CreateTestWidget(
225 views::WidgetDelegate* delegate,
226 int container_id,
227 const gfx::Rect& bounds,
228 bool show) {
229 std::unique_ptr<views::Widget> widget(new views::Widget);
230 views::Widget::InitParams params;
231 params.delegate = delegate;
232 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
233 params.bounds = bounds;
234 params.parent = Shell::GetPrimaryRootWindow()->GetChildById(container_id);
235 widget->Init(std::move(params));
236 if (show)
237 widget->Show();
238 return widget;
239 }
240
CreateAppWindow(const gfx::Rect & bounds_in_screen,AppType app_type,int shell_window_id)241 std::unique_ptr<aura::Window> AshTestBase::CreateAppWindow(
242 const gfx::Rect& bounds_in_screen,
243 AppType app_type,
244 int shell_window_id) {
245 // |widget| is configured to be owned by the underlying window.
246 views::Widget* widget = new views::Widget;
247 views::Widget::InitParams params;
248 // TestWidgetDelegate is owned by |widget|.
249 params.delegate = new TestWidgetDelegate();
250 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET;
251 params.bounds =
252 bounds_in_screen.IsEmpty() ? gfx::Rect(0, 0, 300, 300) : bounds_in_screen;
253 params.context = Shell::GetPrimaryRootWindow();
254 if (app_type != AppType::NON_APP) {
255 params.init_properties_container.SetProperty(aura::client::kAppType,
256 static_cast<int>(app_type));
257 }
258 widget->Init(std::move(params));
259 widget->GetNativeWindow()->set_id(shell_window_id);
260 widget->Show();
261 return base::WrapUnique(widget->GetNativeWindow());
262 }
263
CreateTestWindow(const gfx::Rect & bounds_in_screen,aura::client::WindowType type,int shell_window_id)264 std::unique_ptr<aura::Window> AshTestBase::CreateTestWindow(
265 const gfx::Rect& bounds_in_screen,
266 aura::client::WindowType type,
267 int shell_window_id) {
268 if (type != aura::client::WINDOW_TYPE_NORMAL) {
269 return base::WrapUnique(CreateTestWindowInShellWithDelegateAndType(
270 nullptr, type, shell_window_id, bounds_in_screen));
271 }
272
273 return CreateAppWindow(bounds_in_screen, AppType::NON_APP, shell_window_id);
274 }
275
CreateToplevelTestWindow(const gfx::Rect & bounds_in_screen,int shell_window_id)276 std::unique_ptr<aura::Window> AshTestBase::CreateToplevelTestWindow(
277 const gfx::Rect& bounds_in_screen,
278 int shell_window_id) {
279 aura::test::TestWindowDelegate* delegate =
280 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate();
281 return base::WrapUnique<aura::Window>(
282 CreateTestWindowInShellWithDelegateAndType(
283 delegate, aura::client::WINDOW_TYPE_NORMAL, shell_window_id,
284 bounds_in_screen));
285 }
286
CreateTestWindowInShellWithId(int id)287 aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) {
288 return CreateTestWindowInShellWithDelegate(NULL, id, gfx::Rect());
289 }
290
CreateTestWindowInShellWithBounds(const gfx::Rect & bounds)291 aura::Window* AshTestBase::CreateTestWindowInShellWithBounds(
292 const gfx::Rect& bounds) {
293 return CreateTestWindowInShellWithDelegate(NULL, 0, bounds);
294 }
295
CreateTestWindowInShell(SkColor color,int id,const gfx::Rect & bounds)296 aura::Window* AshTestBase::CreateTestWindowInShell(SkColor color,
297 int id,
298 const gfx::Rect& bounds) {
299 return CreateTestWindowInShellWithDelegate(
300 new aura::test::ColorTestWindowDelegate(color), id, bounds);
301 }
302
CreateChildWindow(aura::Window * parent,const gfx::Rect & bounds,int shell_window_id)303 std::unique_ptr<aura::Window> AshTestBase::CreateChildWindow(
304 aura::Window* parent,
305 const gfx::Rect& bounds,
306 int shell_window_id) {
307 std::unique_ptr<aura::Window> window =
308 window_factory::NewWindow(nullptr, aura::client::WINDOW_TYPE_NORMAL);
309 window->Init(ui::LAYER_NOT_DRAWN);
310 window->SetBounds(bounds);
311 window->set_id(shell_window_id);
312 parent->AddChild(window.get());
313 window->Show();
314 return window;
315 }
316
CreateTestWindowInShellWithDelegate(aura::WindowDelegate * delegate,int id,const gfx::Rect & bounds)317 aura::Window* AshTestBase::CreateTestWindowInShellWithDelegate(
318 aura::WindowDelegate* delegate,
319 int id,
320 const gfx::Rect& bounds) {
321 return CreateTestWindowInShellWithDelegateAndType(
322 delegate, aura::client::WINDOW_TYPE_NORMAL, id, bounds);
323 }
324
CreateTestWindowInShellWithDelegateAndType(aura::WindowDelegate * delegate,aura::client::WindowType type,int id,const gfx::Rect & bounds)325 aura::Window* AshTestBase::CreateTestWindowInShellWithDelegateAndType(
326 aura::WindowDelegate* delegate,
327 aura::client::WindowType type,
328 int id,
329 const gfx::Rect& bounds) {
330 aura::Window* window = window_factory::NewWindow(delegate).release();
331 window->set_id(id);
332 window->SetType(type);
333 window->Init(ui::LAYER_TEXTURED);
334
335 if (bounds.IsEmpty()) {
336 ParentWindowInPrimaryRootWindow(window);
337 } else {
338 display::Display display =
339 display::Screen::GetScreen()->GetDisplayMatching(bounds);
340 aura::Window* root = Shell::GetRootWindowForDisplayId(display.id());
341 gfx::Point origin = bounds.origin();
342 ::wm::ConvertPointFromScreen(root, &origin);
343 window->SetBounds(gfx::Rect(origin, bounds.size()));
344 aura::client::ParentWindowWithContext(window, root, bounds);
345 }
346 window->Show();
347
348 window->SetProperty(aura::client::kResizeBehaviorKey,
349 aura::client::kResizeBehaviorCanMaximize |
350 aura::client::kResizeBehaviorCanMinimize |
351 aura::client::kResizeBehaviorCanResize);
352 return window;
353 }
354
ParentWindowInPrimaryRootWindow(aura::Window * window)355 void AshTestBase::ParentWindowInPrimaryRootWindow(aura::Window* window) {
356 aura::client::ParentWindowWithContext(window, Shell::GetPrimaryRootWindow(),
357 gfx::Rect());
358 }
359
SetUserPref(const std::string & user_email,const std::string & path,const base::Value & value)360 void AshTestBase::SetUserPref(const std::string& user_email,
361 const std::string& path,
362 const base::Value& value) {
363 AccountId accountId = AccountId::FromUserEmail(user_email);
364 PrefService* prefs =
365 GetSessionControllerClient()->GetUserPrefService(accountId);
366 prefs->Set(path, value);
367 }
368
GetScreenshotDelegate()369 TestScreenshotDelegate* AshTestBase::GetScreenshotDelegate() {
370 return static_cast<TestScreenshotDelegate*>(
371 Shell::Get()->screenshot_controller()->screenshot_delegate_.get());
372 }
373
GetSessionControllerClient()374 TestSessionControllerClient* AshTestBase::GetSessionControllerClient() {
375 return ash_test_helper_->test_session_controller_client();
376 }
377
GetSystemTrayClient()378 TestSystemTrayClient* AshTestBase::GetSystemTrayClient() {
379 return ash_test_helper_->system_tray_client();
380 }
381
GetAppListTestHelper()382 AppListTestHelper* AshTestBase::GetAppListTestHelper() {
383 return ash_test_helper_->app_list_test_helper();
384 }
385
GetAmbientAshTestHelper()386 AmbientAshTestHelper* AshTestBase::GetAmbientAshTestHelper() {
387 return ash_test_helper_->ambient_ash_test_helper();
388 }
389
CreateUserSessions(int n)390 void AshTestBase::CreateUserSessions(int n) {
391 GetSessionControllerClient()->CreatePredefinedUserSessions(n);
392 }
393
SimulateUserLogin(const std::string & user_email,user_manager::UserType user_type)394 void AshTestBase::SimulateUserLogin(const std::string& user_email,
395 user_manager::UserType user_type) {
396 TestSessionControllerClient* session = GetSessionControllerClient();
397 session->AddUserSession(user_email, user_type);
398 session->SwitchActiveUser(AccountId::FromUserEmail(user_email));
399 session->SetSessionState(SessionState::ACTIVE);
400 }
401
SimulateNewUserFirstLogin(const std::string & user_email)402 void AshTestBase::SimulateNewUserFirstLogin(const std::string& user_email) {
403 TestSessionControllerClient* session = GetSessionControllerClient();
404 session->AddUserSession(user_email, user_manager::USER_TYPE_REGULAR,
405 true /* provide_pref_service */,
406 true /* is_new_profile */);
407 session->SwitchActiveUser(AccountId::FromUserEmail(user_email));
408 session->SetSessionState(session_manager::SessionState::ACTIVE);
409 }
410
SimulateGuestLogin()411 void AshTestBase::SimulateGuestLogin() {
412 const std::string guest = user_manager::kGuestUserName;
413 TestSessionControllerClient* session = GetSessionControllerClient();
414 session->AddUserSession(guest, user_manager::USER_TYPE_GUEST);
415 session->SwitchActiveUser(AccountId::FromUserEmail(guest));
416 session->SetSessionState(SessionState::ACTIVE);
417 }
418
SimulateKioskMode(user_manager::UserType user_type)419 void AshTestBase::SimulateKioskMode(user_manager::UserType user_type) {
420 DCHECK(user_type == user_manager::USER_TYPE_ARC_KIOSK_APP ||
421 user_type == user_manager::USER_TYPE_KIOSK_APP);
422
423 const std::string user_email = "fake_kiosk@kioks-apps.device-local.localhost";
424 TestSessionControllerClient* session = GetSessionControllerClient();
425 session->SetIsRunningInAppMode(true);
426 session->AddUserSession(user_email, user_type);
427 session->SwitchActiveUser(AccountId::FromUserEmail(user_email));
428 session->SetSessionState(SessionState::ACTIVE);
429 }
430
SetAccessibilityPanelHeight(int panel_height)431 void AshTestBase::SetAccessibilityPanelHeight(int panel_height) {
432 Shell::GetPrimaryRootWindowController()
433 ->GetAccessibilityPanelLayoutManagerForTest()
434 ->SetPanelBounds(gfx::Rect(0, 0, 0, panel_height),
435 AccessibilityPanelState::FULL_WIDTH);
436 }
437
ClearLogin()438 void AshTestBase::ClearLogin() {
439 GetSessionControllerClient()->Reset();
440 }
441
SetCanLockScreen(bool can_lock)442 void AshTestBase::SetCanLockScreen(bool can_lock) {
443 GetSessionControllerClient()->SetCanLockScreen(can_lock);
444 }
445
SetShouldLockScreenAutomatically(bool should_lock)446 void AshTestBase::SetShouldLockScreenAutomatically(bool should_lock) {
447 GetSessionControllerClient()->SetShouldLockScreenAutomatically(should_lock);
448 }
449
SetUserAddingScreenRunning(bool user_adding_screen_running)450 void AshTestBase::SetUserAddingScreenRunning(bool user_adding_screen_running) {
451 GetSessionControllerClient()->SetSessionState(
452 user_adding_screen_running ? SessionState::LOGIN_SECONDARY
453 : SessionState::ACTIVE);
454 }
455
BlockUserSession(UserSessionBlockReason block_reason)456 void AshTestBase::BlockUserSession(UserSessionBlockReason block_reason) {
457 switch (block_reason) {
458 case BLOCKED_BY_LOCK_SCREEN:
459 CreateUserSessions(1);
460 GetSessionControllerClient()->LockScreen();
461 break;
462 case BLOCKED_BY_LOGIN_SCREEN:
463 ClearLogin();
464 break;
465 case BLOCKED_BY_USER_ADDING_SCREEN:
466 SetUserAddingScreenRunning(true);
467 break;
468 default:
469 NOTREACHED();
470 break;
471 }
472 }
473
UnblockUserSession()474 void AshTestBase::UnblockUserSession() {
475 CreateUserSessions(1);
476 GetSessionControllerClient()->UnlockScreen();
477 }
478
SetVirtualKeyboardEnabled(bool enabled)479 void AshTestBase::SetVirtualKeyboardEnabled(bool enabled) {
480 // Note there are a lot of flags that can be set to control whether the
481 // keyboard is shown or not. You can see the logic in
482 // |KeyboardUIController::IsKeyboardEnableRequested|.
483 // The |kTouchEnabled| flag seems like a logical candidate to pick, but it
484 // does not work because the flag will automatically be toggled off once the
485 // |DeviceDataManager| detects there is a physical keyboard present. That's
486 // why I picked the |kPolicyEnabled| and |kPolicyDisabled| flags instead.
487 auto enable_flag = keyboard::KeyboardEnableFlag::kPolicyEnabled;
488 auto disable_flag = keyboard::KeyboardEnableFlag::kPolicyDisabled;
489 auto* keyboard_controller = Shell::Get()->keyboard_controller();
490
491 if (enabled) {
492 keyboard_controller->SetEnableFlag(enable_flag);
493 keyboard_controller->ClearEnableFlag(disable_flag);
494 } else {
495 keyboard_controller->ClearEnableFlag(enable_flag);
496 keyboard_controller->SetEnableFlag(disable_flag);
497 }
498 // Ensure that observer methods and mojo calls between KeyboardControllerImpl,
499 // keyboard::KeyboardUIController*, and AshKeyboardUI complete.
500 base::RunLoop().RunUntilIdle();
501 }
502
DisableIME()503 void AshTestBase::DisableIME() {
504 aura::test::DisableIME(Shell::GetPrimaryRootWindow()->GetHost());
505 }
506
display_manager()507 display::DisplayManager* AshTestBase::display_manager() {
508 return Shell::Get()->display_manager();
509 }
510
power_manager_client() const511 chromeos::FakePowerManagerClient* AshTestBase::power_manager_client() const {
512 return chromeos::FakePowerManagerClient::Get();
513 }
514
TestIfMouseWarpsAt(ui::test::EventGenerator * event_generator,const gfx::Point & point_in_screen)515 bool AshTestBase::TestIfMouseWarpsAt(ui::test::EventGenerator* event_generator,
516 const gfx::Point& point_in_screen) {
517 DCHECK(!Shell::Get()->display_manager()->IsInUnifiedMode());
518 static_cast<ExtendedMouseWarpController*>(
519 Shell::Get()->mouse_cursor_filter()->mouse_warp_controller_for_test())
520 ->allow_non_native_event_for_test();
521 display::Screen* screen = display::Screen::GetScreen();
522 display::Display original_display =
523 screen->GetDisplayNearestPoint(point_in_screen);
524 event_generator->MoveMouseTo(point_in_screen);
525 return original_display.id() !=
526 screen
527 ->GetDisplayNearestPoint(
528 aura::Env::GetInstance()->last_mouse_location())
529 .id();
530 }
531
SimulateMouseClickAt(ui::test::EventGenerator * event_generator,const views::View * target_view)532 void AshTestBase::SimulateMouseClickAt(
533 ui::test::EventGenerator* event_generator,
534 const views::View* target_view) {
535 DCHECK(target_view);
536 event_generator->MoveMouseTo(target_view->GetBoundsInScreen().CenterPoint());
537 event_generator->ClickLeftButton();
538 }
539
SwapPrimaryDisplay()540 void AshTestBase::SwapPrimaryDisplay() {
541 if (display::Screen::GetScreen()->GetNumDisplays() <= 1)
542 return;
543 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
544 display::test::DisplayManagerTestApi(display_manager())
545 .GetSecondaryDisplay()
546 .id());
547 }
548
GetPrimaryDisplay() const549 display::Display AshTestBase::GetPrimaryDisplay() const {
550 return display::Screen::GetScreen()->GetDisplayNearestWindow(
551 Shell::GetPrimaryRootWindow());
552 }
553
GetSecondaryDisplay() const554 display::Display AshTestBase::GetSecondaryDisplay() const {
555 return ash_test_helper_->GetSecondaryDisplay();
556 }
557
558 } // namespace ash
559