Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / ash / wm / ash_native_cursor_manager_interactive_uitest.cc
blob83df158964464be84e5c6cc8d9a7d1019508f9f9
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 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);
40 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();
49 namespace {
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);
57 return info;
60 void MoveMouseSync(aura::Window* window, int x, int y) {
61 #if defined(USE_X11)
62 XWarpPointer(gfx::GetXDisplay(),
63 None,
64 window->GetHost()->GetAcceleratedWidget(),
65 0, 0, 0, 0,
66 x, y);
67 #endif
68 // Send and wait for a key event to make sure that mouse
69 // events are fully processed.
70 base::RunLoop loop;
71 ui_controls::SendKeyPressNotifyWhenDone(
72 window,
73 ui::VKEY_SPACE,
74 false,
75 false,
76 false,
77 false,
78 loop.QuitClosure());
79 loop.Run();
82 } // namespace
84 #if defined(USE_X11)
85 #define MAYBE_CursorChangeOnEnterNotify CursorChangeOnEnterNotify
86 #else
87 #define MAYBE_CursorChangeOnEnterNotify DISABLED_CursorChangeOnEnterNotify
88 #endif
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());
111 } // namespace ash