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/wm/custom_frame_view_ash.h" | 5 #include "ash/wm/custom_frame_view_ash.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 9 #include "ash/wm/maximize_bubble_controller.h" | 9 #include "ash/wm/maximize_bubble_controller.h" |
| 10 #include "ash/wm/property_util.h" | 10 #include "ash/wm/property_util.h" |
| 11 #include "ash/wm/window_util.h" | 11 #include "ash/wm/window_util.h" |
| 12 #include "ash/wm/workspace/frame_caption_button_container_view.h" | 12 #include "ash/wm/workspace/frame_caption_button_container_view.h" |
| 13 #include "ash/wm/workspace/frame_maximize_button.h" | 13 #include "ash/wm/workspace/frame_maximize_button.h" |
| 14 #include "ash/wm/workspace/snap_sizer.h" | |
| 15 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 16 #include "ui/aura/client/aura_constants.h" | 15 #include "ui/aura/client/aura_constants.h" |
| 17 #include "ui/aura/client/focus_client.h" | 16 #include "ui/aura/client/focus_client.h" |
| 18 #include "ui/aura/test/event_generator.h" | 17 #include "ui/aura/test/event_generator.h" |
| 19 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
| 20 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 21 #include "ui/base/events/event_utils.h" | 20 #include "ui/base/events/event_utils.h" |
| 22 #include "ui/base/gestures/gesture_configuration.h" | 21 #include "ui/base/gestures/gesture_configuration.h" |
| 23 #include "ui/views/controls/button/image_button.h" | 22 #include "ui/views/controls/button/image_button.h" |
| 24 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 | 191 |
| 193 // Snap right. | 192 // Snap right. |
| 194 { | 193 { |
| 195 generator.PressLeftButton(); | 194 generator.PressLeftButton(); |
| 196 generator.MoveMouseBy(10, 0); | 195 generator.MoveMouseBy(10, 0); |
| 197 generator.ReleaseLeftButton(); | 196 generator.ReleaseLeftButton(); |
| 198 RunAllPendingInMessageLoop(); | 197 RunAllPendingInMessageLoop(); |
| 199 | 198 |
| 200 EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); | 199 EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); |
| 201 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); | 200 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); |
| 202 internal::SnapSizer sizer(window, center, | 201 gfx::Rect target_bounds = ash::wm::GetSnappedWindowBoundsInParent( |
| 203 internal::SnapSizer::RIGHT_EDGE, | 202 window, ash::wm::SNAP_RIGHT_EDGE); |
| 204 internal::SnapSizer::OTHER_INPUT); | 203 EXPECT_EQ(target_bounds.ToString(), window->bounds().ToString()); |
| 205 EXPECT_EQ(sizer.target_bounds().ToString(), window->bounds().ToString()); | |
| 206 } | 204 } |
| 207 | 205 |
| 208 // Snap left. | 206 // Snap left. |
| 209 { | 207 { |
| 210 center = view->GetBoundsInScreen().CenterPoint(); | 208 center = view->GetBoundsInScreen().CenterPoint(); |
| 211 generator.MoveMouseTo(center); | 209 generator.MoveMouseTo(center); |
| 212 generator.PressLeftButton(); | 210 generator.PressLeftButton(); |
| 213 generator.MoveMouseBy(-10, 0); | 211 generator.MoveMouseBy(-10, 0); |
| 214 generator.ReleaseLeftButton(); | 212 generator.ReleaseLeftButton(); |
| 215 RunAllPendingInMessageLoop(); | 213 RunAllPendingInMessageLoop(); |
| 216 | 214 |
| 217 EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); | 215 EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); |
| 218 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); | 216 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); |
| 219 internal::SnapSizer sizer(window, center, | 217 gfx::Rect target_bounds = ash::wm::GetSnappedWindowBoundsInParent( |
| 220 internal::SnapSizer::LEFT_EDGE, | 218 window, ash::wm::SNAP_LEFT_EDGE); |
| 221 internal::SnapSizer::OTHER_INPUT); | 219 EXPECT_EQ(target_bounds.ToString(), window->bounds().ToString()); |
| 222 EXPECT_EQ(sizer.target_bounds().ToString(), window->bounds().ToString()); | |
| 223 } | 220 } |
| 224 | 221 |
| 225 // Minimize. | 222 // Minimize. |
| 226 { | 223 { |
| 227 center = view->GetBoundsInScreen().CenterPoint(); | 224 center = view->GetBoundsInScreen().CenterPoint(); |
| 228 generator.MoveMouseTo(center); | 225 generator.MoveMouseTo(center); |
| 229 generator.PressLeftButton(); | 226 generator.PressLeftButton(); |
| 230 generator.MoveMouseBy(0, 10); | 227 generator.MoveMouseBy(0, 10); |
| 231 generator.ReleaseLeftButton(); | 228 generator.ReleaseLeftButton(); |
| 232 RunAllPendingInMessageLoop(); | 229 RunAllPendingInMessageLoop(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 243 center = view->GetBoundsInScreen().CenterPoint(); | 240 center = view->GetBoundsInScreen().CenterPoint(); |
| 244 gfx::Point end = center; | 241 gfx::Point end = center; |
| 245 end.Offset(40, 0); | 242 end.Offset(40, 0); |
| 246 generator.GestureScrollSequence(center, end, | 243 generator.GestureScrollSequence(center, end, |
| 247 base::TimeDelta::FromMilliseconds(100), | 244 base::TimeDelta::FromMilliseconds(100), |
| 248 3); | 245 3); |
| 249 RunAllPendingInMessageLoop(); | 246 RunAllPendingInMessageLoop(); |
| 250 | 247 |
| 251 EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); | 248 EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); |
| 252 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); | 249 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); |
| 253 // This is a short resizing distance and different touch behavior | 250 gfx::Rect target_bounds = ash::wm::GetSnappedWindowBoundsInParent( |
| 254 // applies which leads in half of the screen being used. | 251 window, ash::wm::SNAP_RIGHT_EDGE); |
| 255 EXPECT_EQ("400,0 400x552", window->bounds().ToString()); | 252 EXPECT_EQ(target_bounds.ToString(), window->bounds().ToString()); |
|
Mr4D (OOO till 08-26)
2013/08/29 01:03:15
again - better tests of results?
pkotwicz
2013/08/30 21:10:57
I think this is good enough for these tests which
| |
| 256 } | 253 } |
| 257 | 254 |
| 258 // Snap left. | 255 // Snap left. |
| 259 { | 256 { |
| 260 center = view->GetBoundsInScreen().CenterPoint(); | 257 center = view->GetBoundsInScreen().CenterPoint(); |
| 261 gfx::Point end = center; | 258 gfx::Point end = center; |
| 262 end.Offset(-40, 0); | 259 end.Offset(-40, 0); |
| 263 generator.GestureScrollSequence(center, end, | 260 generator.GestureScrollSequence(center, end, |
| 264 base::TimeDelta::FromMilliseconds(100), | 261 base::TimeDelta::FromMilliseconds(100), |
| 265 3); | 262 3); |
| 266 RunAllPendingInMessageLoop(); | 263 RunAllPendingInMessageLoop(); |
| 267 | 264 |
| 268 EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); | 265 EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); |
| 269 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); | 266 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); |
| 270 internal::SnapSizer sizer(window, center, | 267 gfx::Rect target_bounds = ash::wm::GetSnappedWindowBoundsInParent( |
| 271 internal::SnapSizer::LEFT_EDGE, | 268 window, ash::wm::SNAP_LEFT_EDGE); |
| 272 internal::SnapSizer::OTHER_INPUT); | 269 EXPECT_EQ(target_bounds.ToString(), window->bounds().ToString()); |
| 273 EXPECT_EQ(sizer.target_bounds().ToString(), window->bounds().ToString()); | |
| 274 } | 270 } |
| 275 | 271 |
| 276 // Minimize. | 272 // Minimize. |
| 277 { | 273 { |
| 278 center = view->GetBoundsInScreen().CenterPoint(); | 274 center = view->GetBoundsInScreen().CenterPoint(); |
| 279 gfx::Point end = center; | 275 gfx::Point end = center; |
| 280 end.Offset(0, 40); | 276 end.Offset(0, 40); |
| 281 generator.GestureScrollSequence(center, end, | 277 generator.GestureScrollSequence(center, end, |
| 282 base::TimeDelta::FromMilliseconds(100), | 278 base::TimeDelta::FromMilliseconds(100), |
| 283 3); | 279 3); |
| 284 RunAllPendingInMessageLoop(); | 280 RunAllPendingInMessageLoop(); |
| 285 | 281 |
| 286 EXPECT_TRUE(ash::wm::IsWindowMinimized(window)); | 282 EXPECT_TRUE(ash::wm::IsWindowMinimized(window)); |
| 287 } | 283 } |
| 288 | 284 |
| 289 // Test with gesture events. | 285 // Test with gesture events. |
| 290 } | 286 } |
| 291 | 287 |
| 292 #if defined(OS_WIN) | |
| 293 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962 | |
| 294 #define MAYBE_TouchDragResizeCloseToCornerDiffersFromMouse \ | |
| 295 DISABLED_TouchDragResizeCloseToCornerDiffersFromMouse | |
| 296 #else | |
| 297 #define MAYBE_TouchDragResizeCloseToCornerDiffersFromMouse \ | |
| 298 TouchDragResizeCloseToCornerDiffersFromMouse | |
| 299 #endif | |
| 300 | |
| 301 // Tests Left/Right snapping with resize button touch dragging - which should | |
| 302 // trigger dependent on the available drag distance. | |
| 303 TEST_F(CustomFrameViewAshTest, | |
| 304 MAYBE_TouchDragResizeCloseToCornerDiffersFromMouse) { | |
| 305 aura::Window* window = widget()->GetNativeWindow(); | |
| 306 views::View* view = maximize_button(); | |
| 307 | |
| 308 gfx::Rect work_area = widget()->GetWorkAreaBoundsInScreen(); | |
| 309 gfx::Rect bounds = window->bounds(); | |
| 310 bounds.set_x(work_area.width() - bounds.width()); | |
| 311 widget()->SetBounds(bounds); | |
| 312 | |
| 313 gfx::Point start_point = view->GetBoundsInScreen().CenterPoint(); | |
| 314 // We want to move all the way to the right (the few pixels we have). | |
| 315 gfx::Point end_point = gfx::Point(work_area.width(), start_point.y()); | |
| 316 | |
| 317 aura::test::EventGenerator generator(window->GetRootWindow(), start_point); | |
| 318 | |
| 319 EXPECT_TRUE(ash::wm::IsWindowNormal(window)); | |
| 320 | |
| 321 // Snap right with a touch drag. | |
| 322 generator.GestureScrollSequence(start_point, | |
| 323 end_point, | |
| 324 base::TimeDelta::FromMilliseconds(100), | |
| 325 10); | |
| 326 RunAllPendingInMessageLoop(); | |
| 327 | |
| 328 EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); | |
| 329 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); | |
| 330 gfx::Rect touch_result = window->bounds(); | |
| 331 EXPECT_NE(bounds.ToString(), touch_result.ToString()); | |
| 332 | |
| 333 // Set the position back to where it was before and re-try with a mouse. | |
| 334 widget()->SetBounds(bounds); | |
| 335 | |
| 336 generator.MoveMouseTo(start_point); | |
| 337 generator.PressLeftButton(); | |
| 338 generator.MoveMouseTo(end_point, 10); | |
| 339 generator.ReleaseLeftButton(); | |
| 340 RunAllPendingInMessageLoop(); | |
| 341 | |
| 342 EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); | |
| 343 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); | |
| 344 gfx::Rect mouse_result = window->bounds(); | |
| 345 | |
| 346 // The difference between the two operations should be that the mouse | |
| 347 // operation should have just started to resize and the touch operation is | |
| 348 // already all the way down to the smallest possible size. | |
| 349 EXPECT_NE(mouse_result.ToString(), touch_result.ToString()); | |
| 350 EXPECT_GT(mouse_result.width(), touch_result.width()); | |
| 351 } | |
| 352 | |
| 353 // Test that closing the (browser) window with an opened balloon does not | 288 // Test that closing the (browser) window with an opened balloon does not |
| 354 // crash the system. In other words: Make sure that shutting down the frame | 289 // crash the system. In other words: Make sure that shutting down the frame |
| 355 // destroys the opened balloon in an orderly fashion. | 290 // destroys the opened balloon in an orderly fashion. |
| 356 TEST_F(CustomFrameViewAshTest, MaximizeButtonExternalShutDown) { | 291 TEST_F(CustomFrameViewAshTest, MaximizeButtonExternalShutDown) { |
| 357 aura::Window* window = widget()->GetNativeWindow(); | 292 aura::Window* window = widget()->GetNativeWindow(); |
| 358 ash::FrameMaximizeButton* maximize_button = | 293 ash::FrameMaximizeButton* maximize_button = |
| 359 CustomFrameViewAshTest::maximize_button(); | 294 CustomFrameViewAshTest::maximize_button(); |
| 360 maximize_button->set_bubble_appearance_delay_ms(0); | 295 maximize_button->set_bubble_appearance_delay_ms(0); |
| 361 gfx::Point button_pos = maximize_button->GetBoundsInScreen().CenterPoint(); | 296 gfx::Point button_pos = maximize_button->GetBoundsInScreen().CenterPoint(); |
| 362 gfx::Point off_pos(button_pos.x() + 100, button_pos.y() + 100); | 297 gfx::Point off_pos(button_pos.x() + 100, button_pos.y() + 100); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 GetButtonForUnitTest(SNAP_LEFT)->GetBoundsInScreen().CenterPoint(); | 401 GetButtonForUnitTest(SNAP_LEFT)->GetBoundsInScreen().CenterPoint(); |
| 467 generator.MoveMouseTo(left_max_pos); | 402 generator.MoveMouseTo(left_max_pos); |
| 468 EXPECT_TRUE(maximize_button->phantom_window_open()); | 403 EXPECT_TRUE(maximize_button->phantom_window_open()); |
| 469 generator.ClickLeftButton(); | 404 generator.ClickLeftButton(); |
| 470 | 405 |
| 471 EXPECT_FALSE(maximize_button->maximizer()); | 406 EXPECT_FALSE(maximize_button->maximizer()); |
| 472 EXPECT_FALSE(maximize_button->phantom_window_open()); | 407 EXPECT_FALSE(maximize_button->phantom_window_open()); |
| 473 | 408 |
| 474 EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); | 409 EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); |
| 475 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); | 410 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); |
| 476 internal::SnapSizer sizer(window, button_pos, | 411 gfx::Rect target_bounds = ash::wm::GetSnappedWindowBoundsInParent( |
| 477 internal::SnapSizer::LEFT_EDGE, | 412 window, ash::wm::SNAP_LEFT_EDGE); |
| 478 internal::SnapSizer::OTHER_INPUT); | 413 EXPECT_EQ(target_bounds.ToString(), window->bounds().ToString()); |
| 479 sizer.SelectDefaultSizeAndDisableResize(); | |
| 480 EXPECT_EQ(sizer.target_bounds().ToString(), window->bounds().ToString()); | |
| 481 } | 414 } |
| 482 | 415 |
| 483 // Test that the activation focus does not change when the bubble gets shown. | 416 // Test that the activation focus does not change when the bubble gets shown. |
| 484 TEST_F(CustomFrameViewAshTest, MaximizeKeepFocus) { | 417 TEST_F(CustomFrameViewAshTest, MaximizeKeepFocus) { |
| 485 aura::Window* window = widget()->GetNativeWindow(); | 418 aura::Window* window = widget()->GetNativeWindow(); |
| 486 ash::FrameMaximizeButton* maximize_button = | 419 ash::FrameMaximizeButton* maximize_button = |
| 487 CustomFrameViewAshTest::maximize_button(); | 420 CustomFrameViewAshTest::maximize_button(); |
| 488 maximize_button->set_bubble_appearance_delay_ms(0); | 421 maximize_button->set_bubble_appearance_delay_ms(0); |
| 489 gfx::Point button_pos = maximize_button->GetBoundsInScreen().CenterPoint(); | 422 gfx::Point button_pos = maximize_button->GetBoundsInScreen().CenterPoint(); |
| 490 gfx::Point off_pos(button_pos.x() + 100, button_pos.y() + 100); | 423 gfx::Point off_pos(button_pos.x() + 100, button_pos.y() + 100); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 806 | 739 |
| 807 // Check that there was no size change. | 740 // Check that there was no size change. |
| 808 EXPECT_EQ(widget()->GetWindowBoundsInScreen().size().ToString(), | 741 EXPECT_EQ(widget()->GetWindowBoundsInScreen().size().ToString(), |
| 809 initial_bounds.size().ToString()); | 742 initial_bounds.size().ToString()); |
| 810 // Check that there is no phantom window left open. | 743 // Check that there is no phantom window left open. |
| 811 EXPECT_FALSE(maximize_button->phantom_window_open()); | 744 EXPECT_FALSE(maximize_button->phantom_window_open()); |
| 812 } | 745 } |
| 813 | 746 |
| 814 } // namespace test | 747 } // namespace test |
| 815 } // namespace ash | 748 } // namespace ash |
| OLD | NEW |