Implement the Remote Playback API.
[WebKit-https.git] / LayoutTests / media / remoteplayback-target-availability.html
1 <html>
2     <head>
3         <script src='media-file.js'></script>
4         <script src='video-test.js'></script>
5         <script>
6             var video;
7             var callbackId;
8
9             var nextStep;
10
11             function start()
12             {
13                 findMediaElement();
14
15                 if (window.internals) {
16                     internals.setMockMediaPlaybackTargetPickerEnabled(true);
17                     internals.settings.setAllowsAirPlayForMediaPlayback(true);
18                 }
19
20                 consoleWrite('<br>** test initial callback when device is unavailable');
21
22                 video.remote.watchAvailability(step).then(setCallbackId).catch(failTest);
23                 nextStep = initial;
24             }
25
26             function setCallbackId(id)
27             {
28                 callbackId = id;
29             }
30
31             function step(available)
32             {
33                 consoleWrite(`CALLBACK( available=${available} )`);
34
35                 if (nextStep)
36                     nextStep(available);
37             }
38
39             function initial(available)
40             {
41                 consoleWrite('<br>** simulate device becoming available');
42                 if (window.internals)
43                     internals.setMockMediaPlaybackTargetPickerState('Sleepy TV', 'DeviceAvailable');
44                 nextStep = haveTarget;
45             }
46
47             function haveTarget(available)
48             {
49                 consoleWrite('<br>** test initial callback when device is available');
50
51                 video.remote.cancelWatchAvailability(callbackId);
52                 video.remote.watchAvailability(step).then(setCallbackId).catch(failTest);
53                 nextStep = initialWithTarget;
54             }
55
56             function initialWithTarget(available)
57             {
58                 consoleWrite('<br>** simulate device becoming unavailable');
59                 if (window.internals)
60                     internals.setMockMediaPlaybackTargetPickerState('Sleepy TV', 'DeviceUnavailable');
61                 nextStep = endTest;
62
63             }
64         </script>
65     </head>
66
67     <body onload='start()'>
68         <video controls></video>
69         <p>Test that 'RemotePlaybackAvailabilityCallback' callback is called when playback devices come and go.</p>
70     </body>
71 </html>