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

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: Fixed unit test failure 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
« no previous file with comments | « ash/wm/base_layout_manager_unittest.cc ('k') | ash/wm/maximize_bubble_controller.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/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 // Click a button of window maximize functionality.
488 // If |snap_type| is SNAP_NONE the FrameMaximizeButton gets clicked, otherwise
489 // the associated snap button.
490 // |Window| is the window which owns the maximize button.
491 // |maximize_button| is the FrameMaximizeButton which controls the window.
492 void ClickMaxButton(
493 ash::FrameMaximizeButton* maximize_button,
494 aura::Window* window,
495 SnapType snap_type) {
496 gfx::Point button_pos = maximize_button->GetBoundsInScreen().CenterPoint();
497 gfx::Point off_pos(button_pos.x() + 100, button_pos.y() + 100);
498
499 aura::test::EventGenerator generator(window->GetRootWindow(), off_pos);
500 generator.MoveMouseTo(off_pos);
501 EXPECT_FALSE(maximize_button->maximizer());
502 EXPECT_FALSE(maximize_button->phantom_window_open());
503
504 // Move the mouse cursor over the button.
505 generator.MoveMouseTo(button_pos);
506 EXPECT_TRUE(maximize_button->maximizer());
507 EXPECT_FALSE(maximize_button->phantom_window_open());
508
509 if (snap_type != SNAP_NONE) {
510 gfx::Point left_max_pos = maximize_button->maximizer()->
511 GetButtonForUnitTest(snap_type)->GetBoundsInScreen().CenterPoint();
512 generator.MoveMouseTo(left_max_pos);
513 EXPECT_TRUE(maximize_button->phantom_window_open());
514 }
515 // After pressing the left button the button should get triggered.
516 generator.ClickLeftButton();
517 EXPECT_FALSE(maximize_button->maximizer());
518 }
519
520 // Test that the restore from left/right maximize is properly done.
521 TEST_F(CustomFrameViewAshTest, MaximizeLeftRestore) {
522 views::Widget* widget = CreateWidget();
523 aura::Window* window = widget->GetNativeWindow();
524 widget->SetBounds(gfx::Rect(10, 10, 100, 100));
525 gfx::Rect initial_bounds = widget->GetWindowBoundsInScreen();
526 CustomFrameViewAsh* frame = custom_frame_view_ash(widget);
527 CustomFrameViewAsh::TestApi test(frame);
528 ash::FrameMaximizeButton* maximize_button = test.maximize_button();
529 maximize_button->set_bubble_appearance_delay_ms(0);
530
531 ClickMaxButton(maximize_button, window, SNAP_LEFT);
532 // The window should not be maximized.
533 EXPECT_FALSE(ash::wm::IsWindowMaximized(window));
534 // But the bounds should be different.
535 gfx::Rect new_bounds = widget->GetWindowBoundsInScreen();
536 EXPECT_EQ(0, new_bounds.x());
537 EXPECT_EQ(0, new_bounds.y());
538
539 // Now click the same button again to see that it restores.
540 ClickMaxButton(maximize_button, window, SNAP_LEFT);
541 // But the bounds should be restored.
542 new_bounds = widget->GetWindowBoundsInScreen();
543 EXPECT_EQ(new_bounds.x(), initial_bounds.x());
544 EXPECT_EQ(new_bounds.y(), initial_bounds.x());
545 EXPECT_EQ(new_bounds.width(), initial_bounds.width());
546 EXPECT_EQ(new_bounds.height(), initial_bounds.height());
547 // Make sure that there is no restore rectangle left.
548 EXPECT_EQ(NULL, window->GetProperty(aura::client::kRestoreBoundsKey));
549 }
550
551 // Maximize, left/right maximize and then restore should works.
552 TEST_F(CustomFrameViewAshTest, MaximizeMaximizeLeftRestore) {
553 views::Widget* widget = CreateWidget();
554 aura::Window* window = widget->GetNativeWindow();
555 widget->SetBounds(gfx::Rect(10, 10, 100, 100));
556 gfx::Rect initial_bounds = widget->GetWindowBoundsInScreen();
557 CustomFrameViewAsh* frame = custom_frame_view_ash(widget);
558 CustomFrameViewAsh::TestApi test(frame);
559 ash::FrameMaximizeButton* maximize_button = test.maximize_button();
560 maximize_button->set_bubble_appearance_delay_ms(0);
561
562 ClickMaxButton(maximize_button, window, SNAP_NONE);
563 EXPECT_TRUE(ash::wm::IsWindowMaximized(window));
564
565 ClickMaxButton(maximize_button, window, SNAP_LEFT);
566 EXPECT_FALSE(ash::wm::IsWindowMaximized(window));
567 gfx::Rect new_bounds = widget->GetWindowBoundsInScreen();
568 EXPECT_EQ(0, new_bounds.x());
569 EXPECT_EQ(0, new_bounds.y());
570
571 // Now click the same button again to see that it restores.
572 ClickMaxButton(maximize_button, window, SNAP_LEFT);
573 RunAllPendingInMessageLoop();
574 // But the bounds should be restored.
575 new_bounds = widget->GetWindowBoundsInScreen();
576 EXPECT_EQ(new_bounds.x(), initial_bounds.x());
577 EXPECT_EQ(new_bounds.y(), initial_bounds.x());
578 EXPECT_EQ(new_bounds.width(), initial_bounds.width());
579 EXPECT_EQ(new_bounds.height(), initial_bounds.height());
580 // Make sure that there is no restore rectangle left.
581 EXPECT_EQ(NULL, window->GetProperty(aura::client::kRestoreBoundsKey));
582 }
583
584 // Left/right maximize, maximize and then restore should work.
585 TEST_F(CustomFrameViewAshTest, MaximizeLeftMaximizeRestore) {
586 views::Widget* widget = CreateWidget();
587 aura::Window* window = widget->GetNativeWindow();
588 widget->SetBounds(gfx::Rect(10, 10, 100, 100));
589 gfx::Rect initial_bounds = widget->GetWindowBoundsInScreen();
590 CustomFrameViewAsh* frame = custom_frame_view_ash(widget);
591 CustomFrameViewAsh::TestApi test(frame);
592 ash::FrameMaximizeButton* maximize_button = test.maximize_button();
593 maximize_button->set_bubble_appearance_delay_ms(0);
594
595 ClickMaxButton(maximize_button, window, SNAP_LEFT);
596 EXPECT_FALSE(ash::wm::IsWindowMaximized(window));
597
598 ClickMaxButton(maximize_button, window, SNAP_NONE);
599 EXPECT_TRUE(ash::wm::IsWindowMaximized(window));
600
601 ClickMaxButton(maximize_button, window, SNAP_NONE);
602 EXPECT_FALSE(ash::wm::IsWindowMaximized(window));
603 gfx::Rect new_bounds = widget->GetWindowBoundsInScreen();
604 EXPECT_EQ(new_bounds.x(), initial_bounds.x());
605 EXPECT_EQ(new_bounds.y(), initial_bounds.x());
606 EXPECT_EQ(new_bounds.width(), initial_bounds.width());
607 EXPECT_EQ(new_bounds.height(), initial_bounds.height());
608 // Make sure that there is no restore rectangle left.
609 EXPECT_EQ(NULL, window->GetProperty(aura::client::kRestoreBoundsKey));
610 }
611
486 } // namespace internal 612 } // namespace internal
487 } // namespace ash 613 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/base_layout_manager_unittest.cc ('k') | ash/wm/maximize_bubble_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698