diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index 2edc3b173d82b..7f9473a2b1a2d 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -5,9 +5,11 @@ #define FML_USED_ON_EMBEDDER #include +#include #include #include #include +#include #include #include @@ -676,10 +678,14 @@ static void CheckFrameTimings(const std::vector& timings, } TEST_F(ShellTest, ReportTimingsIsCalled) { - fml::TimePoint start = fml::TimePoint::Now(); auto settings = CreateSettingsForFixture(); std::unique_ptr shell = CreateShell(settings); + // We MUST put |start| after |CreateShell| because the clock source will be + // reset through |TimePoint::SetClockSource()| in + // |DartVMInitializer::Initialize()| within |CreateShell()|. + fml::TimePoint start = fml::TimePoint::Now(); + // Create the surface needed by rasterizer PlatformViewNotifyCreated(shell.get()); @@ -726,19 +732,10 @@ TEST_F(ShellTest, ReportTimingsIsCalled) { } TEST_F(ShellTest, FrameRasterizedCallbackIsCalled) { - fml::TimePoint start = fml::TimePoint::Now(); - auto settings = CreateSettingsForFixture(); - fml::AutoResetWaitableEvent timingLatch; - FrameTiming timing; - - for (auto phase : FrameTiming::kPhases) { - timing.Set(phase, fml::TimePoint()); - // Check that the time points are initially smaller than start, so - // CheckFrameTimings will fail if they're not properly set later. - ASSERT_TRUE(timing.Get(phase) < start); - } + FrameTiming timing; + fml::AutoResetWaitableEvent timingLatch; settings.frame_rasterized_callback = [&timing, &timingLatch](const FrameTiming& t) { timing = t; @@ -747,6 +744,22 @@ TEST_F(ShellTest, FrameRasterizedCallbackIsCalled) { std::unique_ptr shell = CreateShell(settings); + // Wait to make |start| bigger than zero + using namespace std::chrono_literals; + std::this_thread::sleep_for(1ms); + + // We MUST put |start| after |CreateShell()| because the clock source will be + // reset through |TimePoint::SetClockSource()| in + // |DartVMInitializer::Initialize()| within |CreateShell()|. + fml::TimePoint start = fml::TimePoint::Now(); + + for (auto phase : FrameTiming::kPhases) { + timing.Set(phase, fml::TimePoint()); + // Check that the time points are initially smaller than start, so + // CheckFrameTimings will fail if they're not properly set later. + ASSERT_TRUE(timing.Get(phase) < start); + } + // Create the surface needed by rasterizer PlatformViewNotifyCreated(shell.get());