OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ash/drag_drop/drag_drop_tracker.h" |
| 6 |
| 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" |
| 14 |
| 15 namespace ash { |
| 16 namespace test { |
| 17 |
| 18 class DragDropTrackerTest : public test::AshTestBase { |
| 19 public: |
| 20 virtual void SetUp() OVERRIDE { |
| 21 AshTestBase::SetUp(); |
| 22 UpdateDisplay("0+0-200x200,0+201-200x200"); |
| 23 } |
| 24 |
| 25 static aura::Window* CreateWindow(const gfx::Rect& bounds, |
| 26 aura::Window* parent) { |
| 27 static int window_id = 0; |
| 28 return aura::test::CreateTestWindowWithDelegate( |
| 29 new aura::test::TestWindowDelegate, |
| 30 window_id++, |
| 31 bounds, |
| 32 parent); |
| 33 } |
| 34 |
| 35 static aura::Window* GetTarget(aura::RootWindow* root_window, |
| 36 const gfx::Point& location) { |
| 37 scoped_ptr<internal::DragDropTracker> tracker( |
| 38 new internal::DragDropTracker(root_window)); |
| 39 ui::MouseEvent e(ui::ET_MOUSE_DRAGGED, |
| 40 location, |
| 41 location, |
| 42 ui::EF_NONE); |
| 43 aura::Window* target = tracker->GetTarget(e); |
| 44 return target; |
| 45 } |
| 46 |
| 47 static ui::MouseEvent* ConvertMouseEvent(aura::RootWindow* root_window, |
| 48 aura::Window* target, |
| 49 const ui::MouseEvent& event) { |
| 50 scoped_ptr<internal::DragDropTracker> tracker( |
| 51 new internal::DragDropTracker(root_window)); |
| 52 ui::MouseEvent* converted = tracker->ConvertMouseEvent(target, event); |
| 53 return converted; |
| 54 } |
| 55 }; |
| 56 |
| 57 TEST_F(DragDropTrackerTest, GetTarget) { |
| 58 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 59 EXPECT_EQ(2U, root_windows.size()); |
| 60 |
| 61 aura::Window* default_container0 = |
| 62 ash::Shell::GetContainer(root_windows[0], |
| 63 ash::internal::kShellWindowId_DefaultContainer); |
| 64 EXPECT_TRUE(NULL != default_container0); |
| 65 |
| 66 scoped_ptr<aura::Window> window0( |
| 67 CreateWindow(gfx::Rect(0, 0, 100, 100), default_container0)); |
| 68 window0->Show(); |
| 69 |
| 70 aura::Window* default_container1 = |
| 71 ash::Shell::GetContainer(root_windows[1], |
| 72 ash::internal::kShellWindowId_DefaultContainer); |
| 73 EXPECT_TRUE(NULL != default_container1); |
| 74 |
| 75 scoped_ptr<aura::Window> window1( |
| 76 CreateWindow(gfx::Rect(100, 100, 100, 100), default_container1)); |
| 77 window1->Show(); |
| 78 |
| 79 // Start tracking from the RootWindow0 and check the point on RootWindow0 that |
| 80 // |window0| covers. |
| 81 EXPECT_EQ(window0.get(), GetTarget(root_windows[0], gfx::Point(50, 50))); |
| 82 |
| 83 // Start tracking from the RootWindow0 and check the point on RootWindow0 that |
| 84 // neither |window0| nor |window1| covers. |
| 85 EXPECT_NE(window0.get(), GetTarget(root_windows[0], gfx::Point(150, 150))); |
| 86 EXPECT_NE(window1.get(), GetTarget(root_windows[0], gfx::Point(150, 150))); |
| 87 |
| 88 // Start tracking from the RootWindow0 and check the point on RootWindow1 that |
| 89 // |window1| covers. |
| 90 EXPECT_EQ(window1.get(), GetTarget(root_windows[0], gfx::Point(150, 350))); |
| 91 |
| 92 // Start tracking from the RootWindow0 and check the point on RootWindow1 that |
| 93 // neither |window0| nor |window1| covers. |
| 94 EXPECT_NE(window0.get(), GetTarget(root_windows[0], gfx::Point(50, 250))); |
| 95 EXPECT_NE(window1.get(), GetTarget(root_windows[0], gfx::Point(50, 250))); |
| 96 |
| 97 // Start tracking from the RootWindow1 and check the point on RootWindow0 that |
| 98 // |window0| covers. |
| 99 EXPECT_EQ(window0.get(), GetTarget(root_windows[1], gfx::Point(50, -150))); |
| 100 |
| 101 // Start tracking from the RootWindow1 and check the point on RootWindow0 that |
| 102 // neither |window0| nor |window1| covers. |
| 103 EXPECT_NE(window0.get(), GetTarget(root_windows[1], gfx::Point(150, -50))); |
| 104 EXPECT_NE(window1.get(), GetTarget(root_windows[1], gfx::Point(150, -50))); |
| 105 |
| 106 // Start tracking from the RootWindow1 and check the point on RootWindow1 that |
| 107 // |window1| covers. |
| 108 EXPECT_EQ(window1.get(), GetTarget(root_windows[1], gfx::Point(150, 150))); |
| 109 |
| 110 // Start tracking from the RootWindow1 and check the point on RootWindow1 that |
| 111 // neither |window0| nor |window1| covers. |
| 112 EXPECT_NE(window0.get(), GetTarget(root_windows[1], gfx::Point(50, 50))); |
| 113 EXPECT_NE(window1.get(), GetTarget(root_windows[1], gfx::Point(50, 50))); |
| 114 } |
| 115 |
| 116 TEST_F(DragDropTrackerTest, ConvertMouseEvent) { |
| 117 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 118 EXPECT_EQ(2U, root_windows.size()); |
| 119 |
| 120 aura::Window* default_container0 = |
| 121 ash::Shell::GetContainer(root_windows[0], |
| 122 ash::internal::kShellWindowId_DefaultContainer); |
| 123 EXPECT_TRUE(NULL != default_container0); |
| 124 |
| 125 scoped_ptr<aura::Window> window0( |
| 126 CreateWindow(gfx::Rect(0, 0, 100, 100), default_container0)); |
| 127 window0->Show(); |
| 128 |
| 129 aura::Window* default_container1 = |
| 130 ash::Shell::GetContainer(root_windows[1], |
| 131 ash::internal::kShellWindowId_DefaultContainer); |
| 132 EXPECT_TRUE(NULL != default_container1); |
| 133 |
| 134 scoped_ptr<aura::Window> window1( |
| 135 CreateWindow(gfx::Rect(100, 100, 100, 100), default_container1)); |
| 136 window1->Show(); |
| 137 |
| 138 // Start tracking from the RootWindow0 and converts the mouse event into |
| 139 // |window0|'s coodinates. |
| 140 ui::MouseEvent original00(ui::ET_MOUSE_DRAGGED, |
| 141 gfx::Point(50, 50), |
| 142 gfx::Point(50, 50), |
| 143 ui::EF_NONE); |
| 144 scoped_ptr<ui::MouseEvent> converted00(ConvertMouseEvent(root_windows[0], |
| 145 window0.get(), |
| 146 original00)); |
| 147 EXPECT_EQ(original00.type(), converted00->type()); |
| 148 EXPECT_EQ(gfx::Point(50, 50), converted00->location()); |
| 149 EXPECT_EQ(gfx::Point(50, 50), converted00->root_location()); |
| 150 EXPECT_EQ(original00.flags(), converted00->flags()); |
| 151 |
| 152 // Start tracking from the RootWindow0 and converts the mouse event into |
| 153 // |window1|'s coodinates. |
| 154 ui::MouseEvent original01(ui::ET_MOUSE_DRAGGED, |
| 155 gfx::Point(150, 350), |
| 156 gfx::Point(150, 350), |
| 157 ui::EF_NONE); |
| 158 scoped_ptr<ui::MouseEvent> converted01(ConvertMouseEvent(root_windows[0], |
| 159 window1.get(), |
| 160 original01)); |
| 161 EXPECT_EQ(original01.type(), converted01->type()); |
| 162 EXPECT_EQ(gfx::Point(50, 50), converted01->location()); |
| 163 EXPECT_EQ(gfx::Point(150, 150), converted01->root_location()); |
| 164 EXPECT_EQ(original01.flags(), converted01->flags()); |
| 165 |
| 166 // Start tracking from the RootWindow1 and converts the mouse event into |
| 167 // |window0|'s coodinates. |
| 168 ui::MouseEvent original10(ui::ET_MOUSE_DRAGGED, |
| 169 gfx::Point(50, -150), |
| 170 gfx::Point(50, -150), |
| 171 ui::EF_NONE); |
| 172 scoped_ptr<ui::MouseEvent> converted10(ConvertMouseEvent(root_windows[1], |
| 173 window0.get(), |
| 174 original10)); |
| 175 EXPECT_EQ(original10.type(), converted10->type()); |
| 176 EXPECT_EQ(gfx::Point(50, 50), converted10->location()); |
| 177 EXPECT_EQ(gfx::Point(50, 50), converted10->root_location()); |
| 178 EXPECT_EQ(original10.flags(), converted10->flags()); |
| 179 |
| 180 // Start tracking from the RootWindow1 and converts the mouse event into |
| 181 // |window1|'s coodinates. |
| 182 ui::MouseEvent original11(ui::ET_MOUSE_DRAGGED, |
| 183 gfx::Point(150, 150), |
| 184 gfx::Point(150, 150), |
| 185 ui::EF_NONE); |
| 186 scoped_ptr<ui::MouseEvent> converted11(ConvertMouseEvent(root_windows[1], |
| 187 window1.get(), |
| 188 original11)); |
| 189 EXPECT_EQ(original11.type(), converted11->type()); |
| 190 EXPECT_EQ(gfx::Point(50, 50), converted11->location()); |
| 191 EXPECT_EQ(gfx::Point(150, 150), converted11->root_location()); |
| 192 EXPECT_EQ(original11.flags(), converted11->flags()); |
| 193 } |
| 194 |
| 195 } // namespace test |
| 196 } // namespace aura |
OLD | NEW |