Index: ash/shelf/shelf_layout_manager_unittest.cc |
diff --git a/ash/shelf/shelf_layout_manager_unittest.cc b/ash/shelf/shelf_layout_manager_unittest.cc |
index 2781e6c2c630a3bb396cf41b0e50d6640d5c5ddb..bd5ee98800d9ad4fb52d45b8a72262dde2766f0f 100644 |
--- a/ash/shelf/shelf_layout_manager_unittest.cc |
+++ b/ash/shelf/shelf_layout_manager_unittest.cc |
@@ -70,6 +70,67 @@ SystemTray* GetSystemTray() { |
return Shell::GetPrimaryRootWindowController()->GetSystemTray(); |
} |
+// Class which waits till the shelf finishes animating to the target size and |
+// counts the number of animation steps. |
+class ShelfAnimationWaiter : views::WidgetObserver { |
sadrul
2013/08/13 17:21:34
: public
|
+ public: |
+ ShelfAnimationWaiter(const gfx::Rect& target_bounds) |
sadrul
2013/08/13 17:21:34
explicit
pkotwicz
2013/08/14 17:03:21
Done.
|
+ : target_bounds_(target_bounds), |
+ animation_steps_(0), |
+ done_waiting_(false) { |
+ GetShelfWidget()->AddObserver(this); |
+ } |
+ |
+ virtual ~ShelfAnimationWaiter() { |
+ GetShelfWidget()->RemoveObserver(this); |
+ } |
+ |
+ // Wait till the shelf finishes animating to its expected bounds. |
+ void WaitTillDoneAnimating() { |
+ if (IsDoneAnimating()) |
+ done_waiting_ = true; |
+ else |
+ base::MessageLoop::current()->Run(); |
+ } |
+ |
+ // Returns true if the animation has completed and it was valid. |
+ bool WasValidAnimation() const { |
+ return done_waiting_ && animation_steps_ > 0; |
+ } |
+ |
+ private: |
+ // Returns true if shelf has finished animating to the target size. |
+ bool IsDoneAnimating() const { |
+ ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); |
+ gfx::Rect current_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); |
+ int size = layout_manager->PrimaryAxisValue(current_bounds.height(), |
+ current_bounds.width()); |
+ int desired_size = layout_manager->PrimaryAxisValue(target_bounds_.height(), |
+ target_bounds_.width()); |
+ return size == desired_size; |
+ } |
+ |
+ // views::WidgetObserver override. |
+ virtual void OnWidgetBoundsChanged(views::Widget* widget, |
+ const gfx::Rect& new_bounds) OVERRIDE { |
+ if (done_waiting_) |
+ return; |
+ |
+ ++animation_steps_; |
+ if (IsDoneAnimating()) { |
+ done_waiting_ = true; |
+ base::MessageLoop::current()->Quit(); |
+ } |
+ } |
+ |
+ gfx::Rect target_bounds_; |
+ int animation_steps_; |
+ bool done_waiting_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ShelfAnimationWaiter); |
+}; |
+ |
+ |
class ShelfDragCallback { |
public: |
ShelfDragCallback(const gfx::Rect& not_visible, const gfx::Rect& visible) |
@@ -576,6 +637,22 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { |
// is fullscreen status. |
widget->Close(); |
RunAllPendingInMessageLoop(); |
+ |
+ // The shelf should be shown because there are no more visible windows. |
+ EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
+ EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
+ EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); |
+ |
+ // Swipe-up to hide. This should have no effect because there are no visible |
+ // windows. |
+ end = below_start - delta; |
+ generator.GestureScrollSequenceWithCallback(below_start, end, |
+ base::TimeDelta::FromMilliseconds(10), kNumScrollSteps, |
+ base::Bind(&ShelfDragCallback::ProcessScroll, |
+ base::Unretained(&handler))); |
+ EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
+ EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
+ EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); |
} |
// Fails on Mac only. Need to be implemented. http://crbug.com/111279. |
@@ -1413,7 +1490,7 @@ TEST_F(ShelfLayoutManagerTest, WindowVisibilityDisablesAutoHide) { |
window1->Minimize(); |
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
- // both minimzed => disable auto hide |
+ // both minimized => disable auto hide |
window2->Minimize(); |
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
@@ -1428,14 +1505,47 @@ TEST_F(ShelfLayoutManagerTest, WindowVisibilityDisablesAutoHide) { |
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
} |
-#if defined(OS_WIN) |
-// RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962 |
-#define MAYBE_GestureRevealsTrayBubble DISABLED_GestureRevealsTrayBubble |
-#else |
-#define MAYBE_GestureRevealsTrayBubble GestureRevealsTrayBubble |
-#endif |
+// Test that the shelf animates back to its normal position upon a user |
+// completing a gesture drag. |
+TEST_F(ShelfLayoutManagerTest, ShelfAnimatesWhenGestureComplete) { |
+ if (!SupportsHostWindowResize()) |
+ return; |
+ |
+ // Create a visible window so auto-hide behavior is enforced. |
+ CreateTestWidget(); |
+ |
+ // Get the bounds of the shelf when it is hidden. |
+ ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
+ shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
+ EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
+ EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
+ |
+ gfx::Rect auto_hidden_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); |
+ shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
+ EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); |
+ |
+ // Reenable the animations so that we can make sure they do occur. |
+ ui::ScopedAnimationDurationScaleMode regular_animations( |
+ ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
+ |
+ aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
+ gfx::Point start = GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint(); |
+ gfx::Point end(start.x(), start.y() - 100); |
+ generator.GestureScrollSequence(start, end, |
+ base::TimeDelta::FromMilliseconds(10), 1); |
+ EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
+ EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
+ |
+ ShelfAnimationWaiter waiter(auto_hidden_bounds); |
+ // Wait till the animation completes and check that it occurred. |
+ waiter.WaitTillDoneAnimating(); |
+ EXPECT_TRUE(waiter.WasValidAnimation()); |
sadrul
2013/08/13 17:21:34
Can we also have a test that the animation happens
pkotwicz
2013/08/14 17:03:21
Done.
|
+} |
+ |
+TEST_F(ShelfLayoutManagerTest, GestureRevealsTrayBubble) { |
+ if (!SupportsHostWindowResize()) |
+ return; |
-TEST_F(ShelfLayoutManagerTest, MAYBE_GestureRevealsTrayBubble) { |
ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
shelf->LayoutShelf(); |