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/wm/toplevel_window_event_handler.h" | 5 #include "ash/wm/toplevel_window_event_handler.h" |
6 | 6 |
7 #include "ash/common/wm/window_state.h" | 7 #include "ash/common/wm/window_state.h" |
8 #include "ash/common/wm/wm_event.h" | 8 #include "ash/common/wm/wm_event.h" |
9 #include "ash/common/wm/workspace_controller.h" | 9 #include "ash/common/wm/workspace_controller.h" |
10 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 const gfx::Size size = w1->bounds().size(); | 128 const gfx::Size size = w1->bounds().size(); |
129 wm::WindowState* window_state = ash::wm::GetWindowState(w1.get()); | 129 wm::WindowState* window_state = ash::wm::GetWindowState(w1.get()); |
130 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w1.get()); | 130 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w1.get()); |
131 | 131 |
132 // Explicitly enable window position auto management, and expect it to be | 132 // Explicitly enable window position auto management, and expect it to be |
133 // restored after drag completes. | 133 // restored after drag completes. |
134 window_state->set_window_position_managed(true); | 134 window_state->set_window_position_managed(true); |
135 generator.PressLeftButton(); | 135 generator.PressLeftButton(); |
136 aura::client::WindowMoveClient* move_client = | 136 aura::client::WindowMoveClient* move_client = |
137 aura::client::GetWindowMoveClient(w1->GetRootWindow()); | 137 aura::client::GetWindowMoveClient(w1->GetRootWindow()); |
138 // generator.PressLeftButton(); | |
139 base::ThreadTaskRunnerHandle::Get()->PostTask( | 138 base::ThreadTaskRunnerHandle::Get()->PostTask( |
140 FROM_HERE, | 139 FROM_HERE, |
141 base::Bind(&ContinueAndCompleteDrag, base::Unretained(&generator), | 140 base::Bind(&ContinueAndCompleteDrag, base::Unretained(&generator), |
142 base::Unretained(window_state), base::Unretained(w1.get()))); | 141 base::Unretained(window_state), base::Unretained(w1.get()))); |
143 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, | 142 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, |
144 move_client->RunMoveLoop(w1.get(), gfx::Vector2d(100, 100), | 143 move_client->RunMoveLoop(w1.get(), gfx::Vector2d(100, 100), |
145 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); | 144 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
146 // Window position auto manage property should be restored to true. | 145 // Window position auto manage property should be restored to true. |
147 EXPECT_TRUE(window_state->window_position_managed()); | 146 EXPECT_TRUE(window_state->window_position_managed()); |
148 // Position should have been offset by 100,100. | 147 // Position should have been offset by 100,100. |
(...skipping 13 matching lines...) Expand all Loading... |
162 move_client->RunMoveLoop(w1.get(), gfx::Vector2d(100, 100), | 161 move_client->RunMoveLoop(w1.get(), gfx::Vector2d(100, 100), |
163 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); | 162 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
164 // Window position auto manage property should be restored to true. | 163 // Window position auto manage property should be restored to true. |
165 EXPECT_FALSE(window_state->window_position_managed()); | 164 EXPECT_FALSE(window_state->window_position_managed()); |
166 // Position should have been offset by 100,100. | 165 // Position should have been offset by 100,100. |
167 EXPECT_EQ("200,200", w1->bounds().origin().ToString()); | 166 EXPECT_EQ("200,200", w1->bounds().origin().ToString()); |
168 // Size should remain the same. | 167 // Size should remain the same. |
169 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); | 168 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); |
170 } | 169 } |
171 | 170 |
172 namespace { | |
173 | |
174 class CancelDragObserver : public aura::WindowObserver { | |
175 public: | |
176 CancelDragObserver() {} | |
177 ~CancelDragObserver() override {} | |
178 | |
179 void OnWindowHierarchyChanging(const HierarchyChangeParams& params) override { | |
180 aura::client::CaptureClient* client = | |
181 aura::client::GetCaptureClient(params.target->GetRootWindow()); | |
182 client->SetCapture(nullptr); | |
183 } | |
184 | |
185 private: | |
186 DISALLOW_COPY_AND_ASSIGN(CancelDragObserver); | |
187 }; | |
188 | |
189 } // namespace | |
190 | |
191 // Cancelling drag while starting window drag should not crash. | |
192 TEST_F(ToplevelWindowEventHandlerTest, CancelWhileDragStart) { | |
193 std::unique_ptr<aura::Window> w1(CreateWindow(HTCAPTION)); | |
194 CancelDragObserver observer; | |
195 w1->AddObserver(&observer); | |
196 gfx::Point origin = w1->bounds().origin(); | |
197 DragFromCenterBy(w1.get(), 100, 100); | |
198 EXPECT_EQ(origin, w1->bounds().origin()); | |
199 w1->RemoveObserver(&observer); | |
200 } | |
201 | |
202 TEST_F(ToplevelWindowEventHandlerTest, BottomRight) { | 171 TEST_F(ToplevelWindowEventHandlerTest, BottomRight) { |
203 std::unique_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT)); | 172 std::unique_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT)); |
204 gfx::Point position = w1->bounds().origin(); | 173 gfx::Point position = w1->bounds().origin(); |
205 DragFromCenterBy(w1.get(), 100, 100); | 174 DragFromCenterBy(w1.get(), 100, 100); |
206 // Position should not have changed. | 175 // Position should not have changed. |
207 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); | 176 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); |
208 // Size should have increased by 100,100. | 177 // Size should have increased by 100,100. |
209 EXPECT_EQ(gfx::Size(200, 200).ToString(), w1->bounds().size().ToString()); | 178 EXPECT_EQ(gfx::Size(200, 200).ToString(), w1->bounds().size().ToString()); |
210 } | 179 } |
211 | 180 |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 display_manager()->SetLayoutForCurrentDisplays(builder.Build()); | 798 display_manager()->SetLayoutForCurrentDisplays(builder.Build()); |
830 | 799 |
831 const gfx::Size initial_window_size(330, 230); | 800 const gfx::Size initial_window_size(330, 230); |
832 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegateAndType( | 801 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegateAndType( |
833 new TestWindowDelegate(HTCAPTION), ui::wm::WINDOW_TYPE_NORMAL, 0, | 802 new TestWindowDelegate(HTCAPTION), ui::wm::WINDOW_TYPE_NORMAL, 0, |
834 gfx::Rect(initial_window_size))); | 803 gfx::Rect(initial_window_size))); |
835 | 804 |
836 // Snap the window to the right. | 805 // Snap the window to the right. |
837 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | 806 wm::WindowState* window_state = wm::GetWindowState(w1.get()); |
838 ASSERT_TRUE(window_state->CanSnap()); | 807 ASSERT_TRUE(window_state->CanSnap()); |
839 const wm::WMEvent event(wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT); | 808 const wm::WMEvent event(wm::WM_EVENT_CYCLE_SNAP_RIGHT); |
840 window_state->OnWMEvent(&event); | 809 window_state->OnWMEvent(&event); |
841 ASSERT_TRUE(window_state->IsSnapped()); | 810 ASSERT_TRUE(window_state->IsSnapped()); |
842 | 811 |
843 // Drag the window to the secondary display. | 812 // Drag the window to the secondary display. |
844 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w1.get()); | 813 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w1.get()); |
845 generator.DragMouseTo(472, -462); | 814 generator.DragMouseTo(472, -462); |
846 | 815 |
847 // Expect the window is no longer snapped and its size was restored to the | 816 // Expect the window is no longer snapped and its size was restored to the |
848 // initial size. | 817 // initial size. |
849 EXPECT_FALSE(window_state->IsSnapped()); | 818 EXPECT_FALSE(window_state->IsSnapped()); |
850 EXPECT_EQ(initial_window_size.ToString(), w1->bounds().size().ToString()); | 819 EXPECT_EQ(initial_window_size.ToString(), w1->bounds().size().ToString()); |
851 | 820 |
852 // The window is now fully contained in the secondary display. | 821 // The window is now fully contained in the secondary display. |
853 EXPECT_TRUE(display_manager()->GetSecondaryDisplay().bounds().Contains( | 822 EXPECT_TRUE(display_manager()->GetSecondaryDisplay().bounds().Contains( |
854 w1->GetBoundsInScreen())); | 823 w1->GetBoundsInScreen())); |
855 } | 824 } |
856 | 825 |
857 // Showing the resize shadows when the mouse is over the window edges is tested | 826 // Showing the resize shadows when the mouse is over the window edges is tested |
858 // in resize_shadow_and_cursor_test.cc | 827 // in resize_shadow_and_cursor_test.cc |
859 | 828 |
860 } // namespace test | 829 } // namespace test |
861 } // namespace ash | 830 } // namespace ash |
OLD | NEW |