Added documentation to web_view.js/web_view_experimental.js regarding the webview...
[chromium-blink-merge.git] / ash / drag_drop / drag_drop_tracker_unittest.cc
blob41eb089eccd7a837821d76123569afd6db9305b7
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/root_window.h"
12 #include "ui/aura/test/test_windows.h"
13 #include "ui/aura/window.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<internal::DragDropTracker> tracker(
35 new internal::DragDropTracker(Shell::GetPrimaryRootWindow(),
36 NULL));
37 ui::MouseEvent e(ui::ET_MOUSE_DRAGGED,
38 location,
39 location,
40 ui::EF_NONE,
41 ui::EF_NONE);
42 aura::Window* target = tracker->GetTarget(e);
43 return target;
46 static ui::LocatedEvent* ConvertEvent(aura::Window* target,
47 const ui::MouseEvent& event) {
48 scoped_ptr<internal::DragDropTracker> tracker(
49 new internal::DragDropTracker(Shell::GetPrimaryRootWindow(),
50 NULL));
51 ui::LocatedEvent* converted = tracker->ConvertEvent(target, event);
52 return converted;
56 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports
57 // non-X11 platforms.
58 #if defined(USE_X11)
59 #define MAYBE_GetTarget GetTarget
60 #else
61 #define MAYBE_GetTarget DISABLED_GetTarget
62 #endif
64 TEST_F(DragDropTrackerTest, MAYBE_GetTarget) {
65 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
66 EXPECT_EQ(2U, root_windows.size());
68 scoped_ptr<aura::Window> window0(
69 CreateTestWindow(gfx::Rect(0, 0, 100, 100)));
70 window0->Show();
72 scoped_ptr<aura::Window> window1(
73 CreateTestWindow(gfx::Rect(300, 100, 100, 100)));
74 window1->Show();
75 EXPECT_EQ(root_windows[0], window0->GetRootWindow());
76 EXPECT_EQ(root_windows[1], window1->GetRootWindow());
77 EXPECT_EQ("0,0 100x100", window0->GetBoundsInScreen().ToString());
78 EXPECT_EQ("300,100 100x100", window1->GetBoundsInScreen().ToString());
80 // Make RootWindow0 active so that capture window is parented to it.
81 Shell::GetInstance()->set_target_root_window(root_windows[0]);
83 // Start tracking from the RootWindow1 and check the point on RootWindow0 that
84 // |window0| covers.
85 EXPECT_EQ(window0.get(), GetTarget(gfx::Point(50, 50)));
87 // Start tracking from the RootWindow0 and check the point on RootWindow0 that
88 // neither |window0| nor |window1| covers.
89 EXPECT_NE(window0.get(), GetTarget(gfx::Point(150, 150)));
90 EXPECT_NE(window1.get(), GetTarget(gfx::Point(150, 150)));
92 // Start tracking from the RootWindow0 and check the point on RootWindow1 that
93 // |window1| covers.
94 EXPECT_EQ(window1.get(), GetTarget(gfx::Point(350, 150)));
96 // Start tracking from the RootWindow0 and check the point on RootWindow1 that
97 // neither |window0| nor |window1| covers.
98 EXPECT_NE(window0.get(), GetTarget(gfx::Point(50, 250)));
99 EXPECT_NE(window1.get(), GetTarget(gfx::Point(50, 250)));
101 // Make RootWindow1 active so that capture window is parented to it.
102 Shell::GetInstance()->set_target_root_window(root_windows[1]);
104 // Start tracking from the RootWindow1 and check the point on RootWindow0 that
105 // |window0| covers.
106 EXPECT_EQ(window0.get(), GetTarget(gfx::Point(-150, 50)));
108 // Start tracking from the RootWindow1 and check the point on RootWindow0 that
109 // neither |window0| nor |window1| covers.
110 EXPECT_NE(window0.get(), GetTarget(gfx::Point(150, -50)));
111 EXPECT_NE(window1.get(), GetTarget(gfx::Point(150, -50)));
113 // Start tracking from the RootWindow1 and check the point on RootWindow1 that
114 // |window1| covers.
115 EXPECT_EQ(window1.get(), GetTarget(gfx::Point(150, 150)));
117 // Start tracking from the RootWindow1 and check the point on RootWindow1 that
118 // neither |window0| nor |window1| covers.
119 EXPECT_NE(window0.get(), GetTarget(gfx::Point(50, 50)));
120 EXPECT_NE(window1.get(), GetTarget(gfx::Point(50, 50)));
123 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports
124 // non-X11 platforms.
125 #if defined(USE_X11)
126 #define MAYBE_ConvertEvent ConvertEvent
127 #else
128 #define MAYBE_ConvertEvent DISABLED_ConvertEvent
129 #endif
131 TEST_F(DragDropTrackerTest, MAYBE_ConvertEvent) {
132 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
133 EXPECT_EQ(2U, root_windows.size());
135 scoped_ptr<aura::Window> window0(
136 CreateTestWindow(gfx::Rect(0, 0, 100, 100)));
137 window0->Show();
139 scoped_ptr<aura::Window> window1(
140 CreateTestWindow(gfx::Rect(300, 100, 100, 100)));
141 window1->Show();
143 // Make RootWindow0 active so that capture window is parented to it.
144 Shell::GetInstance()->set_target_root_window(root_windows[0]);
146 // Start tracking from the RootWindow0 and converts the mouse event into
147 // |window0|'s coodinates.
148 ui::MouseEvent original00(ui::ET_MOUSE_DRAGGED,
149 gfx::Point(50, 50),
150 gfx::Point(50, 50),
151 ui::EF_NONE,
152 ui::EF_NONE);
153 scoped_ptr<ui::LocatedEvent> converted00(ConvertEvent(window0.get(),
154 original00));
155 EXPECT_EQ(original00.type(), converted00->type());
156 EXPECT_EQ("50,50", converted00->location().ToString());
157 EXPECT_EQ("50,50", converted00->root_location().ToString());
158 EXPECT_EQ(original00.flags(), converted00->flags());
160 // Start tracking from the RootWindow0 and converts the mouse event into
161 // |window1|'s coodinates.
162 ui::MouseEvent original01(ui::ET_MOUSE_DRAGGED,
163 gfx::Point(350, 150),
164 gfx::Point(350, 150),
165 ui::EF_NONE,
166 ui::EF_NONE);
167 scoped_ptr<ui::LocatedEvent> converted01(ConvertEvent(window1.get(),
168 original01));
169 EXPECT_EQ(original01.type(), converted01->type());
170 EXPECT_EQ("50,50", converted01->location().ToString());
171 EXPECT_EQ("150,150", converted01->root_location().ToString());
172 EXPECT_EQ(original01.flags(), converted01->flags());
174 // Make RootWindow1 active so that capture window is parented to it.
175 Shell::GetInstance()->set_target_root_window(root_windows[1]);
177 // Start tracking from the RootWindow1 and converts the mouse event into
178 // |window0|'s coodinates.
179 ui::MouseEvent original10(ui::ET_MOUSE_DRAGGED,
180 gfx::Point(-150, 50),
181 gfx::Point(-150, 50),
182 ui::EF_NONE,
183 ui::EF_NONE);
184 scoped_ptr<ui::LocatedEvent> converted10(ConvertEvent(window0.get(),
185 original10));
186 EXPECT_EQ(original10.type(), converted10->type());
187 EXPECT_EQ("50,50", converted10->location().ToString());
188 EXPECT_EQ("50,50", converted10->root_location().ToString());
189 EXPECT_EQ(original10.flags(), converted10->flags());
191 // Start tracking from the RootWindow1 and converts the mouse event into
192 // |window1|'s coodinates.
193 ui::MouseEvent original11(ui::ET_MOUSE_DRAGGED,
194 gfx::Point(150, 150),
195 gfx::Point(150, 150),
196 ui::EF_NONE,
197 ui::EF_NONE);
198 scoped_ptr<ui::LocatedEvent> converted11(ConvertEvent(window1.get(),
199 original11));
200 EXPECT_EQ(original11.type(), converted11->type());
201 EXPECT_EQ("50,50", converted11->location().ToString());
202 EXPECT_EQ("150,150", converted11->root_location().ToString());
203 EXPECT_EQ(original11.flags(), converted11->flags());
206 } // namespace test
207 } // namespace aura