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" 5 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/run_loop.h" 12#include "ui/aura/root_window.h" 13#include "ui/aura/window.h" 14#include "ui/base/test/ui_controls.h" 15 16#if defined(USE_X11) 17#include <X11/Xlib.h> 18 19#include "base/message_loop/message_pump_x11.h" 20#endif 21 22namespace ash { 23 24using views::corewm::CursorManager; 25typedef test::AshTestBase AshNativeCursorManagerTest; 26 27namespace { 28 29internal::DisplayInfo CreateDisplayInfo(int64 id, 30 const gfx::Rect& bounds, 31 float device_scale_factor) { 32 internal::DisplayInfo info(id, "", false); 33 info.SetBounds(bounds); 34 info.set_device_scale_factor(device_scale_factor); 35 return info; 36} 37 38void MoveMouseSync(aura::Window* window, int x, int y) { 39#if defined(USE_X11) 40 XWarpPointer(base::MessagePumpX11::GetDefaultXDisplay(), 41 None, 42 window->GetDispatcher()->host()->GetAcceleratedWidget(), 43 0, 0, 0, 0, 44 x, y); 45#endif 46 // Send and wait for a key event to make sure that mouse 47 // events are fully processed. 48 base::RunLoop loop; 49 ui_controls::SendKeyPressNotifyWhenDone( 50 window, 51 ui::VKEY_SPACE, 52 false, 53 false, 54 false, 55 false, 56 loop.QuitClosure()); 57 loop.Run(); 58} 59 60} // namespace 61 62#if defined(USE_X11) 63#define MAYBE_CursorChangeOnEnterNotify CursorChangeOnEnterNotify 64#else 65#define MAYBE_CursorChangeOnEnterNotify DISABLED_CursorChangeOnEnterNotify 66#endif 67 68TEST_F(AshNativeCursorManagerTest, MAYBE_CursorChangeOnEnterNotify) { 69 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); 70 test::CursorManagerTestApi test_api(cursor_manager); 71 72 internal::DisplayManager* display_manager = 73 Shell::GetInstance()->display_manager(); 74 internal::DisplayInfo display_info1 = 75 CreateDisplayInfo(10, gfx::Rect(0, 0, 500, 300), 1.0f); 76 internal::DisplayInfo display_info2 = 77 CreateDisplayInfo(20, gfx::Rect(500, 0, 500, 300), 2.0f); 78 std::vector<internal::DisplayInfo> display_info_list; 79 display_info_list.push_back(display_info1); 80 display_info_list.push_back(display_info2); 81 display_manager->OnNativeDisplaysChanged(display_info_list); 82 83 MoveMouseSync(Shell::GetAllRootWindows()[0], 10, 10); 84 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); 85 86 MoveMouseSync(Shell::GetAllRootWindows()[0], 600, 10); 87 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor()); 88} 89 90} // namespace ash 91