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.
4 #include "ash/wm/ash_native_cursor_manager.h"
6 #include "ash/display/display_info.h"
7 #include "ash/display/display_manager.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ash/test/cursor_manager_test_api.h"
11 #include "base/path_service.h"
12 #include "base/run_loop.h"
13 #include "ui/aura/window.h"
14 #include "ui/aura/window_tree_host.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/base/test/ui_controls.h"
17 #include "ui/base/ui_base_paths.h"
18 #include "ui/gl/gl_surface.h"
23 #include "ui/gfx/x/x11_types.h"
28 class AshNativeCursorManagerTest
: public test::AshTestBase
{
30 AshNativeCursorManagerTest() {}
31 virtual ~AshNativeCursorManagerTest() {}
33 virtual void SetUp() override
{
34 gfx::GLSurface::InitializeOneOffForTests();
36 ui::RegisterPathProvider();
37 ui::ResourceBundle::InitSharedInstanceWithLocale(
38 "en-US", NULL
, ui::ResourceBundle::LOAD_COMMON_RESOURCES
);
39 base::FilePath resources_pack_path
;
40 PathService::Get(base::DIR_MODULE
, &resources_pack_path
);
42 resources_pack_path
.Append(FILE_PATH_LITERAL("resources.pak"));
43 ResourceBundle::GetSharedInstance().AddDataPackFromPath(
44 resources_pack_path
, ui::SCALE_FACTOR_NONE
);
46 test::AshTestBase::SetUp();
52 DisplayInfo
CreateDisplayInfo(int64 id
,
53 const gfx::Rect
& bounds
,
54 float device_scale_factor
) {
55 DisplayInfo
info(id
, "", false);
56 info
.SetBounds(bounds
);
57 info
.set_device_scale_factor(device_scale_factor
);
61 void MoveMouseSync(aura::Window
* window
, int x
, int y
) {
63 XWarpPointer(gfx::GetXDisplay(),
65 window
->GetHost()->GetAcceleratedWidget(),
69 // Send and wait for a key event to make sure that mouse
70 // events are fully processed.
72 ui_controls::SendKeyPressNotifyWhenDone(
86 #define MAYBE_CursorChangeOnEnterNotify CursorChangeOnEnterNotify
88 #define MAYBE_CursorChangeOnEnterNotify DISABLED_CursorChangeOnEnterNotify
91 TEST_F(AshNativeCursorManagerTest
, MAYBE_CursorChangeOnEnterNotify
) {
92 ::wm::CursorManager
* cursor_manager
= Shell::GetInstance()->cursor_manager();
93 test::CursorManagerTestApi
test_api(cursor_manager
);
95 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
96 DisplayInfo display_info1
=
97 CreateDisplayInfo(10, gfx::Rect(0, 0, 500, 300), 1.0f
);
98 DisplayInfo display_info2
=
99 CreateDisplayInfo(20, gfx::Rect(500, 0, 500, 300), 2.0f
);
100 std::vector
<DisplayInfo
> display_info_list
;
101 display_info_list
.push_back(display_info1
);
102 display_info_list
.push_back(display_info2
);
103 display_manager
->OnNativeDisplaysChanged(display_info_list
);
105 MoveMouseSync(Shell::GetAllRootWindows()[0], 10, 10);
106 EXPECT_EQ(1.0f
, test_api
.GetCurrentCursor().device_scale_factor());
108 MoveMouseSync(Shell::GetAllRootWindows()[0], 600, 10);
109 EXPECT_EQ(2.0f
, test_api
.GetCurrentCursor().device_scale_factor());