[Modern Media Controls] Turn media/modern-media-controls/ios-inline-media-controls...
[WebKit-https.git] / LayoutTests / media / video-loop.html
index af1bc18..4e44416 100644 (file)
@@ -6,11 +6,23 @@
     
         <script>
             var seekCount = 0;
+            var playCount = 0;
     
             function play()
             {
-                consoleWrite("<br>++ seek to near the end, wait for 'seeked' event to announce loop");
+                if (video.readyState < HTMLMediaElement.HAVE_METADATA) {
+                    setTimeout(play, 100);
+                    return;
+                }
+
+                if (++playCount > 1)
+                    return;
+
+                consoleWrite("<br><em>++ seek to near the end, wait for 'seeked' event to announce loop.</em>");
                 testExpected("video.paused", false);
+                
+                // Pause playback so the movie can't possibly loop before the seeked event fires
+                run("video.pause()");
                 waitForEvent("seeked", seeked);
                 run("video.currentTime = video.duration - 0.4");
                 consoleWrite("");
     
             function seeked()
             {
-                ++seekCount;
-                if (seekCount == 2) {
-                    consoleWrite("<br>++ video just looped, toggle 'loop' and seek to near end");
-                    testExpected("video.paused", false);
-                    testExpected("video.ended", false);
-                    testExpected("mediaElement.currentTime", 0, '>=');
+                switch (++seekCount)
+                {
+                    case 1:
+                        consoleWrite("<br><em>++ first seek completed, beginning playback.</em>");
+                        testExpected("video.paused", true);
+                        testExpected("video.ended", false);
+                        run("video.play()");
+                        consoleWrite("");
+                        break;
+                    case 2:
+                        consoleWrite("<br><em>++ second seek completed because video looped, toggle 'loop' and seek to near end again.</em>");
+                        testExpected("video.paused", false);
+                        testExpected("video.ended", false);
+                        run("video.pause()");
 
-                    // don't use "testExpected()" so we won't log the actual duration as the floating point result may differ with different engines
-                    reportExpected(mediaElement.currentTime < mediaElement.duration, "mediaElement.currentTime", "<", "mediaElement.duration", mediaElement.currentTime);
-                    run("video.loop = false");
-                    run("video.currentTime = video.duration - 0.4");
-                    consoleWrite("");
+                        testExpected("mediaElement.currentTime", 0, '>=');
+    
+                        // don't use "testExpected()" so we won't log the actual duration as the floating point result may differ with different engines
+                        reportExpected(mediaElement.currentTime < mediaElement.duration, "mediaElement.currentTime", "<", "mediaElement.duration", mediaElement.currentTime);
+                        run("video.loop = false");
+                        run("video.currentTime = video.duration - 0.4");
+                        consoleWrite("");
+                        break;
+                    case 3:
+                        consoleWrite("<br><em>++ third seek completed, beginning playback for the last time.</em>");
+                        testExpected("video.paused", true);
+                        testExpected("video.ended", false);
+                        run("video.play()");
+                        consoleWrite("");
+                        break;
+                    default:
+                        failTest("Video should have only seeked three times.");
+                        break;
+                        
                 }
             }
     
             function ended() 
             {
+                consoleWrite("<br><em>++ played to end and stopped.</em>");
                 testExpected("video.ended", true);
 
                 // don't use "testExpected()" so we won't log the actual duration as the floating point result may differ with different engines
@@ -48,7 +83,7 @@
             {
                 findMediaElement();
 
-                consoleWrite("++ Test setting/removing the attribute");
+                consoleWrite("<em>++ Test setting/removing the attribute.</em>");
                 testExpected("video.getAttribute('loop')", null);
                 testExpected("video.loop", false);
             
@@ -63,7 +98,7 @@
                 waitForEvent('play', play);
                 waitForEvent("ended", ended);
 
-                consoleWrite("<br>++ Set 'loop' to true and start playing");
+                consoleWrite("<br><em>++ Set 'loop' to true and begin playing.</em>");
                 var mediaFile = findMediaFile("video", "content/test");
                 run("video.loop = true");
                 video.src = mediaFile;
     </head>
     <body>
         <video controls autoplay ></video>
-        <p>Test looping.</p>
+        <p><b>Test looping by:</b>
+        <ol>
+            <li>Play to end with 'loop' set to true.</li>
+            <li>When 'seeked' event fires, verify that time has jumped back and movie is playing.</li>
+            <li>Set 'loop' to false and play again.</li>
+            <li>Verify that 'ended' event fires.</li>
+        </ol>
+        </p>
         <script>start()</script>
     </body>
 </html>