| 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/workspace_controller.h" | 8 #include "ash/common/wm/workspace_controller.h" |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 TouchDragFromCenterBy(w1.get(), 100, 100); | 106 TouchDragFromCenterBy(w1.get(), 100, 100); |
| 107 // Position should have been offset by 100,100. | 107 // Position should have been offset by 100,100. |
| 108 EXPECT_EQ("200,200", w1->bounds().origin().ToString()); | 108 EXPECT_EQ("200,200", w1->bounds().origin().ToString()); |
| 109 // Size should not have. | 109 // Size should not have. |
| 110 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); | 110 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 namespace { | 113 namespace { |
| 114 | 114 |
| 115 void ContinueAndCompleteDrag(ui::test::EventGenerator* generator, |
| 116 wm::WindowState* window_state, |
| 117 aura::Window* window) { |
| 118 ASSERT_TRUE(window->HasCapture()); |
| 119 ASSERT_FALSE(window_state->window_position_managed()); |
| 120 generator->DragMouseBy(100, 100); |
| 121 generator->ReleaseLeftButton(); |
| 122 } |
| 123 |
| 124 } // namespace |
| 125 |
| 126 // Tests dragging restores expected window position auto manage property |
| 127 // correctly. |
| 128 TEST_F(ToplevelWindowEventHandlerTest, WindowPositionAutoManagement) { |
| 129 std::unique_ptr<aura::Window> w1(CreateWindow(HTNOWHERE)); |
| 130 const gfx::Size size = w1->bounds().size(); |
| 131 wm::WindowState* window_state = ash::wm::GetWindowState(w1.get()); |
| 132 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w1.get()); |
| 133 |
| 134 // Explicitly enable window position auto management, and expect it to be |
| 135 // restored after drag completes. |
| 136 window_state->set_window_position_managed(true); |
| 137 generator.PressLeftButton(); |
| 138 aura::client::WindowMoveClient* move_client = |
| 139 aura::client::GetWindowMoveClient(w1->GetRootWindow()); |
| 140 // generator.PressLeftButton(); |
| 141 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 142 FROM_HERE, |
| 143 base::Bind(&ContinueAndCompleteDrag, base::Unretained(&generator), |
| 144 base::Unretained(window_state), base::Unretained(w1.get()))); |
| 145 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, |
| 146 move_client->RunMoveLoop(w1.get(), gfx::Vector2d(100, 100), |
| 147 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
| 148 // Window position auto manage property should be restored to true. |
| 149 EXPECT_TRUE(window_state->window_position_managed()); |
| 150 // Position should have been offset by 100,100. |
| 151 EXPECT_EQ("100,100", w1->bounds().origin().ToString()); |
| 152 // Size should remain the same. |
| 153 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); |
| 154 |
| 155 // Explicitly disable window position auto management, and expect it to be |
| 156 // restored after drag completes. |
| 157 window_state->set_window_position_managed(false); |
| 158 generator.PressLeftButton(); |
| 159 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 160 FROM_HERE, |
| 161 base::Bind(&ContinueAndCompleteDrag, base::Unretained(&generator), |
| 162 base::Unretained(window_state), base::Unretained(w1.get()))); |
| 163 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, |
| 164 move_client->RunMoveLoop(w1.get(), gfx::Vector2d(100, 100), |
| 165 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
| 166 // Window position auto manage property should be restored to true. |
| 167 EXPECT_FALSE(window_state->window_position_managed()); |
| 168 // Position should have been offset by 100,100. |
| 169 EXPECT_EQ("200,200", w1->bounds().origin().ToString()); |
| 170 // Size should remain the same. |
| 171 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); |
| 172 } |
| 173 |
| 174 namespace { |
| 175 |
| 115 class CancelDragObserver : public aura::WindowObserver { | 176 class CancelDragObserver : public aura::WindowObserver { |
| 116 public: | 177 public: |
| 117 CancelDragObserver() {} | 178 CancelDragObserver() {} |
| 118 ~CancelDragObserver() override {} | 179 ~CancelDragObserver() override {} |
| 119 | 180 |
| 120 void OnWindowHierarchyChanging(const HierarchyChangeParams& params) override { | 181 void OnWindowHierarchyChanging(const HierarchyChangeParams& params) override { |
| 121 aura::client::CaptureClient* client = | 182 aura::client::CaptureClient* client = |
| 122 aura::client::GetCaptureClient(params.target->GetRootWindow()); | 183 aura::client::GetCaptureClient(params.target->GetRootWindow()); |
| 123 client->SetCapture(nullptr); | 184 client->SetCapture(nullptr); |
| 124 } | 185 } |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, | 821 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, |
| 761 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), | 822 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), |
| 762 aura::client::WINDOW_MOVE_SOURCE_TOUCH)); | 823 aura::client::WINDOW_MOVE_SOURCE_TOUCH)); |
| 763 } | 824 } |
| 764 | 825 |
| 765 // 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 |
| 766 // in resize_shadow_and_cursor_test.cc | 827 // in resize_shadow_and_cursor_test.cc |
| 767 | 828 |
| 768 } // namespace test | 829 } // namespace test |
| 769 } // namespace ash | 830 } // namespace ash |
| OLD | NEW |