Bug 1387894 - Fix the WPT and mochitest test_document-timeline.html for unconditional clamping r=birtles

We fix this by clamping the requestAnimationFrame timestamp in the test before comparing it.
We don't clamp the requestAnimationFrame timestamp normally because it would be meaningless:
rAF fires on a regular frequency and someone perfoming a fine-grained timing attack will be
able to determine the timestamp from when it fires.

We need to use parseFloat to knock off any extra epislon we gain.

This shouldn't cause any major blow-ups because timelines are disabled in release and beta,
so at least any potential fallout would be constrained.

Differential Revision: https://phabricator.services.mozilla.com/D38807

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tom Ritter 2019-07-30 15:11:50 +00:00
Родитель 83a41908c3
Коммит 905b162e22
2 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -10,6 +10,10 @@
<script>
'use strict';
function matchUnconditionalClamping(timestamp) {
return parseFloat((Math.floor(timestamp / .02) * .02).toPrecision(8), 10);
}
test(function() {
assert_equals(document.timeline, document.timeline,
'document.timeline returns the same object every time');
@ -43,7 +47,7 @@ async_test(function(t) {
// window.performance.now() because currentTime is only updated on a sample
// so we use requestAnimationFrame instead.
window.requestAnimationFrame(t.step_func(function(rafTime) {
assert_equals(document.timeline.currentTime, rafTime,
assert_equals(document.timeline.currentTime, matchUnconditionalClamping(rafTime),
'document.timeline.currentTime matches' +
' requestAnimationFrame time');
t.done();

Просмотреть файл

@ -9,6 +9,10 @@
<script>
'use strict';
function matchUnconditionalClamping(timestamp) {
return parseFloat((Math.floor(timestamp / .02) * .02).toPrecision(8), 10);
}
async_test(t => {
assert_greater_than_equal(document.timeline.currentTime, 0,
'The current time is initially is positive or zero');
@ -27,7 +31,7 @@ async_test(t => {
// so we use requestAnimationFrame instead.
window.requestAnimationFrame(rafTime => {
t.step(() => {
assert_equals(document.timeline.currentTime, rafTime,
assert_equals(document.timeline.currentTime, matchUnconditionalClamping(rafTime),
'The current time matches requestAnimationFrame time');
});
t.done();