[Modern Media Controls] Turn media/modern-media-controls/ios-inline-media-controls...
[WebKit-https.git] / LayoutTests / media / video-background-tab-playback.html
1 <html>
2     <head>
3         <script src=media-file.js></script>
4         <script src=video-test.js></script>
5         <script>
6             var state = 0;
7
8             function checkState()
9             {
10                 consoleWrite("<br>** 100ms timer fired...");
11                 switch (state) {
12                 case "background":
13                     testExpected("video.paused", true);
14                     state = "foreground";
15                     consoleWrite("<br>** Simulate switch back to foreground, video should remain paused.");
16                     run("internals.applicationWillEnterForeground()");
17                     setTimeout(checkState, 100);
18                     consoleWrite("");
19                     break;
20                 case "foreground":
21                     testExpected("video.paused", true);
22                     consoleWrite("");
23                     testRunner.resetPageVisibility();
24                     endTest();
25                     break;
26                 }
27             }
28
29             function playing(evt)
30             {
31                 consoleWrite("<br>** Simulate switching the tab to background, video should pause.");
32                 run("testRunner.setPageVisibility('hidden')");
33                 setTimeout(checkState, 100);
34                 state = "background";
35                 consoleWrite("");
36             }
37
38             function canplaythrough(evt)
39             {
40                 consoleWrite("");
41                 run("video.play()");
42             }
43
44             function start()
45             {
46                 if (!window.internals) {
47                     failTest('This test requires window.internals.');
48                     return;
49                 }
50
51                 findMediaElement();
52                 video.src = findMediaFile("video", "content/test");
53                 waitForEvent('canplaythrough', canplaythrough);
54                 waitForEvent('playing', playing);
55
56                 run("internals.setMediaSessionRestrictions('videoaudio', 'BackgroundTabPlaybackRestricted')");
57                 state = "foreground";
58                 consoleWrite("");
59             }
60         </script>
61     </head>
62
63     <body onload="start()">
64         <video controls></video>
65         <p>Test tab with &lt;video&gt; moving to background when playback is not allowed in background.</p>
66     </body>
67 </html>