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/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
11 #include "ash/wm/lock_state_controller.h" | 11 #include "ash/wm/lock_state_controller.h" |
12 #include "ash/wm/resize_shadow.h" | 12 #include "ash/wm/resize_shadow.h" |
13 #include "ash/wm/resize_shadow_controller.h" | 13 #include "ash/wm/resize_shadow_controller.h" |
14 #include "ash/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
15 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
16 #include "ash/wm/workspace_controller.h" | 16 #include "ash/wm/workspace_controller.h" |
17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "ui/aura/client/aura_constants.h" | 21 #include "ui/aura/client/aura_constants.h" |
22 #include "ui/aura/test/aura_test_base.h" | 22 #include "ui/aura/test/aura_test_base.h" |
23 #include "ui/aura/test/event_generator.h" | |
24 #include "ui/aura/test/test_window_delegate.h" | 23 #include "ui/aura/test/test_window_delegate.h" |
25 #include "ui/aura/window_event_dispatcher.h" | 24 #include "ui/aura/window_event_dispatcher.h" |
26 #include "ui/base/hit_test.h" | 25 #include "ui/base/hit_test.h" |
27 #include "ui/events/event.h" | 26 #include "ui/events/event.h" |
| 27 #include "ui/events/test/event_generator.h" |
28 #include "ui/gfx/screen.h" | 28 #include "ui/gfx/screen.h" |
29 #include "ui/wm/core/window_util.h" | 29 #include "ui/wm/core/window_util.h" |
30 #include "ui/wm/public/window_move_client.h" | 30 #include "ui/wm/public/window_move_client.h" |
31 | 31 |
32 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
33 // Windows headers define macros for these function names which screw with us. | 33 // Windows headers define macros for these function names which screw with us. |
34 #if defined(CreateWindow) | 34 #if defined(CreateWindow) |
35 #undef CreateWindow | 35 #undef CreateWindow |
36 #endif | 36 #endif |
37 #endif | 37 #endif |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 w1->Init(aura::WINDOW_LAYER_TEXTURED); | 73 w1->Init(aura::WINDOW_LAYER_TEXTURED); |
74 aura::Window* parent = Shell::GetContainer( | 74 aura::Window* parent = Shell::GetContainer( |
75 Shell::GetPrimaryRootWindow(), kShellWindowId_AlwaysOnTopContainer); | 75 Shell::GetPrimaryRootWindow(), kShellWindowId_AlwaysOnTopContainer); |
76 parent->AddChild(w1); | 76 parent->AddChild(w1); |
77 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); | 77 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); |
78 w1->Show(); | 78 w1->Show(); |
79 return w1; | 79 return w1; |
80 } | 80 } |
81 | 81 |
82 void DragFromCenterBy(aura::Window* window, int dx, int dy) { | 82 void DragFromCenterBy(aura::Window* window, int dx, int dy) { |
83 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); | 83 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); |
84 generator.DragMouseBy(dx, dy); | 84 generator.DragMouseBy(dx, dy); |
85 } | 85 } |
86 | 86 |
87 void TouchDragFromCenterBy(aura::Window* window, int dx, int dy) { | 87 void TouchDragFromCenterBy(aura::Window* window, int dx, int dy) { |
88 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); | 88 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); |
89 generator.PressMoveAndReleaseTouchBy(dx, dy); | 89 generator.PressMoveAndReleaseTouchBy(dx, dy); |
90 } | 90 } |
91 | 91 |
92 scoped_ptr<ToplevelWindowEventHandler> handler_; | 92 scoped_ptr<ToplevelWindowEventHandler> handler_; |
93 | 93 |
94 private: | 94 private: |
95 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventHandlerTest); | 95 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventHandlerTest); |
96 }; | 96 }; |
97 | 97 |
98 } | 98 } |
(...skipping 24 matching lines...) Expand all Loading... |
123 EXPECT_EQ(gfx::Size(200, 200).ToString(), w1->bounds().size().ToString()); | 123 EXPECT_EQ(gfx::Size(200, 200).ToString(), w1->bounds().size().ToString()); |
124 } | 124 } |
125 | 125 |
126 TEST_F(ToplevelWindowEventHandlerTest, GrowBox) { | 126 TEST_F(ToplevelWindowEventHandlerTest, GrowBox) { |
127 scoped_ptr<aura::Window> w1(CreateWindow(HTGROWBOX)); | 127 scoped_ptr<aura::Window> w1(CreateWindow(HTGROWBOX)); |
128 TestWindowDelegate* window_delegate = | 128 TestWindowDelegate* window_delegate = |
129 static_cast<TestWindowDelegate*>(w1->delegate()); | 129 static_cast<TestWindowDelegate*>(w1->delegate()); |
130 window_delegate->set_minimum_size(gfx::Size(40, 40)); | 130 window_delegate->set_minimum_size(gfx::Size(40, 40)); |
131 | 131 |
132 gfx::Point position = w1->bounds().origin(); | 132 gfx::Point position = w1->bounds().origin(); |
133 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 133 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
134 generator.MoveMouseToCenterOf(w1.get()); | 134 generator.MoveMouseToCenterOf(w1.get()); |
135 generator.DragMouseBy(100, 100); | 135 generator.DragMouseBy(100, 100); |
136 // Position should not have changed. | 136 // Position should not have changed. |
137 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); | 137 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); |
138 // Size should have increased by 100,100. | 138 // Size should have increased by 100,100. |
139 EXPECT_EQ(gfx::Size(200, 200).ToString(), w1->bounds().size().ToString()); | 139 EXPECT_EQ(gfx::Size(200, 200).ToString(), w1->bounds().size().ToString()); |
140 | 140 |
141 // Shrink the wnidow by (-100, -100). | 141 // Shrink the wnidow by (-100, -100). |
142 generator.DragMouseBy(-100, -100); | 142 generator.DragMouseBy(-100, -100); |
143 // Position should not have changed. | 143 // Position should not have changed. |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); | 367 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); |
368 | 368 |
369 TouchDragFromCenterBy(w1.get(), 100, 100); | 369 TouchDragFromCenterBy(w1.get(), 100, 100); |
370 EXPECT_EQ("0,0", w1->bounds().origin().ToString()); | 370 EXPECT_EQ("0,0", w1->bounds().origin().ToString()); |
371 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); | 371 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); |
372 } | 372 } |
373 | 373 |
374 // Verifies we don't let windows drag to a -y location. | 374 // Verifies we don't let windows drag to a -y location. |
375 TEST_F(ToplevelWindowEventHandlerTest, DontDragToNegativeY) { | 375 TEST_F(ToplevelWindowEventHandlerTest, DontDragToNegativeY) { |
376 scoped_ptr<aura::Window> target(CreateWindow(HTTOP)); | 376 scoped_ptr<aura::Window> target(CreateWindow(HTTOP)); |
377 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 377 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
378 target.get()); | 378 target.get()); |
379 generator.MoveMouseTo(0, 5); | 379 generator.MoveMouseTo(0, 5); |
380 generator.DragMouseBy(0, -5); | 380 generator.DragMouseBy(0, -5); |
381 // The y location and height should not have changed. | 381 // The y location and height should not have changed. |
382 EXPECT_EQ(0, target->bounds().y()); | 382 EXPECT_EQ(0, target->bounds().y()); |
383 EXPECT_EQ(100, target->bounds().height()); | 383 EXPECT_EQ(100, target->bounds().height()); |
384 } | 384 } |
385 | 385 |
386 // Verifies we don't let windows go bigger than the display width. | 386 // Verifies we don't let windows go bigger than the display width. |
387 TEST_F(ToplevelWindowEventHandlerTest, DontGotWiderThanScreen) { | 387 TEST_F(ToplevelWindowEventHandlerTest, DontGotWiderThanScreen) { |
388 scoped_ptr<aura::Window> target(CreateWindow(HTRIGHT)); | 388 scoped_ptr<aura::Window> target(CreateWindow(HTRIGHT)); |
389 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow( | 389 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow( |
390 target.get()).bounds(); | 390 target.get()).bounds(); |
391 DragFromCenterBy(target.get(), work_area.width() * 2, 0); | 391 DragFromCenterBy(target.get(), work_area.width() * 2, 0); |
392 // The y location and height should not have changed. | 392 // The y location and height should not have changed. |
393 EXPECT_EQ(work_area.width(), target->bounds().width()); | 393 EXPECT_EQ(work_area.width(), target->bounds().width()); |
394 } | 394 } |
395 | 395 |
396 // Verifies that touch-gestures drag the window correctly. | 396 // Verifies that touch-gestures drag the window correctly. |
397 TEST_F(ToplevelWindowEventHandlerTest, GestureDrag) { | 397 TEST_F(ToplevelWindowEventHandlerTest, GestureDrag) { |
398 scoped_ptr<aura::Window> target( | 398 scoped_ptr<aura::Window> target( |
399 CreateTestWindowInShellWithDelegate( | 399 CreateTestWindowInShellWithDelegate( |
400 new TestWindowDelegate(HTCAPTION), | 400 new TestWindowDelegate(HTCAPTION), |
401 0, | 401 0, |
402 gfx::Rect(0, 0, 100, 100))); | 402 gfx::Rect(0, 0, 100, 100))); |
403 wm::WindowState* window_state = wm::GetWindowState(target.get()); | 403 wm::WindowState* window_state = wm::GetWindowState(target.get()); |
404 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 404 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
405 target.get()); | 405 target.get()); |
406 gfx::Rect old_bounds = target->bounds(); | 406 gfx::Rect old_bounds = target->bounds(); |
407 gfx::Point location(5, 5); | 407 gfx::Point location(5, 5); |
408 target->SetProperty(aura::client::kCanMaximizeKey, true); | 408 target->SetProperty(aura::client::kCanMaximizeKey, true); |
409 | 409 |
410 gfx::Point end = location; | 410 gfx::Point end = location; |
411 | 411 |
412 // Snap right; | 412 // Snap right; |
413 end.Offset(100, 0); | 413 end.Offset(100, 0); |
414 generator.GestureScrollSequence(location, end, | 414 generator.GestureScrollSequence(location, end, |
415 base::TimeDelta::FromMilliseconds(5), | 415 base::TimeDelta::FromMilliseconds(5), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 Shell::GetInstance()->lock_state_controller(); | 474 Shell::GetInstance()->lock_state_controller(); |
475 state_controller->OnLoginStateChanged(user::LOGGED_IN_NONE); | 475 state_controller->OnLoginStateChanged(user::LOGGED_IN_NONE); |
476 state_controller->OnLockStateChanged(false); | 476 state_controller->OnLockStateChanged(false); |
477 SetUserLoggedIn(false); | 477 SetUserLoggedIn(false); |
478 | 478 |
479 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); | 479 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); |
480 aura::Window* lock = | 480 aura::Window* lock = |
481 RootWindowController::ForWindow(target.get()) | 481 RootWindowController::ForWindow(target.get()) |
482 ->GetContainer(kShellWindowId_LockSystemModalContainer); | 482 ->GetContainer(kShellWindowId_LockSystemModalContainer); |
483 lock->AddChild(target.get()); | 483 lock->AddChild(target.get()); |
484 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 484 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
485 target.get()); | 485 target.get()); |
486 gfx::Rect old_bounds = target->bounds(); | 486 gfx::Rect old_bounds = target->bounds(); |
487 gfx::Point location(5, 5); | 487 gfx::Point location(5, 5); |
488 target->SetProperty(aura::client::kCanMaximizeKey, true); | 488 target->SetProperty(aura::client::kCanMaximizeKey, true); |
489 | 489 |
490 gfx::Point end = location; | 490 gfx::Point end = location; |
491 end.Offset(0, 100); | 491 end.Offset(0, 100); |
492 generator.GestureScrollSequence(location, end, | 492 generator.GestureScrollSequence(location, end, |
493 base::TimeDelta::FromMilliseconds(5), | 493 base::TimeDelta::FromMilliseconds(5), |
494 10); | 494 10); |
495 RunAllPendingInMessageLoop(); | 495 RunAllPendingInMessageLoop(); |
496 EXPECT_FALSE(wm::GetWindowState(target.get())->IsMinimized()); | 496 EXPECT_FALSE(wm::GetWindowState(target.get())->IsMinimized()); |
497 } | 497 } |
498 | 498 |
499 TEST_F(ToplevelWindowEventHandlerTest, GestureDragToRestore) { | 499 TEST_F(ToplevelWindowEventHandlerTest, GestureDragToRestore) { |
500 scoped_ptr<aura::Window> window( | 500 scoped_ptr<aura::Window> window( |
501 CreateTestWindowInShellWithDelegate( | 501 CreateTestWindowInShellWithDelegate( |
502 new TestWindowDelegate(HTCAPTION), | 502 new TestWindowDelegate(HTCAPTION), |
503 0, | 503 0, |
504 gfx::Rect(10, 20, 30, 40))); | 504 gfx::Rect(10, 20, 30, 40))); |
505 window->Show(); | 505 window->Show(); |
506 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 506 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
507 window_state->Activate(); | 507 window_state->Activate(); |
508 | 508 |
509 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 509 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
510 window.get()); | 510 window.get()); |
511 gfx::Rect old_bounds = window->bounds(); | 511 gfx::Rect old_bounds = window->bounds(); |
512 gfx::Point location, end; | 512 gfx::Point location, end; |
513 end = location = window->GetBoundsInRootWindow().CenterPoint(); | 513 end = location = window->GetBoundsInRootWindow().CenterPoint(); |
514 end.Offset(0, 100); | 514 end.Offset(0, 100); |
515 generator.GestureScrollSequence(location, end, | 515 generator.GestureScrollSequence(location, end, |
516 base::TimeDelta::FromMilliseconds(5), | 516 base::TimeDelta::FromMilliseconds(5), |
517 10); | 517 10); |
518 RunAllPendingInMessageLoop(); | 518 RunAllPendingInMessageLoop(); |
519 EXPECT_NE(old_bounds.ToString(), window->bounds().ToString()); | 519 EXPECT_NE(old_bounds.ToString(), window->bounds().ToString()); |
520 EXPECT_TRUE(window_state->IsMinimized()); | 520 EXPECT_TRUE(window_state->IsMinimized()); |
521 EXPECT_TRUE(window_state->unminimize_to_restore_bounds()); | 521 EXPECT_TRUE(window_state->unminimize_to_restore_bounds()); |
522 EXPECT_EQ(old_bounds.ToString(), | 522 EXPECT_EQ(old_bounds.ToString(), |
523 window_state->GetRestoreBoundsInScreen().ToString()); | 523 window_state->GetRestoreBoundsInScreen().ToString()); |
524 } | 524 } |
525 | 525 |
526 // Tests that an unresizable window cannot be dragged or snapped using gestures. | 526 // Tests that an unresizable window cannot be dragged or snapped using gestures. |
527 TEST_F(ToplevelWindowEventHandlerTest, GestureDragForUnresizableWindow) { | 527 TEST_F(ToplevelWindowEventHandlerTest, GestureDragForUnresizableWindow) { |
528 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); | 528 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); |
529 wm::WindowState* window_state = wm::GetWindowState(target.get()); | 529 wm::WindowState* window_state = wm::GetWindowState(target.get()); |
530 | 530 |
531 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 531 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
532 target.get()); | 532 target.get()); |
533 gfx::Rect old_bounds = target->bounds(); | 533 gfx::Rect old_bounds = target->bounds(); |
534 gfx::Point location(5, 5); | 534 gfx::Point location(5, 5); |
535 | 535 |
536 target->SetProperty(aura::client::kCanResizeKey, false); | 536 target->SetProperty(aura::client::kCanResizeKey, false); |
537 | 537 |
538 gfx::Point end = location; | 538 gfx::Point end = location; |
539 | 539 |
540 // Try to snap right. The window is not resizable. So it should not snap. | 540 // Try to snap right. The window is not resizable. So it should not snap. |
541 end.Offset(100, 0); | 541 end.Offset(100, 0); |
542 generator.GestureScrollSequence(location, end, | 542 generator.GestureScrollSequence(location, end, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 scoped_ptr<aura::Window> target( | 576 scoped_ptr<aura::Window> target( |
577 CreateTestWindowInShellWithDelegate( | 577 CreateTestWindowInShellWithDelegate( |
578 new TestWindowDelegate(HTCAPTION), | 578 new TestWindowDelegate(HTCAPTION), |
579 0, | 579 0, |
580 gfx::Rect(0, 0, 100, 100))); | 580 gfx::Rect(0, 0, 100, 100))); |
581 scoped_ptr<aura::Window> notmoved( | 581 scoped_ptr<aura::Window> notmoved( |
582 CreateTestWindowInShellWithDelegate( | 582 CreateTestWindowInShellWithDelegate( |
583 new TestWindowDelegate(HTCAPTION), | 583 new TestWindowDelegate(HTCAPTION), |
584 1, gfx::Rect(100, 0, 100, 100))); | 584 1, gfx::Rect(100, 0, 100, 100))); |
585 | 585 |
586 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 586 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
587 target.get()); | 587 target.get()); |
588 gfx::Rect old_bounds = target->bounds(); | 588 gfx::Rect old_bounds = target->bounds(); |
589 gfx::Point location(5, 5); | 589 gfx::Point location(5, 5); |
590 target->SetProperty(aura::client::kCanMaximizeKey, true); | 590 target->SetProperty(aura::client::kCanMaximizeKey, true); |
591 | 591 |
592 // Send some touch events to start dragging |target|. | 592 // Send some touch events to start dragging |target|. |
593 generator.MoveTouch(location); | 593 generator.MoveTouch(location); |
594 generator.PressTouch(); | 594 generator.PressTouch(); |
595 location.Offset(40, 5); | 595 location.Offset(40, 5); |
596 generator.MoveTouch(location); | 596 generator.MoveTouch(location); |
597 | 597 |
598 // Try to drag |notmoved| window. This should not move the window. | 598 // Try to drag |notmoved| window. This should not move the window. |
599 { | 599 { |
600 gfx::Rect bounds = notmoved->bounds(); | 600 gfx::Rect bounds = notmoved->bounds(); |
601 aura::test::EventGenerator gen(Shell::GetPrimaryRootWindow(), | 601 ui::test::EventGenerator gen(Shell::GetPrimaryRootWindow(), notmoved.get()); |
602 notmoved.get()); | |
603 gfx::Point start = notmoved->bounds().origin() + gfx::Vector2d(10, 10); | 602 gfx::Point start = notmoved->bounds().origin() + gfx::Vector2d(10, 10); |
604 gfx::Point end = start + gfx::Vector2d(100, 10); | 603 gfx::Point end = start + gfx::Vector2d(100, 10); |
605 gen.GestureScrollSequence(start, end, | 604 gen.GestureScrollSequence(start, end, |
606 base::TimeDelta::FromMilliseconds(10), | 605 base::TimeDelta::FromMilliseconds(10), |
607 10); | 606 10); |
608 EXPECT_EQ(bounds.ToString(), notmoved->bounds().ToString()); | 607 EXPECT_EQ(bounds.ToString(), notmoved->bounds().ToString()); |
609 } | 608 } |
610 } | 609 } |
611 | 610 |
612 // Verifies pressing escape resets the bounds to the original bounds. | 611 // Verifies pressing escape resets the bounds to the original bounds. |
613 // Disabled crbug.com/166219. | 612 // Disabled crbug.com/166219. |
614 #if defined(OS_WIN) | 613 #if defined(OS_WIN) |
615 #define MAYBE_EscapeReverts DISABLED_EscapeReverts | 614 #define MAYBE_EscapeReverts DISABLED_EscapeReverts |
616 #else | 615 #else |
617 #define MAYBE_EscapeReverts EscapeReverts | 616 #define MAYBE_EscapeReverts EscapeReverts |
618 #endif | 617 #endif |
619 TEST_F(ToplevelWindowEventHandlerTest, MAYBE_EscapeReverts) { | 618 TEST_F(ToplevelWindowEventHandlerTest, MAYBE_EscapeReverts) { |
620 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT)); | 619 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT)); |
621 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 620 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
622 target.get()); | 621 target.get()); |
623 generator.PressLeftButton(); | 622 generator.PressLeftButton(); |
624 generator.MoveMouseBy(10, 11); | 623 generator.MoveMouseBy(10, 11); |
625 | 624 |
626 // Execute any scheduled draws so that pending mouse events are processed. | 625 // Execute any scheduled draws so that pending mouse events are processed. |
627 RunAllPendingInMessageLoop(); | 626 RunAllPendingInMessageLoop(); |
628 | 627 |
629 EXPECT_EQ("0,0 110x111", target->bounds().ToString()); | 628 EXPECT_EQ("0,0 110x111", target->bounds().ToString()); |
630 generator.PressKey(ui::VKEY_ESCAPE, 0); | 629 generator.PressKey(ui::VKEY_ESCAPE, 0); |
631 generator.ReleaseKey(ui::VKEY_ESCAPE, 0); | 630 generator.ReleaseKey(ui::VKEY_ESCAPE, 0); |
632 EXPECT_EQ("0,0 100x100", target->bounds().ToString()); | 631 EXPECT_EQ("0,0 100x100", target->bounds().ToString()); |
633 } | 632 } |
634 | 633 |
635 // Verifies window minimization/maximization completes drag. | 634 // Verifies window minimization/maximization completes drag. |
636 // Disabled crbug.com/166219. | 635 // Disabled crbug.com/166219. |
637 #if defined(OS_WIN) | 636 #if defined(OS_WIN) |
638 #define MAYBE_MinimizeMaximizeCompletes DISABLED_MinimizeMaximizeCompletes | 637 #define MAYBE_MinimizeMaximizeCompletes DISABLED_MinimizeMaximizeCompletes |
639 #else | 638 #else |
640 #define MAYBE_MinimizeMaximizeCompletes MinimizeMaximizeCompletes | 639 #define MAYBE_MinimizeMaximizeCompletes MinimizeMaximizeCompletes |
641 #endif | 640 #endif |
642 TEST_F(ToplevelWindowEventHandlerTest, MAYBE_MinimizeMaximizeCompletes) { | 641 TEST_F(ToplevelWindowEventHandlerTest, MAYBE_MinimizeMaximizeCompletes) { |
643 // Once window is minimized, window dragging completes. | 642 // Once window is minimized, window dragging completes. |
644 { | 643 { |
645 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); | 644 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); |
646 target->Focus(); | 645 target->Focus(); |
647 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 646 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
648 target.get()); | 647 target.get()); |
649 generator.PressLeftButton(); | 648 generator.PressLeftButton(); |
650 generator.MoveMouseBy(10, 11); | 649 generator.MoveMouseBy(10, 11); |
651 RunAllPendingInMessageLoop(); | 650 RunAllPendingInMessageLoop(); |
652 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); | 651 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); |
653 wm::WindowState* window_state = wm::GetWindowState(target.get()); | 652 wm::WindowState* window_state = wm::GetWindowState(target.get()); |
654 window_state->Minimize(); | 653 window_state->Minimize(); |
655 window_state->Restore(); | 654 window_state->Restore(); |
656 | 655 |
657 generator.PressLeftButton(); | 656 generator.PressLeftButton(); |
658 generator.MoveMouseBy(10, 11); | 657 generator.MoveMouseBy(10, 11); |
659 RunAllPendingInMessageLoop(); | 658 RunAllPendingInMessageLoop(); |
660 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); | 659 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); |
661 } | 660 } |
662 | 661 |
663 // Once window is maximized, window dragging completes. | 662 // Once window is maximized, window dragging completes. |
664 { | 663 { |
665 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); | 664 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); |
666 target->Focus(); | 665 target->Focus(); |
667 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 666 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
668 target.get()); | 667 target.get()); |
669 generator.PressLeftButton(); | 668 generator.PressLeftButton(); |
670 generator.MoveMouseBy(10, 11); | 669 generator.MoveMouseBy(10, 11); |
671 RunAllPendingInMessageLoop(); | 670 RunAllPendingInMessageLoop(); |
672 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); | 671 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); |
673 wm::WindowState* window_state = wm::GetWindowState(target.get()); | 672 wm::WindowState* window_state = wm::GetWindowState(target.get()); |
674 window_state->Maximize(); | 673 window_state->Maximize(); |
675 window_state->Restore(); | 674 window_state->Restore(); |
676 | 675 |
677 generator.PressLeftButton(); | 676 generator.PressLeftButton(); |
678 generator.MoveMouseBy(10, 11); | 677 generator.MoveMouseBy(10, 11); |
679 RunAllPendingInMessageLoop(); | 678 RunAllPendingInMessageLoop(); |
680 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); | 679 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); |
681 } | 680 } |
682 } | 681 } |
683 | 682 |
684 // Verifies that a drag cannot be started via | 683 // Verifies that a drag cannot be started via |
685 // aura::client::WindowMoveClient::RunMoveLoop() while another drag is already | 684 // aura::client::WindowMoveClient::RunMoveLoop() while another drag is already |
686 // in progress. | 685 // in progress. |
687 TEST_F(ToplevelWindowEventHandlerTest, RunMoveLoopFailsDuringInProgressDrag) { | 686 TEST_F(ToplevelWindowEventHandlerTest, RunMoveLoopFailsDuringInProgressDrag) { |
688 scoped_ptr<aura::Window> window1(CreateWindow(HTCAPTION)); | 687 scoped_ptr<aura::Window> window1(CreateWindow(HTCAPTION)); |
689 EXPECT_EQ("0,0 100x100", window1->bounds().ToString()); | 688 EXPECT_EQ("0,0 100x100", window1->bounds().ToString()); |
690 scoped_ptr<aura::Window> window2(CreateWindow(HTCAPTION)); | 689 scoped_ptr<aura::Window> window2(CreateWindow(HTCAPTION)); |
691 | 690 |
692 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 691 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
693 window1.get()); | 692 window1.get()); |
694 window1->Focus(); | 693 window1->Focus(); |
695 generator.PressLeftButton(); | 694 generator.PressLeftButton(); |
696 generator.MoveMouseBy(10, 11); | 695 generator.MoveMouseBy(10, 11); |
697 EXPECT_EQ("10,11 100x100", window1->bounds().ToString()); | 696 EXPECT_EQ("10,11 100x100", window1->bounds().ToString()); |
698 | 697 |
699 aura::client::WindowMoveClient* move_client = | 698 aura::client::WindowMoveClient* move_client = |
700 aura::client::GetWindowMoveClient(window2->GetRootWindow()); | 699 aura::client::GetWindowMoveClient(window2->GetRootWindow()); |
701 EXPECT_EQ(aura::client::MOVE_CANCELED, | 700 EXPECT_EQ(aura::client::MOVE_CANCELED, |
702 move_client->RunMoveLoop(window2.get(), gfx::Vector2d(), | 701 move_client->RunMoveLoop(window2.get(), gfx::Vector2d(), |
703 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); | 702 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
704 | 703 |
705 generator.ReleaseLeftButton(); | 704 generator.ReleaseLeftButton(); |
706 EXPECT_EQ("10,11 100x100", window1->bounds().ToString()); | 705 EXPECT_EQ("10,11 100x100", window1->bounds().ToString()); |
707 } | 706 } |
708 | 707 |
709 namespace { | 708 namespace { |
710 | 709 |
711 void SendMouseReleaseAndReleaseCapture(aura::test::EventGenerator* generator, | 710 void SendMouseReleaseAndReleaseCapture(ui::test::EventGenerator* generator, |
712 aura::Window* window) { | 711 aura::Window* window) { |
713 generator->ReleaseLeftButton(); | 712 generator->ReleaseLeftButton(); |
714 window->ReleaseCapture(); | 713 window->ReleaseCapture(); |
715 } | 714 } |
716 | 715 |
717 } // namespace | 716 } // namespace |
718 | 717 |
719 // Test that a drag is successful even if ET_MOUSE_CAPTURE_CHANGED is sent | 718 // Test that a drag is successful even if ET_MOUSE_CAPTURE_CHANGED is sent |
720 // immediately after the mouse release. views::Widget has this behavior. | 719 // immediately after the mouse release. views::Widget has this behavior. |
721 TEST_F(ToplevelWindowEventHandlerTest, CaptureLossAfterMouseRelease) { | 720 TEST_F(ToplevelWindowEventHandlerTest, CaptureLossAfterMouseRelease) { |
722 scoped_ptr<aura::Window> window(CreateWindow(HTNOWHERE)); | 721 scoped_ptr<aura::Window> window(CreateWindow(HTNOWHERE)); |
723 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 722 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
724 window.get()); | 723 window.get()); |
725 generator.PressLeftButton(); | 724 generator.PressLeftButton(); |
726 window->SetCapture(); | 725 window->SetCapture(); |
727 | 726 |
728 aura::client::WindowMoveClient* move_client = | 727 aura::client::WindowMoveClient* move_client = |
729 aura::client::GetWindowMoveClient(window->GetRootWindow()); | 728 aura::client::GetWindowMoveClient(window->GetRootWindow()); |
730 base::MessageLoopForUI::current()->PostTask( | 729 base::MessageLoopForUI::current()->PostTask( |
731 FROM_HERE, | 730 FROM_HERE, |
732 base::Bind(&SendMouseReleaseAndReleaseCapture, | 731 base::Bind(&SendMouseReleaseAndReleaseCapture, |
733 base::Unretained(&generator), | 732 base::Unretained(&generator), |
734 base::Unretained(window.get()))); | 733 base::Unretained(window.get()))); |
735 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, | 734 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, |
736 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), | 735 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), |
737 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); | 736 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
738 } | 737 } |
739 | 738 |
740 // Showing the resize shadows when the mouse is over the window edges is tested | 739 // Showing the resize shadows when the mouse is over the window edges is tested |
741 // in resize_shadow_and_cursor_test.cc | 740 // in resize_shadow_and_cursor_test.cc |
742 | 741 |
743 } // namespace test | 742 } // namespace test |
744 } // namespace ash | 743 } // namespace ash |
OLD | NEW |