Commit 73d4ef09 authored by Manu Cornet's avatar Manu Cornet

CrOS Shelf: Add a class to wait for any widget's animations to finish

Reuse the existing ShelfAnimationWaiter and generalize it a little bit.

TBR: mmourgos
Bug: 1050788
Change-Id: Ica852940cb765143c242c2fa3f101c28cca6922a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2051025Reviewed-by: default avatarManu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740458}
parent 3c76ec62
......@@ -1865,6 +1865,8 @@ test("ash_unittests") {
"shelf/test/overview_animation_waiter.h",
"shelf/test/shelf_layout_manager_test_base.cc",
"shelf/test/shelf_layout_manager_test_base.h",
"shelf/test/widget_animation_waiter.cc",
"shelf/test/widget_animation_waiter.h",
"shell_state_unittest.cc",
"shell_unittest.cc",
"sticky_keys/sticky_keys_overlay_unittest.cc",
......
......@@ -52,6 +52,7 @@
#include "ash/shelf/test/hotseat_state_watcher.h"
#include "ash/shelf/test/overview_animation_waiter.h"
#include "ash/shelf/test/shelf_layout_manager_test_base.h"
#include "ash/shelf/test/widget_animation_waiter.h"
#include "ash/shell.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_test_helper.h"
......@@ -84,7 +85,6 @@
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/ui_base_switches.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/display/display.h"
......@@ -132,54 +132,6 @@ gfx::Rect GetScreenAvailableBounds() {
return available_bounds;
}
// TODO(mmourgos): Move ShelfAnimationWaiter into a separate file in
// ash/shelf/test.
// Class which waits until the ShelfWidget finishes animating and verifies that
// the layer transform animation was valid.
class ShelfAnimationWaiter : ui::LayerAnimationObserver {
public:
explicit ShelfAnimationWaiter(gfx::Rect target_bounds)
: target_bounds_(target_bounds),
animator_(GetShelfWidget()->GetLayer()->GetAnimator()) {
animator_->AddObserver(this);
}
~ShelfAnimationWaiter() override { animator_->RemoveObserver(this); }
// ui::LayerAnimationObserver:
void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override {
if (!animator_->is_animating() && animation_scheduled_) {
EXPECT_EQ(GetShelfWidget()->GetWindowBoundsInScreen(), target_bounds_);
EXPECT_EQ(GetShelfWidget()->GetLayer()->transform(), gfx::Transform());
is_valid_animation_ = true;
animator_->RemoveObserver(this);
run_loop_.Quit();
}
}
void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override {}
void OnLayerAnimationScheduled(
ui::LayerAnimationSequence* sequence) override {
animation_scheduled_ = true;
EXPECT_NE(GetShelfWidget()->GetLayer()->transform(), gfx::Transform());
}
void WaitForAnimation() { run_loop_.Run(); }
// Returns true if the animation has completed.
bool WasValidAnimation() {
return animation_scheduled_ && is_valid_animation_;
}
private:
gfx::Rect target_bounds_;
ui::LayerAnimator* animator_;
base::RunLoop run_loop_;
bool is_valid_animation_ = false;
bool animation_scheduled_ = false;
DISALLOW_COPY_AND_ASSIGN(ShelfAnimationWaiter);
};
class TestDisplayObserver : public display::DisplayObserver {
public:
TestDisplayObserver() { display::Screen::GetScreen()->AddObserver(this); }
......@@ -1513,7 +1465,7 @@ TEST_P(ShelfLayoutManagerTest,
GetShelfWidget()->GetWindowBoundsInScreen();
gfx::Point start(shelf_bounds_in_screen.CenterPoint());
gfx::Point end(start.x(), shelf_bounds_in_screen.bottom());
ShelfAnimationWaiter waiter(visible_bounds);
WidgetAnimationWaiter waiter(GetShelfWidget(), visible_bounds);
generator->GestureScrollSequence(start, end,
base::TimeDelta::FromMilliseconds(10), 5);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
......@@ -1552,7 +1504,7 @@ TEST_P(ShelfLayoutManagerTest, ShelfAnimatesToVisibleWhenGestureInComplete) {
gfx::Point end(start.x(), start.y() - 100);
ui::test::EventGenerator* generator = GetEventGenerator();
ShelfAnimationWaiter waiter(visible_bounds);
WidgetAnimationWaiter waiter(GetShelfWidget(), visible_bounds);
generator->GestureScrollSequence(start, end,
base::TimeDelta::FromMilliseconds(10), 1);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
......@@ -1588,7 +1540,7 @@ TEST_P(ShelfLayoutManagerTest,
// Show the shelf first.
display::Display display =
display::Screen::GetScreen()->GetPrimaryDisplay();
ShelfAnimationWaiter waiter1(visible_bounds);
WidgetAnimationWaiter waiter1(GetShelfWidget(), visible_bounds);
generator->MoveMouseTo(display.bounds().bottom_center());
waiter1.WaitForAnimation();
EXPECT_TRUE(waiter1.WasValidAnimation());
......@@ -1598,7 +1550,7 @@ TEST_P(ShelfLayoutManagerTest,
gfx::Point start =
GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
gfx::Point end = gfx::Point(start.x(), start.y() + 100);
ShelfAnimationWaiter waiter2(auto_hidden_bounds);
WidgetAnimationWaiter waiter2(GetShelfWidget(), auto_hidden_bounds);
generator->GestureScrollSequence(start, end,
base::TimeDelta::FromMilliseconds(10), 1);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
......
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shelf/test/widget_animation_waiter.h"
#include "ash/test/ash_test_base.h"
#include "ui/compositor/layer_animation_delegate.h"
#include "ui/compositor/layer_animator.h"
#include "ui/views/widget/widget.h"
namespace ash {
WidgetAnimationWaiter::WidgetAnimationWaiter(views::Widget* widget,
gfx::Rect target_bounds)
: target_bounds_(target_bounds), widget_(widget) {
widget->GetLayer()->GetAnimator()->AddObserver(this);
}
WidgetAnimationWaiter::~WidgetAnimationWaiter() {
widget_->GetLayer()->GetAnimator()->RemoveObserver(this);
}
void WidgetAnimationWaiter::OnLayerAnimationEnded(
ui::LayerAnimationSequence* sequence) {
if (!widget_->GetLayer()->GetAnimator()->is_animating() &&
animation_scheduled_) {
EXPECT_EQ(widget_->GetWindowBoundsInScreen(), target_bounds_);
EXPECT_EQ(widget_->GetLayer()->transform(), gfx::Transform());
is_valid_animation_ = true;
widget_->GetLayer()->GetAnimator()->RemoveObserver(this);
run_loop_.Quit();
}
}
void WidgetAnimationWaiter::OnLayerAnimationAborted(
ui::LayerAnimationSequence* sequence) {}
void WidgetAnimationWaiter::OnLayerAnimationScheduled(
ui::LayerAnimationSequence* sequence) {
animation_scheduled_ = true;
EXPECT_NE(widget_->GetLayer()->transform(), gfx::Transform());
}
void WidgetAnimationWaiter::WaitForAnimation() {
run_loop_.Run();
}
bool WidgetAnimationWaiter::WasValidAnimation() {
return animation_scheduled_ && is_valid_animation_;
}
} // namespace ash
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SHELF_TEST_WIDGET_ANIMATION_WAITER_H_
#define ASH_SHELF_TEST_WIDGET_ANIMATION_WAITER_H_
#include "base/run_loop.h"
#include "ui/compositor/layer_animation_observer.h"
namespace gfx {
class Rect;
}
namespace views {
class Widget;
}
namespace ash {
// Class which waits until for a widget to finish animating and verifies
// that the layer transform animation was valid.
class WidgetAnimationWaiter : ui::LayerAnimationObserver {
public:
WidgetAnimationWaiter(views::Widget* widget, gfx::Rect target_bounds);
~WidgetAnimationWaiter() override;
// ui::LayerAnimationObserver:
void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override;
void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override;
void OnLayerAnimationScheduled(ui::LayerAnimationSequence* sequence) override;
void WaitForAnimation();
// Returns true if the animation has completed.
bool WasValidAnimation();
private:
gfx::Rect target_bounds_;
// Unowned
views::Widget* widget_;
base::RunLoop run_loop_;
bool is_valid_animation_ = false;
bool animation_scheduled_ = false;
};
} // namespace ash
#endif // ASH_SHELF_TEST_WIDGET_ANIMATION_WAITER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment