[Modern Media Controls] Turn media/modern-media-controls/ios-inline-media-controls...
[WebKit-https.git] / LayoutTests / media / video-background-playback.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 playThroughCount = 0;
8             var state = 0;
9             var audio;
10             var video
11
12             function logEvent(evt)
13             {
14                 consoleWrite("EVENT(" + evt.type + ")");
15             }
16
17             function checkState()
18             {
19                 consoleWrite("<br>** 100ms timer fired...");
20                 switch (state) {
21                 case "background":
22                     testExpected("video.paused", true);
23                     testExpected("audio.paused", false);
24                     state = "foreground";
25                     consoleWrite("<br>** Simulate switch back to foreground, video should resume.");
26                     run("internals.applicationWillEnterForeground()");
27                     setTimeout(checkState, 100);
28                     consoleWrite("");
29                     break;
30                 case "foreground":
31                     testExpected("video.paused", false);
32                     testExpected("audio.paused", false);
33                     consoleWrite("");
34                     endTest();
35                     break;
36                 }
37             }
38
39             function playing(evt)
40             {
41                 logEvent(evt);
42                 if (++playCount != 2)
43                     return;
44
45                 consoleWrite("<br>** Simulate switch to background, video should pause.");
46                 run("internals.applicationDidEnterBackground()");
47                 setTimeout(checkState, 100);
48                 state = "background";
49                 consoleWrite("");
50             }
51
52             function canplaythrough(evt)
53             {
54                 logEvent(evt);
55                 if (++playThroughCount < 2)
56                     return;
57                 consoleWrite("");
58                 run("audio.play()");
59                 run("video.play()");
60             }
61
62             function start()
63             {
64                 if (!window.internals) {
65                     failTest('This test requires window.internals.');
66                     return;
67                 }
68
69                 var elements = document.getElementsByTagName('video');
70                 for (var i = 0; i < elements.length; ++i) {
71                     elements[i].addEventListener("canplaythrough", canplaythrough);
72                     elements[i].addEventListener('playing', playing);
73                     elements[i].addEventListener('pause', logEvent);
74                 }
75                 video = elements[0];
76                 video.src = findMediaFile("video", "content/test");
77
78                 audio = elements[1];
79                 audio.src = findMediaFile("audio", "content/silence");
80
81                 run("internals.setMediaSessionRestrictions('videoaudio', 'BackgroundProcessPlaybackRestricted')");
82                 state = "foreground";
83                 consoleWrite("");
84             }
85         </script>
86     </head>
87
88     <body onload="start()">
89         <video controls id="one"></video>
90         <video controls id="two"></video>
91         <p>Test switching application state when &lt;video&gt; is not allowed to play in background.</p>
92     </body>
93 </html>