blob: 76bf3e3c2e32d208255c0867a0c86bf886fed3c6 [file] [log] [blame]
eric.carlson@apple.com22d66602014-02-04 19:09:34 +00001<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.");
jer.noble@apple.comc328bed2017-06-16 21:59:23 +000026 run("internals.applicationWillEnterForeground()");
eric.carlson@apple.com22d66602014-02-04 19:09:34 +000027 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.");
jer.noble@apple.comc328bed2017-06-16 21:59:23 +000046 run("internals.applicationDidEnterBackground()");
eric.carlson@apple.com22d66602014-02-04 19:09:34 +000047 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
jer.noble@apple.come8fe8e82016-10-31 16:36:00 +000081 run("internals.setMediaSessionRestrictions('videoaudio', 'BackgroundProcessPlaybackRestricted')");
eric.carlson@apple.com22d66602014-02-04 19:09:34 +000082 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>