Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | |
| 2 var expectedStartTimes = new Array(); | 1 var expectedStartTimes = new Array(); |
|
fs
2016/07/12 18:04:24
Could we try making this not use random state on t
Srirama
2016/07/13 18:48:32
Done, assuming that you are talking about the arra
fs
2016/07/15 19:36:48
Well, preferably all globals in the "helper" scrip
| |
| 3 var expectedEndTimes = new Array(); | 2 var expectedEndTimes = new Array(); |
| 4 var timeRangeCount = 0; | 3 var timeRangeCount = 0; |
| 5 var currentTimeRange = 0; | 4 var currentTimeRange = 0; |
| 6 var currentTest = 0; | 5 var playDuration = 0; |
| 7 var willPauseInExistingRange = false; | 6 var startTimeOfPlay = 0; |
| 8 var willExtendAnExistingRange = false; | 7 var startTime = 0; |
| 9 | 8 |
| 10 var testStartTime = 0; | 9 function testRanges() { |
| 11 var logTestTiming = false; | 10 assert_equals(video.played.length, timeRangeCount); |
| 12 | 11 |
| 13 //@@@@@ Uncomment the following line to log the time each "video-played" sub-tes t takes in test output | |
| 14 //@@@@@ logTestTiming = true; | |
| 15 | |
| 16 function logRanges() | |
| 17 { | |
| 18 consoleWrite(""); | |
| 19 for (i = 0; i < timeRangeCount; i++) { | 12 for (i = 0; i < timeRangeCount; i++) { |
| 20 consoleWrite("**** range " + i + " ( " + video.played.start(i).toFixed( 2) + ".." + video.played.end(i).toFixed(2) + ")"); | 13 assert_equals(video.played.start(i).toFixed(2), expectedStartTimes[i]); |
| 14 assert_equals(video.played.end(i).toFixed(2), expectedEndTimes[i]); | |
| 21 } | 15 } |
| 22 } | 16 } |
| 23 | 17 |
| 24 function testRanges() | 18 function waitForPauseAndContinue(t, nextFunc, extendsRange) { |
| 25 { | 19 video.onpause = t.step_func(function() { |
| 26 if (testStartTime) { | 20 var currentTime = video.currentTime.toFixed(2); |
| 27 logRanges(); | 21 if (extendsRange) { |
| 28 | 22 if(expectedEndTimes[currentTimeRange] < currentTime |
| 29 var duration = (window.performance.now() - testStartTime) / 1000; | 23 || expectedEndTimes[currentTimeRange] == undefined) { |
| 30 consoleWrite("**** Test " + currentTest + " took " + duration.toFixed(2) + " seconds"); | 24 expectedEndTimes[currentTimeRange] = currentTime; |
| 31 } | 25 } |
| 32 | 26 } else { |
| 33 testExpected("video.played.length", timeRangeCount); | 27 expectedEndTimes.splice(currentTimeRange, 0, currentTime); |
| 34 | 28 } |
| 35 for (i = 0; i < timeRangeCount; i++) { | 29 testRanges(); |
| 36 testExpected("video.played.start(" + (i) + ").toFixed(2)", expectedStart Times[i]); | 30 if (nextFunc) |
| 37 testExpected("video.played.end(" + (i) + ").toFixed(2)", expectedEndTi mes[i]); | 31 nextFunc(); |
| 38 } | 32 else |
| 33 t.done(); | |
| 34 }); | |
| 39 } | 35 } |
| 40 | 36 function willCreateNewRange() { |
| 41 function nextTest() | |
| 42 { | |
| 43 if (logTestTiming) | |
| 44 testStartTime = window.performance.now(); | |
| 45 | |
| 46 if (currentTest >= testFunctions.length) | |
| 47 endTest(); | |
| 48 else | |
| 49 (testFunctions[currentTest])(); | |
| 50 currentTest++; | |
| 51 } | |
| 52 | |
| 53 function pause(evt) | |
| 54 { | |
| 55 currentTime = video.currentTime.toFixed(2); | |
| 56 | |
| 57 if (!willExtendAnExistingRange) | |
| 58 expectedEndTimes.splice(currentTimeRange, 0, currentTime) | |
| 59 else if(expectedEndTimes[currentTimeRange] < currentTime || expectedEndT imes[currentTimeRange] == undefined) | |
| 60 expectedEndTimes[currentTimeRange] = currentTime; | |
| 61 | |
| 62 testRanges(); | |
| 63 nextTest(); | |
| 64 } | |
| 65 | |
| 66 function canplay(event) | |
| 67 { | |
| 68 testRanges(); | |
| 69 nextTest(); | |
| 70 } | |
| 71 | |
| 72 function willCreateNewRange() | |
| 73 { | |
| 74 expectedStartTimes.splice(currentTimeRange, 0, video.currentTime.toFixed(2)) | 37 expectedStartTimes.splice(currentTimeRange, 0, video.currentTime.toFixed(2)) |
| 75 ++timeRangeCount; | 38 ++timeRangeCount; |
| 76 } | 39 } |
| 77 | 40 |
| 78 function startPlayingInNewRange() | 41 function callPauseIfTimeIsReached() { |
| 79 { | 42 var playedTime = video.currentTime - startTimeOfPlay; |
| 80 willCreateNewRange(); | 43 if (playedTime < 0) { |
| 81 startPlaying(); | 44 // Deal with "loop" attribute. This allows only one loop, hence the firs t warning |
| 45 // at the begining of platForDuration(). | |
| 46 playedTime = video.duration - startTimeOfPlay + video.currentTime; | |
| 47 } | |
| 48 | |
| 49 var elapsed = (performance.now() / 1000) - startTime; | |
| 50 assert_less_than_equal(elapsed, 3.0); | |
| 51 if (playedTime >= playDuration || video.currentTime == video.duration) | |
| 52 video.pause(); | |
| 53 else { | |
| 54 var delta = (playDuration - playedTime) * 1000; | |
| 55 setTimeout(this.step_func(callPauseIfTimeIsReached), delta); | |
| 56 } | |
| 82 } | 57 } |
| 83 | 58 |
| 84 function startPlaying() | 59 function playForDuration(duration, t) { |
| 85 { | 60 playDuration = duration; |
| 86 playForMillisecs(100); // Triggers pause() | 61 assert_less_than_equal(playDuration, video.duration); |
| 62 | |
| 63 // A 2 second timeout was sometimes insufficient to play 1.25 seconds of mov ie, | |
| 64 // though more than 1 second of movie typically had played prior to those fa ilures. | |
| 65 // Use a larger value than 2 here. | |
| 66 var timeoutThreshold = 3.0; | |
| 67 assert_greater_than_equal(video.duration, timeoutThreshold); | |
| 68 assert_less_than_equal(playDuration, timeoutThreshold - 1.5); | |
| 69 video.play(); | |
| 70 startTime = performance.now() / 1000; | |
| 71 startTimeOfPlay = video.currentTime; | |
| 72 | |
| 73 // Add a small amount to the timer because it will take a non-zero | |
| 74 // amount of time for the video to start playing. | |
| 75 setTimeout(t.step_func(callPauseIfTimeIsReached), (duration * 1000) + 100); | |
| 87 } | 76 } |
| 88 | 77 |
| 89 function secToMilli(seconds) | 78 function startPlayingInNewRange(t) { |
| 90 { | 79 willCreateNewRange(); |
| 91 return seconds * 1000.; | 80 playForDuration(0.1, t); |
| 92 } | 81 } |
| 93 | |
| 94 function milliToSecs(milliseconds) | |
| 95 { | |
| 96 return milliseconds / 1000; | |
| 97 } | |
| 98 | |
| 99 function nowInSecs() | |
| 100 { | |
| 101 return milliToSecs(window.performance.now()); | |
| 102 } | |
| 103 | |
| 104 function playForMillisecs(milliseconds) | |
| 105 { | |
| 106 var playDuration = milliToSecs(milliseconds); | |
| 107 if (playDuration > video.duration) { | |
| 108 failTest("WARNING: playForMillisecs() does not support range (" + playDu ration + ") bigger than video duration (" + video.duration + ") (yet)"); | |
| 109 return; | |
| 110 } | |
| 111 | |
| 112 // A 2 second timeout was sometimes insufficient to play 1.25 seconds of mov ie, though more | |
| 113 // than 1 second of movie typically had played prior to those failures. Use a larger value | |
| 114 // than 2 here. | |
| 115 var timeoutThreshold = 3.; | |
| 116 | |
| 117 if (video.duration < timeoutThreshold) { | |
| 118 failTest("WARNING: playForMillisecs() does not support video duration(" + video.duration + ") smaller than timeout threshold (" + timeoutThreshold + ")" ); | |
| 119 return; | |
| 120 } | |
| 121 | |
| 122 if (playDuration > timeoutThreshold - 1.5) { | |
| 123 failTest("WARNING: playForMillisecs() does not support range (" + playDu ration + ") within 1.5 seconds of timeout threshold (" + timeoutThreshold + ")") ; | |
| 124 return; | |
| 125 } | |
| 126 | |
| 127 run("video.play()"); | |
| 128 | |
| 129 var startTime = nowInSecs(); | |
| 130 var playedFromTime = video.currentTime; | |
| 131 var callPauseIfTimeIsReached = function () | |
| 132 { | |
| 133 var playedTime = video.currentTime - playedFromTime; | |
| 134 | |
| 135 if (playedTime < 0) { | |
| 136 // Deal with 'loop' attribute. This allows only one loop, hence the first warning | |
| 137 // at the begining of playForMillisecs(). | |
| 138 playedTime = video.duration - playedFromTime + video.currentTime; | |
| 139 } | |
| 140 | |
| 141 var elapsed = nowInSecs() - startTime; | |
| 142 if (elapsed > timeoutThreshold) { | |
| 143 // Just in case something goes wrong. | |
| 144 failTest("ERROR: test stalled, waited " + elapsed + " seconds for mo vie to play " + playedTime + " seconds"); | |
| 145 return; | |
| 146 } | |
| 147 | |
| 148 if (playedTime >= playDuration || video.currentTime == video.duration) | |
| 149 run("video.pause()"); | |
| 150 else { | |
| 151 var delta = milliseconds - playedTime * 1000; | |
| 152 setTimeout(callPauseIfTimeIsReached, delta); | |
| 153 } | |
| 154 } | |
| 155 | |
| 156 // Add a small amount to the timer because it will take a non-zero amount of time for the | |
| 157 // video to start playing. | |
| 158 setTimeout(callPauseIfTimeIsReached, milliseconds + 100); | |
| 159 } | |
| 160 | |
| 161 function videoPlayedMain() | |
| 162 { | |
| 163 findMediaElement(); | |
| 164 | |
| 165 video.src = findMediaFile("video", "content/test"); | |
| 166 | |
| 167 waitForEvent("error"); | |
| 168 waitForEvent("loadstart"); | |
| 169 waitForEvent("ratechange"); | |
| 170 waitForEvent("loadedmetadata"); | |
| 171 waitForEventOnce("canplay", canplay); // Will trigger nextTest() which launc hes the tests. | |
| 172 waitForEvent("pause", pause); | |
| 173 | |
| 174 video.load(); | |
| 175 } | |
| OLD | NEW |