Commit 70979cfb authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Chromium LUCI CQ

Fix animation throughput reporter test flakiness

* I give up using mock time because it still doesn't drive
  begin frame correctly.
* Factor out the TestReporter as a ThroughputReporterTesterBase template.
* Changed animation_throughput_reporter_unittest to use it.
Bug: 1157649

Change-Id: I876167808bc6c11872de64bfc9bc6e4263592f1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2581519Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841281}
parent 640f5b3d
...@@ -151,6 +151,8 @@ static_library("test_support") { ...@@ -151,6 +151,8 @@ static_library("test_support") {
"test/test_suite.h", "test/test_suite.h",
"test/test_utils.cc", "test/test_utils.cc",
"test/test_utils.h", "test/test_utils.h",
"test/throughput_report_checker.cc",
"test/throughput_report_checker.h",
] ]
if (is_android) { if (is_android) {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ui/compositor/layer_animator.h" #include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/compositor/test/animation_throughput_reporter_test_base.h" #include "ui/compositor/test/animation_throughput_reporter_test_base.h"
#include "ui/compositor/test/throughput_report_checker.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
namespace ui { namespace ui {
...@@ -27,22 +28,18 @@ TEST_F(AnimationThroughputReporterTest, ImplicitAnimation) { ...@@ -27,22 +28,18 @@ TEST_F(AnimationThroughputReporterTest, ImplicitAnimation) {
layer.SetOpacity(0.5f); layer.SetOpacity(0.5f);
root_layer()->Add(&layer); root_layer()->Add(&layer);
base::RunLoop run_loop; ThroughputReportChecker checker(this);
{ {
LayerAnimator* animator = layer.GetAnimator(); LayerAnimator* animator = layer.GetAnimator();
AnimationThroughputReporter reporter( AnimationThroughputReporter reporter(animator,
animator, base::BindLambdaForTesting( checker.repeating_callback());
[&](const cc::FrameSequenceMetrics::CustomReportData&) {
run_loop.Quit();
}));
ScopedLayerAnimationSettings settings(animator); ScopedLayerAnimationSettings settings(animator);
settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(48)); settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(48));
layer.SetOpacity(1.0f); layer.SetOpacity(1.0f);
} }
// The animation starts in next frame (16ms) and ends 48 ms later. // The animation starts in next frame (16ms) and ends 48 ms later.
Advance(base::TimeDelta::FromMilliseconds(64)); EXPECT_TRUE(checker.WaitUntilReported());
run_loop.Run();
} }
// Tests animation throughput collection with implicit animation setup before // Tests animation throughput collection with implicit animation setup before
...@@ -51,14 +48,11 @@ TEST_F(AnimationThroughputReporterTest, ImplicitAnimationLateAttach) { ...@@ -51,14 +48,11 @@ TEST_F(AnimationThroughputReporterTest, ImplicitAnimationLateAttach) {
Layer layer; Layer layer;
layer.SetOpacity(0.5f); layer.SetOpacity(0.5f);
base::RunLoop run_loop; ThroughputReportChecker checker(this);
{ {
LayerAnimator* animator = layer.GetAnimator(); LayerAnimator* animator = layer.GetAnimator();
AnimationThroughputReporter reporter( AnimationThroughputReporter reporter(animator,
animator, base::BindLambdaForTesting( checker.repeating_callback());
[&](const cc::FrameSequenceMetrics::CustomReportData&) {
run_loop.Quit();
}));
ScopedLayerAnimationSettings settings(animator); ScopedLayerAnimationSettings settings(animator);
settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(48)); settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(48));
...@@ -67,8 +61,7 @@ TEST_F(AnimationThroughputReporterTest, ImplicitAnimationLateAttach) { ...@@ -67,8 +61,7 @@ TEST_F(AnimationThroughputReporterTest, ImplicitAnimationLateAttach) {
// Attach to root after animation setup. // Attach to root after animation setup.
root_layer()->Add(&layer); root_layer()->Add(&layer);
Advance(base::TimeDelta::FromMilliseconds(64)); EXPECT_TRUE(checker.WaitUntilReported());
run_loop.Run();
} }
// Tests animation throughput collection with explicitly created animation // Tests animation throughput collection with explicitly created animation
...@@ -78,21 +71,15 @@ TEST_F(AnimationThroughputReporterTest, ExplicitAnimation) { ...@@ -78,21 +71,15 @@ TEST_F(AnimationThroughputReporterTest, ExplicitAnimation) {
layer.SetOpacity(0.5f); layer.SetOpacity(0.5f);
root_layer()->Add(&layer); root_layer()->Add(&layer);
base::RunLoop run_loop; ThroughputReportChecker checker(this);
{ LayerAnimator* animator = layer.GetAnimator();
LayerAnimator* animator = layer.GetAnimator(); AnimationThroughputReporter reporter(animator, checker.repeating_callback());
AnimationThroughputReporter reporter(
animator, base::BindLambdaForTesting( animator->ScheduleAnimation(
[&](const cc::FrameSequenceMetrics::CustomReportData&) { new LayerAnimationSequence(LayerAnimationElement::CreateOpacityElement(
run_loop.Quit(); 1.0f, base::TimeDelta::FromMilliseconds(48))));
}));
EXPECT_TRUE(checker.WaitUntilReported());
animator->ScheduleAnimation(
new LayerAnimationSequence(LayerAnimationElement::CreateOpacityElement(
1.0f, base::TimeDelta::FromMilliseconds(48))));
}
Advance(base::TimeDelta::FromMilliseconds(64));
run_loop.Run();
} }
// Tests animation throughput collection for a persisted animator of a Layer. // Tests animation throughput collection for a persisted animator of a Layer.
...@@ -106,24 +93,18 @@ TEST_F(AnimationThroughputReporterTest, PersistedAnimation) { ...@@ -106,24 +93,18 @@ TEST_F(AnimationThroughputReporterTest, PersistedAnimation) {
new LayerAnimator(base::TimeDelta::FromMilliseconds(48)); new LayerAnimator(base::TimeDelta::FromMilliseconds(48));
layer->SetAnimator(animator); layer->SetAnimator(animator);
std::unique_ptr<base::RunLoop> run_loop = std::make_unique<base::RunLoop>();
// |reporter| keeps reporting as long as it is alive. // |reporter| keeps reporting as long as it is alive.
AnimationThroughputReporter reporter( ThroughputReportChecker checker(this);
animator, base::BindLambdaForTesting( AnimationThroughputReporter reporter(animator, checker.repeating_callback());
[&](const cc::FrameSequenceMetrics::CustomReportData&) {
run_loop->Quit();
}));
// Report data for animation of opacity goes to 1. // Report data for animation of opacity goes to 1.
layer->SetOpacity(1.0f); layer->SetOpacity(1.0f);
Advance(base::TimeDelta::FromMilliseconds(64)); EXPECT_TRUE(checker.WaitUntilReported());
run_loop->Run();
// Report data for animation of opacity goes to 0.5. // Report data for animation of opacity goes to 0.5.
run_loop = std::make_unique<base::RunLoop>(); checker.reset();
layer->SetOpacity(0.5f); layer->SetOpacity(0.5f);
Advance(base::TimeDelta::FromMilliseconds(64)); EXPECT_TRUE(checker.WaitUntilReported());
run_loop->Run();
} }
// Tests animation throughput not reported when animation is aborted. // Tests animation throughput not reported when animation is aborted.
...@@ -132,13 +113,14 @@ TEST_F(AnimationThroughputReporterTest, AbortedAnimation) { ...@@ -132,13 +113,14 @@ TEST_F(AnimationThroughputReporterTest, AbortedAnimation) {
layer->SetOpacity(0.5f); layer->SetOpacity(0.5f);
root_layer()->Add(layer.get()); root_layer()->Add(layer.get());
ThroughputReportChecker checker(this, /*fail_if_reported=*/true);
// Reporter started monitoring animation, then deleted, which should be
// reported when the animation ends.
{ {
LayerAnimator* animator = layer->GetAnimator(); LayerAnimator* animator = layer->GetAnimator();
AnimationThroughputReporter reporter( AnimationThroughputReporter reporter(animator,
animator, base::BindLambdaForTesting( checker.repeating_callback());
[&](const cc::FrameSequenceMetrics::CustomReportData&) {
ADD_FAILURE() << "No report for aborted animations.";
}));
ScopedLayerAnimationSettings settings(animator); ScopedLayerAnimationSettings settings(animator);
settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(48)); settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(48));
...@@ -150,6 +132,9 @@ TEST_F(AnimationThroughputReporterTest, AbortedAnimation) { ...@@ -150,6 +132,9 @@ TEST_F(AnimationThroughputReporterTest, AbortedAnimation) {
// Wait a bit to ensure that report does not happen. // Wait a bit to ensure that report does not happen.
Advance(base::TimeDelta::FromMilliseconds(100)); Advance(base::TimeDelta::FromMilliseconds(100));
// TODO(crbug.com/1158510): Test the scenario where the report exists when the
// layer is removed.
} }
// Tests no report and no leak when underlying layer is gone before reporter. // Tests no report and no leak when underlying layer is gone before reporter.
...@@ -158,13 +143,9 @@ TEST_F(AnimationThroughputReporterTest, LayerDestroyedBeforeReporter) { ...@@ -158,13 +143,9 @@ TEST_F(AnimationThroughputReporterTest, LayerDestroyedBeforeReporter) {
layer->SetOpacity(0.5f); layer->SetOpacity(0.5f);
root_layer()->Add(layer.get()); root_layer()->Add(layer.get());
ThroughputReportChecker checker(this, /*fail_if_reported=*/true);
LayerAnimator* animator = layer->GetAnimator(); LayerAnimator* animator = layer->GetAnimator();
AnimationThroughputReporter reporter( AnimationThroughputReporter reporter(animator, checker.repeating_callback());
animator, base::BindLambdaForTesting(
[&](const cc::FrameSequenceMetrics::CustomReportData&) {
ADD_FAILURE() << "No report for aborted animations.";
}));
{ {
ScopedLayerAnimationSettings settings(animator); ScopedLayerAnimationSettings settings(animator);
settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(48)); settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(48));
...@@ -184,14 +165,11 @@ TEST_F(AnimationThroughputReporterTest, NoReportOnDetach) { ...@@ -184,14 +165,11 @@ TEST_F(AnimationThroughputReporterTest, NoReportOnDetach) {
layer->SetOpacity(0.5f); layer->SetOpacity(0.5f);
root_layer()->Add(layer.get()); root_layer()->Add(layer.get());
ThroughputReportChecker checker(this, /*fail_if_reported=*/true);
{ {
LayerAnimator* animator = layer->GetAnimator(); LayerAnimator* animator = layer->GetAnimator();
AnimationThroughputReporter reporter( AnimationThroughputReporter reporter(animator,
animator, base::BindLambdaForTesting( checker.repeating_callback());
[&](const cc::FrameSequenceMetrics::CustomReportData&) {
ADD_FAILURE() << "No report for aborted animations.";
}));
ScopedLayerAnimationSettings settings(animator); ScopedLayerAnimationSettings settings(animator);
settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(48)); settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(48));
layer->SetOpacity(1.0f); layer->SetOpacity(1.0f);
...@@ -211,16 +189,12 @@ TEST_F(AnimationThroughputReporterTest, EndDetachedNoReportNoLeak) { ...@@ -211,16 +189,12 @@ TEST_F(AnimationThroughputReporterTest, EndDetachedNoReportNoLeak) {
auto layer = std::make_unique<Layer>(); auto layer = std::make_unique<Layer>();
layer->SetOpacity(0.5f); layer->SetOpacity(0.5f);
ThroughputReportChecker checker(this, /*fail_if_reported=*/true);
LayerAnimator* animator = layer->GetAnimator(); LayerAnimator* animator = layer->GetAnimator();
// Schedule an animation without being attached to a root. // Schedule an animation without being attached to a root.
{ {
AnimationThroughputReporter reporter( AnimationThroughputReporter reporter(animator,
animator, base::BindLambdaForTesting( checker.repeating_callback());
[&](const cc::FrameSequenceMetrics::CustomReportData&) {
ADD_FAILURE() << "No report for aborted animations.";
}));
ScopedLayerAnimationSettings settings(animator); ScopedLayerAnimationSettings settings(animator);
settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(50)); settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(50));
layer->SetOpacity(1.0f); layer->SetOpacity(1.0f);
...@@ -243,16 +217,12 @@ TEST_F(AnimationThroughputReporterTest, ReportForAnimateToNewTarget) { ...@@ -243,16 +217,12 @@ TEST_F(AnimationThroughputReporterTest, ReportForAnimateToNewTarget) {
layer->SetBounds(gfx::Rect(0, 0, 1, 2)); layer->SetBounds(gfx::Rect(0, 0, 1, 2));
root_layer()->Add(layer.get()); root_layer()->Add(layer.get());
ThroughputReportChecker checker(this, /*fail_if_reported=*/true);
LayerAnimator* animator = layer->GetAnimator(); LayerAnimator* animator = layer->GetAnimator();
// Schedule an animation that will be preempted. No report should happen. // Schedule an animation that will be preempted. No report should happen.
{ {
AnimationThroughputReporter reporter( AnimationThroughputReporter reporter(animator,
animator, base::BindLambdaForTesting( checker.repeating_callback());
[&](const cc::FrameSequenceMetrics::CustomReportData&) {
ADD_FAILURE() << "No report for aborted animations.";
}));
ScopedLayerAnimationSettings settings(animator); ScopedLayerAnimationSettings settings(animator);
settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(50)); settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(50));
layer->SetOpacity(0.5f); layer->SetOpacity(0.5f);
...@@ -260,14 +230,10 @@ TEST_F(AnimationThroughputReporterTest, ReportForAnimateToNewTarget) { ...@@ -260,14 +230,10 @@ TEST_F(AnimationThroughputReporterTest, ReportForAnimateToNewTarget) {
} }
// Animate to new target. Report should happen. // Animate to new target. Report should happen.
base::RunLoop run_loop; ThroughputReportChecker checker2(this);
{ {
AnimationThroughputReporter reporter( AnimationThroughputReporter reporter(animator,
animator, base::BindLambdaForTesting( checker2.repeating_callback());
[&](const cc::FrameSequenceMetrics::CustomReportData&) {
run_loop.Quit();
}));
ScopedLayerAnimationSettings settings(animator); ScopedLayerAnimationSettings settings(animator);
settings.SetPreemptionStrategy( settings.SetPreemptionStrategy(
LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
...@@ -275,8 +241,7 @@ TEST_F(AnimationThroughputReporterTest, ReportForAnimateToNewTarget) { ...@@ -275,8 +241,7 @@ TEST_F(AnimationThroughputReporterTest, ReportForAnimateToNewTarget) {
layer->SetOpacity(1.0f); layer->SetOpacity(1.0f);
layer->SetBounds(gfx::Rect(0, 0, 5, 6)); layer->SetBounds(gfx::Rect(0, 0, 5, 6));
} }
Advance(base::TimeDelta::FromMilliseconds(64)); EXPECT_TRUE(checker2.WaitUntilReported());
run_loop.Run();
} }
} // namespace ui } // namespace ui
...@@ -47,14 +47,14 @@ void AnimationThroughputReporterTestBase::TearDown() { ...@@ -47,14 +47,14 @@ void AnimationThroughputReporterTestBase::TearDown() {
void AnimationThroughputReporterTestBase::Advance( void AnimationThroughputReporterTestBase::Advance(
const base::TimeDelta& delta) { const base::TimeDelta& delta) {
#if BUILDFLAG(IS_CHROMEOS_ASH) run_loop_ = std::make_unique<base::RunLoop>();
task_environment_.FastForwardBy(delta);
#else
base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), delta); FROM_HERE, run_loop_->QuitClosure(), delta);
run_loop.Run(); run_loop_->Run();
#endif }
void AnimationThroughputReporterTestBase::QuitRunLoop() {
run_loop_->Quit();
} }
} // namespace ui } // namespace ui
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/test/test_compositor_host.h" #include "ui/compositor/test/test_compositor_host.h"
namespace base {
class RunLoop;
}
namespace ui { namespace ui {
class TestContextFactories; class TestContextFactories;
...@@ -39,13 +43,11 @@ class AnimationThroughputReporterTestBase : public testing::Test { ...@@ -39,13 +43,11 @@ class AnimationThroughputReporterTestBase : public testing::Test {
// Advances the time by |delta|. // Advances the time by |delta|.
void Advance(const base::TimeDelta& delta); void Advance(const base::TimeDelta& delta);
void QuitRunLoop();
private: private:
base::test::TaskEnvironment task_environment_{ base::test::TaskEnvironment task_environment_{
#if BUILDFLAG(IS_CHROMEOS_ASH) base::test::TaskEnvironment::MainThreadType::UI};
base::test::TaskEnvironment::TimeSource::MOCK_TIME,
#endif
base::test::TaskEnvironment::MainThreadType::UI
};
std::unique_ptr<TestContextFactories> context_factories_; std::unique_ptr<TestContextFactories> context_factories_;
std::unique_ptr<TestCompositorHost> host_; std::unique_ptr<TestCompositorHost> host_;
...@@ -54,6 +56,8 @@ class AnimationThroughputReporterTestBase : public testing::Test { ...@@ -54,6 +56,8 @@ class AnimationThroughputReporterTestBase : public testing::Test {
// A timer to generate continuous compositor frames to trigger throughput // A timer to generate continuous compositor frames to trigger throughput
// data being transferred back. // data being transferred back.
base::RepeatingTimer frame_generation_timer_; base::RepeatingTimer frame_generation_timer_;
std::unique_ptr<base::RunLoop> run_loop_;
}; };
} // namespace ui } // namespace ui
......
// Copyright 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 "ui/compositor/test/throughput_report_checker.h"
#include "base/time/time.h"
#include "ui/compositor/test/animation_throughput_reporter_test_base.h"
namespace ui {
bool ThroughputReportChecker::WaitUntilReported() {
DCHECK(!reported_);
test_base_->Advance(base::TimeDelta::FromSeconds(5));
return reported_;
}
void ThroughputReportChecker::OnReport(
const cc::FrameSequenceMetrics::CustomReportData&) {
reported_ = true;
if (fail_if_reported_)
ADD_FAILURE() << "It should not be reported.";
test_base_->QuitRunLoop();
}
} // namespace ui
// Copyright 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 UI_COMPOSITOR_TEST_THROUGHPUT_REPORT_CHECKER_H_
#define UI_COMPOSITOR_TEST_THROUGHPUT_REPORT_CHECKER_H_
#include <memory>
#include "base/bind.h"
#include "cc/metrics/frame_sequence_metrics.h"
namespace ui {
class AnimationThroughputReporterTestBase;
class ThroughputReportChecker {
public:
using ReportRepeatingCallback = base::RepeatingCallback<void(
const cc::FrameSequenceMetrics::CustomReportData&)>;
using ReportOnceCallback = base::OnceCallback<void(
const cc::FrameSequenceMetrics::CustomReportData&)>;
explicit ThroughputReportChecker(
AnimationThroughputReporterTestBase* test_base,
bool fail_if_reported = false)
: test_base_(test_base), fail_if_reported_(fail_if_reported) {}
ThroughputReportChecker(const ThroughputReportChecker&) = delete;
ThroughputReportChecker& operator=(const ThroughputReportChecker&) = delete;
~ThroughputReportChecker() = default;
bool reported() const { return reported_; }
void reset() { reported_ = false; }
ReportRepeatingCallback repeating_callback() {
return base::BindRepeating(&ThroughputReportChecker::OnReport,
base::Unretained(this));
}
ReportOnceCallback once_callback() {
return base::BindOnce(&ThroughputReportChecker::OnReport,
base::Unretained(this));
}
// It waits until reported up to 5 seconds timeout. Returns true if it's
// reported.
bool WaitUntilReported();
private:
void OnReport(const cc::FrameSequenceMetrics::CustomReportData&);
AnimationThroughputReporterTestBase* test_base_;
bool reported_ = false;
bool fail_if_reported_ = false;
};
} // namespace ui
#endif // UI_COMPOSITOR_TEST_THROUGHPUT_REPORT_CHECKER_H_
...@@ -10,114 +10,47 @@ ...@@ -10,114 +10,47 @@
#include "base/test/bind.h" #include "base/test/bind.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "cc/metrics/frame_sequence_metrics.h" #include "cc/metrics/frame_sequence_metrics.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_sequence.h" #include "ui/compositor/layer_animation_sequence.h"
#include "ui/compositor/layer_animator.h" #include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/compositor/test/animation_throughput_reporter_test_base.h" #include "ui/compositor/test/animation_throughput_reporter_test_base.h"
#include "ui/gfx/geometry/rect.h" #include "ui/compositor/test/throughput_report_checker.h"
namespace ui { namespace ui {
namespace {
class TestReporter : public TotalAnimationThroughputReporter {
public:
explicit TestReporter(AnimationThroughputReporterTestBase* test_base)
: ui::TotalAnimationThroughputReporter(
test_base->compositor(),
base::BindRepeating(&TestReporter::Reported,
base::Unretained(this))),
test_base_(test_base) {}
TestReporter(AnimationThroughputReporterTestBase* test_base,
bool should_delete)
: ui::TotalAnimationThroughputReporter(
test_base->compositor(),
base::BindOnce(&TestReporter::Reported, base::Unretained(this)),
should_delete),
test_base_(test_base) {}
TestReporter(const TestReporter&) = delete;
TestReporter& operator=(const TestReporter&) = delete;
~TestReporter() override = default;
void AdvanceUntilReported(const base::TimeDelta& delta) {
DCHECK(!reported_);
test_base_->Advance(delta);
#if !BUILDFLAG(IS_CHROMEOS_ASH)
// Non ash-chrome platform uses native event loop which doesn't work well
// with mock time, so we still need to run the event loop.
if (!reported_) {
run_loop_ = std::make_unique<base::RunLoop>();
run_loop_->Run();
}
#endif
}
bool reported() const { return reported_; }
void reset() { reported_ = false; }
private:
void Reported(const cc::FrameSequenceMetrics::CustomReportData&) {
reported_ = true;
#if !BUILDFLAG(IS_CHROMEOS_ASH)
if (run_loop_)
run_loop_->Quit();
#endif
}
AnimationThroughputReporterTestBase* test_base_;
bool reported_ = false;
#if !BUILDFLAG(IS_CHROMEOS_ASH)
std::unique_ptr<base::RunLoop> run_loop_;
#endif
};
} // namespace
using TotalAnimationThroughputReporterTest = using TotalAnimationThroughputReporterTest =
AnimationThroughputReporterTestBase; AnimationThroughputReporterTestBase;
// Flaky on ChromeOS: crbug.com/1157649 TEST_F(TotalAnimationThroughputReporterTest, SingleAnimation) {
#if defined(OS_CHROMEOS)
#define MAYBE_SingleAnimation DISABLED_SingleAnimation
#else
#define MAYBE_SingleAnimation SingleAnimation
#endif
TEST_F(TotalAnimationThroughputReporterTest, MAYBE_SingleAnimation) {
Layer layer; Layer layer;
layer.SetOpacity(0.5f); layer.SetOpacity(0.5f);
root_layer()->Add(&layer); root_layer()->Add(&layer);
TestReporter reporter(this); ThroughputReportChecker checker(this);
TotalAnimationThroughputReporter reporter(compositor(),
checker.repeating_callback());
{ {
LayerAnimator* animator = layer.GetAnimator(); LayerAnimator* animator = layer.GetAnimator();
ScopedLayerAnimationSettings settings(animator); ScopedLayerAnimationSettings settings(animator);
settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(48)); settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(48));
layer.SetOpacity(1.0f); layer.SetOpacity(1.0f);
} }
Advance(base::TimeDelta::FromMilliseconds(32)); Advance(base::TimeDelta::FromMilliseconds(32));
EXPECT_FALSE(reporter.reported()); EXPECT_FALSE(checker.reported());
reporter.AdvanceUntilReported(base::TimeDelta::FromMilliseconds(32)); EXPECT_TRUE(checker.WaitUntilReported());
EXPECT_TRUE(reporter.reported());
} }
// Flaky on ChromeOS: crbug.com/1157649
#if defined(OS_CHROMEOS)
#define MAYBE_StopAnimation DISABLED_StopAnimation
#else
#define MAYBE_StopAnimation StopAnimation
#endif
// Tests the stopping last animation will trigger the animation. // Tests the stopping last animation will trigger the animation.
TEST_F(TotalAnimationThroughputReporterTest, MAYBE_StopAnimation) { TEST_F(TotalAnimationThroughputReporterTest, StopAnimation) {
Layer layer; Layer layer;
layer.SetOpacity(0.5f); layer.SetOpacity(0.5f);
root_layer()->Add(&layer); root_layer()->Add(&layer);
TestReporter reporter(this); ThroughputReportChecker checker(this);
TotalAnimationThroughputReporter reporter(compositor(),
checker.repeating_callback());
{ {
LayerAnimator* animator = layer.GetAnimator(); LayerAnimator* animator = layer.GetAnimator();
...@@ -126,10 +59,9 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_StopAnimation) { ...@@ -126,10 +59,9 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_StopAnimation) {
layer.SetOpacity(1.0f); layer.SetOpacity(1.0f);
} }
Advance(base::TimeDelta::FromMilliseconds(32)); Advance(base::TimeDelta::FromMilliseconds(32));
EXPECT_FALSE(reporter.reported()); EXPECT_FALSE(checker.reported());
layer.GetAnimator()->StopAnimating(); layer.GetAnimator()->StopAnimating();
reporter.AdvanceUntilReported(base::TimeDelta::FromMilliseconds(32)); EXPECT_TRUE(checker.WaitUntilReported());
EXPECT_TRUE(reporter.reported());
} }
// Tests the longest animation will trigger the report. // Tests the longest animation will trigger the report.
...@@ -138,7 +70,9 @@ TEST_F(TotalAnimationThroughputReporterTest, MultipleAnimations) { ...@@ -138,7 +70,9 @@ TEST_F(TotalAnimationThroughputReporterTest, MultipleAnimations) {
layer1.SetOpacity(0.5f); layer1.SetOpacity(0.5f);
root_layer()->Add(&layer1); root_layer()->Add(&layer1);
TestReporter reporter(this); ThroughputReportChecker checker(this);
TotalAnimationThroughputReporter reporter(compositor(),
checker.repeating_callback());
{ {
LayerAnimator* animator = layer1.GetAnimator(); LayerAnimator* animator = layer1.GetAnimator();
...@@ -159,29 +93,22 @@ TEST_F(TotalAnimationThroughputReporterTest, MultipleAnimations) { ...@@ -159,29 +93,22 @@ TEST_F(TotalAnimationThroughputReporterTest, MultipleAnimations) {
} }
Advance(base::TimeDelta::FromMilliseconds(32)); Advance(base::TimeDelta::FromMilliseconds(32));
EXPECT_FALSE(reporter.reported()); EXPECT_FALSE(checker.reported());
Advance(base::TimeDelta::FromMilliseconds(32)); Advance(base::TimeDelta::FromMilliseconds(32));
EXPECT_FALSE(reporter.reported()); EXPECT_FALSE(checker.reported());
reporter.AdvanceUntilReported(base::TimeDelta::FromMilliseconds(200)); EXPECT_TRUE(checker.WaitUntilReported());
EXPECT_TRUE(reporter.reported());
} }
// Flaky on ChromeOS: crbug.com/1157649
#if defined(OS_CHROMEOS)
#define MAYBE_MultipleAnimationsOnSingleLayer \
DISABLED_MultipleAnimationsOnSingleLayer
#else
#define MAYBE_MultipleAnimationsOnSingleLayer MultipleAnimationsOnSingleLayer
#endif
// Tests the longest animation on a single layer will triger the report. // Tests the longest animation on a single layer will triger the report.
TEST_F(TotalAnimationThroughputReporterTest, TEST_F(TotalAnimationThroughputReporterTest, MultipleAnimationsOnSingleLayer) {
MAYBE_MultipleAnimationsOnSingleLayer) {
Layer layer; Layer layer;
layer.SetOpacity(0.5f); layer.SetOpacity(0.5f);
layer.SetLayerBrightness(0.5f); layer.SetLayerBrightness(0.5f);
root_layer()->Add(&layer); root_layer()->Add(&layer);
TestReporter reporter(this); ThroughputReportChecker checker(this);
TotalAnimationThroughputReporter reporter(compositor(),
checker.repeating_callback());
{ {
LayerAnimator* animator = layer.GetAnimator(); LayerAnimator* animator = layer.GetAnimator();
...@@ -198,24 +125,19 @@ TEST_F(TotalAnimationThroughputReporterTest, ...@@ -198,24 +125,19 @@ TEST_F(TotalAnimationThroughputReporterTest,
} }
Advance(base::TimeDelta::FromMilliseconds(64)); Advance(base::TimeDelta::FromMilliseconds(64));
EXPECT_FALSE(reporter.reported()); EXPECT_FALSE(checker.reported());
reporter.AdvanceUntilReported(base::TimeDelta::FromMilliseconds(48)); EXPECT_TRUE(checker.WaitUntilReported());
EXPECT_TRUE(reporter.reported());
} }
// Flaky on ChromeOS: crbug.com/1157649
#if defined(OS_CHROMEOS)
#define MAYBE_AddAnimationWhileAnimating DISABLED_AddAnimationWhileAnimating
#else
#define MAYBE_AddAnimationWhileAnimating AddAnimationWhileAnimating
#endif
// Tests adding new animation will extends the duration. // Tests adding new animation will extends the duration.
TEST_F(TotalAnimationThroughputReporterTest, MAYBE_AddAnimationWhileAnimating) { TEST_F(TotalAnimationThroughputReporterTest, AddAnimationWhileAnimating) {
Layer layer1; Layer layer1;
layer1.SetOpacity(0.5f); layer1.SetOpacity(0.5f);
root_layer()->Add(&layer1); root_layer()->Add(&layer1);
TestReporter reporter(this); ThroughputReportChecker checker(this);
TotalAnimationThroughputReporter reporter(compositor(),
checker.repeating_callback());
{ {
LayerAnimator* animator = layer1.GetAnimator(); LayerAnimator* animator = layer1.GetAnimator();
...@@ -225,7 +147,7 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_AddAnimationWhileAnimating) { ...@@ -225,7 +147,7 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_AddAnimationWhileAnimating) {
} }
Advance(base::TimeDelta::FromMilliseconds(32)); Advance(base::TimeDelta::FromMilliseconds(32));
EXPECT_FALSE(reporter.reported()); EXPECT_FALSE(checker.reported());
// Add new animation while animating. // Add new animation while animating.
Layer layer2; Layer layer2;
...@@ -242,25 +164,20 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_AddAnimationWhileAnimating) { ...@@ -242,25 +164,20 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_AddAnimationWhileAnimating) {
// The animation time is extended. // The animation time is extended.
Advance(base::TimeDelta::FromMilliseconds(32)); Advance(base::TimeDelta::FromMilliseconds(32));
EXPECT_FALSE(reporter.reported()); EXPECT_FALSE(checker.reported());
reporter.AdvanceUntilReported(base::TimeDelta::FromMilliseconds(32)); EXPECT_TRUE(checker.WaitUntilReported());
EXPECT_TRUE(reporter.reported());
} }
// Flaky on ChromeOS: crbug.com/1157649
#if defined(OS_CHROMEOS)
#define MAYBE_RemoveWhileAnimating DISABLED_RemoveWhileAnimating
#else
#define MAYBE_RemoveWhileAnimating RemoveWhileAnimating
#endif
// Tests removing last animation will call report callback. // Tests removing last animation will call report callback.
TEST_F(TotalAnimationThroughputReporterTest, MAYBE_RemoveWhileAnimating) { TEST_F(TotalAnimationThroughputReporterTest, RemoveWhileAnimating) {
auto layer1 = std::make_unique<Layer>(); auto layer1 = std::make_unique<Layer>();
layer1->SetOpacity(0.5f); layer1->SetOpacity(0.5f);
root_layer()->Add(layer1.get()); root_layer()->Add(layer1.get());
TestReporter reporter(this); ThroughputReportChecker checker(this);
TotalAnimationThroughputReporter reporter(compositor(),
checker.repeating_callback());
{ {
LayerAnimator* animator = layer1->GetAnimator(); LayerAnimator* animator = layer1->GetAnimator();
...@@ -281,22 +198,15 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_RemoveWhileAnimating) { ...@@ -281,22 +198,15 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_RemoveWhileAnimating) {
layer2.SetOpacity(1.0f); layer2.SetOpacity(1.0f);
} }
Advance(base::TimeDelta::FromMilliseconds(48)); Advance(base::TimeDelta::FromMilliseconds(48));
EXPECT_FALSE(reporter.reported()); EXPECT_FALSE(checker.reported());
layer1.reset(); layer1.reset();
// Aborting will be processed in next frame. // Aborting will be processed in next frame.
reporter.AdvanceUntilReported(base::TimeDelta::FromMilliseconds(16)); EXPECT_TRUE(checker.WaitUntilReported());
EXPECT_TRUE(reporter.reported());
} }
// Flaky on ChromeOS: crbug.com/1157649
#if defined(OS_CHROMEOS)
#define MAYBE_StartWhileAnimating DISABLED_StartWhileAnimating
#else
#define MAYBE_StartWhileAnimating StartWhileAnimating
#endif
// Make sure the reporter can start measuring even if the animation // Make sure the reporter can start measuring even if the animation
// has started. // has started.
TEST_F(TotalAnimationThroughputReporterTest, MAYBE_StartWhileAnimating) { TEST_F(TotalAnimationThroughputReporterTest, StartWhileAnimating) {
Layer layer; Layer layer;
layer.SetOpacity(0.5f); layer.SetOpacity(0.5f);
root_layer()->Add(&layer); root_layer()->Add(&layer);
...@@ -309,20 +219,15 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_StartWhileAnimating) { ...@@ -309,20 +219,15 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_StartWhileAnimating) {
layer.SetOpacity(1.0f); layer.SetOpacity(1.0f);
} }
Advance(base::TimeDelta::FromMilliseconds(32)); Advance(base::TimeDelta::FromMilliseconds(32));
TestReporter reporter(this); ThroughputReportChecker checker(this);
TotalAnimationThroughputReporter reporter(compositor(),
checker.repeating_callback());
EXPECT_TRUE(reporter.IsMeasuringForTesting()); EXPECT_TRUE(reporter.IsMeasuringForTesting());
reporter.AdvanceUntilReported(base::TimeDelta::FromMilliseconds(100)); EXPECT_TRUE(checker.WaitUntilReported());
EXPECT_TRUE(reporter.reported());
} }
// Flaky on ChromeOS: crbug.com/1157649
#if defined(OS_CHROMEOS)
#define MAYBE_PersistedAnimation DISABLED_PersistedAnimation
#else
#define MAYBE_PersistedAnimation PersistedAnimation
#endif
// Tests the reporter is called multiple times for persistent animation. // Tests the reporter is called multiple times for persistent animation.
TEST_F(TotalAnimationThroughputReporterTest, MAYBE_PersistedAnimation) { TEST_F(TotalAnimationThroughputReporterTest, PersistedAnimation) {
Layer layer; Layer layer;
layer.SetOpacity(0.5f); layer.SetOpacity(0.5f);
root_layer()->Add(&layer); root_layer()->Add(&layer);
...@@ -333,28 +238,22 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_PersistedAnimation) { ...@@ -333,28 +238,22 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_PersistedAnimation) {
layer.SetAnimator(animator); layer.SetAnimator(animator);
// |reporter| keeps reporting as long as it is alive. // |reporter| keeps reporting as long as it is alive.
TestReporter reporter(this); ThroughputReportChecker checker(this);
TotalAnimationThroughputReporter reporter(compositor(),
checker.repeating_callback());
// Report data for animation of opacity goes to 1. // Report data for animation of opacity goes to 1.
layer.SetOpacity(1.0f); layer.SetOpacity(1.0f);
reporter.AdvanceUntilReported(base::TimeDelta::FromMilliseconds(100)); EXPECT_TRUE(checker.WaitUntilReported());
EXPECT_TRUE(reporter.reported());
// Report data for animation of opacity goes to 0.5. // Report data for animation of opacity goes to 0.5.
reporter.reset(); checker.reset();
layer.SetOpacity(0.5f); layer.SetOpacity(0.5f);
reporter.AdvanceUntilReported(base::TimeDelta::FromMilliseconds(100)); EXPECT_TRUE(checker.WaitUntilReported());
EXPECT_TRUE(reporter.reported());
} }
// Flaky on ChromeOS: crbug.com/1157649
#if defined(OS_CHROMEOS)
#define MAYBE_OnceReporter DISABLED_OnceReporter
#else
#define MAYBE_OnceReporter OnceReporter
#endif
// Make sure the once reporter is called only once. // Make sure the once reporter is called only once.
TEST_F(TotalAnimationThroughputReporterTest, MAYBE_OnceReporter) { TEST_F(TotalAnimationThroughputReporterTest, OnceReporter) {
Layer layer; Layer layer;
layer.SetOpacity(0.5f); layer.SetOpacity(0.5f);
root_layer()->Add(&layer); root_layer()->Add(&layer);
...@@ -364,29 +263,24 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_OnceReporter) { ...@@ -364,29 +263,24 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_OnceReporter) {
new LayerAnimator(base::TimeDelta::FromMilliseconds(32)); new LayerAnimator(base::TimeDelta::FromMilliseconds(32));
layer.SetAnimator(animator); layer.SetAnimator(animator);
TestReporter reporter(this, /*should_delete=*/false); ThroughputReportChecker checker(this);
TotalAnimationThroughputReporter reporter(
compositor(), checker.once_callback(), /*should_delete=*/false);
// Report data for animation of opacity goes to 1. // Report data for animation of opacity goes to 1.
layer.SetOpacity(1.0f); layer.SetOpacity(1.0f);
reporter.AdvanceUntilReported(base::TimeDelta::FromMilliseconds(100)); EXPECT_TRUE(checker.WaitUntilReported());
EXPECT_TRUE(reporter.reported());
// Report data for animation of opacity goes to 0.5. // Report data for animation of opacity goes to 0.5.
reporter.reset(); checker.reset();
layer.SetOpacity(1.0f); layer.SetOpacity(1.0f);
Advance(base::TimeDelta::FromMilliseconds(100)); Advance(base::TimeDelta::FromMilliseconds(100));
EXPECT_FALSE(reporter.reported()); EXPECT_FALSE(checker.reported());
} }
// Flaky on ChromeOS: crbug.com/1157649
#if defined(OS_CHROMEOS)
#define MAYBE_OnceReporterShouldDelete DISABLED_OnceReporterShouldDelete
#else
#define MAYBE_OnceReporterShouldDelete OnceReporterShouldDelete
#endif
// One reporter marked as "should_delete" should be deleted when // One reporter marked as "should_delete" should be deleted when
// reported. // reported.
TEST_F(TotalAnimationThroughputReporterTest, MAYBE_OnceReporterShouldDelete) { TEST_F(TotalAnimationThroughputReporterTest, OnceReporterShouldDelete) {
class DeleteTestReporter : public TotalAnimationThroughputReporter { class DeleteTestReporter : public TotalAnimationThroughputReporter {
public: public:
DeleteTestReporter(Compositor* compositor, DeleteTestReporter(Compositor* compositor,
...@@ -425,14 +319,7 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_OnceReporterShouldDelete) { ...@@ -425,14 +319,7 @@ TEST_F(TotalAnimationThroughputReporterTest, MAYBE_OnceReporterShouldDelete) {
// Report data for animation of opacity goes to 1. // Report data for animation of opacity goes to 1.
layer.SetOpacity(1.0f); layer.SetOpacity(1.0f);
#if BUILDFLAG(IS_CHROMEOS_ASH)
Advance(base::TimeDelta::FromMilliseconds(48));
EXPECT_FALSE(run_loop.running());
#else
// Non ash-chrome platform uses native event loop which doesn't work
// with mock time, so we need to run more the event loop.
run_loop.Run(); run_loop.Run();
#endif
EXPECT_TRUE(deleted); EXPECT_TRUE(deleted);
} }
......
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