1 <video controls
></video>
2 <p>Test that progress events are generated during loading of media resource.
</p>
3 <script src=../../media-resources/video-test.js
></script>
4 <script src=../../media-resources/media-file.js
></script>
6 waitForEventAndFail('error');
8 // Given long enough duration, We should not reach ended playback state.
9 waitForEventAndFail('ended');
11 // Tuned throttling should not induce player stall or suspended load.
12 waitForEventAndFail('stalled');
13 waitForEventAndFail('suspend');
14 waitForEventAndFail('waiting');
16 var progressCount
= 0;
17 var lastProgressEventTime
= 0;
18 function progressListener(event
)
20 // Implementations can vary the frequency within tolerance, so we must protect against flaky logs.
21 // Remain silent here unless failure detected.
22 if (video
.networkState
!= HTMLMediaElement
.NETWORK_LOADING
) {
23 failTest('Unexpected networkState ' + video
.networkState
+
24 ' when handling \'progress\' event. Is fetch completed or suspending?');
29 lastProgressEventTime
= window
.performance
.now();
31 video
.addEventListener('progress', progressListener
);
33 function canplayListener(event
)
35 // Begin video playback to mitigate flakiness due to implementations suspending loads
36 // on limited buffer capacity.
38 video
.removeEventListener('canplay', canplayListener
);
40 video
.addEventListener('canplay', canplayListener
);
42 var progressCountAtLastCheck
= 0;
44 // Spec requires 350ms +/- 200ms minimum 'progress' event interval when loading.
45 var maxProgressFiringIntervalInMS
= 550;
46 // Multiple 'progress' events may fire within spec's tolerance window.
47 var maxProgressCountIncrease
= 3;
48 function checkProgressCount()
52 // Implementations can vary the frequency within tolerance, so we must protect against flakiness.
53 // Keep progressCount values involved in checks here out of report unless failure detected.
54 consoleWrite('Interval ' + checkCount
+ ' has elapsed. Checking progress event count delta.');
55 var progressCountDelta
= progressCount
- progressCountAtLastCheck
;
56 if (progressCountDelta
<= 0) {
57 failTest('progressCount (' + progressCount
+ ') did not increase since the last check.');
61 var surplusProgress
= progressCountDelta
- maxProgressCountIncrease
;
62 if (surplusProgress
> 0) {
63 failTest('Received at least ' + surplusProgress
+ ' too many progress event(s) since the last check.');
67 if (checkCount
== 3) {
72 progressCountAtLastCheck
= progressCount
;
73 var msSinceLastProgressEvent
= window
.performance
.now() - lastProgressEventTime
;
74 var msUntilNextCheck
= maxProgressFiringIntervalInMS
- msSinceLastProgressEvent
;
76 if (msUntilNextCheck
<= 0) {
77 failTest('ProgressCheck scheduling error: msUntilNextCheck is ' + msUntilNextCheck
);
81 setTimeout(checkProgressCount
, msUntilNextCheck
);
84 waitForEvent('loadstart', function()
86 // No 'progress' event should fire prior to 'loadstart'.
87 testExpected('progressCount', 0, '==');
88 setTimeout(checkProgressCount
, maxProgressFiringIntervalInMS
);
91 var mediaFile
= findMediaFile('video', 'resources/test');
92 var mimeType
= mimeTypeForFile(mediaFile
);
93 // Assumes minimum file size selected is > 100 kB.
94 // At least 4*maxProgressFiringIntervalInMS is how long we want to stretch the full
95 // loading, because we perform checks after 3 of these intervals while still
96 // loading. 100 kB over 2.2 seconds is 45 kBps.
99 video
.src
= 'video-throttled-load.cgi' + '?name=' + mediaFile
+ '&throttle=' + kBps
+ '&type=' + mimeType
;