OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/display/mirror_window_controller.h" | 5 #include "ash/display/mirror_window_controller.h" |
6 | 6 |
7 #include "ash/display/display_manager.h" | 7 #include "ash/display/display_manager.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
10 #include "ash/test/mirror_window_test_api.h" | 10 #include "ash/test/mirror_window_test_api.h" |
11 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
12 #include "ui/aura/test/event_generator.h" | 12 #include "ui/aura/test/event_generator.h" |
13 #include "ui/aura/test/test_window_delegate.h" | 13 #include "ui/aura/test/test_window_delegate.h" |
14 #include "ui/aura/test/test_windows.h" | 14 #include "ui/aura/test/test_windows.h" |
15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
16 #include "ui/base/hit_test.h" | 16 #include "ui/base/hit_test.h" |
17 | 17 |
18 namespace ash { | 18 namespace ash { |
19 namespace internal { | 19 namespace internal { |
20 | 20 |
21 typedef test::AshTestBase MirrorWindowControllerTest; | 21 typedef test::AshTestBase MirrorWindowControllerTest; |
22 | 22 |
23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
24 // Software mirroring does not work on win. | 24 // Software mirroring does not work on win. |
25 #define MAYBE_MirrorCursor DISABLED_MirrorCursor | 25 #define MAYBE_MirrorCursorBasic DISABLED_MirrorCursorBasic |
| 26 #define MAYBE_MirrorCursorLocations DISABLED_MirrorCursorLocations |
26 #else | 27 #else |
27 #define MAYBE_MirrorCursor MirrorCursor | 28 #define MAYBE_MirrorCursorBasic MirrorCursorBasic |
| 29 #define MAYBE_MirrorCursorLocations MirrorCursorLocations |
28 #endif | 30 #endif |
29 | 31 |
30 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursor) { | 32 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorBasic) { |
31 test::MirrorWindowTestApi test_api; | 33 test::MirrorWindowTestApi test_api; |
32 aura::test::TestWindowDelegate test_window_delegate; | 34 aura::test::TestWindowDelegate test_window_delegate; |
33 test_window_delegate.set_window_component(HTTOP); | 35 test_window_delegate.set_window_component(HTTOP); |
34 | 36 |
35 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 37 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
36 display_manager->SetSoftwareMirroring(true); | 38 display_manager->SetSoftwareMirroring(true); |
37 UpdateDisplay("400x400,400x400"); | 39 UpdateDisplay("400x400,400x400"); |
38 aura::RootWindow* root = Shell::GetInstance()->GetPrimaryRootWindow(); | 40 aura::RootWindow* root = Shell::GetInstance()->GetPrimaryRootWindow(); |
39 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( | 41 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( |
40 &test_window_delegate, | 42 &test_window_delegate, |
41 0, | 43 0, |
42 gfx::Rect(50, 50, 100, 100), | 44 gfx::Rect(50, 50, 100, 100), |
43 root)); | 45 root)); |
44 window->Show(); | 46 window->Show(); |
45 window->SetName("foo"); | 47 window->SetName("foo"); |
46 | 48 |
47 EXPECT_TRUE(test_api.GetCursorWindow()); | 49 EXPECT_TRUE(test_api.GetCursorWindow()); |
48 EXPECT_EQ("50,50 100x100", window->bounds().ToString()); | 50 EXPECT_EQ("50,50 100x100", window->bounds().ToString()); |
49 | 51 |
50 aura::test::EventGenerator generator(root); | 52 aura::test::EventGenerator generator(root); |
51 generator.MoveMouseTo(10, 10); | 53 generator.MoveMouseTo(10, 10); |
52 | 54 |
53 // Test if cursor movement is propertly reflected in mirror window. | 55 // Test if cursor movement is propertly reflected in mirror window. |
54 gfx::Point hot_point = test_api.GetCursorHotPoint(); | 56 gfx::Point hot_point = test_api.GetCursorHotPoint(); |
55 gfx::Point cursor_window_origin = | 57 gfx::Point cursor_window_origin = |
56 test_api.GetCursorWindow()->bounds().origin(); | 58 test_api.GetCursorWindow()->bounds().origin(); |
| 59 EXPECT_EQ("4,4", hot_point.ToString()); |
57 EXPECT_EQ(10 - hot_point.x(), cursor_window_origin.x()); | 60 EXPECT_EQ(10 - hot_point.x(), cursor_window_origin.x()); |
58 EXPECT_EQ(10 - hot_point.y(), cursor_window_origin.y()); | 61 EXPECT_EQ(10 - hot_point.y(), cursor_window_origin.y()); |
59 EXPECT_EQ(ui::kCursorNull, test_api.GetCurrentCursorType()); | 62 EXPECT_EQ(ui::kCursorNull, test_api.GetCurrentCursorType()); |
60 EXPECT_TRUE(test_api.GetCursorWindow()->IsVisible()); | 63 EXPECT_TRUE(test_api.GetCursorWindow()->IsVisible()); |
61 | 64 |
62 // Test if cursor type change is propertly reflected in mirror window. | 65 // Test if cursor type change is propertly reflected in mirror window. |
63 generator.MoveMouseTo(100, 100); | 66 generator.MoveMouseTo(100, 100); |
64 hot_point = test_api.GetCursorHotPoint(); | 67 hot_point = test_api.GetCursorHotPoint(); |
65 cursor_window_origin = test_api.GetCursorWindow()->bounds().origin(); | 68 cursor_window_origin = test_api.GetCursorWindow()->bounds().origin(); |
66 EXPECT_EQ(100 - hot_point.x(), cursor_window_origin.x()); | 69 EXPECT_EQ(100 - hot_point.x(), cursor_window_origin.x()); |
67 EXPECT_EQ(100 - hot_point.y(), cursor_window_origin.y()); | 70 EXPECT_EQ(100 - hot_point.y(), cursor_window_origin.y()); |
68 EXPECT_EQ(ui::kCursorNorthResize, test_api.GetCurrentCursorType()); | 71 EXPECT_EQ(ui::kCursorNorthResize, test_api.GetCurrentCursorType()); |
69 | 72 |
70 // Test if visibility change is propertly reflected in mirror window. | 73 // Test if visibility change is propertly reflected in mirror window. |
71 // A key event hides cursor. | 74 // A key event hides cursor. |
72 generator.PressKey(ui::VKEY_A, 0); | 75 generator.PressKey(ui::VKEY_A, 0); |
73 generator.ReleaseKey(ui::VKEY_A, 0); | 76 generator.ReleaseKey(ui::VKEY_A, 0); |
74 EXPECT_FALSE(test_api.GetCursorWindow()->IsVisible()); | 77 EXPECT_FALSE(test_api.GetCursorWindow()->IsVisible()); |
75 | 78 |
76 // Mouse event makes it visible again. | 79 // Mouse event makes it visible again. |
77 generator.MoveMouseTo(300, 300); | 80 generator.MoveMouseTo(300, 300); |
78 hot_point = test_api.GetCursorHotPoint(); | 81 hot_point = test_api.GetCursorHotPoint(); |
79 cursor_window_origin = test_api.GetCursorWindow()->bounds().origin(); | 82 cursor_window_origin = test_api.GetCursorWindow()->bounds().origin(); |
80 EXPECT_EQ(300 - hot_point.x(), cursor_window_origin.x()); | 83 EXPECT_EQ(300 - hot_point.x(), cursor_window_origin.x()); |
81 EXPECT_EQ(300 - hot_point.y(), cursor_window_origin.y()); | 84 EXPECT_EQ(300 - hot_point.y(), cursor_window_origin.y()); |
82 EXPECT_EQ(ui::kCursorNull, test_api.GetCurrentCursorType()); | 85 EXPECT_EQ(ui::kCursorNull, test_api.GetCurrentCursorType()); |
83 EXPECT_TRUE(test_api.GetCursorWindow()->IsVisible()); | 86 EXPECT_TRUE(test_api.GetCursorWindow()->IsVisible()); |
84 } | 87 } |
85 | 88 |
| 89 // Make sure that the mirror cursor's location is same as |
| 90 // the source display's host location in the mirror root window's |
| 91 // coordinates. |
| 92 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorLocations) { |
| 93 test::MirrorWindowTestApi test_api; |
| 94 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 95 display_manager->SetSoftwareMirroring(true); |
| 96 |
| 97 // Test with device scale factor. |
| 98 UpdateDisplay("400x600*2,400x600"); |
| 99 |
| 100 aura::RootWindow* root = Shell::GetInstance()->GetPrimaryRootWindow(); |
| 101 aura::test::EventGenerator generator(root); |
| 102 generator.MoveMouseToInHost(10, 20); |
| 103 |
| 104 gfx::Point hot_point = test_api.GetCursorHotPoint(); |
| 105 EXPECT_EQ("8,9", hot_point.ToString()); |
| 106 gfx::Point cursor_window_origin = |
| 107 test_api.GetCursorWindow()->bounds().origin(); |
| 108 EXPECT_EQ(10 - hot_point.x(), cursor_window_origin.x()); |
| 109 EXPECT_EQ(20 - hot_point.y(), cursor_window_origin.y()); |
| 110 |
| 111 // Test with ui scale |
| 112 UpdateDisplay("400x600*0.5,400x600"); |
| 113 generator.MoveMouseToInHost(20, 30); |
| 114 |
| 115 hot_point = test_api.GetCursorHotPoint(); |
| 116 EXPECT_EQ("4,4", hot_point.ToString()); |
| 117 cursor_window_origin = test_api.GetCursorWindow()->bounds().origin(); |
| 118 EXPECT_EQ(20 - hot_point.x(), cursor_window_origin.x()); |
| 119 EXPECT_EQ(30 - hot_point.y(), cursor_window_origin.y()); |
| 120 |
| 121 // Test with rotation |
| 122 UpdateDisplay("400x600/r,400x600"); |
| 123 generator.MoveMouseToInHost(30, 40); |
| 124 |
| 125 hot_point = test_api.GetCursorHotPoint(); |
| 126 EXPECT_EQ("4,4", hot_point.ToString()); |
| 127 cursor_window_origin = test_api.GetCursorWindow()->bounds().origin(); |
| 128 EXPECT_EQ(30 - hot_point.x(), cursor_window_origin.x()); |
| 129 EXPECT_EQ(40 - hot_point.y(), cursor_window_origin.y()); |
| 130 } |
| 131 |
86 } // namsspace internal | 132 } // namsspace internal |
87 } // namespace ash | 133 } // namespace ash |
OLD | NEW |