Commit 8bf781d2 authored by Naina Raisinghani's avatar Naina Raisinghani Committed by Commit Bot

UseCounter to check if setting playbackRate causes a compensatory

seek

Add UseCounter to check if setting playbackRate causes a compensatory
seek forcing a change in start_time_. This is as we want to spec this
behaviour on an API level.

Bug: 
Change-Id: Ic6ab06bb482b4e086d2559904bd4f6f4ccdd52eb
Reviewed-on: https://chromium-review.googlesource.com/700057
Commit-Queue: nainar <nainar@chromium.org>
Reviewed-by: default avatardstockwell <dstockwell@chromium.org>
Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506672}
parent 2c0e0228
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body></body>
<script>
'use strict';
// From UseCounter.h
var AnimationSetPlaybackRateCompensatorySeek = 2162;
var MS_PER_SEC = 1000;
function createDiv() {
var element = document.createElement('div');
document.body.appendChild(element);
return element;
}
var div = createDiv();
var animation = div.animate(null, 100 * MS_PER_SEC);
var startTimeBefore = animation.startTime;
animation.currentTime = 7 * MS_PER_SEC; // ms
async_test(t => {
return animation.ready.then(t.step_func_done(() => {
animation.finish();
assert_equals(animation.playState, "finished");
assert_not_equals(animation.startTime, null)
animation.playbackRate = 0.5;
assert_false(internals.isUseCounted(document, AnimationSetPlaybackRateCompensatorySeek));
}))
}, 'Check to ensure that we UseCount when you cause a compensatory seek by setting playbackRate when finished');
</script>
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body></body>
<script>
'use strict';
// From UseCounter.h
var AnimationSetPlaybackRateCompensatorySeek = 2162;
var MS_PER_SEC = 1000;
function createDiv() {
var element = document.createElement('div');
document.body.appendChild(element);
return element;
}
var div = createDiv();
var animation = div.animate(null, 100 * MS_PER_SEC);
var startTimeBefore = animation.startTime;
animation.currentTime = 7 * MS_PER_SEC; // ms
async_test(t => {
return animation.ready.then(t.step_func_done(() => {
var current_time = animation.currentTime;
animation.pause();
animation.currentTime = current_time;
assert_equals(animation.playState, "paused");
animation.playbackRate = 0.5;
assert_false(internals.isUseCounted(document, AnimationSetPlaybackRateCompensatorySeek));
}))
}, 'Check to ensure that we UseCount when you cause a compensatory seek by setting playbackRate when paused');
</script>
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body></body>
<script>
'use strict';
// From UseCounter.h
var AnimationSetPlaybackRateCompensatorySeek = 2162;
var MS_PER_SEC = 1000;
function createDiv() {
var element = document.createElement('div');
document.body.appendChild(element);
return element;
}
var div = createDiv();
var animation = div.animate(null, 100 * MS_PER_SEC);
var startTimeBefore = animation.startTime;
animation.currentTime = 7 * MS_PER_SEC; // ms
async_test(t => {
return animation.ready.then(t.step_func_done(() => {
assert_equals(animation.playState, "running");
assert_not_equals(startTimeBefore, animation.startTime);
assert_false(internals.isUseCounted(document, AnimationSetPlaybackRateCompensatorySeek));
animation.playbackRate = 1.0;
assert_false(internals.isUseCounted(document, AnimationSetPlaybackRateCompensatorySeek));
animation.playbackRate = 0.5;
assert_true(internals.isUseCounted(document, AnimationSetPlaybackRateCompensatorySeek));
}))
}, 'Check to ensure that we UseCount when you cause a compensatory seek by setting playbackRate when playing');
</script>
......@@ -717,7 +717,16 @@ void Animation::setPlaybackRate(double playback_rate) {
PlayStateUpdateScope update_scope(*this, kTimingUpdateOnDemand);
double start_time_before = start_time_;
SetPlaybackRateInternal(playback_rate);
// Adds a UseCounter to check if setting playbackRate causes a compensatory
// seek forcing a change in start_time_
if (!std::isnan(start_time_before) && start_time_ != start_time_before &&
play_state_ != kFinished) {
UseCounter::Count(GetExecutionContext(),
WebFeature::kAnimationSetPlaybackRateCompensatorySeek);
}
}
void Animation::SetPlaybackRateInternal(double playback_rate) {
......
......@@ -1692,6 +1692,7 @@ enum WebFeature {
kSyncXhrInPageDismissal = 2159,
kAsyncXhrInPageDismissal = 2160,
kV8LineOrParagraphSeparatorAsLineTerminator = 2161,
kAnimationSetPlaybackRateCompensatorySeek = 2162,
// Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots.
......
......@@ -16435,6 +16435,7 @@ uploading your change for review. These are checked by presubmit scripts.
<int value="2159" label="SyncXhrInPageDismissal"/>
<int value="2160" label="AsyncXhrInPageDismissal"/>
<int value="2161" label="V8LineOrParagraphSeparatorAsLineTerminator"/>
<int value="2162" label="AnimationSetPlaybackRateCompensatorySeek"/>
</enum>
<enum name="FeedbackSource">
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