[Sync] Fix namespace for sync_driver component
[chromium-blink-merge.git] / ash / drag_drop / drag_drop_tracker_unittest.cc
blob6b470e89c544b0ef5d3f34e127dd31ad04cd6087
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
3 // found in the LICENSE file.
5 #include "ash/drag_drop/drag_drop_tracker.h"
7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h"
9 #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/window.h"
13 #include "ui/aura/window_event_dispatcher.h"
15 namespace ash {
16 namespace test {
18 class DragDropTrackerTest : public test::AshTestBase {
19 public:
20 virtual void SetUp() OVERRIDE {
21 AshTestBase::SetUp();
22 UpdateDisplay("200x200,300x300");
25 aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
26 static int window_id = 0;
27 return CreateTestWindowInShellWithDelegate(
28 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(),
29 window_id++,
30 bounds);
33 static aura::Window* GetTarget(const gfx::Point& location) {
34 scoped_ptr<DragDropTracker> tracker(
35 new DragDropTracker(Shell::GetPrimaryRootWindow(), NULL));
36 ui::MouseEvent e(ui::ET_MOUSE_DRAGGED,
37 location,
38 location,
39 ui::EF_NONE,
40 ui::EF_NONE);
41 aura::Window* target = tracker->GetTarget(e);
42 return target;
45 static ui::LocatedEvent* ConvertEvent(aura::Window* target,
46 const ui::MouseEvent& event) {
47 scoped_ptr<DragDropTracker> tracker(
48 new DragDropTracker(Shell::GetPrimaryRootWindow(), NULL));
49 ui::LocatedEvent* converted = tracker->ConvertEvent(target, event);
50 return converted;
54 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports
55 // non-X11 platforms.
56 #if defined(USE_X11)
57 #define MAYBE_GetTarget GetTarget
58 #else
59 #define MAYBE_GetTarget DISABLED_GetTarget
60 #endif
62 TEST_F(DragDropTrackerTest, MAYBE_GetTarget) {
63 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
64 EXPECT_EQ(2U, root_windows.size());
66 scoped_ptr<aura::Window> window0(
67 CreateTestWindow(gfx::Rect(0, 0, 100, 100)));
68 window0->Show();
70 scoped_ptr<aura::Window> window1(
71 CreateTestWindow(gfx::Rect(300, 100, 100, 100)));
72 window1->Show();
73 EXPECT_EQ(root_windows[0], window0->GetRootWindow());
74 EXPECT_EQ(root_windows[1], window1->GetRootWindow());
75 EXPECT_EQ("0,0 100x100", window0->GetBoundsInScreen().ToString());
76 EXPECT_EQ("300,100 100x100", window1->GetBoundsInScreen().ToString());
78 // Make RootWindow0 active so that capture window is parented to it.
79 Shell::GetInstance()->set_target_root_window(root_windows[0]);
81 // Start tracking from the RootWindow1 and check the point on RootWindow0 that
82 // |window0| covers.
83 EXPECT_EQ(window0.get(), GetTarget(gfx::Point(50, 50)));
85 // Start tracking from the RootWindow0 and check the point on RootWindow0 that
86 // neither |window0| nor |window1| covers.
87 EXPECT_NE(window0.get(), GetTarget(gfx::Point(150, 150)));
88 EXPECT_NE(window1.get(), GetTarget(gfx::Point(150, 150)));
90 // Start tracking from the RootWindow0 and check the point on RootWindow1 that
91 // |window1| covers.
92 EXPECT_EQ(window1.get(), GetTarget(gfx::Point(350, 150)));
94 // Start tracking from the RootWindow0 and check the point on RootWindow1 that
95 // neither |window0| nor |window1| covers.
96 EXPECT_NE(window0.get(), GetTarget(gfx::Point(50, 250)));
97 EXPECT_NE(window1.get(), GetTarget(gfx::Point(50, 250)));
99 // Make RootWindow1 active so that capture window is parented to it.
100 Shell::GetInstance()->set_target_root_window(root_windows[1]);
102 // Start tracking from the RootWindow1 and check the point on RootWindow0 that
103 // |window0| covers.
104 EXPECT_EQ(window0.get(), GetTarget(gfx::Point(-150, 50)));
106 // Start tracking from the RootWindow1 and check the point on RootWindow0 that
107 // neither |window0| nor |window1| covers.
108 EXPECT_NE(window0.get(), GetTarget(gfx::Point(150, -50)));
109 EXPECT_NE(window1.get(), GetTarget(gfx::Point(150, -50)));
111 // Start tracking from the RootWindow1 and check the point on RootWindow1 that
112 // |window1| covers.
113 EXPECT_EQ(window1.get(), GetTarget(gfx::Point(150, 150)));
115 // Start tracking from the RootWindow1 and check the point on RootWindow1 that
116 // neither |window0| nor |window1| covers.
117 EXPECT_NE(window0.get(), GetTarget(gfx::Point(50, 50)));
118 EXPECT_NE(window1.get(), GetTarget(gfx::Point(50, 50)));
121 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports
122 // non-X11 platforms.
123 #if defined(USE_X11)
124 #define MAYBE_ConvertEvent ConvertEvent
125 #else
126 #define MAYBE_ConvertEvent DISABLED_ConvertEvent
127 #endif
129 TEST_F(DragDropTrackerTest, MAYBE_ConvertEvent) {
130 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
131 EXPECT_EQ(2U, root_windows.size());
133 scoped_ptr<aura::Window> window0(
134 CreateTestWindow(gfx::Rect(0, 0, 100, 100)));
135 window0->Show();
137 scoped_ptr<aura::Window> window1(
138 CreateTestWindow(gfx::Rect(300, 100, 100, 100)));
139 window1->Show();
141 // Make RootWindow0 active so that capture window is parented to it.
142 Shell::GetInstance()->set_target_root_window(root_windows[0]);
144 // Start tracking from the RootWindow0 and converts the mouse event into
145 // |window0|'s coodinates.
146 ui::MouseEvent original00(ui::ET_MOUSE_DRAGGED,
147 gfx::Point(50, 50),
148 gfx::Point(50, 50),
149 ui::EF_NONE,
150 ui::EF_NONE);
151 scoped_ptr<ui::LocatedEvent> converted00(ConvertEvent(window0.get(),
152 original00));
153 EXPECT_EQ(original00.type(), converted00->type());
154 EXPECT_EQ("50,50", converted00->location().ToString());
155 EXPECT_EQ("50,50", converted00->root_location().ToString());
156 EXPECT_EQ(original00.flags(), converted00->flags());
158 // Start tracking from the RootWindow0 and converts the mouse event into
159 // |window1|'s coodinates.
160 ui::MouseEvent original01(ui::ET_MOUSE_DRAGGED,
161 gfx::Point(350, 150),
162 gfx::Point(350, 150),
163 ui::EF_NONE,
164 ui::EF_NONE);
165 scoped_ptr<ui::LocatedEvent> converted01(ConvertEvent(window1.get(),
166 original01));
167 EXPECT_EQ(original01.type(), converted01->type());
168 EXPECT_EQ("50,50", converted01->location().ToString());
169 EXPECT_EQ("150,150", converted01->root_location().ToString());
170 EXPECT_EQ(original01.flags(), converted01->flags());
172 // Make RootWindow1 active so that capture window is parented to it.
173 Shell::GetInstance()->set_target_root_window(root_windows[1]);
175 // Start tracking from the RootWindow1 and converts the mouse event into
176 // |window0|'s coodinates.
177 ui::MouseEvent original10(ui::ET_MOUSE_DRAGGED,
178 gfx::Point(-150, 50),
179 gfx::Point(-150, 50),
180 ui::EF_NONE,
181 ui::EF_NONE);
182 scoped_ptr<ui::LocatedEvent> converted10(ConvertEvent(window0.get(),
183 original10));
184 EXPECT_EQ(original10.type(), converted10->type());
185 EXPECT_EQ("50,50", converted10->location().ToString());
186 EXPECT_EQ("50,50", converted10->root_location().ToString());
187 EXPECT_EQ(original10.flags(), converted10->flags());
189 // Start tracking from the RootWindow1 and converts the mouse event into
190 // |window1|'s coodinates.
191 ui::MouseEvent original11(ui::ET_MOUSE_DRAGGED,
192 gfx::Point(150, 150),
193 gfx::Point(150, 150),
194 ui::EF_NONE,
195 ui::EF_NONE);
196 scoped_ptr<ui::LocatedEvent> converted11(ConvertEvent(window1.get(),
197 original11));
198 EXPECT_EQ(original11.type(), converted11->type());
199 EXPECT_EQ("50,50", converted11->location().ToString());
200 EXPECT_EQ("150,150", converted11->root_location().ToString());
201 EXPECT_EQ(original11.flags(), converted11->flags());
204 } // namespace test
205 } // namespace aura