Commit 9c1d49e3 authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

Verify home launcher animation metrics in unit test

This CL verifies that home launcher animation smoothness metrics are
recorded correctly in the following two scenarios:
(1) Enter/exit overview mode
(2) Show home launcher from in-app shelf by gesture swipe.

Bug: 1059449
Change-Id: If908f0d0a0e5f545fbbbe6f06a1b47f1cc9beaf8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2155351Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760560}
parent 7c4642e0
......@@ -4,6 +4,8 @@
#include "ash/home_screen/drag_window_from_shelf_controller.h"
#include "ash/app_list/test/app_list_test_helper.h"
#include "ash/app_list/views/app_list_view.h"
#include "ash/home_screen/drag_window_from_shelf_controller_test_api.h"
#include "ash/home_screen/home_screen_controller.h"
#include "ash/home_screen/home_screen_delegate.h"
......@@ -88,6 +90,21 @@ class DragWindowFromShelfControllerTest : public AshTestBase {
window_drag_controller_->FinalizeDraggedWindow();
}
void CancelDrag() { window_drag_controller_->CancelDrag(); }
void WaitForHomeLauncherAnimationToFinish() {
// Wait until home launcher animation finishes.
while (GetAppListTestHelper()
->GetAppListView()
->GetWidget()
->GetLayer()
->GetAnimator()
->is_animating()) {
base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromMilliseconds(200));
run_loop.Run();
}
}
SplitViewController* split_view_controller() {
return SplitViewController::Get(Shell::GetPrimaryRootWindow());
......@@ -372,6 +389,35 @@ TEST_F(DragWindowFromShelfControllerTest, FlingInOverview) {
EXPECT_TRUE(WindowState::Get(window.get())->IsMinimized());
}
// Verify that metrics of home launcher animation are recorded correctly when
// swiping up from shelf with sufficient velocity.
TEST_F(DragWindowFromShelfControllerTest, VerifyHomeLauncherAnimationMetrics) {
// Set non-zero animation duration to report animation metrics.
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
UpdateDisplay("400x400");
const gfx::Rect shelf_bounds =
Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds();
auto window = CreateTestWindow();
base::HistogramTester histogram_tester;
// Ensure that fling velocity is sufficient to show homelauncher without
// triggering overview mode.
StartDrag(window.get(), shelf_bounds.CenterPoint(), HotseatState::kExtended);
Drag(gfx::Point(200, 200), 0.f,
DragWindowFromShelfController::kOpenOverviewThreshold + 1);
EndDrag(gfx::Point(0, 350),
base::make_optional(
-DragWindowFromShelfController::kVelocityToHomeScreenThreshold));
WaitForHomeLauncherAnimationToFinish();
// Verify that animation to show the home launcher is recorded.
histogram_tester.ExpectTotalCount(
"Apps.HomeLauncherTransition.AnimationSmoothness.FadeOutOverview", 1);
}
// Test if splitview is active when fling happens, the window will be put in
// overview.
TEST_F(DragWindowFromShelfControllerTest, DragOrFlingInSplitView) {
......
......@@ -4,11 +4,14 @@
#include "ash/home_screen/swipe_home_to_overview_controller.h"
#include "ash/app_list/test/app_list_test_helper.h"
#include "ash/app_list/views/app_list_view.h"
#include "ash/home_screen/home_screen_controller.h"
#include "ash/home_screen/home_screen_delegate.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_metrics.h"
#include "ash/shelf/test/overview_animation_waiter.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/overview/overview_controller.h"
......@@ -18,6 +21,7 @@
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_tick_clock.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect_f.h"
......@@ -25,9 +29,12 @@ namespace ash {
namespace {
gfx::RectF GetShelfBounds() {
return gfx::RectF(
Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds());
gfx::Rect GetShelfBounds() {
return Shelf::ForWindow(Shell::GetPrimaryRootWindow())->GetIdealBounds();
}
gfx::RectF GetShelfBoundsInFloat() {
return gfx::RectF(GetShelfBounds());
}
} // namespace
......@@ -89,6 +96,22 @@ class SwipeHomeToOverviewControllerTest : public AshTestBase {
->FireNow();
}
void WaitForHomeLauncherAnimationToFinish() {
// Wait until home launcher animation finishes.
while (GetAppListTestHelper()
->GetAppListView()
->GetWidget()
->GetLayer()
->GetAnimator()
->is_animating()) {
base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromMilliseconds(200));
run_loop.Run();
}
}
base::TimeTicks GetTimerDesiredRunTime() const {
return home_to_overview_controller_->overview_transition_timer_for_testing()
->desired_run_time();
......@@ -108,8 +131,63 @@ class SwipeHomeToOverviewControllerTest : public AshTestBase {
DISALLOW_COPY_AND_ASSIGN(SwipeHomeToOverviewControllerTest);
};
// Verify that the metrics of home launcher animation are recorded correctly
// when entering/exiting overview mode.
TEST_F(SwipeHomeToOverviewControllerTest, VerifyHomeLauncherMetrics) {
// Set non-zero animation duration to report animation metrics.
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
const gfx::Rect shelf_bounds = GetShelfBounds();
const int transition_threshold =
SwipeHomeToOverviewController::kVerticalThresholdForOverviewTransition;
base::HistogramTester histogram_tester;
// Enter overview mode by gesture swipe on shelf.
{
GetEventGenerator()->set_current_screen_location(
shelf_bounds.CenterPoint());
GetEventGenerator()->PressTouch();
GetEventGenerator()->MoveTouchBy(
0, -transition_threshold - shelf_bounds.height() / 2 - 10);
// Move touch location by a tiny distance to ensure the slow scroll speed
// which is required to trigger the overview animation.
GetEventGenerator()->MoveTouchBy(0, -1);
// Wait until overview animation finishes.
OverviewAnimationWaiter enter_overview_waiter;
enter_overview_waiter.Wait();
GetEventGenerator()->ReleaseTouch();
WaitForHomeLauncherAnimationToFinish();
}
// Verify that the animation to hide the home launcher is recorded.
histogram_tester.ExpectTotalCount(
"Apps.HomeLauncherTransition.AnimationSmoothness.FadeInOverview", 1);
histogram_tester.ExpectTotalCount(
"Apps.HomeLauncherTransition.AnimationSmoothness.FadeOutOverview", 0);
// Exit overview mode by gesture tap.
GetEventGenerator()->GestureTapAt(
GetContext()->GetBoundsInScreen().top_center());
// Wait until overview animation finishes.
OverviewAnimationWaiter exit_overview_waiter;
exit_overview_waiter.Wait();
WaitForHomeLauncherAnimationToFinish();
// Verify that the animation to show the home launcher is recorded.
histogram_tester.ExpectTotalCount(
"Apps.HomeLauncherTransition.AnimationSmoothness.FadeInOverview", 1);
histogram_tester.ExpectTotalCount(
"Apps.HomeLauncherTransition.AnimationSmoothness.FadeOutOverview", 1);
}
TEST_F(SwipeHomeToOverviewControllerTest, BasicFlow) {
const gfx::RectF shelf_bounds = GetShelfBounds();
const gfx::RectF shelf_bounds = GetShelfBoundsInFloat();
base::HistogramTester histogram_tester;
histogram_tester.ExpectBucketCount(
......@@ -195,7 +273,7 @@ TEST_F(SwipeHomeToOverviewControllerTest, BasicFlow) {
}
TEST_F(SwipeHomeToOverviewControllerTest, EndDragBeforeTimeout) {
const gfx::RectF shelf_bounds = GetShelfBounds();
const gfx::RectF shelf_bounds = GetShelfBoundsInFloat();
StartDrag();
......@@ -236,7 +314,7 @@ TEST_F(SwipeHomeToOverviewControllerTest, EndDragBeforeTimeout) {
}
TEST_F(SwipeHomeToOverviewControllerTest, CancelDragBeforeTimeout) {
const gfx::RectF shelf_bounds = GetShelfBounds();
const gfx::RectF shelf_bounds = GetShelfBoundsInFloat();
StartDrag();
......@@ -275,7 +353,7 @@ TEST_F(SwipeHomeToOverviewControllerTest, CancelDragBeforeTimeout) {
}
TEST_F(SwipeHomeToOverviewControllerTest, DragMovementRestartsTimeout) {
const gfx::RectF shelf_bounds = GetShelfBounds();
const gfx::RectF shelf_bounds = GetShelfBoundsInFloat();
StartDrag();
......@@ -322,7 +400,7 @@ TEST_F(SwipeHomeToOverviewControllerTest, DragMovementRestartsTimeout) {
TEST_F(SwipeHomeToOverviewControllerTest,
SmallDragMovementDoesNotRestartTimeout) {
const gfx::RectF shelf_bounds = GetShelfBounds();
const gfx::RectF shelf_bounds = GetShelfBoundsInFloat();
StartDrag();
......@@ -376,7 +454,7 @@ TEST_F(SwipeHomeToOverviewControllerTest,
}
TEST_F(SwipeHomeToOverviewControllerTest, DragBellowThresholdStopsTimer) {
const gfx::RectF shelf_bounds = GetShelfBounds();
const gfx::RectF shelf_bounds = GetShelfBoundsInFloat();
StartDrag();
Drag(shelf_bounds.CenterPoint(), 0.f, 1.f);
......@@ -451,7 +529,7 @@ TEST_F(SwipeHomeToOverviewControllerTest, DragBellowThresholdStopsTimer) {
}
TEST_F(SwipeHomeToOverviewControllerTest, ScaleChangesDuringDrag) {
const gfx::RectF shelf_bounds = GetShelfBounds();
const gfx::RectF shelf_bounds = GetShelfBoundsInFloat();
StartDrag();
Drag(shelf_bounds.CenterPoint(), 0.f, 1.f);
......
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