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

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

Issue 10883069: Added restore functionality for maximize full/left/right (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
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/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/window_util.h" 10 #include "ash/wm/window_util.h"
11 #include "ash/wm/workspace/frame_maximize_button.h" 11 #include "ash/wm/workspace/frame_maximize_button.h"
12 #include "ash/wm/workspace/snap_sizer.h" 12 #include "ash/wm/workspace/snap_sizer.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "ui/aura/aura_switches.h" 14 #include "ui/aura/aura_switches.h"
15 #include "ui/aura/client/aura_constants.h"
15 #include "ui/aura/focus_manager.h" 16 #include "ui/aura/focus_manager.h"
16 #include "ui/aura/test/event_generator.h" 17 #include "ui/aura/test/event_generator.h"
17 #include "ui/aura/root_window.h" 18 #include "ui/aura/root_window.h"
18 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
19 #include "ui/base/gestures/gesture_configuration.h" 20 #include "ui/base/gestures/gesture_configuration.h"
20 #include "ui/views/controls/button/image_button.h" 21 #include "ui/views/controls/button/image_button.h"
21 #include "ui/views/test/test_views_delegate.h" 22 #include "ui/views/test/test_views_delegate.h"
22 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
23 #include "ui/views/widget/widget_delegate.h" 24 #include "ui/views/widget/widget_delegate.h"
24 25
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 477
477 // Pressing then additionally the left button shouldn't activate either. 478 // Pressing then additionally the left button shouldn't activate either.
478 generator.PressLeftButton(); 479 generator.PressLeftButton();
479 RunAllPendingInMessageLoop(); 480 RunAllPendingInMessageLoop();
480 EXPECT_FALSE(maximize_button->is_snap_enabled()); 481 EXPECT_FALSE(maximize_button->is_snap_enabled());
481 generator.ReleaseRightButton(); 482 generator.ReleaseRightButton();
482 generator.ReleaseLeftButton(); 483 generator.ReleaseLeftButton();
483 EXPECT_FALSE(ash::wm::IsWindowMaximized(window)); 484 EXPECT_FALSE(ash::wm::IsWindowMaximized(window));
484 } 485 }
485 486
487 void ClickMaxButton(ash::FrameMaximizeButton* maximize_button,
sky 2012/08/27 22:18:16 Wrap maximize_button to next line so that it lines
Mr4D (OOO till 08-26) 2012/08/28 01:30:25 Done.
488 aura::Window* window,
489 SnapType snap_type) {
490 gfx::Point button_pos = maximize_button->GetBoundsInScreen().CenterPoint();
491 gfx::Point off_pos(button_pos.x() + 100, button_pos.y() + 100);
492
493 aura::test::EventGenerator generator(window->GetRootWindow(), off_pos);
494 generator.MoveMouseTo(off_pos);
495 EXPECT_FALSE(maximize_button->maximizer());
496 EXPECT_FALSE(maximize_button->phantom_window_open());
497
498 // Move the mouse cursor over the button.
499 generator.MoveMouseTo(button_pos);
500 EXPECT_TRUE(maximize_button->maximizer());
501 EXPECT_FALSE(maximize_button->phantom_window_open());
502
503 if (snap_type != SNAP_NONE) {
504 gfx::Point left_max_pos = maximize_button->maximizer()->
505 GetButtonForUnitTest(snap_type)->GetBoundsInScreen().CenterPoint();
506 generator.MoveMouseTo(left_max_pos);
507 EXPECT_TRUE(maximize_button->phantom_window_open());
508 }
509 // After pressing the left button the button should get triggered.
510 generator.ClickLeftButton();
511 EXPECT_FALSE(maximize_button->maximizer());
512 }
513
514 // Test that the restore from left/right maximize is properly done.
515 TEST_F(CustomFrameViewAshTest, MaximizeLeftRestore) {
516 views::Widget* widget = CreateWidget();
517 aura::Window* window = widget->GetNativeWindow();
518 widget->SetBounds(gfx::Rect(10, 10, 100, 100));
519 gfx::Rect initial_bounds = widget->GetWindowBoundsInScreen();
520 CustomFrameViewAsh* frame = custom_frame_view_ash(widget);
521 CustomFrameViewAsh::TestApi test(frame);
522 ash::FrameMaximizeButton* maximize_button = test.maximize_button();
523 maximize_button->set_bubble_appearance_delay_ms(0);
524
525 ClickMaxButton(maximize_button, window, SNAP_LEFT);
526 RunAllPendingInMessageLoop();
sky 2012/08/27 22:18:16 Why do you need to explicitly run the message loop
Mr4D (OOO till 08-26) 2012/08/28 01:30:25 I have seen that other tests were doing this, so I
527 // The window should not be maximized.
528 EXPECT_FALSE(ash::wm::IsWindowMaximized(window));
529 // But the bounds should be different.
530 gfx::Rect new_bounds = widget->GetWindowBoundsInScreen();
531 EXPECT_EQ(0, new_bounds.x());
532 EXPECT_EQ(0, new_bounds.y());
533
534 // Now click the same button again to see that it restores.
535 ClickMaxButton(maximize_button, window, SNAP_LEFT);
536 RunAllPendingInMessageLoop();
537 // But the bounds should be restored.
538 new_bounds = widget->GetWindowBoundsInScreen();
539 EXPECT_EQ(new_bounds.x(), initial_bounds.x());
540 EXPECT_EQ(new_bounds.y(), initial_bounds.x());
541 EXPECT_EQ(new_bounds.width(), initial_bounds.width());
542 EXPECT_EQ(new_bounds.height(), initial_bounds.height());
543 // Make sure that there is no restore rectangle left.
544 EXPECT_EQ(NULL, window->GetProperty(aura::client::kRestoreBoundsKey));
545 }
546
547 // Maximize, left/right maximize and then restore should works.
548 TEST_F(CustomFrameViewAshTest, MaximizeMaximizeLeftRestore) {
549 views::Widget* widget = CreateWidget();
550 aura::Window* window = widget->GetNativeWindow();
551 widget->SetBounds(gfx::Rect(10, 10, 100, 100));
552 gfx::Rect initial_bounds = widget->GetWindowBoundsInScreen();
553 CustomFrameViewAsh* frame = custom_frame_view_ash(widget);
554 CustomFrameViewAsh::TestApi test(frame);
555 ash::FrameMaximizeButton* maximize_button = test.maximize_button();
556 maximize_button->set_bubble_appearance_delay_ms(0);
557
558 ClickMaxButton(maximize_button, window, SNAP_NONE);
559 RunAllPendingInMessageLoop();
560 EXPECT_TRUE(ash::wm::IsWindowMaximized(window));
561
562 ClickMaxButton(maximize_button, window, SNAP_LEFT);
563 RunAllPendingInMessageLoop();
564 EXPECT_FALSE(ash::wm::IsWindowMaximized(window));
565 gfx::Rect new_bounds = widget->GetWindowBoundsInScreen();
566 EXPECT_EQ(0, new_bounds.x());
567 EXPECT_EQ(0, new_bounds.y());
568
569 // Now click the same button again to see that it restores.
570 ClickMaxButton(maximize_button, window, SNAP_LEFT);
571 RunAllPendingInMessageLoop();
572 // But the bounds should be restored.
573 new_bounds = widget->GetWindowBoundsInScreen();
574 EXPECT_EQ(new_bounds.x(), initial_bounds.x());
575 EXPECT_EQ(new_bounds.y(), initial_bounds.x());
576 EXPECT_EQ(new_bounds.width(), initial_bounds.width());
577 EXPECT_EQ(new_bounds.height(), initial_bounds.height());
578 // Make sure that there is no restore rectangle left.
579 EXPECT_EQ(NULL, window->GetProperty(aura::client::kRestoreBoundsKey));
580 }
581
582 // Left/right maximize, maximize and then restore should work.
583 TEST_F(CustomFrameViewAshTest, MaximizeLeftMaximizeRestore) {
584 views::Widget* widget = CreateWidget();
585 aura::Window* window = widget->GetNativeWindow();
586 widget->SetBounds(gfx::Rect(10, 10, 100, 100));
587 gfx::Rect initial_bounds = widget->GetWindowBoundsInScreen();
588 CustomFrameViewAsh* frame = custom_frame_view_ash(widget);
589 CustomFrameViewAsh::TestApi test(frame);
590 ash::FrameMaximizeButton* maximize_button = test.maximize_button();
591 maximize_button->set_bubble_appearance_delay_ms(0);
592
593 ClickMaxButton(maximize_button, window, SNAP_LEFT);
594 RunAllPendingInMessageLoop();
595 EXPECT_FALSE(ash::wm::IsWindowMaximized(window));
596
597 ClickMaxButton(maximize_button, window, SNAP_NONE);
598 RunAllPendingInMessageLoop();
599 EXPECT_TRUE(ash::wm::IsWindowMaximized(window));
600
601 ClickMaxButton(maximize_button, window, SNAP_NONE);
602 RunAllPendingInMessageLoop();
603 EXPECT_FALSE(ash::wm::IsWindowMaximized(window));
604 gfx::Rect new_bounds = widget->GetWindowBoundsInScreen();
605 EXPECT_EQ(new_bounds.x(), initial_bounds.x());
606 EXPECT_EQ(new_bounds.y(), initial_bounds.x());
607 EXPECT_EQ(new_bounds.width(), initial_bounds.width());
608 EXPECT_EQ(new_bounds.height(), initial_bounds.height());
609 // Make sure that there is no restore rectangle left.
610 EXPECT_EQ(NULL, window->GetProperty(aura::client::kRestoreBoundsKey));
611 }
612
486 } // namespace internal 613 } // namespace internal
487 } // namespace ash 614 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698