Make Remote Control commands testable
[WebKit-https.git] / LayoutTests / media / video-remote-control-playpause.html
1 <html>
2     <head>
3         <script src=media-file.js></script>
4         <script src=video-test.js></script>
5         <script>
6             var playCount = 0;
7             var pauseCount = 0;
8             var seekedCount = 0;
9             var playThroughCount = 0;
10             var videos = [];
11
12             function logEvent(evt)
13             {
14                 consoleWrite("EVENT(" + evt.type + ")");
15             }
16
17             function ended(evt)
18             {
19                 logEvent(evt);
20             }
21
22             function seeked(evt)
23             {
24                 logEvent(evt);
25
26                 switch (++seekedCount)
27                 {
28                 case 2:
29                     consoleWrite("<br>** Send a play command, it should go to videos[0] because it was playing most recently.");
30                     run("internals.postRemoteControlCommand('play')");
31                     consoleWrite("");
32                     break;
33                 }
34             }
35
36             function pause(evt)
37             {
38                 logEvent(evt);
39
40                 switch (++pauseCount)
41                 {
42                 case 1:
43                     testExpected("event.target.id", "two");
44                     testExpected("videos[0].paused", false);
45                     testExpected("videos[1].paused", true);
46                     consoleWrite("<br>** Pause video[0], so they both stop playing...");
47                     run("videos[0].pause()");
48                     consoleWrite("");
49                     break;
50                 case 2:
51                     testExpected("event.target.id", "one");
52                     testExpected("videos[0].paused", true);
53                     testExpected("videos[1].paused", true);
54
55                     consoleWrite("<br>** Seek so video[1] will pause automatically when playback ends.");
56                     
57                     var seekTime = (videos[1].duration - .5).toFixed(1);
58                     run("videos[0].currentTime = 0");
59                     run("videos[1].currentTime = " + seekTime);
60                     consoleWrite("");
61                     break;
62                 case 3:
63                     testExpected("event.target.id", "two");
64                     testExpected("videos[0].paused", false);
65                     testExpected("videos[1].paused", true);
66
67                     consoleWrite("<br>** Send a pause command, videos[0] is still playing so it should get the command.");
68                     run("internals.postRemoteControlCommand('pause')");
69                     consoleWrite("");
70                     break;
71                 case 4:
72                     testExpected("event.target.id", "one");
73                     testExpected("videos[0].paused", true);
74                     testExpected("videos[1].paused", true);
75                     consoleWrite("");
76                     endTest();
77                     break;
78                 case 4:
79                 }
80             }
81
82             function playing(evt)
83             {
84                 logEvent(evt);
85
86                 switch (++playCount)
87                 {
88                 case 2:
89                     consoleWrite("<br>** Send a pause command, it should go to video[1].");
90                     run("internals.postRemoteControlCommand('pause')");
91                     consoleWrite("");
92                     break;
93                 case 3:
94                     testExpected("event.target.id", "one");
95                     consoleWrite("<br>** Start videos[1], wait for it to pause at duration.");
96                     run("videos[1].play()");
97                     consoleWrite("");
98                     break;
99                 case 4:
100                     testExpected("event.target.id", "two");
101                     consoleWrite("");
102                     break;
103                 }
104             }
105
106             function canplaythrough(evt)
107             {
108                 logEvent(evt);
109
110                 if (++playThroughCount < 2)
111                     return;
112
113                 consoleWrite("<br>** Play both videos, the last one started (video[1]) should get focus...");
114                 run("videos[0].play()");
115                 run("videos[1].play()");
116
117                 consoleWrite("");
118             }
119
120             function start()
121             {
122                 if (!window.internals) {
123                     failTest('This test requires window.internals.');
124                     return;
125                 }
126
127                 videos = document.getElementsByTagName('video');
128                 for (var i = 0; i < videos.length; ++i) {
129                     video = videos[i];
130                     video.addEventListener("canplaythrough", canplaythrough);
131                     video.addEventListener('playing', playing);
132                     video.addEventListener('pause', pause);
133                     video.addEventListener('seeked', seeked);
134                     video.addEventListener('ended');
135                     video.src = findMediaFile("video", "content/test");
136                 }
137             }
138         </script>
139     </head>
140
141     <body onload="start()">
142         <video controls id="one"></video>
143         <video controls id="two"></video>
144         <p>Test play and pause with "remote control" interface.</p>
145     </body>
146 </html>