| 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/workspace/workspace_event_handler.h" | 5 #include "ash/wm/workspace/workspace_event_handler.h" |
| 6 | 6 |
| 7 #include "ash/screen_ash.h" | 7 #include "ash/screen_ash.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "ash/wm/property_util.h" | 10 #include "ash/wm/window_state.h" |
| 11 #include "ash/wm/window_util.h" | 11 #include "ash/wm/window_util.h" |
| 12 #include "ash/wm/workspace_controller.h" | 12 #include "ash/wm/workspace_controller.h" |
| 13 #include "ash/wm/workspace_controller_test_helper.h" | 13 #include "ash/wm/workspace_controller_test_helper.h" |
| 14 #include "ui/aura/client/aura_constants.h" | 14 #include "ui/aura/client/aura_constants.h" |
| 15 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
| 16 #include "ui/aura/test/event_generator.h" | 16 #include "ui/aura/test/event_generator.h" |
| 17 #include "ui/aura/test/test_window_delegate.h" | 17 #include "ui/aura/test/test_window_delegate.h" |
| 18 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 19 #include "ui/base/hit_test.h" | 19 #include "ui/base/hit_test.h" |
| 20 #include "ui/gfx/screen.h" | 20 #include "ui/gfx/screen.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 generator.ReleaseLeftButton(); | 102 generator.ReleaseLeftButton(); |
| 103 generator.set_flags(ui::EF_IS_DOUBLE_CLICK); | 103 generator.set_flags(ui::EF_IS_DOUBLE_CLICK); |
| 104 generator.PressLeftButton(); | 104 generator.PressLeftButton(); |
| 105 generator.MoveMouseTo(generator.current_location(), 1); | 105 generator.MoveMouseTo(generator.current_location(), 1); |
| 106 generator.ReleaseLeftButton(); | 106 generator.ReleaseLeftButton(); |
| 107 gfx::Rect bounds_in_screen = window->GetBoundsInScreen(); | 107 gfx::Rect bounds_in_screen = window->GetBoundsInScreen(); |
| 108 EXPECT_EQ(restored_bounds.x(), bounds_in_screen.x()); | 108 EXPECT_EQ(restored_bounds.x(), bounds_in_screen.x()); |
| 109 EXPECT_EQ(restored_bounds.width(), bounds_in_screen.width()); | 109 EXPECT_EQ(restored_bounds.width(), bounds_in_screen.width()); |
| 110 EXPECT_EQ(work_area.y(), bounds_in_screen.y()); | 110 EXPECT_EQ(work_area.y(), bounds_in_screen.y()); |
| 111 EXPECT_EQ(work_area.height(), bounds_in_screen.height()); | 111 EXPECT_EQ(work_area.height(), bounds_in_screen.height()); |
| 112 |
| 113 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 112 // Single-axis maximization is not considered real maximization. | 114 // Single-axis maximization is not considered real maximization. |
| 113 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); | 115 EXPECT_FALSE(window_state->IsMaximized()); |
| 114 | 116 |
| 115 // Restore. | 117 // Restore. |
| 116 generator.DoubleClickLeftButton(); | 118 generator.DoubleClickLeftButton(); |
| 117 bounds_in_screen = window->GetBoundsInScreen(); | 119 bounds_in_screen = window->GetBoundsInScreen(); |
| 118 EXPECT_EQ(restored_bounds.ToString(), bounds_in_screen.ToString()); | 120 EXPECT_EQ(restored_bounds.ToString(), bounds_in_screen.ToString()); |
| 119 // Note that it should not even be restored at this point, it should have | 121 // Note that it should not even be restored at this point, it should have |
| 120 // also cleared the restore rectangle. | 122 // also cleared the restore rectangle. |
| 121 EXPECT_EQ(NULL, GetRestoreBoundsInScreen(window.get())); | 123 EXPECT_FALSE(window_state->HasRestoreBounds()); |
| 122 | 124 |
| 123 // Double-click the top resize edge again to maximize vertically, then double | 125 // Double-click the top resize edge again to maximize vertically, then double |
| 124 // click again to restore. | 126 // click again to restore. |
| 125 generator.DoubleClickLeftButton(); | 127 generator.DoubleClickLeftButton(); |
| 126 wd.set_window_component(HTCAPTION); | 128 wd.set_window_component(HTCAPTION); |
| 127 generator.DoubleClickLeftButton(); | 129 generator.DoubleClickLeftButton(); |
| 128 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); | 130 EXPECT_FALSE(window_state->IsMaximized()); |
| 129 bounds_in_screen = window->GetBoundsInScreen(); | 131 bounds_in_screen = window->GetBoundsInScreen(); |
| 130 EXPECT_EQ(restored_bounds.ToString(), bounds_in_screen.ToString()); | 132 EXPECT_EQ(restored_bounds.ToString(), bounds_in_screen.ToString()); |
| 131 | 133 |
| 132 // Double clicking the left resize edge should maximize horizontally. | 134 // Double clicking the left resize edge should maximize horizontally. |
| 133 wd.set_window_component(HTLEFT); | 135 wd.set_window_component(HTLEFT); |
| 134 generator.DoubleClickLeftButton(); | 136 generator.DoubleClickLeftButton(); |
| 135 bounds_in_screen = window->GetBoundsInScreen(); | 137 bounds_in_screen = window->GetBoundsInScreen(); |
| 136 EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y()); | 138 EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y()); |
| 137 EXPECT_EQ(restored_bounds.height(), bounds_in_screen.height()); | 139 EXPECT_EQ(restored_bounds.height(), bounds_in_screen.height()); |
| 138 EXPECT_EQ(work_area.x(), bounds_in_screen.x()); | 140 EXPECT_EQ(work_area.x(), bounds_in_screen.x()); |
| 139 EXPECT_EQ(work_area.width(), bounds_in_screen.width()); | 141 EXPECT_EQ(work_area.width(), bounds_in_screen.width()); |
| 140 // Single-axis maximization is not considered real maximization. | 142 // Single-axis maximization is not considered real maximization. |
| 141 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); | 143 EXPECT_FALSE(window_state->IsMaximized()); |
| 142 | 144 |
| 143 // Restore. | 145 // Restore. |
| 144 wd.set_window_component(HTCAPTION); | 146 wd.set_window_component(HTCAPTION); |
| 145 generator.DoubleClickLeftButton(); | 147 generator.DoubleClickLeftButton(); |
| 146 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 148 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 147 | 149 |
| 148 #if defined(OS_WIN) | 150 #if defined(OS_WIN) |
| 149 // Multi display test does not run on Win8 bot. crbug.com/247427. | 151 // Multi display test does not run on Win8 bot. crbug.com/247427. |
| 150 if (base::win::GetVersion() >= base::win::VERSION_WIN8) | 152 if (base::win::GetVersion() >= base::win::VERSION_WIN8) |
| 151 return; | 153 return; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 167 generator2.set_flags(ui::EF_IS_DOUBLE_CLICK); | 169 generator2.set_flags(ui::EF_IS_DOUBLE_CLICK); |
| 168 generator2.PressLeftButton(); | 170 generator2.PressLeftButton(); |
| 169 generator2.MoveMouseTo(generator.current_location(), 1); | 171 generator2.MoveMouseTo(generator.current_location(), 1); |
| 170 generator2.ReleaseLeftButton(); | 172 generator2.ReleaseLeftButton(); |
| 171 generator.DoubleClickLeftButton(); | 173 generator.DoubleClickLeftButton(); |
| 172 bounds_in_screen = window->GetBoundsInScreen(); | 174 bounds_in_screen = window->GetBoundsInScreen(); |
| 173 EXPECT_EQ(restored_bounds.x(), bounds_in_screen.x()); | 175 EXPECT_EQ(restored_bounds.x(), bounds_in_screen.x()); |
| 174 EXPECT_EQ(restored_bounds.width(), bounds_in_screen.width()); | 176 EXPECT_EQ(restored_bounds.width(), bounds_in_screen.width()); |
| 175 EXPECT_EQ(work_area2.y(), bounds_in_screen.y()); | 177 EXPECT_EQ(work_area2.y(), bounds_in_screen.y()); |
| 176 EXPECT_EQ(work_area2.height(), bounds_in_screen.height()); | 178 EXPECT_EQ(work_area2.height(), bounds_in_screen.height()); |
| 177 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); | 179 EXPECT_FALSE(window_state->IsMaximized()); |
| 178 | 180 |
| 179 // Restore. | 181 // Restore. |
| 180 wd.set_window_component(HTCAPTION); | 182 wd.set_window_component(HTCAPTION); |
| 181 generator2.DoubleClickLeftButton(); | 183 generator2.DoubleClickLeftButton(); |
| 182 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 184 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 183 | 185 |
| 184 // X-axis maximization. | 186 // X-axis maximization. |
| 185 wd.set_window_component(HTLEFT); | 187 wd.set_window_component(HTLEFT); |
| 186 generator2.DoubleClickLeftButton(); | 188 generator2.DoubleClickLeftButton(); |
| 187 bounds_in_screen = window->GetBoundsInScreen(); | 189 bounds_in_screen = window->GetBoundsInScreen(); |
| 188 EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y()); | 190 EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y()); |
| 189 EXPECT_EQ(restored_bounds.height(), bounds_in_screen.height()); | 191 EXPECT_EQ(restored_bounds.height(), bounds_in_screen.height()); |
| 190 EXPECT_EQ(work_area2.x(), bounds_in_screen.x()); | 192 EXPECT_EQ(work_area2.x(), bounds_in_screen.x()); |
| 191 EXPECT_EQ(work_area2.width(), bounds_in_screen.width()); | 193 EXPECT_EQ(work_area2.width(), bounds_in_screen.width()); |
| 192 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); | 194 EXPECT_FALSE(window_state->IsMaximized()); |
| 193 | 195 |
| 194 // Restore. | 196 // Restore. |
| 195 wd.set_window_component(HTCAPTION); | 197 wd.set_window_component(HTCAPTION); |
| 196 generator2.DoubleClickLeftButton(); | 198 generator2.DoubleClickLeftButton(); |
| 197 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 199 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 198 } | 200 } |
| 199 | 201 |
| 200 TEST_F(WorkspaceEventHandlerTest, | 202 TEST_F(WorkspaceEventHandlerTest, |
| 201 DoubleClickSingleAxisDoesntResizeVerticalEdgeIfConstrained) { | 203 DoubleClickSingleAxisDoesntResizeVerticalEdgeIfConstrained) { |
| 202 gfx::Rect restored_bounds(10, 10, 50, 50); | 204 gfx::Rect restored_bounds(10, 10, 50, 50); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 EXPECT_EQ(restored_bounds.x(), window->bounds().x()); | 246 EXPECT_EQ(restored_bounds.x(), window->bounds().x()); |
| 245 EXPECT_EQ(restored_bounds.width(), window->bounds().width()); | 247 EXPECT_EQ(restored_bounds.width(), window->bounds().width()); |
| 246 } | 248 } |
| 247 | 249 |
| 248 TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) { | 250 TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) { |
| 249 aura::test::TestWindowDelegate wd; | 251 aura::test::TestWindowDelegate wd; |
| 250 scoped_ptr<aura::Window> window( | 252 scoped_ptr<aura::Window> window( |
| 251 CreateTestWindow(&wd, gfx::Rect(1, 2, 30, 40))); | 253 CreateTestWindow(&wd, gfx::Rect(1, 2, 30, 40))); |
| 252 window->SetProperty(aura::client::kCanMaximizeKey, true); | 254 window->SetProperty(aura::client::kCanMaximizeKey, true); |
| 253 wd.set_window_component(HTCAPTION); | 255 wd.set_window_component(HTCAPTION); |
| 254 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); | 256 |
| 257 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 258 EXPECT_FALSE(window_state->IsMaximized()); |
| 255 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); | 259 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); |
| 256 aura::test::EventGenerator generator(root, window.get()); | 260 aura::test::EventGenerator generator(root, window.get()); |
| 257 generator.DoubleClickLeftButton(); | 261 generator.DoubleClickLeftButton(); |
| 258 EXPECT_NE("1,2 30x40", window->bounds().ToString()); | 262 EXPECT_NE("1,2 30x40", window->bounds().ToString()); |
| 259 | 263 |
| 260 EXPECT_TRUE(wm::IsWindowMaximized(window.get())); | 264 EXPECT_TRUE(window_state->IsMaximized()); |
| 261 generator.DoubleClickLeftButton(); | 265 generator.DoubleClickLeftButton(); |
| 262 | 266 |
| 263 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); | 267 EXPECT_FALSE(window_state->IsMaximized()); |
| 264 EXPECT_EQ("1,2 30x40", window->bounds().ToString()); | 268 EXPECT_EQ("1,2 30x40", window->bounds().ToString()); |
| 265 | 269 |
| 266 // Double-clicking the middle button shouldn't toggle the maximized state. | 270 // Double-clicking the middle button shouldn't toggle the maximized state. |
| 267 WindowPropertyObserver observer(window.get()); | 271 WindowPropertyObserver observer(window.get()); |
| 268 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, generator.current_location(), | 272 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, generator.current_location(), |
| 269 generator.current_location(), | 273 generator.current_location(), |
| 270 ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK); | 274 ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK); |
| 271 root->AsRootWindowHostDelegate()->OnHostMouseEvent(&press); | 275 root->AsRootWindowHostDelegate()->OnHostMouseEvent(&press); |
| 272 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, generator.current_location(), | 276 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, generator.current_location(), |
| 273 generator.current_location(), | 277 generator.current_location(), |
| 274 ui::EF_IS_DOUBLE_CLICK); | 278 ui::EF_IS_DOUBLE_CLICK); |
| 275 root->AsRootWindowHostDelegate()->OnHostMouseEvent(&release); | 279 root->AsRootWindowHostDelegate()->OnHostMouseEvent(&release); |
| 276 | 280 |
| 277 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); | 281 EXPECT_FALSE(window_state->IsMaximized()); |
| 278 EXPECT_EQ("1,2 30x40", window->bounds().ToString()); | 282 EXPECT_EQ("1,2 30x40", window->bounds().ToString()); |
| 279 EXPECT_FALSE(observer.DidPropertyChange(aura::client::kShowStateKey)); | 283 EXPECT_FALSE(observer.DidPropertyChange(aura::client::kShowStateKey)); |
| 280 } | 284 } |
| 281 | 285 |
| 282 TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) { | 286 TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) { |
| 283 aura::test::TestWindowDelegate wd; | 287 aura::test::TestWindowDelegate wd; |
| 284 gfx::Rect bounds(10, 20, 30, 40); | 288 gfx::Rect bounds(10, 20, 30, 40); |
| 285 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds)); | 289 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds)); |
| 286 window->SetProperty(aura::client::kCanMaximizeKey, true); | 290 window->SetProperty(aura::client::kCanMaximizeKey, true); |
| 287 wd.set_window_component(HTCAPTION); | 291 wd.set_window_component(HTCAPTION); |
| 288 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); | 292 |
| 293 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 294 EXPECT_FALSE(window_state->IsMaximized()); |
| 289 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 295 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 290 window.get()); | 296 window.get()); |
| 291 generator.GestureTapAt(gfx::Point(25, 25)); | 297 generator.GestureTapAt(gfx::Point(25, 25)); |
| 292 generator.GestureTapAt(gfx::Point(25, 25)); | 298 generator.GestureTapAt(gfx::Point(25, 25)); |
| 293 RunAllPendingInMessageLoop(); | 299 RunAllPendingInMessageLoop(); |
| 294 EXPECT_NE(bounds.ToString(), window->bounds().ToString()); | 300 EXPECT_NE(bounds.ToString(), window->bounds().ToString()); |
| 295 EXPECT_TRUE(wm::IsWindowMaximized(window.get())); | 301 EXPECT_TRUE(window_state->IsMaximized()); |
| 296 | 302 |
| 297 generator.GestureTapAt(gfx::Point(5, 5)); | 303 generator.GestureTapAt(gfx::Point(5, 5)); |
| 298 generator.GestureTapAt(gfx::Point(10, 10)); | 304 generator.GestureTapAt(gfx::Point(10, 10)); |
| 299 | 305 |
| 300 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); | 306 EXPECT_FALSE(window_state->IsMaximized()); |
| 301 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); | 307 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); |
| 302 } | 308 } |
| 303 | 309 |
| 304 // Verifies deleting the window while dragging doesn't crash. | 310 // Verifies deleting the window while dragging doesn't crash. |
| 305 TEST_F(WorkspaceEventHandlerTest, DeleteWhenDragging) { | 311 TEST_F(WorkspaceEventHandlerTest, DeleteWhenDragging) { |
| 306 // Create a large window in the background. This is necessary so that when we | 312 // Create a large window in the background. This is necessary so that when we |
| 307 // delete |window| WorkspaceEventHandler is still the active event handler. | 313 // delete |window| WorkspaceEventHandler is still the active event handler. |
| 308 aura::test::TestWindowDelegate wd2; | 314 aura::test::TestWindowDelegate wd2; |
| 309 scoped_ptr<aura::Window> window2( | 315 scoped_ptr<aura::Window> window2( |
| 310 CreateTestWindow(&wd2, gfx::Rect(0, 0, 500, 500))); | 316 CreateTestWindow(&wd2, gfx::Rect(0, 0, 500, 500))); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 332 ASSERT_TRUE(aura::client::GetWindowMoveClient(window->parent())); | 338 ASSERT_TRUE(aura::client::GetWindowMoveClient(window->parent())); |
| 333 base::MessageLoop::current()->DeleteSoon(FROM_HERE, window.get()); | 339 base::MessageLoop::current()->DeleteSoon(FROM_HERE, window.get()); |
| 334 aura::client::GetWindowMoveClient(window->parent()) | 340 aura::client::GetWindowMoveClient(window->parent()) |
| 335 ->RunMoveLoop(window.release(), | 341 ->RunMoveLoop(window.release(), |
| 336 gfx::Vector2d(), | 342 gfx::Vector2d(), |
| 337 aura::client::WINDOW_MOVE_SOURCE_MOUSE); | 343 aura::client::WINDOW_MOVE_SOURCE_MOUSE); |
| 338 } | 344 } |
| 339 | 345 |
| 340 } // namespace internal | 346 } // namespace internal |
| 341 } // namespace ash | 347 } // namespace ash |
| OLD | NEW |