Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <title>Tests that TextTrack's cues are indexed and updated in order during video playback. Test uses the cuechange event.</title> |
| 3 <head> | 3 <script src="../media-file.js"></script> |
| 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> | |
| 6 <video> | |
| 7 <track src="captions-webvtt/cues-chrono-order.vtt" kind="captions" default> | |
| 8 </video> | |
| 9 <script> | |
| 10 async_test(function(t) { | |
| 11 var video = document.querySelector("video"); | |
| 12 var testTrack = document.querySelector("track"); | |
| 5 | 13 |
| 6 <script src=../media-file.js></script> | 14 video.src = findMediaFile("video", "../content/test"); |
| 7 <!-- TODO(philipj): Convert test to testharness.js. crbug.com/588956 | 15 video.oncanplaythrough = t.step_func(attemptTests); |
| 8 (Please avoid writing new tests using video-test.js) --> | |
| 9 <script src=../video-test.js></script> | |
| 10 | 16 |
| 11 <script> | 17 function attemptTests() { |
| 18 assert_equals(testTrack.track.cues.length, 3); | |
| 19 testTrack.oncuechange = t.step_func(cueChangedFromTrackElement); | |
| 20 video.play(); | |
| 21 } | |
| 12 | 22 |
| 13 var cueChangeCount = 0; | 23 var currentCueIndex; |
| 14 var currentCue; | 24 var cueChangeCount = 0; |
| 15 var testTrack; | 25 function cueChangedFromTrackElement() { |
| 26 currentCueIndex = Math.floor(cueChangeCount / 2); | |
| 27 currentCue = event.target.track.cues[currentCueIndex]; | |
| 28 checkCue(); | |
| 16 | 29 |
| 17 var trackLoaded = false; | 30 ++cueChangeCount; |
| 18 var videoCanPlayThrough = false; | 31 if (cueChangeCount == testTrack.track.cues.length * 2) |
| 32 t.done(); | |
| 33 } | |
| 19 | 34 |
| 20 function attemptTests() | 35 function checkCue() { |
| 21 { | 36 if (cueChangeCount % 2 == 0) { |
| 22 if (!trackLoaded || !videoCanPlayThrough) | 37 // Cue entered. |
|
mlamouri (slow - plz ping)
2016/04/22 10:27:56
Could the check be done outside this method?
Srirama
2016/04/22 12:13:31
For each cue, this function is called on "enter" a
mlamouri (slow - plz ping)
2016/04/25 15:37:47
I meant adding the check in `cueChangedFromTrackEl
Srirama
2016/04/26 06:49:27
Sorry, didn't read the comment properly.
Inlined i
| |
| 23 return; | 38 assert_equals(currentCue, testTrack.track.activeCues[0]); |
| 24 | 39 assert_equals(currentCue.id, (currentCueIndex + 1).toString()); |
| 25 testTrack = document.getElementById("testTrack"); | |
| 26 testExpected("testTrack.track.cues.length", 3); | |
| 27 testTrack.addEventListener('cuechange', cueChangedFromTrackElement); | |
| 28 testTrack.track.addEventListener('cuechange', cueChangedFromTextTrac k); | |
| 29 run("video.play()"); | |
| 30 consoleWrite(""); | |
| 31 } | 40 } |
| 32 | 41 } |
| 33 function cueChangedFromTextTrack() | 42 }); |
| 34 { | 43 </script> |
| 35 consoleWrite("EVENT(cuechange) from TextTrack"); | |
| 36 } | |
| 37 | |
| 38 function cueChangedFromTrackElement() | |
| 39 { | |
| 40 consoleWrite("EVENT(cuechange) from <track>"); | |
| 41 | |
| 42 currentCueIndex = Math.floor(cueChangeCount / 2); | |
| 43 currentCue = event.target.track.cues[currentCueIndex]; | |
| 44 checkCue(); | |
| 45 | |
| 46 ++cueChangeCount; | |
| 47 if (cueChangeCount == testTrack.track.cues.length * 2) | |
| 48 endTest(); | |
| 49 } | |
| 50 | |
| 51 function checkCue() | |
| 52 { | |
| 53 if (cueChangeCount % 2 == 0) { | |
| 54 consoleWrite("Cue entered"); | |
| 55 testExpected(currentCue, testTrack.track.activeCues[0]); | |
| 56 testExpected("currentCue.id", currentCueIndex + 1); | |
| 57 } else | |
| 58 consoleWrite("Cue exited"); | |
| 59 consoleWrite(""); | |
| 60 } | |
| 61 | |
| 62 waitForEvent('canplaythrough', | |
| 63 function () | |
| 64 { | |
| 65 videoCanPlayThrough = true; | |
| 66 attemptTests(); | |
| 67 } | |
| 68 ); | |
| 69 | |
| 70 function loaded() | |
| 71 { | |
| 72 trackLoaded = true; | |
| 73 attemptTests(); | |
| 74 } | |
| 75 | |
| 76 function start() | |
| 77 { | |
| 78 findMediaElement(); | |
| 79 video.src = findMediaFile("video", "../content/test"); | |
| 80 } | |
| 81 | |
| 82 </script> | |
| 83 </head> | |
| 84 <body onload="start()"> | |
| 85 <p>Tests that TextTrack's cues are indexed and updated in order during v ideo playback. Test uses the cuechange event.</p> | |
| 86 <video controls> | |
| 87 <track id="testTrack" src="captions-webvtt/cues-chrono-order.vtt" ki nd="captions" onload="loaded()" default> | |
| 88 </video> | |
| 89 </body> | |
| 90 </html> | |
| OLD | NEW |