OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/drag_drop/drag_drop_tracker.h" | 5 #include "ash/drag_drop/drag_drop_tracker.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "ash/shell.h" | 9 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
9 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "ui/aura/test/test_windows.h" | 12 #include "ui/aura/test/test_windows.h" |
12 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
13 #include "ui/aura/window_event_dispatcher.h" | 14 #include "ui/aura/window_event_dispatcher.h" |
14 #include "ui/events/event_utils.h" | 15 #include "ui/events/event_utils.h" |
15 | 16 |
16 namespace ash { | 17 namespace ash { |
17 namespace test { | 18 namespace test { |
18 | 19 |
19 class DragDropTrackerTest : public test::AshTestBase { | 20 class DragDropTrackerTest : public test::AshTestBase { |
20 public: | 21 public: |
21 void SetUp() override { AshTestBase::SetUp(); } | 22 void SetUp() override { AshTestBase::SetUp(); } |
22 | 23 |
23 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { | 24 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { |
24 static int window_id = 0; | 25 static int window_id = 0; |
25 return CreateTestWindowInShellWithDelegate( | 26 return CreateTestWindowInShellWithDelegate( |
26 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), | 27 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), |
27 window_id++, | 28 window_id++, |
28 bounds); | 29 bounds); |
29 } | 30 } |
30 | 31 |
31 static aura::Window* GetTarget(const gfx::Point& location) { | 32 static aura::Window* GetTarget(const gfx::Point& location) { |
32 scoped_ptr<DragDropTracker> tracker( | 33 std::unique_ptr<DragDropTracker> tracker( |
33 new DragDropTracker(Shell::GetPrimaryRootWindow(), NULL)); | 34 new DragDropTracker(Shell::GetPrimaryRootWindow(), NULL)); |
34 ui::MouseEvent e(ui::ET_MOUSE_DRAGGED, location, location, | 35 ui::MouseEvent e(ui::ET_MOUSE_DRAGGED, location, location, |
35 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 36 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
36 aura::Window* target = tracker->GetTarget(e); | 37 aura::Window* target = tracker->GetTarget(e); |
37 return target; | 38 return target; |
38 } | 39 } |
39 | 40 |
40 static ui::LocatedEvent* ConvertEvent(aura::Window* target, | 41 static ui::LocatedEvent* ConvertEvent(aura::Window* target, |
41 const ui::MouseEvent& event) { | 42 const ui::MouseEvent& event) { |
42 scoped_ptr<DragDropTracker> tracker( | 43 std::unique_ptr<DragDropTracker> tracker( |
43 new DragDropTracker(Shell::GetPrimaryRootWindow(), NULL)); | 44 new DragDropTracker(Shell::GetPrimaryRootWindow(), NULL)); |
44 ui::LocatedEvent* converted = tracker->ConvertEvent(target, event); | 45 ui::LocatedEvent* converted = tracker->ConvertEvent(target, event); |
45 return converted; | 46 return converted; |
46 } | 47 } |
47 }; | 48 }; |
48 | 49 |
49 TEST_F(DragDropTrackerTest, GetTarget) { | 50 TEST_F(DragDropTrackerTest, GetTarget) { |
50 if (!SupportsMultipleDisplays()) | 51 if (!SupportsMultipleDisplays()) |
51 return; | 52 return; |
52 | 53 |
53 UpdateDisplay("200x200,300x300"); | 54 UpdateDisplay("200x200,300x300"); |
54 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 55 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
55 EXPECT_EQ(2U, root_windows.size()); | 56 EXPECT_EQ(2U, root_windows.size()); |
56 | 57 |
57 scoped_ptr<aura::Window> window0( | 58 std::unique_ptr<aura::Window> window0( |
58 CreateTestWindow(gfx::Rect(0, 0, 100, 100))); | 59 CreateTestWindow(gfx::Rect(0, 0, 100, 100))); |
59 window0->Show(); | 60 window0->Show(); |
60 | 61 |
61 scoped_ptr<aura::Window> window1( | 62 std::unique_ptr<aura::Window> window1( |
62 CreateTestWindow(gfx::Rect(300, 100, 100, 100))); | 63 CreateTestWindow(gfx::Rect(300, 100, 100, 100))); |
63 window1->Show(); | 64 window1->Show(); |
64 EXPECT_EQ(root_windows[0], window0->GetRootWindow()); | 65 EXPECT_EQ(root_windows[0], window0->GetRootWindow()); |
65 EXPECT_EQ(root_windows[1], window1->GetRootWindow()); | 66 EXPECT_EQ(root_windows[1], window1->GetRootWindow()); |
66 EXPECT_EQ("0,0 100x100", window0->GetBoundsInScreen().ToString()); | 67 EXPECT_EQ("0,0 100x100", window0->GetBoundsInScreen().ToString()); |
67 EXPECT_EQ("300,100 100x100", window1->GetBoundsInScreen().ToString()); | 68 EXPECT_EQ("300,100 100x100", window1->GetBoundsInScreen().ToString()); |
68 | 69 |
69 // Make RootWindow0 active so that capture window is parented to it. | 70 // Make RootWindow0 active so that capture window is parented to it. |
70 Shell::GetInstance()->set_target_root_window(root_windows[0]); | 71 Shell::GetInstance()->set_target_root_window(root_windows[0]); |
71 | 72 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 111 } |
111 | 112 |
112 TEST_F(DragDropTrackerTest, ConvertEvent) { | 113 TEST_F(DragDropTrackerTest, ConvertEvent) { |
113 if (!SupportsMultipleDisplays()) | 114 if (!SupportsMultipleDisplays()) |
114 return; | 115 return; |
115 | 116 |
116 UpdateDisplay("200x200,300x300"); | 117 UpdateDisplay("200x200,300x300"); |
117 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 118 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
118 EXPECT_EQ(2U, root_windows.size()); | 119 EXPECT_EQ(2U, root_windows.size()); |
119 | 120 |
120 scoped_ptr<aura::Window> window0( | 121 std::unique_ptr<aura::Window> window0( |
121 CreateTestWindow(gfx::Rect(0, 0, 100, 100))); | 122 CreateTestWindow(gfx::Rect(0, 0, 100, 100))); |
122 window0->Show(); | 123 window0->Show(); |
123 | 124 |
124 scoped_ptr<aura::Window> window1( | 125 std::unique_ptr<aura::Window> window1( |
125 CreateTestWindow(gfx::Rect(300, 100, 100, 100))); | 126 CreateTestWindow(gfx::Rect(300, 100, 100, 100))); |
126 window1->Show(); | 127 window1->Show(); |
127 | 128 |
128 // Make RootWindow0 active so that capture window is parented to it. | 129 // Make RootWindow0 active so that capture window is parented to it. |
129 Shell::GetInstance()->set_target_root_window(root_windows[0]); | 130 Shell::GetInstance()->set_target_root_window(root_windows[0]); |
130 | 131 |
131 // Start tracking from the RootWindow0 and converts the mouse event into | 132 // Start tracking from the RootWindow0 and converts the mouse event into |
132 // |window0|'s coodinates. | 133 // |window0|'s coodinates. |
133 ui::MouseEvent original00(ui::ET_MOUSE_DRAGGED, gfx::Point(50, 50), | 134 ui::MouseEvent original00(ui::ET_MOUSE_DRAGGED, gfx::Point(50, 50), |
134 gfx::Point(50, 50), ui::EventTimeForNow(), | 135 gfx::Point(50, 50), ui::EventTimeForNow(), |
135 ui::EF_NONE, ui::EF_NONE); | 136 ui::EF_NONE, ui::EF_NONE); |
136 scoped_ptr<ui::LocatedEvent> converted00(ConvertEvent(window0.get(), | 137 std::unique_ptr<ui::LocatedEvent> converted00( |
137 original00)); | 138 ConvertEvent(window0.get(), original00)); |
138 EXPECT_EQ(original00.type(), converted00->type()); | 139 EXPECT_EQ(original00.type(), converted00->type()); |
139 EXPECT_EQ("50,50", converted00->location().ToString()); | 140 EXPECT_EQ("50,50", converted00->location().ToString()); |
140 EXPECT_EQ("50,50", converted00->root_location().ToString()); | 141 EXPECT_EQ("50,50", converted00->root_location().ToString()); |
141 EXPECT_EQ(original00.flags(), converted00->flags()); | 142 EXPECT_EQ(original00.flags(), converted00->flags()); |
142 | 143 |
143 // Start tracking from the RootWindow0 and converts the mouse event into | 144 // Start tracking from the RootWindow0 and converts the mouse event into |
144 // |window1|'s coodinates. | 145 // |window1|'s coodinates. |
145 ui::MouseEvent original01(ui::ET_MOUSE_DRAGGED, gfx::Point(350, 150), | 146 ui::MouseEvent original01(ui::ET_MOUSE_DRAGGED, gfx::Point(350, 150), |
146 gfx::Point(350, 150), ui::EventTimeForNow(), | 147 gfx::Point(350, 150), ui::EventTimeForNow(), |
147 ui::EF_NONE, ui::EF_NONE); | 148 ui::EF_NONE, ui::EF_NONE); |
148 scoped_ptr<ui::LocatedEvent> converted01(ConvertEvent(window1.get(), | 149 std::unique_ptr<ui::LocatedEvent> converted01( |
149 original01)); | 150 ConvertEvent(window1.get(), original01)); |
150 EXPECT_EQ(original01.type(), converted01->type()); | 151 EXPECT_EQ(original01.type(), converted01->type()); |
151 EXPECT_EQ("50,50", converted01->location().ToString()); | 152 EXPECT_EQ("50,50", converted01->location().ToString()); |
152 EXPECT_EQ("150,150", converted01->root_location().ToString()); | 153 EXPECT_EQ("150,150", converted01->root_location().ToString()); |
153 EXPECT_EQ(original01.flags(), converted01->flags()); | 154 EXPECT_EQ(original01.flags(), converted01->flags()); |
154 | 155 |
155 // Make RootWindow1 active so that capture window is parented to it. | 156 // Make RootWindow1 active so that capture window is parented to it. |
156 Shell::GetInstance()->set_target_root_window(root_windows[1]); | 157 Shell::GetInstance()->set_target_root_window(root_windows[1]); |
157 | 158 |
158 // Start tracking from the RootWindow1 and converts the mouse event into | 159 // Start tracking from the RootWindow1 and converts the mouse event into |
159 // |window0|'s coodinates. | 160 // |window0|'s coodinates. |
160 ui::MouseEvent original10(ui::ET_MOUSE_DRAGGED, gfx::Point(-150, 50), | 161 ui::MouseEvent original10(ui::ET_MOUSE_DRAGGED, gfx::Point(-150, 50), |
161 gfx::Point(-150, 50), ui::EventTimeForNow(), | 162 gfx::Point(-150, 50), ui::EventTimeForNow(), |
162 ui::EF_NONE, ui::EF_NONE); | 163 ui::EF_NONE, ui::EF_NONE); |
163 scoped_ptr<ui::LocatedEvent> converted10(ConvertEvent(window0.get(), | 164 std::unique_ptr<ui::LocatedEvent> converted10( |
164 original10)); | 165 ConvertEvent(window0.get(), original10)); |
165 EXPECT_EQ(original10.type(), converted10->type()); | 166 EXPECT_EQ(original10.type(), converted10->type()); |
166 EXPECT_EQ("50,50", converted10->location().ToString()); | 167 EXPECT_EQ("50,50", converted10->location().ToString()); |
167 EXPECT_EQ("50,50", converted10->root_location().ToString()); | 168 EXPECT_EQ("50,50", converted10->root_location().ToString()); |
168 EXPECT_EQ(original10.flags(), converted10->flags()); | 169 EXPECT_EQ(original10.flags(), converted10->flags()); |
169 | 170 |
170 // Start tracking from the RootWindow1 and converts the mouse event into | 171 // Start tracking from the RootWindow1 and converts the mouse event into |
171 // |window1|'s coodinates. | 172 // |window1|'s coodinates. |
172 ui::MouseEvent original11(ui::ET_MOUSE_DRAGGED, gfx::Point(150, 150), | 173 ui::MouseEvent original11(ui::ET_MOUSE_DRAGGED, gfx::Point(150, 150), |
173 gfx::Point(150, 150), ui::EventTimeForNow(), | 174 gfx::Point(150, 150), ui::EventTimeForNow(), |
174 ui::EF_NONE, ui::EF_NONE); | 175 ui::EF_NONE, ui::EF_NONE); |
175 scoped_ptr<ui::LocatedEvent> converted11(ConvertEvent(window1.get(), | 176 std::unique_ptr<ui::LocatedEvent> converted11( |
176 original11)); | 177 ConvertEvent(window1.get(), original11)); |
177 EXPECT_EQ(original11.type(), converted11->type()); | 178 EXPECT_EQ(original11.type(), converted11->type()); |
178 EXPECT_EQ("50,50", converted11->location().ToString()); | 179 EXPECT_EQ("50,50", converted11->location().ToString()); |
179 EXPECT_EQ("150,150", converted11->root_location().ToString()); | 180 EXPECT_EQ("150,150", converted11->root_location().ToString()); |
180 EXPECT_EQ(original11.flags(), converted11->flags()); | 181 EXPECT_EQ(original11.flags(), converted11->flags()); |
181 } | 182 } |
182 | 183 |
183 } // namespace test | 184 } // namespace test |
184 } // namespace aura | 185 } // namespace aura |
OLD | NEW |