Commit c01892b1 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Use timeout to wait until there is no presentation callback.

Use WeakPtr in PresentationCallback to avoid use-after-scope

Bug: 1043465
Test: run 100 times and no flaky
Change-Id: Iae88d5449c7ae22a05c1b968b938ee0cbdce4c2b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2036873
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarJun Mukai <mukai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738356}
parent 66c4d794
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "build/build_config.h" #include "base/timer/timer.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/compositor/compositor.h" #include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
...@@ -22,25 +23,35 @@ using PresentationTimeRecorderTest = ash::AshTestBase; ...@@ -22,25 +23,35 @@ using PresentationTimeRecorderTest = ash::AshTestBase;
constexpr char kName[] = "Histogram"; constexpr char kName[] = "Histogram";
constexpr char kMaxLatencyName[] = "MaxLatency.Histogram"; constexpr char kMaxLatencyName[] = "MaxLatency.Histogram";
// The test is flaky on CrOS. crbug.com/1043465. TEST_F(PresentationTimeRecorderTest, Histogram) {
#if defined(OS_CHROMEOS)
#define MAYBE_Histogram DISABLED_Histogram
#else
#define MAYBE_Histogram Histogram
#endif
TEST_F(PresentationTimeRecorderTest, MAYBE_Histogram) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
auto* compositor = CurrentContext()->layer()->GetCompositor(); auto* compositor = CurrentContext()->layer()->GetCompositor();
auto test_recorder = CreatePresentationTimeHistogramRecorder( auto test_recorder = CreatePresentationTimeHistogramRecorder(
compositor, kName, kMaxLatencyName); compositor, kName, kMaxLatencyName);
bool timeout = false;
// Flush pending draw requests. // Flush pending draw callbask by waiting for presentation until it times out.
for (int i = 0; i < 30; i++) { do {
compositor->ScheduleFullRedraw(); base::RunLoop runloop;
WaitForNextFrameToBePresented(compositor); base::OneShotTimer timer;
base::RunLoop().RunUntilIdle(); // We assume if the new frame wasn't generated for 100ms (6 frames worth
} // time) there is no pending draw request.
timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(100),
base::BindLambdaForTesting([&runloop, &timeout]() {
runloop.Quit();
timeout = true;
}));
base::WeakPtrFactory<base::RunLoop> runloop_factory(&runloop);
compositor->RequestPresentationTimeForNextFrame(base::BindOnce(
[](base::WeakPtr<base::RunLoop> runloop,
const gfx::PresentationFeedback& feedback) {
if (runloop)
runloop->Quit();
},
runloop_factory.GetWeakPtr()));
runloop.Run();
timer.Stop();
} while (!timeout);
compositor->ScheduleFullRedraw(); compositor->ScheduleFullRedraw();
histogram_tester.ExpectTotalCount(kName, 0); histogram_tester.ExpectTotalCount(kName, 0);
......
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