Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: ash/wm/toplevel_window_event_handler_unittest.cc

Issue 2095193002: clang-format all of //ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/wm/toplevel_window_event_handler.cc ('k') | ash/wm/video_detector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/shell_window_ids.h" 7 #include "ash/common/shell_window_ids.h"
8 #include "ash/common/wm/window_state.h" 8 #include "ash/common/wm/window_state.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 void TouchDragFromCenterBy(aura::Window* window, int dx, int dy) { 85 void TouchDragFromCenterBy(aura::Window* window, int dx, int dy) {
86 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); 86 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window);
87 generator.PressMoveAndReleaseTouchBy(dx, dy); 87 generator.PressMoveAndReleaseTouchBy(dx, dy);
88 } 88 }
89 89
90 std::unique_ptr<ToplevelWindowEventHandler> handler_; 90 std::unique_ptr<ToplevelWindowEventHandler> handler_;
91 91
92 private: 92 private:
93 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventHandlerTest); 93 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventHandlerTest);
94 }; 94 };
95
96 } 95 }
97 96
98 TEST_F(ToplevelWindowEventHandlerTest, Caption) { 97 TEST_F(ToplevelWindowEventHandlerTest, Caption) {
99 std::unique_ptr<aura::Window> w1(CreateWindow(HTCAPTION)); 98 std::unique_ptr<aura::Window> w1(CreateWindow(HTCAPTION));
100 gfx::Size size = w1->bounds().size(); 99 gfx::Size size = w1->bounds().size();
101 DragFromCenterBy(w1.get(), 100, 100); 100 DragFromCenterBy(w1.get(), 100, 100);
102 // Position should have been offset by 100,100. 101 // Position should have been offset by 100,100.
103 EXPECT_EQ("100,100", w1->bounds().origin().ToString()); 102 EXPECT_EQ("100,100", w1->bounds().origin().ToString());
104 // Size should not have. 103 // Size should not have.
105 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); 104 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString());
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 target.get()); 433 target.get());
435 gfx::Rect old_bounds = target->bounds(); 434 gfx::Rect old_bounds = target->bounds();
436 gfx::Point location(5, 5); 435 gfx::Point location(5, 5);
437 target->SetProperty(aura::client::kCanMaximizeKey, true); 436 target->SetProperty(aura::client::kCanMaximizeKey, true);
438 437
439 gfx::Point end = location; 438 gfx::Point end = location;
440 439
441 // Snap right; 440 // Snap right;
442 end.Offset(100, 0); 441 end.Offset(100, 0);
443 generator.GestureScrollSequence(location, end, 442 generator.GestureScrollSequence(location, end,
444 base::TimeDelta::FromMilliseconds(5), 443 base::TimeDelta::FromMilliseconds(5), 10);
445 10);
446 RunAllPendingInMessageLoop(); 444 RunAllPendingInMessageLoop();
447 445
448 // Verify that the window has moved after the gesture. 446 // Verify that the window has moved after the gesture.
449 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString()); 447 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString());
450 EXPECT_EQ(wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED, window_state->GetStateType()); 448 EXPECT_EQ(wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED, window_state->GetStateType());
451 449
452 old_bounds = target->bounds(); 450 old_bounds = target->bounds();
453 451
454 // Snap left. 452 // Snap left.
455 end = location = target->GetBoundsInRootWindow().CenterPoint(); 453 end = location = target->GetBoundsInRootWindow().CenterPoint();
456 end.Offset(-100, 0); 454 end.Offset(-100, 0);
457 generator.GestureScrollSequence(location, end, 455 generator.GestureScrollSequence(location, end,
458 base::TimeDelta::FromMilliseconds(5), 456 base::TimeDelta::FromMilliseconds(5), 10);
459 10);
460 RunAllPendingInMessageLoop(); 457 RunAllPendingInMessageLoop();
461 458
462 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString()); 459 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString());
463 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); 460 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
464 461
465 gfx::Rect bounds_before_maximization = target->bounds(); 462 gfx::Rect bounds_before_maximization = target->bounds();
466 bounds_before_maximization.Offset(0, 100); 463 bounds_before_maximization.Offset(0, 100);
467 target->SetBounds(bounds_before_maximization); 464 target->SetBounds(bounds_before_maximization);
468 old_bounds = target->bounds(); 465 old_bounds = target->bounds();
469 466
470 // Maximize. 467 // Maximize.
471 end = location = target->GetBoundsInRootWindow().CenterPoint(); 468 end = location = target->GetBoundsInRootWindow().CenterPoint();
472 end.Offset(0, -100); 469 end.Offset(0, -100);
473 generator.GestureScrollSequence(location, end, 470 generator.GestureScrollSequence(location, end,
474 base::TimeDelta::FromMilliseconds(5), 471 base::TimeDelta::FromMilliseconds(5), 10);
475 10);
476 RunAllPendingInMessageLoop(); 472 RunAllPendingInMessageLoop();
477 473
478 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString()); 474 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString());
479 EXPECT_TRUE(window_state->IsMaximized()); 475 EXPECT_TRUE(window_state->IsMaximized());
480 EXPECT_EQ(old_bounds.ToString(), 476 EXPECT_EQ(old_bounds.ToString(),
481 window_state->GetRestoreBoundsInScreen().ToString()); 477 window_state->GetRestoreBoundsInScreen().ToString());
482 478
483 window_state->Restore(); 479 window_state->Restore();
484 target->SetBounds(old_bounds); 480 target->SetBounds(old_bounds);
485 481
486 // Minimize. 482 // Minimize.
487 end = location = target->GetBoundsInRootWindow().CenterPoint(); 483 end = location = target->GetBoundsInRootWindow().CenterPoint();
488 end.Offset(0, 100); 484 end.Offset(0, 100);
489 generator.GestureScrollSequence(location, end, 485 generator.GestureScrollSequence(location, end,
490 base::TimeDelta::FromMilliseconds(5), 486 base::TimeDelta::FromMilliseconds(5), 10);
491 10);
492 RunAllPendingInMessageLoop(); 487 RunAllPendingInMessageLoop();
493 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString()); 488 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString());
494 EXPECT_TRUE(window_state->IsMinimized()); 489 EXPECT_TRUE(window_state->IsMinimized());
495 EXPECT_TRUE(window_state->unminimize_to_restore_bounds()); 490 EXPECT_TRUE(window_state->unminimize_to_restore_bounds());
496 EXPECT_EQ(old_bounds.ToString(), 491 EXPECT_EQ(old_bounds.ToString(),
497 window_state->GetRestoreBoundsInScreen().ToString()); 492 window_state->GetRestoreBoundsInScreen().ToString());
498 } 493 }
499 494
500 // Tests that a gesture cannot minimize an unminimizeable window. 495 // Tests that a gesture cannot minimize an unminimizeable window.
501 TEST_F(ToplevelWindowEventHandlerTest, 496 TEST_F(ToplevelWindowEventHandlerTest,
502 GestureAttemptMinimizeUnminimizeableWindow) { 497 GestureAttemptMinimizeUnminimizeableWindow) {
503 std::unique_ptr<aura::Window> target(CreateWindow(HTCAPTION)); 498 std::unique_ptr<aura::Window> target(CreateWindow(HTCAPTION));
504 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 499 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
505 target.get()); 500 target.get());
506 gfx::Point location(5, 5); 501 gfx::Point location(5, 5);
507 target->SetProperty(aura::client::kCanMaximizeKey, true); 502 target->SetProperty(aura::client::kCanMaximizeKey, true);
508 target->SetProperty(aura::client::kCanMinimizeKey, false); 503 target->SetProperty(aura::client::kCanMinimizeKey, false);
509 504
510 gfx::Point end = location; 505 gfx::Point end = location;
511 end.Offset(0, 100); 506 end.Offset(0, 100);
512 generator.GestureScrollSequence(location, end, 507 generator.GestureScrollSequence(location, end,
513 base::TimeDelta::FromMilliseconds(5), 508 base::TimeDelta::FromMilliseconds(5), 10);
514 10);
515 RunAllPendingInMessageLoop(); 509 RunAllPendingInMessageLoop();
516 EXPECT_FALSE(wm::GetWindowState(target.get())->IsMinimized()); 510 EXPECT_FALSE(wm::GetWindowState(target.get())->IsMinimized());
517 } 511 }
518 512
519 TEST_F(ToplevelWindowEventHandlerTest, GestureDragToRestore) { 513 TEST_F(ToplevelWindowEventHandlerTest, GestureDragToRestore) {
520 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 514 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
521 new TestWindowDelegate(HTCAPTION), 0, gfx::Rect(10, 20, 30, 40))); 515 new TestWindowDelegate(HTCAPTION), 0, gfx::Rect(10, 20, 30, 40)));
522 window->Show(); 516 window->Show();
523 wm::WindowState* window_state = wm::GetWindowState(window.get()); 517 wm::WindowState* window_state = wm::GetWindowState(window.get());
524 window_state->Activate(); 518 window_state->Activate();
525 519
526 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 520 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
527 window.get()); 521 window.get());
528 gfx::Rect old_bounds = window->bounds(); 522 gfx::Rect old_bounds = window->bounds();
529 gfx::Point location, end; 523 gfx::Point location, end;
530 end = location = window->GetBoundsInRootWindow().CenterPoint(); 524 end = location = window->GetBoundsInRootWindow().CenterPoint();
531 end.Offset(0, 100); 525 end.Offset(0, 100);
532 generator.GestureScrollSequence(location, end, 526 generator.GestureScrollSequence(location, end,
533 base::TimeDelta::FromMilliseconds(5), 527 base::TimeDelta::FromMilliseconds(5), 10);
534 10);
535 RunAllPendingInMessageLoop(); 528 RunAllPendingInMessageLoop();
536 EXPECT_NE(old_bounds.ToString(), window->bounds().ToString()); 529 EXPECT_NE(old_bounds.ToString(), window->bounds().ToString());
537 EXPECT_TRUE(window_state->IsMinimized()); 530 EXPECT_TRUE(window_state->IsMinimized());
538 EXPECT_TRUE(window_state->unminimize_to_restore_bounds()); 531 EXPECT_TRUE(window_state->unminimize_to_restore_bounds());
539 EXPECT_EQ(old_bounds.ToString(), 532 EXPECT_EQ(old_bounds.ToString(),
540 window_state->GetRestoreBoundsInScreen().ToString()); 533 window_state->GetRestoreBoundsInScreen().ToString());
541 } 534 }
542 535
543 // Tests that an unresizable window cannot be dragged or snapped using gestures. 536 // Tests that an unresizable window cannot be dragged or snapped using gestures.
544 TEST_F(ToplevelWindowEventHandlerTest, GestureDragForUnresizableWindow) { 537 TEST_F(ToplevelWindowEventHandlerTest, GestureDragForUnresizableWindow) {
545 std::unique_ptr<aura::Window> target(CreateWindow(HTCAPTION)); 538 std::unique_ptr<aura::Window> target(CreateWindow(HTCAPTION));
546 wm::WindowState* window_state = wm::GetWindowState(target.get()); 539 wm::WindowState* window_state = wm::GetWindowState(target.get());
547 540
548 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 541 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
549 target.get()); 542 target.get());
550 gfx::Rect old_bounds = target->bounds(); 543 gfx::Rect old_bounds = target->bounds();
551 gfx::Point location(5, 5); 544 gfx::Point location(5, 5);
552 545
553 target->SetProperty(aura::client::kCanResizeKey, false); 546 target->SetProperty(aura::client::kCanResizeKey, false);
554 547
555 gfx::Point end = location; 548 gfx::Point end = location;
556 549
557 // Try to snap right. The window is not resizable. So it should not snap. 550 // Try to snap right. The window is not resizable. So it should not snap.
558 end.Offset(100, 0); 551 end.Offset(100, 0);
559 generator.GestureScrollSequence(location, end, 552 generator.GestureScrollSequence(location, end,
560 base::TimeDelta::FromMilliseconds(5), 553 base::TimeDelta::FromMilliseconds(5), 10);
561 10);
562 RunAllPendingInMessageLoop(); 554 RunAllPendingInMessageLoop();
563 555
564 // Verify that the window has moved after the gesture. 556 // Verify that the window has moved after the gesture.
565 gfx::Rect expected_bounds(old_bounds); 557 gfx::Rect expected_bounds(old_bounds);
566 expected_bounds.Offset(gfx::Vector2d(100, 0)); 558 expected_bounds.Offset(gfx::Vector2d(100, 0));
567 EXPECT_EQ(expected_bounds.ToString(), target->bounds().ToString()); 559 EXPECT_EQ(expected_bounds.ToString(), target->bounds().ToString());
568 560
569 // Verify that the window did not snap left. 561 // Verify that the window did not snap left.
570 EXPECT_TRUE(window_state->IsNormalStateType()); 562 EXPECT_TRUE(window_state->IsNormalStateType());
571 563
572 old_bounds = target->bounds(); 564 old_bounds = target->bounds();
573 565
574 // Try to snap left. It should not snap. 566 // Try to snap left. It should not snap.
575 end = location = target->GetBoundsInRootWindow().CenterPoint(); 567 end = location = target->GetBoundsInRootWindow().CenterPoint();
576 end.Offset(-100, 0); 568 end.Offset(-100, 0);
577 generator.GestureScrollSequence(location, end, 569 generator.GestureScrollSequence(location, end,
578 base::TimeDelta::FromMilliseconds(5), 570 base::TimeDelta::FromMilliseconds(5), 10);
579 10);
580 RunAllPendingInMessageLoop(); 571 RunAllPendingInMessageLoop();
581 572
582 // Verify that the window has moved after the gesture. 573 // Verify that the window has moved after the gesture.
583 expected_bounds = old_bounds; 574 expected_bounds = old_bounds;
584 expected_bounds.Offset(gfx::Vector2d(-100, 0)); 575 expected_bounds.Offset(gfx::Vector2d(-100, 0));
585 EXPECT_EQ(expected_bounds.ToString(), target->bounds().ToString()); 576 EXPECT_EQ(expected_bounds.ToString(), target->bounds().ToString());
586 577
587 // Verify that the window did not snap left. 578 // Verify that the window did not snap left.
588 EXPECT_TRUE(window_state->IsNormalStateType()); 579 EXPECT_TRUE(window_state->IsNormalStateType());
589 } 580 }
(...skipping 15 matching lines...) Expand all
605 generator.PressTouch(); 596 generator.PressTouch();
606 location.Offset(40, 5); 597 location.Offset(40, 5);
607 generator.MoveTouch(location); 598 generator.MoveTouch(location);
608 599
609 // Try to drag |notmoved| window. This should not move the window. 600 // Try to drag |notmoved| window. This should not move the window.
610 { 601 {
611 gfx::Rect bounds = notmoved->bounds(); 602 gfx::Rect bounds = notmoved->bounds();
612 ui::test::EventGenerator gen(Shell::GetPrimaryRootWindow(), notmoved.get()); 603 ui::test::EventGenerator gen(Shell::GetPrimaryRootWindow(), notmoved.get());
613 gfx::Point start = notmoved->bounds().origin() + gfx::Vector2d(10, 10); 604 gfx::Point start = notmoved->bounds().origin() + gfx::Vector2d(10, 10);
614 gfx::Point end = start + gfx::Vector2d(100, 10); 605 gfx::Point end = start + gfx::Vector2d(100, 10);
615 gen.GestureScrollSequence(start, end, 606 gen.GestureScrollSequence(start, end, base::TimeDelta::FromMilliseconds(10),
616 base::TimeDelta::FromMilliseconds(10), 607 10);
617 10);
618 EXPECT_EQ(bounds.ToString(), notmoved->bounds().ToString()); 608 EXPECT_EQ(bounds.ToString(), notmoved->bounds().ToString());
619 } 609 }
620 } 610 }
621 611
622 // Verifies pressing escape resets the bounds to the original bounds. 612 // Verifies pressing escape resets the bounds to the original bounds.
623 // Disabled crbug.com/166219. 613 // Disabled crbug.com/166219.
624 #if defined(OS_WIN) 614 #if defined(OS_WIN)
625 #define MAYBE_EscapeReverts DISABLED_EscapeReverts 615 #define MAYBE_EscapeReverts DISABLED_EscapeReverts
626 #else 616 #else
627 #define MAYBE_EscapeReverts EscapeReverts 617 #define MAYBE_EscapeReverts EscapeReverts
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 window1.get()); 693 window1.get());
704 window1->Focus(); 694 window1->Focus();
705 generator.PressLeftButton(); 695 generator.PressLeftButton();
706 generator.MoveMouseBy(10, 11); 696 generator.MoveMouseBy(10, 11);
707 EXPECT_EQ("10,11 100x100", window1->bounds().ToString()); 697 EXPECT_EQ("10,11 100x100", window1->bounds().ToString());
708 698
709 aura::client::WindowMoveClient* move_client = 699 aura::client::WindowMoveClient* move_client =
710 aura::client::GetWindowMoveClient(window2->GetRootWindow()); 700 aura::client::GetWindowMoveClient(window2->GetRootWindow());
711 EXPECT_EQ(aura::client::MOVE_CANCELED, 701 EXPECT_EQ(aura::client::MOVE_CANCELED,
712 move_client->RunMoveLoop(window2.get(), gfx::Vector2d(), 702 move_client->RunMoveLoop(window2.get(), gfx::Vector2d(),
713 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); 703 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
714 704
715 generator.ReleaseLeftButton(); 705 generator.ReleaseLeftButton();
716 EXPECT_EQ("10,11 100x100", window1->bounds().ToString()); 706 EXPECT_EQ("10,11 100x100", window1->bounds().ToString());
717 } 707 }
718 708
719 namespace { 709 namespace {
720 710
721 void SendMouseReleaseAndReleaseCapture(ui::test::EventGenerator* generator, 711 void SendMouseReleaseAndReleaseCapture(ui::test::EventGenerator* generator,
722 aura::Window* window) { 712 aura::Window* window) {
723 generator->ReleaseLeftButton(); 713 generator->ReleaseLeftButton();
(...skipping 12 matching lines...) Expand all
736 window->SetCapture(); 726 window->SetCapture();
737 727
738 aura::client::WindowMoveClient* move_client = 728 aura::client::WindowMoveClient* move_client =
739 aura::client::GetWindowMoveClient(window->GetRootWindow()); 729 aura::client::GetWindowMoveClient(window->GetRootWindow());
740 base::ThreadTaskRunnerHandle::Get()->PostTask( 730 base::ThreadTaskRunnerHandle::Get()->PostTask(
741 FROM_HERE, 731 FROM_HERE,
742 base::Bind(&SendMouseReleaseAndReleaseCapture, 732 base::Bind(&SendMouseReleaseAndReleaseCapture,
743 base::Unretained(&generator), base::Unretained(window.get()))); 733 base::Unretained(&generator), base::Unretained(window.get())));
744 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, 734 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL,
745 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), 735 move_client->RunMoveLoop(window.get(), gfx::Vector2d(),
746 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); 736 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
747 } 737 }
748 738
749 namespace { 739 namespace {
750 740
751 // Checks that |window| has capture and releases capture. 741 // Checks that |window| has capture and releases capture.
752 void CheckHasCaptureAndReleaseCapture(aura::Window* window) { 742 void CheckHasCaptureAndReleaseCapture(aura::Window* window) {
753 ASSERT_TRUE(window->HasCapture()); 743 ASSERT_TRUE(window->HasCapture());
754 window->ReleaseCapture(); 744 window->ReleaseCapture();
755 } 745 }
756 746
(...skipping 13 matching lines...) Expand all
770 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, 760 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL,
771 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), 761 move_client->RunMoveLoop(window.get(), gfx::Vector2d(),
772 aura::client::WINDOW_MOVE_SOURCE_TOUCH)); 762 aura::client::WINDOW_MOVE_SOURCE_TOUCH));
773 } 763 }
774 764
775 // Showing the resize shadows when the mouse is over the window edges is tested 765 // Showing the resize shadows when the mouse is over the window edges is tested
776 // in resize_shadow_and_cursor_test.cc 766 // in resize_shadow_and_cursor_test.cc
777 767
778 } // namespace test 768 } // namespace test
779 } // namespace ash 769 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/toplevel_window_event_handler.cc ('k') | ash/wm/video_detector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698