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