blob: fd2d27f84f46612f1cf725c3df8559218cb93466 [file] [log] [blame]
<html>
<head>
<script src='media-file.js'></script>
<script src='video-test.js'></script>
<script>
let pendingTimeout;
async function start()
{
findMediaElement();
if (window.internals) {
internals.setMockMediaPlaybackTargetPickerEnabled(true);
internals.settings.setAllowsAirPlayForMediaPlayback(true);
}
consoleWrite('<br>** prompt() when disableRemotePlayback is set should fail');
run('video.disableRemotePlayback = true');
try {
await video.remote.prompt();
failTest('prompt() succeeded when remote playback is disabled');
} catch(error) {
consoleWrite(`EXPECTED ERROR: ${ error }`);
}
run('video.disableRemotePlayback = false');
consoleWrite('<br>** prompt() outside of a user action should fail');
try {
await video.remote.prompt();
failTest('prompt() succeeded outside of a user action');
} catch(error) {
consoleWrite(`EXPECTED ERROR: ${ error }`);
}
consoleWrite('<br>** prompt() when no targets are available should fail');
runWithKeyDown(() => {
video.remote.prompt().then(failTest).catch(handleNoTargetError);
});
}
async function handleNoTargetError(error)
{
consoleWrite(`EXPECTED ERROR: ${ error }`);
consoleWrite('<br>** Simulate a device becoming available')
pendingTimeout = setTimeout(_ => {
failTest(`<br>Remote device not available after 8 seconds!`);
}, 8000);
if (window.internals)
internals.setMockMediaPlaybackTargetPickerState('', 'DeviceAvailable');
try {
await video.remote.watchAvailability(availabilityChanged);
} catch (error) {
failTest(`<br>'watchAvailability' threw error ${error}`);
}
}
async function availabilityChanged(available)
{
if (!available)
return;
video.remote.cancelWatchAvailability();
clearTimeout(pendingTimeout);
if (video.src)
return;
run('video.src = findMediaFile("video", "content/test")');
await waitForEventWithTimeout(video, 'canplaythrough', 8000, "'canplaythrough' not fired after 8 seconds");
consoleWrite('<br>** Simulate a device becoming selected');
runWithKeyDown(() => {
video.remote.prompt().catch(failTest);
});
if (window.internals)
internals.setMockMediaPlaybackTargetPickerState('Sleepy TV', 'DeviceAvailable');
await waitForEventWithTimeout(video.remote, 'connecting', 8000, "'connecting' not fired after 8 seconds");
await waitForEventWithTimeout(video.remote, 'connect', 8000, "'connect' not fired after 8 seconds");
endTest();
}
</script>
</head>
<body onload='start()'>
<video controls></video>
<p>Test the operation of prompt().</p>
</body>
</html>