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 ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL
);
38 base::FilePath resources_pack_path
;
39 PathService::Get(base::DIR_MODULE
, &resources_pack_path
);
41 resources_pack_path
.Append(FILE_PATH_LITERAL("resources.pak"));
42 ResourceBundle::GetSharedInstance().AddDataPackFromPath(
43 resources_pack_path
, ui::SCALE_FACTOR_NONE
);
45 test::AshTestBase::SetUp();
51 DisplayInfo
CreateDisplayInfo(int64 id
,
52 const gfx::Rect
& bounds
,
53 float device_scale_factor
) {
54 DisplayInfo
info(id
, "", false);
55 info
.SetBounds(bounds
);
56 info
.set_device_scale_factor(device_scale_factor
);
60 void MoveMouseSync(aura::Window
* window
, int x
, int y
) {
62 XWarpPointer(gfx::GetXDisplay(),
64 window
->GetHost()->GetAcceleratedWidget(),
68 // Send and wait for a key event to make sure that mouse
69 // events are fully processed.
71 ui_controls::SendKeyPressNotifyWhenDone(
85 #define MAYBE_CursorChangeOnEnterNotify CursorChangeOnEnterNotify
87 #define MAYBE_CursorChangeOnEnterNotify DISABLED_CursorChangeOnEnterNotify
90 TEST_F(AshNativeCursorManagerTest
, MAYBE_CursorChangeOnEnterNotify
) {
91 ::wm::CursorManager
* cursor_manager
= Shell::GetInstance()->cursor_manager();
92 test::CursorManagerTestApi
test_api(cursor_manager
);
94 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
95 DisplayInfo display_info1
=
96 CreateDisplayInfo(10, gfx::Rect(0, 0, 500, 300), 1.0f
);
97 DisplayInfo display_info2
=
98 CreateDisplayInfo(20, gfx::Rect(500, 0, 500, 300), 2.0f
);
99 std::vector
<DisplayInfo
> display_info_list
;
100 display_info_list
.push_back(display_info1
);
101 display_info_list
.push_back(display_info2
);
102 display_manager
->OnNativeDisplaysChanged(display_info_list
);
104 MoveMouseSync(Shell::GetAllRootWindows()[0], 10, 10);
105 EXPECT_EQ(1.0f
, test_api
.GetCurrentCursor().device_scale_factor());
107 MoveMouseSync(Shell::GetAllRootWindows()[0], 600, 10);
108 EXPECT_EQ(2.0f
, test_api
.GetCurrentCursor().device_scale_factor());