Commit c5284710 authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Rewrite svg/animations/getCurrentTime-pause-unpause.html to avoid flakes

The test in it's current form imposed too strict requirements on the
time that had passed. We cannot guarantee a maximum elapsed time, only a
minimum (and barely that...) Rewrite the test to not impose any
restriction on the maximum elapsed time. Also convert it to use
testharness while at it. Also rewrite/convert the sibling test with
setCurrentTime.

Bug: 824930
Change-Id: I79882b0189e44790e3096c8346c2a0bf47276dd8
Reviewed-on: https://chromium-review.googlesource.com/981145Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#546190}
parent 7d3d2502
PASS successfullyParsed is true
TEST COMPLETE
PASS svg.getCurrentTime() is 0
PASS svg.getCurrentTime() is 0.05
PASS svg.getCurrentTime() is 0.05
PASS successfullyParsed is true
TEST COMPLETE
PASS svg.getCurrentTime() is 0.5
PASS svg.getCurrentTime() is 1
PASS svg.getCurrentTime() is 2
PASS svg.getCurrentTime() is 3.5
<!DOCTYPE html>
<html>
<script src="../../resources/js-test.js"></script>
<script src="resources/SVGAnimationTestCase.js"></script>
<title>SVGSVGElement.getCurrentTime() with setCurrentTime() when animation is paused and unpaused</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<svg height="0">
<rect fill="green" width="20" height="20">
<animate attributeName="x" from="0" to="200" begin="0s" dur="3s"></animate>
</rect>
</svg>
<script>
function load() {
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
svg = document.getElementById("svg");
rect = document.getElementById("rect");
async_test(t => {
window.onload = t.step_func(() => {
let svg = document.querySelector("svg");
svg.pauseAnimations();
setTimeout(function() {
assert_equals(svg.getCurrentTime(), 0, 'initial');
t.step_timeout(t.step_func(() => {
svg.setCurrentTime(0.5);
shouldBeCloseEnough("svg.getCurrentTime()", "0.5", 0.01);
assert_approx_equals(svg.getCurrentTime(), 0.5, 0.01);
svg.unpauseAnimations();
setTimeout(function() {
t.step_timeout(t.step_func(() => {
svg.setCurrentTime(1);
shouldBeCloseEnough("svg.getCurrentTime()", "1", 0.01);
assert_approx_equals(svg.getCurrentTime(), 1, 0.01);
svg.pauseAnimations();
setTimeout(function() {
t.step_timeout(t.step_func(() => {
svg.setCurrentTime(2);
shouldBeCloseEnough("svg.getCurrentTime()", "2", 0.01);
assert_approx_equals(svg.getCurrentTime(), 2, 0.01);
svg.unpauseAnimations();
setTimeout(function() {
t.step_timeout(t.step_func_done(() => {
svg.setCurrentTime(3.5);
shouldBeCloseEnough("svg.getCurrentTime()", "3.5", 0.01);
if (window.testRunner)
testRunner.notifyDone();
}, 20);
}, 20);
}, 0);
}, 0);
}
assert_approx_equals(svg.getCurrentTime(), 3.5, 0.01);
}), 20);
}), 20);
}), 0);
}), 0);
});
});
</script>
<head><title>svg.getCurrentTime() with setCurrentTime() when SVG animation is paused and unpaused</title></head>
<body onload="load()">
<svg id="svg" xmlns="http://www.w3.org/2000/svg">
<rect id="rect" fill="green" width="20" height="20">
<animate attributeName="x" from="0" to="200" begin="0s" dur="3s"></animate>
</rect>
</svg>
</body>
</html>
<!DOCTYPE html>
<!--This tests svg.getCurrentTime() when SVG animation is paused and unpaused.
Sequence of steps are,
1. Pause the SVG animation at the beginning.
2. 10 msec delay
3. Test 1, measure the currentTime which should still be 0.
4. Unpause the SVG animation
5. 50 msec delay
6. Test 2, measure the currentTime which should be .05 sec.
7. Pause the SVG animation
8. 50 msec delay
9. Test 3, measure the currentTime which should still be .05 sec.
-->
<html>
<script src="../../resources/js-test.js"></script>
<script src="resources/SVGAnimationTestCase.js"></script>
<title>SVGSVGElement.getCurrentTime() when animation is paused and unpaused</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<svg height="0">
<rect fill="green" width="20" height="20">
<animate attributeName="x" from="0" to="200" begin="0s" dur="3s"/>
</rect>
</svg>
<script>
function load() {
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
svg = document.getElementById("svg");
rect = document.getElementById("rect");
// Assume that current time is aligned to at least 60hz, and thus within
// half of a frame time.
const errorInSeconds = (1 / 60) / 2;
async_test(t => {
window.onload = t.step_func(() => {
let svg = document.querySelector("svg");
// Pause the animation.
svg.pauseAnimations();
setTimeout(function() {
shouldBeCloseEnough("svg.getCurrentTime()", "0", 0.01);
assert_equals(svg.getCurrentTime(), 0, 'initial');
let currentTimeAfterDelay = 0;
// 10ms delay.
t.step_timeout(t.step_func(() => {
// Current time should still be 0.
assert_equals(svg.getCurrentTime(), 0, 'after 10ms paused');
// Resume the animation.
svg.unpauseAnimations();
setTimeout(function() {
shouldBeCloseEnough("svg.getCurrentTime()", "0.05", 0.02);
// 50ms delay.
t.step_timeout(t.step_func(() => {
// Current time should've advanced close to 50ms (may not be
// exact because the clock is synchronized to rAF.)
currentTimeAfterDelay = svg.getCurrentTime();
assert_greater_than_equal(currentTimeAfterDelay, 0.05 - errorInSeconds, 'after 50ms unpaused');
// Pause the animation.
svg.pauseAnimations();
setTimeout(function() {
shouldBeCloseEnough("svg.getCurrentTime()", "0.05", 0.02);
if (window.testRunner)
testRunner.notifyDone();
}, 50);
}, 50);
}, 10);
}
// 50ms delay.
t.step_timeout(t.step_func_done(() => {
// Current time should not have advanced.
assert_equals(svg.getCurrentTime(), currentTimeAfterDelay, 'after 50ms paused');
}), 50);
}), 60);
}), 10);
});
});
</script>
<head><title>svg.getCurrentTime() when SVG animation is paused and unpaused</title></head>
<body onload="load()">
<svg id="svg" xmlns="http://www.w3.org/2000/svg">
<rect id="rect" fill="green" width="20" height="20">
<animate attributeName="x" from="0" to="200" begin="0s" dur="3s"></animate>
</rect>
</svg>
</body>
</html>
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