| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <title>Test video looping.</title> |
| 3 <head> | 3 <script src="../resources/testharness.js"></script> |
| 4 <script src=media-file.js></script> | 4 <script src="../resources/testharnessreport.js"></script> |
| 5 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 | 5 <script src="media-file.js"></script> |
| 6 (Please avoid writing new tests using video-test.js) --> | 6 <video autoplay></video> |
| 7 <script src=video-test.js></script> | 7 <script> |
| 8 // Test looping by: |
| 9 // Play to end with "loop" set to true. |
| 10 // When "seeked" event fires, verify that time has jumped back and movie is play
ing. |
| 11 // Set "loop" to false and play again. |
| 12 // Verify that "ended" event fires. |
| 13 async_test(function(t) { |
| 14 var video = document.querySelector("video"); |
| 15 // Test setting/removing the attribute. |
| 16 assert_equals(video.getAttribute("loop"), null); |
| 17 assert_false(video.loop); |
| 8 | 18 |
| 9 <script> | 19 video.loop = true; |
| 10 var seekCount = 0; | 20 assert_true(video.loop); |
| 11 var playCount = 0; | 21 assert_not_equals(video.getAttribute("loop"), null); |
| 12 | 22 |
| 13 function play() | 23 video.removeAttribute("loop"); |
| 14 { | 24 assert_false(video.loop); |
| 15 if (video.readyState < HTMLMediaElement.HAVE_METADATA) { | |
| 16 setTimeout(play, 100); | |
| 17 return; | |
| 18 } | |
| 19 | 25 |
| 20 if (++playCount > 1) | 26 video.onplay = t.step_func(function() { |
| 21 return; | 27 video.onplay = null; |
| 28 assert_false(video.paused); |
| 22 | 29 |
| 23 consoleWrite("<br><em>++ seek to near the end, wait for 'seeked'
event to announce loop.</em>"); | 30 // Pause playback so the movie can't possibly loop before the seeked eve
nt fires. |
| 24 testExpected("video.paused", false); | 31 video.pause(); |
| 32 // seek to near the end, wait for "seeked" event to announce loop. |
| 33 var seekCount = 0; |
| 34 video.onseeked = t.step_func(function() { |
| 35 switch (++seekCount) { |
| 36 case 1: |
| 37 // first seek completed, beginning playback. |
| 38 assert_true(video.paused); |
| 39 assert_false(video.ended); |
| 40 video.play(); |
| 41 break; |
| 42 case 2: |
| 43 // second seek completed because video looped, toggle "loop" and
seek to near end again. |
| 44 assert_false(video.paused); |
| 45 assert_false(video.ended); |
| 46 video.pause(); |
| 47 assert_greater_than_equal(video.currentTime, 0); |
| 48 assert_less_than(video.currentTime, video.duration); |
| 49 video.loop = false; |
| 50 video.currentTime = video.duration - 0.4; |
| 51 break; |
| 52 case 3: |
| 53 // third seek completed, beginning playback for the last time. |
| 54 assert_true(video.paused); |
| 55 assert_false(video.ended); |
| 56 video.play(); |
| 57 break; |
| 58 } |
| 59 }); |
| 25 | 60 |
| 26 // Pause playback so the movie can't possibly loop before the se
eked event fires | 61 video.currentTime = video.duration - 0.4; |
| 27 run("video.pause()"); | 62 }); |
| 28 waitForEvent("seeked", seeked); | |
| 29 run("video.currentTime = video.duration - 0.4"); | |
| 30 consoleWrite(""); | |
| 31 } | |
| 32 | 63 |
| 33 function seeked() | 64 video.onended = t.step_func_done(function() { |
| 34 { | 65 assert_true(video.ended); |
| 35 switch (++seekCount) | 66 assert_equals(video.currentTime, video.duration); |
| 36 { | 67 }); |
| 37 case 1: | |
| 38 consoleWrite("<br><em>++ first seek completed, beginning
playback.</em>"); | |
| 39 testExpected("video.paused", true); | |
| 40 testExpected("video.ended", false); | |
| 41 run("video.play()"); | |
| 42 consoleWrite(""); | |
| 43 break; | |
| 44 case 2: | |
| 45 consoleWrite("<br><em>++ second seek completed because v
ideo looped, toggle 'loop' and seek to near end again.</em>"); | |
| 46 testExpected("video.paused", false); | |
| 47 testExpected("video.ended", false); | |
| 48 run("video.pause()"); | |
| 49 | 68 |
| 50 testExpected("mediaElement.currentTime", 0, '>='); | 69 // Set "loop" to true and begin playing. |
| 51 | 70 video.loop = true; |
| 52 // don't use "testExpected()" so we won't log the actual
duration as the floating point result may differ with different engines | 71 video.src = findMediaFile("video", "content/test"); |
| 53 reportExpected(mediaElement.currentTime < mediaElement.d
uration, "mediaElement.currentTime", "<", "mediaElement.duration", mediaElement.
currentTime); | 72 }); |
| 54 run("video.loop = false"); | 73 </script> |
| 55 run("video.currentTime = video.duration - 0.4"); | |
| 56 consoleWrite(""); | |
| 57 break; | |
| 58 case 3: | |
| 59 consoleWrite("<br><em>++ third seek completed, beginning
playback for the last time.</em>"); | |
| 60 testExpected("video.paused", true); | |
| 61 testExpected("video.ended", false); | |
| 62 run("video.play()"); | |
| 63 consoleWrite(""); | |
| 64 break; | |
| 65 default: | |
| 66 failTest("Video should have only seeked three times."); | |
| 67 break; | |
| 68 | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 function ended() | |
| 73 { | |
| 74 consoleWrite("<br><em>++ played to end and stopped.</em>"); | |
| 75 testExpected("video.ended", true); | |
| 76 | |
| 77 // don't use "testExpected()" so we won't log the actual duratio
n as the floating point result may differ with different engines | |
| 78 reportExpected(mediaElement.currentTime == mediaElement.duration
, "mediaElement.currentTime", "==", "mediaElement.duration", mediaElement.curren
tTime); | |
| 79 | |
| 80 consoleWrite(""); | |
| 81 endTest(); | |
| 82 } | |
| 83 | |
| 84 function start() | |
| 85 { | |
| 86 findMediaElement(); | |
| 87 | |
| 88 consoleWrite("<em>++ Test setting/removing the attribute.</em>")
; | |
| 89 testExpected("video.getAttribute('loop')", null); | |
| 90 testExpected("video.loop", false); | |
| 91 | |
| 92 run("video.loop = true"); | |
| 93 testExpected("video.loop", true); | |
| 94 testExpected("video.getAttribute('loop')", null, "!="); | |
| 95 | |
| 96 run("video.removeAttribute('loop')"); | |
| 97 testExpected("video.loop", false); | |
| 98 | |
| 99 waitForEvent('pause'); | |
| 100 waitForEvent('play', play); | |
| 101 waitForEvent("ended", ended); | |
| 102 | |
| 103 consoleWrite("<br><em>++ Set 'loop' to true and begin playing.</
em>"); | |
| 104 var mediaFile = findMediaFile("video", "content/test"); | |
| 105 run("video.loop = true"); | |
| 106 video.src = mediaFile; | |
| 107 consoleWrite(""); | |
| 108 } | |
| 109 </script> | |
| 110 | |
| 111 </head> | |
| 112 <body> | |
| 113 <video controls autoplay ></video> | |
| 114 <p><b>Test looping by:</b> | |
| 115 <ol> | |
| 116 <li>Play to end with 'loop' set to true.</li> | |
| 117 <li>When 'seeked' event fires, verify that time has jumped back and
movie is playing.</li> | |
| 118 <li>Set 'loop' to false and play again.</li> | |
| 119 <li>Verify that 'ended' event fires.</li> | |
| 120 </ol> | |
| 121 </p> | |
| 122 <script>start()</script> | |
| 123 </body> | |
| 124 </html> | |
| OLD | NEW |