Chromium Code Reviews| 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> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/aura/wm_window_aura.h" | |
| 10 #include "ash/common/scoped_root_window_for_new_windows.h" | |
| 9 #include "ash/common/shell_window_ids.h" | 11 #include "ash/common/shell_window_ids.h" |
| 10 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 11 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
| 12 #include "ui/aura/test/test_windows.h" | 14 #include "ui/aura/test/test_windows.h" |
| 13 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_event_dispatcher.h" | 16 #include "ui/aura/window_event_dispatcher.h" |
| 15 #include "ui/events/event_utils.h" | 17 #include "ui/events/event_utils.h" |
| 16 | 18 |
| 17 namespace ash { | 19 namespace ash { |
| 18 namespace test { | 20 namespace test { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 window0->Show(); | 61 window0->Show(); |
| 60 | 62 |
| 61 std::unique_ptr<aura::Window> window1( | 63 std::unique_ptr<aura::Window> window1( |
| 62 CreateTestWindow(gfx::Rect(300, 100, 100, 100))); | 64 CreateTestWindow(gfx::Rect(300, 100, 100, 100))); |
| 63 window1->Show(); | 65 window1->Show(); |
| 64 EXPECT_EQ(root_windows[0], window0->GetRootWindow()); | 66 EXPECT_EQ(root_windows[0], window0->GetRootWindow()); |
| 65 EXPECT_EQ(root_windows[1], window1->GetRootWindow()); | 67 EXPECT_EQ(root_windows[1], window1->GetRootWindow()); |
| 66 EXPECT_EQ("0,0 100x100", window0->GetBoundsInScreen().ToString()); | 68 EXPECT_EQ("0,0 100x100", window0->GetBoundsInScreen().ToString()); |
| 67 EXPECT_EQ("300,100 100x100", window1->GetBoundsInScreen().ToString()); | 69 EXPECT_EQ("300,100 100x100", window1->GetBoundsInScreen().ToString()); |
| 68 | 70 |
| 69 // Make RootWindow0 active so that capture window is parented to it. | 71 { |
| 70 Shell::GetInstance()->set_target_root_window(root_windows[0]); | 72 // Make RootWindow0 active so that capture window is parented to it. |
| 73 ScopedRootWindowForNewWindows root_for_new_windows( | |
|
msw
2016/08/02 01:04:50
optional nit: ScopedRootWindowForNewWindows for fi
James Cook
2016/08/02 16:16:04
Done.
| |
| 74 WmWindowAura::Get(root_windows[0])); | |
| 71 | 75 |
| 72 // Start tracking from the RootWindow1 and check the point on RootWindow0 that | 76 // Start tracking from the RootWindow1 and check the point on RootWindow0 |
| 73 // |window0| covers. | 77 // that |window0| covers. |
| 74 EXPECT_EQ(window0.get(), GetTarget(gfx::Point(50, 50))); | 78 EXPECT_EQ(window0.get(), GetTarget(gfx::Point(50, 50))); |
| 75 | 79 |
| 76 // Start tracking from the RootWindow0 and check the point on RootWindow0 that | 80 // Start tracking from the RootWindow0 and check the point on RootWindow0 |
| 77 // neither |window0| nor |window1| covers. | 81 // that neither |window0| nor |window1| covers. |
| 78 EXPECT_NE(window0.get(), GetTarget(gfx::Point(150, 150))); | 82 EXPECT_NE(window0.get(), GetTarget(gfx::Point(150, 150))); |
| 79 EXPECT_NE(window1.get(), GetTarget(gfx::Point(150, 150))); | 83 EXPECT_NE(window1.get(), GetTarget(gfx::Point(150, 150))); |
| 80 | 84 |
| 81 // Start tracking from the RootWindow0 and check the point on RootWindow1 that | 85 // Start tracking from the RootWindow0 and check the point on RootWindow1 |
| 82 // |window1| covers. | 86 // that |window1| covers. |
| 83 EXPECT_EQ(window1.get(), GetTarget(gfx::Point(350, 150))); | 87 EXPECT_EQ(window1.get(), GetTarget(gfx::Point(350, 150))); |
| 84 | 88 |
| 85 // Start tracking from the RootWindow0 and check the point on RootWindow1 that | 89 // Start tracking from the RootWindow0 and check the point on RootWindow1 |
| 86 // neither |window0| nor |window1| covers. | 90 // that neither |window0| nor |window1| covers. |
| 87 EXPECT_NE(window0.get(), GetTarget(gfx::Point(50, 250))); | 91 EXPECT_NE(window0.get(), GetTarget(gfx::Point(50, 250))); |
| 88 EXPECT_NE(window1.get(), GetTarget(gfx::Point(50, 250))); | 92 EXPECT_NE(window1.get(), GetTarget(gfx::Point(50, 250))); |
| 93 } | |
| 89 | 94 |
| 90 // Make RootWindow1 active so that capture window is parented to it. | 95 { |
| 91 Shell::GetInstance()->set_target_root_window(root_windows[1]); | 96 // Make RootWindow1 active so that capture window is parented to it. |
| 97 ScopedRootWindowForNewWindows root_for_new_windows( | |
| 98 WmWindowAura::Get(root_windows[1])); | |
| 92 | 99 |
| 93 // Start tracking from the RootWindow1 and check the point on RootWindow0 that | 100 // Start tracking from the RootWindow1 and check the point on RootWindow0 |
| 94 // |window0| covers. | 101 // that |window0| covers. |
| 95 EXPECT_EQ(window0.get(), GetTarget(gfx::Point(-150, 50))); | 102 EXPECT_EQ(window0.get(), GetTarget(gfx::Point(-150, 50))); |
| 96 | 103 |
| 97 // Start tracking from the RootWindow1 and check the point on RootWindow0 that | 104 // Start tracking from the RootWindow1 and check the point on RootWindow0 |
| 98 // neither |window0| nor |window1| covers. | 105 // that neither |window0| nor |window1| covers. |
| 99 EXPECT_NE(window0.get(), GetTarget(gfx::Point(150, -50))); | 106 EXPECT_NE(window0.get(), GetTarget(gfx::Point(150, -50))); |
| 100 EXPECT_NE(window1.get(), GetTarget(gfx::Point(150, -50))); | 107 EXPECT_NE(window1.get(), GetTarget(gfx::Point(150, -50))); |
| 101 | 108 |
| 102 // Start tracking from the RootWindow1 and check the point on RootWindow1 that | 109 // Start tracking from the RootWindow1 and check the point on RootWindow1 |
| 103 // |window1| covers. | 110 // that |window1| covers. |
| 104 EXPECT_EQ(window1.get(), GetTarget(gfx::Point(150, 150))); | 111 EXPECT_EQ(window1.get(), GetTarget(gfx::Point(150, 150))); |
| 105 | 112 |
| 106 // Start tracking from the RootWindow1 and check the point on RootWindow1 that | 113 // Start tracking from the RootWindow1 and check the point on RootWindow1 |
| 107 // neither |window0| nor |window1| covers. | 114 // that |window0| nor |window1| covers. |
| 108 EXPECT_NE(window0.get(), GetTarget(gfx::Point(50, 50))); | 115 EXPECT_NE(window0.get(), GetTarget(gfx::Point(50, 50))); |
| 109 EXPECT_NE(window1.get(), GetTarget(gfx::Point(50, 50))); | 116 EXPECT_NE(window1.get(), GetTarget(gfx::Point(50, 50))); |
| 117 } | |
| 110 } | 118 } |
| 111 | 119 |
| 112 TEST_F(DragDropTrackerTest, ConvertEvent) { | 120 TEST_F(DragDropTrackerTest, ConvertEvent) { |
| 113 if (!SupportsMultipleDisplays()) | 121 if (!SupportsMultipleDisplays()) |
| 114 return; | 122 return; |
| 115 | 123 |
| 116 UpdateDisplay("200x200,300x300"); | 124 UpdateDisplay("200x200,300x300"); |
| 117 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 125 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 118 EXPECT_EQ(2U, root_windows.size()); | 126 EXPECT_EQ(2U, root_windows.size()); |
| 119 | 127 |
| 120 std::unique_ptr<aura::Window> window0( | 128 std::unique_ptr<aura::Window> window0( |
| 121 CreateTestWindow(gfx::Rect(0, 0, 100, 100))); | 129 CreateTestWindow(gfx::Rect(0, 0, 100, 100))); |
| 122 window0->Show(); | 130 window0->Show(); |
| 123 | 131 |
| 124 std::unique_ptr<aura::Window> window1( | 132 std::unique_ptr<aura::Window> window1( |
| 125 CreateTestWindow(gfx::Rect(300, 100, 100, 100))); | 133 CreateTestWindow(gfx::Rect(300, 100, 100, 100))); |
| 126 window1->Show(); | 134 window1->Show(); |
| 127 | 135 |
| 128 // Make RootWindow0 active so that capture window is parented to it. | 136 { |
| 129 Shell::GetInstance()->set_target_root_window(root_windows[0]); | 137 // Make RootWindow0 active so that capture window is parented to it. |
| 138 ScopedRootWindowForNewWindows root_for_new_windows( | |
|
msw
2016/08/02 01:04:50
optional nit: ScopedRootWindowForNewWindows for fi
| |
| 139 WmWindowAura::Get(root_windows[0])); | |
| 130 | 140 |
| 131 // Start tracking from the RootWindow0 and converts the mouse event into | 141 // Start tracking from the RootWindow0 and converts the mouse event into |
| 132 // |window0|'s coodinates. | 142 // |window0|'s coodinates. |
| 133 ui::MouseEvent original00(ui::ET_MOUSE_DRAGGED, gfx::Point(50, 50), | 143 ui::MouseEvent original00(ui::ET_MOUSE_DRAGGED, gfx::Point(50, 50), |
| 134 gfx::Point(50, 50), ui::EventTimeForNow(), | 144 gfx::Point(50, 50), ui::EventTimeForNow(), |
| 135 ui::EF_NONE, ui::EF_NONE); | 145 ui::EF_NONE, ui::EF_NONE); |
| 136 std::unique_ptr<ui::LocatedEvent> converted00( | 146 std::unique_ptr<ui::LocatedEvent> converted00( |
| 137 ConvertEvent(window0.get(), original00)); | 147 ConvertEvent(window0.get(), original00)); |
| 138 EXPECT_EQ(original00.type(), converted00->type()); | 148 EXPECT_EQ(original00.type(), converted00->type()); |
| 139 EXPECT_EQ("50,50", converted00->location().ToString()); | 149 EXPECT_EQ("50,50", converted00->location().ToString()); |
| 140 EXPECT_EQ("50,50", converted00->root_location().ToString()); | 150 EXPECT_EQ("50,50", converted00->root_location().ToString()); |
| 141 EXPECT_EQ(original00.flags(), converted00->flags()); | 151 EXPECT_EQ(original00.flags(), converted00->flags()); |
| 142 | 152 |
| 143 // Start tracking from the RootWindow0 and converts the mouse event into | 153 // Start tracking from the RootWindow0 and converts the mouse event into |
| 144 // |window1|'s coodinates. | 154 // |window1|'s coodinates. |
| 145 ui::MouseEvent original01(ui::ET_MOUSE_DRAGGED, gfx::Point(350, 150), | 155 ui::MouseEvent original01(ui::ET_MOUSE_DRAGGED, gfx::Point(350, 150), |
| 146 gfx::Point(350, 150), ui::EventTimeForNow(), | 156 gfx::Point(350, 150), ui::EventTimeForNow(), |
| 147 ui::EF_NONE, ui::EF_NONE); | 157 ui::EF_NONE, ui::EF_NONE); |
| 148 std::unique_ptr<ui::LocatedEvent> converted01( | 158 std::unique_ptr<ui::LocatedEvent> converted01( |
| 149 ConvertEvent(window1.get(), original01)); | 159 ConvertEvent(window1.get(), original01)); |
| 150 EXPECT_EQ(original01.type(), converted01->type()); | 160 EXPECT_EQ(original01.type(), converted01->type()); |
| 151 EXPECT_EQ("50,50", converted01->location().ToString()); | 161 EXPECT_EQ("50,50", converted01->location().ToString()); |
| 152 EXPECT_EQ("150,150", converted01->root_location().ToString()); | 162 EXPECT_EQ("150,150", converted01->root_location().ToString()); |
| 153 EXPECT_EQ(original01.flags(), converted01->flags()); | 163 EXPECT_EQ(original01.flags(), converted01->flags()); |
| 164 } | |
| 154 | 165 |
| 155 // Make RootWindow1 active so that capture window is parented to it. | 166 { |
| 156 Shell::GetInstance()->set_target_root_window(root_windows[1]); | 167 // Make RootWindow1 active so that capture window is parented to it. |
| 168 ScopedRootWindowForNewWindows root_for_new_windows( | |
| 169 WmWindowAura::Get(root_windows[1])); | |
| 157 | 170 |
| 158 // Start tracking from the RootWindow1 and converts the mouse event into | 171 // Start tracking from the RootWindow1 and converts the mouse event into |
| 159 // |window0|'s coodinates. | 172 // |window0|'s coodinates. |
| 160 ui::MouseEvent original10(ui::ET_MOUSE_DRAGGED, gfx::Point(-150, 50), | 173 ui::MouseEvent original10(ui::ET_MOUSE_DRAGGED, gfx::Point(-150, 50), |
| 161 gfx::Point(-150, 50), ui::EventTimeForNow(), | 174 gfx::Point(-150, 50), ui::EventTimeForNow(), |
| 162 ui::EF_NONE, ui::EF_NONE); | 175 ui::EF_NONE, ui::EF_NONE); |
| 163 std::unique_ptr<ui::LocatedEvent> converted10( | 176 std::unique_ptr<ui::LocatedEvent> converted10( |
| 164 ConvertEvent(window0.get(), original10)); | 177 ConvertEvent(window0.get(), original10)); |
| 165 EXPECT_EQ(original10.type(), converted10->type()); | 178 EXPECT_EQ(original10.type(), converted10->type()); |
| 166 EXPECT_EQ("50,50", converted10->location().ToString()); | 179 EXPECT_EQ("50,50", converted10->location().ToString()); |
| 167 EXPECT_EQ("50,50", converted10->root_location().ToString()); | 180 EXPECT_EQ("50,50", converted10->root_location().ToString()); |
| 168 EXPECT_EQ(original10.flags(), converted10->flags()); | 181 EXPECT_EQ(original10.flags(), converted10->flags()); |
| 169 | 182 |
| 170 // Start tracking from the RootWindow1 and converts the mouse event into | 183 // Start tracking from the RootWindow1 and converts the mouse event into |
| 171 // |window1|'s coodinates. | 184 // |window1|'s coodinates. |
| 172 ui::MouseEvent original11(ui::ET_MOUSE_DRAGGED, gfx::Point(150, 150), | 185 ui::MouseEvent original11(ui::ET_MOUSE_DRAGGED, gfx::Point(150, 150), |
| 173 gfx::Point(150, 150), ui::EventTimeForNow(), | 186 gfx::Point(150, 150), ui::EventTimeForNow(), |
| 174 ui::EF_NONE, ui::EF_NONE); | 187 ui::EF_NONE, ui::EF_NONE); |
| 175 std::unique_ptr<ui::LocatedEvent> converted11( | 188 std::unique_ptr<ui::LocatedEvent> converted11( |
| 176 ConvertEvent(window1.get(), original11)); | 189 ConvertEvent(window1.get(), original11)); |
| 177 EXPECT_EQ(original11.type(), converted11->type()); | 190 EXPECT_EQ(original11.type(), converted11->type()); |
| 178 EXPECT_EQ("50,50", converted11->location().ToString()); | 191 EXPECT_EQ("50,50", converted11->location().ToString()); |
| 179 EXPECT_EQ("150,150", converted11->root_location().ToString()); | 192 EXPECT_EQ("150,150", converted11->root_location().ToString()); |
| 180 EXPECT_EQ(original11.flags(), converted11->flags()); | 193 EXPECT_EQ(original11.flags(), converted11->flags()); |
| 194 } | |
| 181 } | 195 } |
| 182 | 196 |
| 183 } // namespace test | 197 } // namespace test |
| 184 } // namespace aura | 198 } // namespace aura |
| OLD | NEW |