From cb297d9bbd8ec3dc6d0789045973e6d95a0c8761 Mon Sep 17 00:00:00 2001 From: Alexei Filippov Date: Tue, 3 Jul 2018 17:19:59 +0000 Subject: [PATCH] DevTools: Fix rounding error in animation startTime calculations. The test was flaky because of the rounding errors. BUG=856955 Change-Id: I089ff4efa05935433c6f1cd3a89f8cbad26879d5 Reviewed-on: https://chromium-review.googlesource.com/1123768 Reviewed-by: Dmitry Gozman Commit-Queue: Alexei Filippov Cr-Commit-Position: refs/heads/master@{#572265} --- .../WebKit/LayoutTests/TestExpectations | 3 --- .../animation/animation-multiple-frames.js | 2 +- .../inspector/inspector_animation_agent.cc | 18 ++++++++++-------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/third_party/WebKit/LayoutTests/TestExpectations b/third_party/WebKit/LayoutTests/TestExpectations index 192d28f7cf1029..f651989276ae51 100644 --- a/third_party/WebKit/LayoutTests/TestExpectations +++ b/third_party/WebKit/LayoutTests/TestExpectations @@ -4729,9 +4729,6 @@ crbug.com/856601 [ Linux ] fast/css/visited-link-hang.html [ Pass Timeout ] crbug.com/856601 [ Linux ] http/tests/devtools/elements/styles-4/styles-inline-element-style-changes-should-not-force-style-recalc.js [ Pass Timeout ] crbug.com/856601 [ Linux ] virtual/feature-policy-permissions/external/wpt/mediacapture-streams/MediaDevices-IDL-enumerateDevices.html [ Pass Timeout ] -# Sheriff 2018-06-27 -crbug.com/856955 [ Win10 Linux ] inspector-protocol/animation/animation-multiple-frames.js [ Failure Pass ] - # Sheriff 2018-06-28 crbug.com/857520 [ Mac Win ] external/wpt/accelerometer/Accelerometer-iframe-access.https.html [ Failure ] diff --git a/third_party/WebKit/LayoutTests/inspector-protocol/animation/animation-multiple-frames.js b/third_party/WebKit/LayoutTests/inspector-protocol/animation/animation-multiple-frames.js index 55e782c9f8bbbe..c9e7b3639176f6 100644 --- a/third_party/WebKit/LayoutTests/inspector-protocol/animation/animation-multiple-frames.js +++ b/third_party/WebKit/LayoutTests/inspector-protocol/animation/animation-multiple-frames.js @@ -23,7 +23,7 @@ if (!lastStartTime || animation.startTime >= lastStartTime) testRunner.log('Animation started: start time is valid'); else if (lastStartTime) - testRunner.log('Animation started: invalid startTime!' + animation.startTime + '.' + lastStartTime); + testRunner.log(`Animation started: invalid startTime: ${animation.startTime} < ${lastStartTime}`); lastStartTime = animation.startTime; numberAnimationsCaptured++; diff --git a/third_party/blink/renderer/core/inspector/inspector_animation_agent.cc b/third_party/blink/renderer/core/inspector/inspector_animation_agent.cc index 4418c0160c10fc..cdd317fd95c204 100644 --- a/third_party/blink/renderer/core/inspector/inspector_animation_agent.cc +++ b/third_party/blink/renderer/core/inspector/inspector_animation_agent.cc @@ -547,16 +547,18 @@ DocumentTimeline& InspectorAnimationAgent::ReferenceTimeline() { double InspectorAnimationAgent::NormalizedStartTime( blink::Animation& animation) { + double time_ms = animation.startTime().value_or(NullValue()); if (ReferenceTimeline().PlaybackRate() == 0) { - return animation.startTime().value_or(NullValue()) + - ReferenceTimeline().currentTime() - - animation.TimelineInternal()->currentTime(); + time_ms += ReferenceTimeline().currentTime() - + animation.TimelineInternal()->currentTime(); + } else { + time_ms += (animation.TimelineInternal()->ZeroTime() - + ReferenceTimeline().ZeroTime()) + .InMillisecondsF() * + ReferenceTimeline().PlaybackRate(); } - return animation.startTime().value_or(NullValue()) + - (animation.TimelineInternal()->ZeroTime() - - ReferenceTimeline().ZeroTime()) - .InMillisecondsF() * - ReferenceTimeline().PlaybackRate(); + // Round to the closest microsecond. + return std::round(time_ms * 1000) / 1000; } void InspectorAnimationAgent::Trace(blink::Visitor* visitor) {