1 <!-- Used by media_constrained_network_perf to record perf metrics. -->
5 <title>Constrained Video Test
</title>
12 <script type=
"text/javascript">
13 var video
= document
.querySelector('video');
15 // Tracks time when page load completes and src= is set.
18 // Tracks time when playback starts.
21 // Metrics to record. See media_constrained_network_perf for more details.
22 // Use -1 to indicate that we haven't recorded these values yet. The PyAuto
23 // controller will poll for these values until they are each >= 0.
24 var epp
= -1, ttp
= -1;
26 // Video play progress to calculate percentage of video played.
29 // String to keep track of video events fired.
32 // A flag to end the test if error or abort events get fired.
35 video
.addEventListener('playing', function(event
) {
36 startTime
= new Date().getTime();
37 ttp
= Math
.max(0, startTime
- loadTime
);
41 video
.addEventListener('ended', setEPP
, false);
42 video
.addEventListener('error', end
, false);
44 var events
= ['loadstart', 'progress', 'suspend', 'waiting', 'emptied',
45 'stalled', 'play', 'pause', 'loadedmetadata', 'loadeddata',
46 'waiting', 'canplay', 'canplaythrough', 'seeking', 'seeked',
47 'ratechange', 'durationchange', 'volumechange'];
49 var len
= events
.length
;
50 for (var i
= 0; i
< len
; i
++) {
51 video
.addEventListener(events
[i
], logEvent
, false);
59 function logEvent(evt
) {
61 eventsMsg
+= d
.toLocaleTimeString() + '.' + d
.getMilliseconds() + ' ' +
62 evt
.target
+ ' ' + evt
.type
+ ' event fired.\n';
65 function setEPP(evt
) {
66 playTime
= new Date().getTime() - startTime
;
67 durMs
= video
.duration
* 1000;
69 epp
= Math
.max(0, (playTime
- durMs
) * 100 / durMs
);
73 function calculateProgress() {
74 if (!isNaN(video
.duration
))
75 vpp
= (video
.currentTime
/ video
.duration
) * 100;
77 if (window
.domAutomationController
)
78 window
.domAutomationController
.send(vpp
);
81 // Called by the PyAuto controller to initiate testing.
82 function startTest(src
) {
83 loadTime
= new Date().getTime();
91 if (window
.domAutomationController
)
92 window
.domAutomationController
.send(true);