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

Side by Side Diff: ash/shelf/shelf_layout_manager_unittest.cc

Issue 22638013: Prevent a user from hiding the shelf via a gesture when there are no visible windows part 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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/shelf/shelf_layout_manager.cc ('k') | ash/shelf/shelf_widget.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/shelf/shelf_layout_manager.h" 5 #include "ash/shelf/shelf_layout_manager.h"
6 6
7 #include "ash/accelerators/accelerator_controller.h" 7 #include "ash/accelerators/accelerator_controller.h"
8 #include "ash/accelerators/accelerator_table.h" 8 #include "ash/accelerators/accelerator_table.h"
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/display/display_controller.h" 10 #include "ash/display/display_controller.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 64
65 ShelfLayoutManager* GetShelfLayoutManager() { 65 ShelfLayoutManager* GetShelfLayoutManager() {
66 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); 66 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
67 } 67 }
68 68
69 SystemTray* GetSystemTray() { 69 SystemTray* GetSystemTray() {
70 return Shell::GetPrimaryRootWindowController()->GetSystemTray(); 70 return Shell::GetPrimaryRootWindowController()->GetSystemTray();
71 } 71 }
72 72
73 // Class which waits till the shelf finishes animating to the target size and
74 // counts the number of animation steps.
75 class ShelfAnimationWaiter : views::WidgetObserver {
76 public:
77 explicit ShelfAnimationWaiter(const gfx::Rect& target_bounds)
78 : target_bounds_(target_bounds),
79 animation_steps_(0),
80 done_waiting_(false) {
81 GetShelfWidget()->AddObserver(this);
82 }
83
84 virtual ~ShelfAnimationWaiter() {
85 GetShelfWidget()->RemoveObserver(this);
86 }
87
88 // Wait till the shelf finishes animating to its expected bounds.
89 void WaitTillDoneAnimating() {
90 if (IsDoneAnimating())
91 done_waiting_ = true;
92 else
93 base::MessageLoop::current()->Run();
94 }
95
96 // Returns true if the animation has completed and it was valid.
97 bool WasValidAnimation() const {
98 return done_waiting_ && animation_steps_ > 0;
99 }
100
101 private:
102 // Returns true if shelf has finished animating to the target size.
103 bool IsDoneAnimating() const {
104 ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
105 gfx::Rect current_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
106 int size = layout_manager->PrimaryAxisValue(current_bounds.height(),
107 current_bounds.width());
108 int desired_size = layout_manager->PrimaryAxisValue(target_bounds_.height(),
109 target_bounds_.width());
110 return (size == desired_size);
111 }
112
113 // views::WidgetObserver override.
114 virtual void OnWidgetBoundsChanged(views::Widget* widget,
115 const gfx::Rect& new_bounds) OVERRIDE {
116 if (done_waiting_)
117 return;
118
119 ++animation_steps_;
120 if (IsDoneAnimating()) {
121 done_waiting_ = true;
122 base::MessageLoop::current()->Quit();
123 }
124 }
125
126 gfx::Rect target_bounds_;
127 int animation_steps_;
128 bool done_waiting_;
129
130 DISALLOW_COPY_AND_ASSIGN(ShelfAnimationWaiter);
131 };
132
73 class ShelfDragCallback { 133 class ShelfDragCallback {
74 public: 134 public:
75 ShelfDragCallback(const gfx::Rect& not_visible, const gfx::Rect& visible) 135 ShelfDragCallback(const gfx::Rect& not_visible, const gfx::Rect& visible)
76 : not_visible_bounds_(not_visible), 136 : not_visible_bounds_(not_visible),
77 visible_bounds_(visible), 137 visible_bounds_(visible),
78 was_visible_on_drag_start_(false) { 138 was_visible_on_drag_start_(false) {
79 EXPECT_EQ(not_visible_bounds_.bottom(), visible_bounds_.bottom()); 139 EXPECT_EQ(not_visible_bounds_.bottom(), visible_bounds_.bottom());
80 } 140 }
81 141
82 virtual ~ShelfDragCallback() { 142 virtual ~ShelfDragCallback() {
(...skipping 1339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 // both visible => normal autohide 1482 // both visible => normal autohide
1423 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 1483 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1424 1484
1425 // either minimzed => normal autohide 1485 // either minimzed => normal autohide
1426 window2->Minimize(); 1486 window2->Minimize();
1427 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 1487 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1428 window2->Restore(); 1488 window2->Restore();
1429 window1->Minimize(); 1489 window1->Minimize();
1430 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 1490 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1431 1491
1432 // both minimzed => disable auto hide 1492 // both minimized => disable auto hide
1433 window2->Minimize(); 1493 window2->Minimize();
1434 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); 1494 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1435 1495
1436 // Test moving windows to/from other display. 1496 // Test moving windows to/from other display.
1437 window2->Restore(); 1497 window2->Restore();
1438 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 1498 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1439 // Move to second display. 1499 // Move to second display.
1440 window2->SetBounds(gfx::Rect(850, 50, 50, 50)); 1500 window2->SetBounds(gfx::Rect(850, 50, 50, 50));
1441 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); 1501 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1442 // Move back to primary display. 1502 // Move back to primary display.
1443 window2->SetBounds(gfx::Rect(50, 50, 50, 50)); 1503 window2->SetBounds(gfx::Rect(50, 50, 50, 50));
1444 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 1504 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1445 } 1505 }
1446 1506
1447 #if defined(OS_WIN) 1507 // Test that the shelf animates back to its normal position upon a user
1448 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962 1508 // completing a gesture drag.
1449 #define MAYBE_GestureRevealsTrayBubble DISABLED_GestureRevealsTrayBubble 1509 TEST_F(ShelfLayoutManagerTest, ShelfAnimatesWhenGestureComplete) {
1450 #else 1510 if (!SupportsHostWindowResize())
1451 #define MAYBE_GestureRevealsTrayBubble GestureRevealsTrayBubble 1511 return;
1452 #endif
1453 1512
1454 TEST_F(ShelfLayoutManagerTest, MAYBE_GestureRevealsTrayBubble) { 1513 // Test the shelf animates back to its original visible bounds when it is
1514 // dragged when there are no visible windows.
1515 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1516 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1517 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1518 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1519 gfx::Rect visible_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
1520 {
1521 // Enable animations so that we can make sure that they occur.
1522 ui::ScopedAnimationDurationScaleMode regular_animations(
1523 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
1524
1525 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1526 gfx::Rect shelf_bounds_in_screen =
1527 GetShelfWidget()->GetWindowBoundsInScreen();
1528 gfx::Point start(shelf_bounds_in_screen.CenterPoint());
1529 gfx::Point end(start.x(), shelf_bounds_in_screen.bottom());
1530 generator.GestureScrollSequence(start, end,
1531 base::TimeDelta::FromMilliseconds(10), 1);
1532 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1533 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1534
1535 ShelfAnimationWaiter waiter(visible_bounds);
1536 // Wait till the animation completes and check that it occurred.
1537 waiter.WaitTillDoneAnimating();
1538 EXPECT_TRUE(waiter.WasValidAnimation());
1539 }
1540
1541 // Create a visible window so auto-hide behavior is enforced.
1542 CreateTestWidget();
1543
1544 // Get the bounds of the shelf when it is hidden.
1545 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1546 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1547 gfx::Rect auto_hidden_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
1548
1549 {
1550 // Enable the animations so that we can make sure they do occur.
1551 ui::ScopedAnimationDurationScaleMode regular_animations(
1552 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
1553
1554 gfx::Point start =
1555 GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
1556 gfx::Point end(start.x(), start.y() - 100);
1557 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1558
1559 // Test that the shelf animates to the visible bounds after a swipe up on
1560 // the auto hidden shelf.
1561 generator.GestureScrollSequence(start, end,
1562 base::TimeDelta::FromMilliseconds(10), 1);
1563 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1564 ShelfAnimationWaiter waiter1(visible_bounds);
1565 waiter1.WaitTillDoneAnimating();
1566 EXPECT_TRUE(waiter1.WasValidAnimation());
1567
1568 // Test that the shelf animates to the auto hidden bounds after a swipe up
1569 // on the visible shelf.
1570 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1571 generator.GestureScrollSequence(start, end,
1572 base::TimeDelta::FromMilliseconds(10), 1);
1573 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1574 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1575 ShelfAnimationWaiter waiter2(auto_hidden_bounds);
1576 waiter2.WaitTillDoneAnimating();
1577 EXPECT_TRUE(waiter2.WasValidAnimation());
1578 }
1579 }
1580
1581 TEST_F(ShelfLayoutManagerTest, GestureRevealsTrayBubble) {
1582 if (!SupportsHostWindowResize())
1583 return;
1584
1455 ShelfLayoutManager* shelf = GetShelfLayoutManager(); 1585 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1456 shelf->LayoutShelf(); 1586 shelf->LayoutShelf();
1457 1587
1458 // Create a visible window so auto-hide behavior is enforced. 1588 // Create a visible window so auto-hide behavior is enforced.
1459 CreateTestWidget(); 1589 CreateTestWidget();
1460 1590
1461 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1591 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1462 SystemTray* tray = GetSystemTray(); 1592 SystemTray* tray = GetSystemTray();
1463 1593
1464 // First, make sure the shelf is visible. 1594 // First, make sure the shelf is visible.
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 scoped_ptr<aura::Window> w1(CreateTestWindow()); 1824 scoped_ptr<aura::Window> w1(CreateTestWindow());
1695 w1->Show(); 1825 w1->Show();
1696 wm::ActivateWindow(w1.get()); 1826 wm::ActivateWindow(w1.get());
1697 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType()); 1827 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType());
1698 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 1828 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1699 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType()); 1829 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType());
1700 } 1830 }
1701 1831
1702 } // namespace internal 1832 } // namespace internal
1703 } // namespace ash 1833 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_layout_manager.cc ('k') | ash/shelf/shelf_widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698