Roll src/third_party/WebKit c8d1660:ae3684d (svn 197337:197343)
[chromium-blink-merge.git] / ash / wm / ash_native_cursor_manager_interactive_uitest.cc
blob50f160ec3ccf3744b1bedeeece32fd31c5d0c521
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"
8 #include "ash/shell.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"
20 #if defined(USE_X11)
21 #include <X11/Xlib.h>
23 #include "ui/gfx/x/x11_types.h"
24 #endif
26 namespace ash {
28 class AshNativeCursorManagerTest : public test::AshTestBase {
29 public:
30 AshNativeCursorManagerTest() {}
31 ~AshNativeCursorManagerTest() override {}
33 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);
41 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();
50 namespace {
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);
58 return info;
61 void MoveMouseSync(aura::Window* window, int x, int y) {
62 #if defined(USE_X11)
63 XWarpPointer(gfx::GetXDisplay(),
64 None,
65 window->GetHost()->GetAcceleratedWidget(),
66 0, 0, 0, 0,
67 x, y);
68 #endif
69 // Send and wait for a key event to make sure that mouse
70 // events are fully processed.
71 base::RunLoop loop;
72 ui_controls::SendKeyPressNotifyWhenDone(
73 window,
74 ui::VKEY_SPACE,
75 false,
76 false,
77 false,
78 false,
79 loop.QuitClosure());
80 loop.Run();
83 } // namespace
85 #if defined(USE_X11)
86 #define MAYBE_CursorChangeOnEnterNotify CursorChangeOnEnterNotify
87 #else
88 #define MAYBE_CursorChangeOnEnterNotify DISABLED_CursorChangeOnEnterNotify
89 #endif
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());
112 } // namespace ash