1 <!-- Used by media_scrub_perf to record scrubbing perf metrics. -->
5 <title>Scrubbing Tests
</title>
6 <script src=
"utils.js" type=
"text/javascript"></script>
9 <label for=
"src">Video src (direct link to media file):
</label>
10 <input id=
"src" type=
"text" size=
"64">
11 <button onclick=
"startTest(document.querySelector('input').value);">
15 <video controls
></video><br>
16 Forward scrubbing time:
<span id=
"forwardScrub"></span><br>
17 Backward scrubbing time:
<span id=
"backwardScrub"></span><br>
18 Mixed scrubbing time:
<span id=
"mixedScrub"></span><br>
19 <span id=
"logs"></span>
21 <script type=
"text/javascript">
22 // Number of seeks per scrub.
24 // The delta between 2 scrubs in secs.
25 var SCRUB_DELTA
= 0.1;
26 // Used by pyauto tests to store the scrubbing times.
27 var forwardScrubTime
= backwardScrubTime
= mixedScrubTime
= 0;
28 // Used for each scrub test based on buffered area.
29 var startTime
= endTime
= 0;
30 // Used by PyAuto to log any error message.
32 // Used by PyAuto to indicate when the test is done.
34 // Timer used to measure scrubbing performance.
35 var timer
= new Timer();
36 // Indicates the current scrubbing direction performed.
37 var currentDirection
= null;
38 // Indicates the expected time of video when each scrub ends. This is the
39 // final seek time each test performs.
40 // Make sure none of the scrubs overlap this time.
41 var EXPECTED_SCRUB_END_TIME
= 0.01;
42 // Seek is not 100% accurate so we need delta in secs where currentTime of
43 // video can vary from its expected time.
54 logs
.innerText
+= text
+ '\n';
57 function getAndClearElement(id
) {
58 var elem
= document
.getElementById(id
);
63 function onCanplaythrough() {
64 startTime
= video
.buffered
.start(0) + SCRUB_DELTA
;
65 endTime
= startTime
+ SCRUBS
* SCRUB_DELTA
;
66 log('Video duration: ' + video
.duration
+ ' secs');
67 log('Scrubbing area: (' + startTime
+ ', ' + endTime
+ ')');
68 currentDirection
= Direction
.FORWARD
;
72 function startScrubTest() {
74 switch (currentDirection
) {
75 case Direction
.FORWARD
:
76 video
.currentTime
= startTime
;
77 scrub(Direction
.FORWARD
, SCRUBS
);
79 case Direction
.BACKWARD
:
80 video
.currentTime
= endTime
;
81 scrub(Direction
.BACKWARD
, SCRUBS
);
84 video
.currentTime
= (startTime
+ endTime
) / 2;
86 for (t
= 0; t
< shortScrubs
; ++t
) {
88 scrub(Direction
.BACKWARD
, SCRUBS
/ shortScrubs
);
90 scrub(Direction
.FORWARD
, SCRUBS
/ shortScrubs
);
93 case Direction
.NO_DIRECTION
:
95 video
.removeEventListener('seeked', seeked
, false);
98 // After each scrub, seek to the expected end time.
99 video
.currentTime
= EXPECTED_SCRUB_END_TIME
;
102 function scrub(direction
, scrubs
) {
103 for (var t
= 0; t
< scrubs
; ++t
) {
104 if (direction
== Direction
.BACKWARD
)
105 video
.currentTime
-= SCRUB_DELTA
;
106 else if (direction
== Direction
.FORWARD
)
107 video
.currentTime
+= SCRUB_DELTA
;
112 if (Math
.abs(video
.currentTime
- EXPECTED_SCRUB_END_TIME
) < DELTA
) {
114 // Update to next scrubbing direction.
120 function logScrubTime() {
121 delta
= Math
.round(timer
.stop(), 0);
122 var scrubElem
= null;
123 if (currentDirection
== Direction
.FORWARD
) {
124 scrubElem
= getAndClearElement('forwardScrub');
125 forwardScrubTime
= delta
;
126 } else if (currentDirection
== Direction
.BACKWARD
) {
127 scrubElem
= getAndClearElement('backwardScrub');
128 backwardScrubTime
= delta
;
130 scrubElem
= getAndClearElement('mixedScrub');
131 mixedScrubTime
= delta
;
133 scrubElem
.innerText
= delta
+ ' ms';
146 // Called by the PyAuto controller to initiate testing.
147 function startTest(src
) {
148 video
= document
.querySelector('video');
149 logs
= getAndClearElement('logs');
152 forwardScrubTime
= backwardScrubTime
= mixedScrubTime
= 0;
154 video
.addEventListener('seeked', seeked
);
155 video
.addEventListener('canplaythrough', onCanplaythrough
);
156 video
.addEventListener('error', function() {
157 end('Error loading media: ' + video
.error
.code
);
161 if (window
.domAutomationController
)
162 window
.domAutomationController
.send(true);