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 "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
12 #include "ui/aura/test/test_windows.h" | 12 #include "ui/aura/test/test_windows.h" |
13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
14 | 14 |
15 namespace ash { | 15 namespace ash { |
16 namespace test { | 16 namespace test { |
17 | 17 |
18 class DragDropTrackerTest : public test::AshTestBase { | 18 class DragDropTrackerTest : public test::AshTestBase { |
19 public: | 19 public: |
20 virtual void SetUp() OVERRIDE { | 20 virtual void SetUp() OVERRIDE { |
21 AshTestBase::SetUp(); | 21 AshTestBase::SetUp(); |
22 UpdateDisplay("200x200,200x200"); | 22 UpdateDisplay("200x200,200x200"); |
23 } | 23 } |
24 | 24 |
25 static aura::Window* CreateTestWindow(const gfx::Rect& bounds, | 25 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { |
26 aura::Window* parent) { | |
27 static int window_id = 0; | 26 static int window_id = 0; |
28 return aura::test::CreateTestWindowWithDelegate( | 27 return CreateTestWindowInShellWithDelegate( |
29 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), | 28 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), |
30 window_id++, | 29 window_id++, |
31 bounds, | 30 bounds); |
32 parent); | |
33 } | 31 } |
34 | 32 |
35 static aura::Window* GetTarget(const gfx::Point& location) { | 33 static aura::Window* GetTarget(const gfx::Point& location) { |
36 scoped_ptr<internal::DragDropTracker> tracker( | 34 scoped_ptr<internal::DragDropTracker> tracker( |
37 new internal::DragDropTracker); | 35 new internal::DragDropTracker(Shell::GetPrimaryRootWindow())); |
38 ui::MouseEvent e(ui::ET_MOUSE_DRAGGED, | 36 ui::MouseEvent e(ui::ET_MOUSE_DRAGGED, |
39 location, | 37 location, |
40 location, | 38 location, |
41 ui::EF_NONE); | 39 ui::EF_NONE); |
42 aura::Window* target = tracker->GetTarget(e); | 40 aura::Window* target = tracker->GetTarget(e); |
43 return target; | 41 return target; |
44 } | 42 } |
45 | 43 |
46 static ui::LocatedEvent* ConvertEvent(aura::Window* target, | 44 static ui::LocatedEvent* ConvertEvent(aura::Window* target, |
47 const ui::MouseEvent& event) { | 45 const ui::MouseEvent& event) { |
48 scoped_ptr<internal::DragDropTracker> tracker( | 46 scoped_ptr<internal::DragDropTracker> tracker( |
49 new internal::DragDropTracker); | 47 new internal::DragDropTracker(Shell::GetPrimaryRootWindow())); |
50 ui::LocatedEvent* converted = tracker->ConvertEvent(target, event); | 48 ui::LocatedEvent* converted = tracker->ConvertEvent(target, event); |
51 return converted; | 49 return converted; |
52 } | 50 } |
53 }; | 51 }; |
54 | 52 |
55 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports | 53 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports |
56 // non-X11 platforms. | 54 // non-X11 platforms. |
57 #if defined(USE_X11) | 55 #if defined(USE_X11) |
58 #define MAYBE_GetTarget GetTarget | 56 #define MAYBE_GetTarget GetTarget |
59 #else | 57 #else |
60 #define MAYBE_GetTarget DISABLED_GetTarget | 58 #define MAYBE_GetTarget DISABLED_GetTarget |
61 #endif | 59 #endif |
62 | 60 |
63 TEST_F(DragDropTrackerTest, MAYBE_GetTarget) { | 61 TEST_F(DragDropTrackerTest, MAYBE_GetTarget) { |
64 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 62 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
65 EXPECT_EQ(2U, root_windows.size()); | 63 EXPECT_EQ(2U, root_windows.size()); |
66 | 64 |
67 Shell::GetInstance()->set_active_root_window(root_windows[0]); | 65 Shell::GetInstance()->set_active_root_window(root_windows[0]); |
68 | 66 |
69 scoped_ptr<aura::Window> window0( | 67 scoped_ptr<aura::Window> window0( |
70 CreateTestWindow(gfx::Rect(0, 0, 100, 100), NULL)); | 68 CreateTestWindow(gfx::Rect(0, 0, 100, 100))); |
71 window0->Show(); | 69 window0->Show(); |
72 | 70 |
73 Shell::GetInstance()->set_active_root_window(root_windows[1]); | 71 Shell::GetInstance()->set_active_root_window(root_windows[1]); |
74 | 72 |
75 scoped_ptr<aura::Window> window1( | 73 scoped_ptr<aura::Window> window1( |
76 CreateTestWindow(gfx::Rect(100, 100, 100, 100), NULL)); | 74 CreateTestWindow(gfx::Rect(100, 100, 100, 100))); |
77 window1->Show(); | 75 window1->Show(); |
78 | 76 |
79 // Make RootWindow0 active so that capture window is parented to it. | 77 // Make RootWindow0 active so that capture window is parented to it. |
80 Shell::GetInstance()->set_active_root_window(root_windows[0]); | 78 Shell::GetInstance()->set_active_root_window(root_windows[0]); |
81 | 79 |
82 // Start tracking from the RootWindow1 and check the point on RootWindow0 that | 80 // Start tracking from the RootWindow1 and check the point on RootWindow0 that |
83 // |window0| covers. | 81 // |window0| covers. |
84 EXPECT_EQ(window0.get(), GetTarget(gfx::Point(50, 50))); | 82 EXPECT_EQ(window0.get(), GetTarget(gfx::Point(50, 50))); |
85 | 83 |
86 // Start tracking from the RootWindow0 and check the point on RootWindow0 that | 84 // Start tracking from the RootWindow0 and check the point on RootWindow0 that |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 #else | 124 #else |
127 #define MAYBE_ConvertEvent DISABLED_ConvertEvent | 125 #define MAYBE_ConvertEvent DISABLED_ConvertEvent |
128 #endif | 126 #endif |
129 | 127 |
130 TEST_F(DragDropTrackerTest, MAYBE_ConvertEvent) { | 128 TEST_F(DragDropTrackerTest, MAYBE_ConvertEvent) { |
131 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 129 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
132 EXPECT_EQ(2U, root_windows.size()); | 130 EXPECT_EQ(2U, root_windows.size()); |
133 | 131 |
134 Shell::GetInstance()->set_active_root_window(root_windows[0]); | 132 Shell::GetInstance()->set_active_root_window(root_windows[0]); |
135 scoped_ptr<aura::Window> window0( | 133 scoped_ptr<aura::Window> window0( |
136 CreateTestWindow(gfx::Rect(0, 0, 100, 100), NULL)); | 134 CreateTestWindow(gfx::Rect(0, 0, 100, 100))); |
137 window0->Show(); | 135 window0->Show(); |
138 | 136 |
139 Shell::GetInstance()->set_active_root_window(root_windows[1]); | 137 Shell::GetInstance()->set_active_root_window(root_windows[1]); |
140 scoped_ptr<aura::Window> window1( | 138 scoped_ptr<aura::Window> window1( |
141 CreateTestWindow(gfx::Rect(100, 100, 100, 100), NULL)); | 139 CreateTestWindow(gfx::Rect(100, 100, 100, 100))); |
142 window1->Show(); | 140 window1->Show(); |
143 | 141 |
144 // Make RootWindow0 active so that capture window is parented to it. | 142 // Make RootWindow0 active so that capture window is parented to it. |
145 Shell::GetInstance()->set_active_root_window(root_windows[0]); | 143 Shell::GetInstance()->set_active_root_window(root_windows[0]); |
146 | 144 |
147 // Start tracking from the RootWindow0 and converts the mouse event into | 145 // Start tracking from the RootWindow0 and converts the mouse event into |
148 // |window0|'s coodinates. | 146 // |window0|'s coodinates. |
149 ui::MouseEvent original00(ui::ET_MOUSE_DRAGGED, | 147 ui::MouseEvent original00(ui::ET_MOUSE_DRAGGED, |
150 gfx::Point(50, 50), | 148 gfx::Point(50, 50), |
151 gfx::Point(50, 50), | 149 gfx::Point(50, 50), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 scoped_ptr<ui::LocatedEvent> converted11(ConvertEvent(window1.get(), | 193 scoped_ptr<ui::LocatedEvent> converted11(ConvertEvent(window1.get(), |
196 original11)); | 194 original11)); |
197 EXPECT_EQ(original11.type(), converted11->type()); | 195 EXPECT_EQ(original11.type(), converted11->type()); |
198 EXPECT_EQ("50,50", converted11->location().ToString()); | 196 EXPECT_EQ("50,50", converted11->location().ToString()); |
199 EXPECT_EQ("150,150", converted11->root_location().ToString()); | 197 EXPECT_EQ("150,150", converted11->root_location().ToString()); |
200 EXPECT_EQ(original11.flags(), converted11->flags()); | 198 EXPECT_EQ(original11.flags(), converted11->flags()); |
201 } | 199 } |
202 | 200 |
203 } // namespace test | 201 } // namespace test |
204 } // namespace aura | 202 } // namespace aura |
OLD | NEW |