2009-04-27 Pierre d'Herbemont <pdherbemont@apple.com>

        Reviewed by Simon Fraser

        Fix video-played.html layout test.

        https://bugs.webkit.org/show_bug.cgi?id=25424

        We implement playForMillisecs() which makes sure the video
        will have been playing for a minimum time.

        Note, this does not ensure a strict synchronization between the time
        asked and the media playback. But given that media playback is the
        slow part we just need to compensate for the delay involved by playback.
        (And not the other way around.)

        Moreover, we split the test in 3 in order to be more gentle which
        slower machines that may tend to timeout more easily on those tests.

        * media/video-played-collapse-expected.txt: Added.
        * media/video-played-collapse.html: Added.
        * media/video-played-expected.txt:
        * media/video-played-reset-expected.txt: Added.
        * media/video-played-reset.html: Added.
        * media/video-played.html:
        - Split tests in multiple files.
        - Makes sure we always play as much as requested by using
        playForMillisecs();
        * media/video-played.js: Added.
        (testRanges):
        (nextTest):
        (pause):
        (canplay):
        (willCreateNewRange):
        (startPlayingInNewRange):
        (startPlaying):
        (secToMilli):
        (milliToSecs):
        (playForMillisecs.callPauseIfTimeIsReached):
        (playForMillisecs):
        (videoPlayedMain):

git-svn-id: svn://svn.chromium.org/blink/trunk@42920 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 66db67b2
2009-04-27 Pierre d'Herbemont <pdherbemont@apple.com>
Reviewed by Simon Fraser
Fix video-played.html layout test.
https://bugs.webkit.org/show_bug.cgi?id=25424
We implement playForMillisecs() which makes sure the video
will have been playing for a minimum time.
Note, this does not ensure a strict synchronization between the time
asked and the media playback. But given that media playback is the
slow part we just need to compensate for the delay involved by playback.
(And not the other way around.)
Moreover, we split the test in 3 in order to be more gentle which
slower machines that may tend to timeout more easily on those tests.
* media/video-played-collapse-expected.txt: Added.
* media/video-played-collapse.html: Added.
* media/video-played-expected.txt:
* media/video-played-reset-expected.txt: Added.
* media/video-played-reset.html: Added.
* media/video-played.html:
- Split tests in multiple files.
- Makes sure we always play as much as requested by using
playForMillisecs();
* media/video-played.js: Added.
(testRanges):
(nextTest):
(pause):
(canplay):
(willCreateNewRange):
(startPlayingInNewRange):
(startPlaying):
(secToMilli):
(milliToSecs):
(playForMillisecs.callPauseIfTimeIsReached):
(playForMillisecs):
(videoPlayedMain):
2009-04-27 Beth Dakin <bdakin@apple.com> 2009-04-27 Beth Dakin <bdakin@apple.com>
Reviewed by Dave Hyatt. Reviewed by Dave Hyatt.
Test of the media element 'played' attribute
EVENT(loadstart)
EVENT(loadedmetadata)
EVENT(canplay)
Test 1 OK
Test playing when there are no ranges
RUN(video.play())
RUN(video.pause())
EVENT(pause)
Test 2 OK
Test 3 OK
Test 4 OK
Create a new range
RUN(video.play())
RUN(video.pause())
EVENT(pause)
Test 5 OK
Test 6 OK
Test 7 OK
Test 8 OK
Test 9 OK
Test playing from one range into another, should collapse the two ranges
RUN(video.play())
RUN(video.pause())
EVENT(pause)
Test 10 OK
Test 11 OK
Test 12 OK
RUN(video.play())
RUN(video.pause())
EVENT(pause)
Test 13 OK
Test 14 OK
Test 15 OK
END OF TEST
<html>
<head>
<title>Test of 'played' attribute</title>
<script src=video-test.js></script>
<script src=video-played.js></script>
<script>
var testFunctions =
[
PlayWithNoRanges,
CreateANewRange,
JumpAndCollapseTwoRanges,
TestLoopingAndPassToTheEnd
];
// NOTE: Result details are not printed for this test because time values are different from machine
// to machine and run to run. Commenting out the following line turns on detailed logging back on, which
// can be useful for debugging test failure.
disableFullTestDetailsPrinting();
function PlayWithNoRanges()
{
consoleWrite("<br><b><em>Test playing when there are no ranges</em></b>");
timeRangeCount = currentTimeRange = 0;
runSilently("video.currentTime = 0.5");
currentTimeRange++;
startPlayingInNewRange();
}
function CreateANewRange()
{
consoleWrite("<br><b><em>Create a new range</em></b>");
var newTime = (video.played.end(0) + 0.05).toFixed(2);
runSilently("video.currentTime = " + newTime);
startPlayingInNewRange();
}
function JumpAndCollapseTwoRanges()
{
consoleWrite("<br><b><em>Test playing from one range into another, should collapse the two ranges</em></b>");
timeRangeCount--;
currentTimeRange = timeRangeCount - 1;
var startTime = expectedStartTimes[0] - 0.1;
expectedStartTimes[0] = startTime;
expectedEndTimes[0] = expectedEndTimes[1];
willPauseInExistingRange = false;
runSilently("video.currentTime = " + startTime);
playForMillisecs(secToMilli(expectedEndTimes[1] - startTime + 0.1)); // Triggers pause()
}
function TestLoopingAndPassToTheEnd()
{
playForMillisecs(100); // Triggers pause()
return;
consoleWrite("<br><b><em>Test looping</em></b>");
var newTime = (video.duration - 0.05).toFixed(2);
runSilently("video.currentTime = " + newTime);
run("video.loop = true");
currentTimeRange = 0; // We'll end in the very first time range
timeRangeCount++;
expectedStartTimes[timeRangeCount-1] = newTime;
expectedEndTimes[timeRangeCount-1] = video.duration.toFixed(2);
willPauseInExistingRange = true;
willExtendAnExistingRange = true;
playForMillisecs(100); // Triggers pause()
}
</script>
</head>
<body onload="videoPlayedMain()">
<video controls></video>
<p>Test of the media element 'played' attribute</p>
</body>
</html>
...@@ -35,7 +35,7 @@ Test 14 OK ...@@ -35,7 +35,7 @@ Test 14 OK
Test 15 OK Test 15 OK
Test 16 OK Test 16 OK
Test jumping into an existing range and play beyond end, should extend range end Test playing into an existing range, should extend range start
RUN(video.play()) RUN(video.play())
RUN(video.pause()) RUN(video.pause())
EVENT(pause) EVENT(pause)
...@@ -47,7 +47,7 @@ Test 21 OK ...@@ -47,7 +47,7 @@ Test 21 OK
Test 22 OK Test 22 OK
Test 23 OK Test 23 OK
Test playing into an existing range, should extend range start Test jumping into an existing range and play beyond end, should extend range end
RUN(video.play()) RUN(video.play())
RUN(video.pause()) RUN(video.pause())
EVENT(pause) EVENT(pause)
...@@ -88,56 +88,5 @@ Test 48 OK ...@@ -88,56 +88,5 @@ Test 48 OK
Test 49 OK Test 49 OK
Test 50 OK Test 50 OK
Test 51 OK Test 51 OK
Test looping
RUN(video.loop = true)
RUN(video.play())
RUN(video.pause())
EVENT(pause)
Test 52 OK
Test 53 OK
Test 54 OK
Test 55 OK
Test 56 OK
Test 57 OK
Test 58 OK
Test 59 OK
Test 60 OK
Test playing from one range into another, should collapse the two ranges
RUN(video.loop = false)
RUN(video.play())
RUN(video.pause())
EVENT(pause)
Test 61 OK
Test 62 OK
Test 63 OK
Test 64 OK
Test 65 OK
Test 66 OK
Test 67 OK
Test to reset to non empty video source
RUN(video.src = "content/test.mp4")
RUN(video.load())
EVENT(loadstart)
EVENT(loadedmetadata)
EVENT(canplay)
Test 68 OK
Test jumping forward into a new range and play
RUN(video.play())
RUN(video.pause())
EVENT(pause)
Test 69 OK
Test 70 OK
Test 71 OK
Test to reset to an empty video source
RUN(video.src = "")
RUN(video.load())
EVENT(loadstart)
EVENT(loadstart)
Test 72 OK
END OF TEST END OF TEST
Test of the media element 'played' attribute
EVENT(loadstart)
EVENT(loadedmetadata)
EVENT(canplay)
Test 1 OK
Test playing when there are no ranges
RUN(video.play())
RUN(video.pause())
EVENT(pause)
Test 2 OK
Test 3 OK
Test 4 OK
Test to reset to non empty video source
RUN(video.src = "content/test.mp4")
RUN(video.load())
EVENT(loadstart)
EVENT(loadedmetadata)
EVENT(canplay)
Test 5 OK
Test jumping forward into a new range and play
RUN(video.play())
RUN(video.pause())
EVENT(pause)
Test 6 OK
Test 7 OK
Test 8 OK
Test to reset to an empty video source
RUN(video.src = "")
RUN(video.load())
EVENT(loadstart)
EVENT(loadstart)
Test 9 OK
END OF TEST
<html>
<head>
<title>Test of 'played' attribute</title>
<script src=video-test.js></script>
<script src=video-played.js></script>
<script>
var testFunctions =
[
PlayWithNoRanges,
ResetToAVideoSource,
JumpAndPlayFwd,
ResetToAnEmptyVideoSource
];
// NOTE: Result details are not printed for this test because time values are different from machine
// to machine and run to run. Commenting out the following line turns on detailed logging back on, which
// can be useful for debugging test failure.
disableFullTestDetailsPrinting();
function PlayWithNoRanges()
{
consoleWrite("<br><b><em>Test playing when there are no ranges</em></b>");
timeRangeCount = currentTimeRange = 0;
startPlayingInNewRange();
}
function ResetToAVideoSource()
{
consoleWrite("<br><b><em>Test to reset to non empty video source</em></b>");
timeRangeCount = currentTimeRange = 0;
expectedStartTimes = new Array();
expectedEndTimes = new Array();
willPauseInExistingRange = false;
willExtendAnExistingRange = false;
run("video.src = \"content/test.mp4\"");
run("video.load()"); // Triggers canplay()
}
function JumpAndPlayFwd()
{
consoleWrite("<br><b><em>Test jumping forward into a new range and play</em></b>");
var newTime = video.duration - 0.5;
runSilently("video.currentTime = " + (newTime.toFixed(2)));
currentTimeRange = 1;
startPlayingInNewRange();
}
function ResetToAnEmptyVideoSource()
{
consoleWrite("<br><b><em>Test to reset to an empty video source</em></b>");
timeRangeCount = currentTimeRange = 0;
expectedStartTimes = new Array();
expectedEndTimes = new Array();
run("video.src = \"\"");
waitForEvent("loadstart", function () { testRanges(); nextTest(); });
run("video.load()"); // Triggers loadstart()
}
</script>
</head>
<body onload="videoPlayedMain()">
<video controls></video>
<p>Test of the media element 'played' attribute</p>
</body>
</html>
var expectedStartTimes = new Array();
var expectedEndTimes = new Array();
var timeRangeCount = 0;
var currentTimeRange = 0;
var currentTest = 0;
var willPauseInExistingRange = false;
var willExtendAnExistingRange = false;
function testRanges()
{
testExpected("video.played.length", timeRangeCount);
for (i = 0; i < timeRangeCount; i++) {
testExpected("video.played.start(" + (i) + ").toFixed(2)", expectedStartTimes[i]);
testExpected("video.played.end(" + (i) + ").toFixed(2)", expectedEndTimes[i]);
}
}
function nextTest()
{
if (currentTest >= testFunctions.length)
endTest();
else
(testFunctions[currentTest])();
currentTest++;
}
function pause(evt)
{
currentTime = video.currentTime.toFixed(2);
if (!willExtendAnExistingRange)
expectedEndTimes.splice(currentTimeRange, 0, currentTime)
else if(expectedEndTimes[currentTimeRange] < currentTime || expectedEndTimes[currentTimeRange] == undefined)
expectedEndTimes[currentTimeRange] = currentTime;
testRanges();
nextTest();
}
function canplay(event)
{
testRanges();
nextTest();
}
function willCreateNewRange()
{
expectedStartTimes.splice(currentTimeRange, 0, video.currentTime.toFixed(2))
++timeRangeCount;
}
function startPlayingInNewRange()
{
willCreateNewRange();
startPlaying();
}
function startPlaying()
{
playForMillisecs(250); // Triggers pause()
}
function secToMilli(seconds)
{
return seconds * 1000.;
}
function milliToSecs(milliseconds)
{
return milliseconds / 1000;
}
function playForMillisecs(milliseconds)
{
if (milliToSecs(milliseconds) > video.duration) {
consoleWrite("WARNING: playForMillisecs() does not support range ("+milliToSecs(milliseconds)+") bigger than video duration ("+video.duration+") (yet)");
return;
}
var playedFromTime = video.currentTime;
run("video.play()");
var callCount = 0;
var callPauseIfTimeIsReached = function ()
{
var playedTime = video.currentTime - playedFromTime;
if (playedTime < 0) {
// Deal with 'loop' attribue. This work only once, hence the warning
// At the begining of playForMillisecs()
playedTime = video.duration - playedFromTime + video.currentTime;
}
if (callCount++ > 10) {
// Just in case something goes wrong.
consoleWrite("WARNING: Call count exceeded");
return;
}
if (playedTime >= milliToSecs(milliseconds) || video.currentTime == video.duration) {
run("video.pause()");
} else {
var waitingTime = milliseconds - playedTime * 1000;
setTimeout(callPauseIfTimeIsReached, waitingTime);
}
}
setTimeout(callPauseIfTimeIsReached, milliseconds);
}
function videoPlayedMain()
{
findMediaElement();
video.src = 'content/test.mp4';
waitForEvent("error");
waitForEvent("loadstart");
waitForEvent("ratechange");
waitForEvent("loadedmetadata");
waitForEvent("canplay", canplay); // Will trigger nextTest() which launches the tests.
waitForEvent("pause", pause);
video.load();
}
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