blob: 2987c2248d5dbba8bf259705668a90ac4f0bb636 [file] [log] [blame]
<script src="../../../resources/js-test-pre.js"></script>
<script src="../resources/media-controls-loader.js" type="text/javascript"></script>
<body>
<video src="../../content/test.mp4" style="width: 320px; height: 240px;" autoplay controls></video>
<div id="host"></div>
<script type="text/javascript">
window.jsTestIsAsync = true;
description("Testing the <code>AirPlaySupport</code> behavior.");
const container = document.querySelector("div#host");
const media = document.querySelector("video");
const mediaController = createControls(container, media, null);
media.addEventListener("canplay", makeAirPlayAvailable);
function makeAirPlayAvailable()
{
debug("Making AirPlay routes available.");
media.addEventListener("webkitplaybacktargetavailabilitychanged", playbackTargetAvailabilityChangedOnce, true);
window.internals.setMockMediaPlaybackTargetPickerEnabled(true);
}
function playbackTargetAvailabilityChangedOnce(event)
{
media.removeEventListener('webkitplaybacktargetavailabilitychanged', playbackTargetAvailabilityChangedOnce, true);
media.addEventListener('webkitplaybacktargetavailabilitychanged', playbackTargetAvailabilityChangedAgain, true);
window.internals.setMockMediaPlaybackTargetPickerState('Sleepy TV', 'DeviceAvailable');
}
function playbackTargetAvailabilityChangedAgain(event)
{
// setMockMediaPlaybackTargetPickerState happens asynchronously in WK2 and a
// "webkitplaybacktargetavailabilitychanged" is always sent when an event listener
// is added, so we may get a "not available" event first.
if (event.availability == 'not-available')
return;
media.removeEventListener('webkitplaybacktargetavailabilitychanged', playbackTargetAvailabilityChangedAgain, true);
shouldBeTrue("mediaController.controls.airplayButton.enabled");
shouldBeFalse("mediaController.controls.airplayButton.on");
shouldBeTrue("mediaController.controls.muteButton.enabled");
shouldBeTrue("mediaController.controls.autoHideController.fadesWhileIdle");
enterAirPlay();
}
function enterAirPlay()
{
debug("");
debug("Entering AirPlay playback mode.");
media.addEventListener("webkitcurrentplaybacktargetiswirelesschanged", currentPlaybackTargetIsWirelessChanged);
media.webkitShowPlaybackTargetPicker();
}
function currentPlaybackTargetIsWirelessChanged(event)
{
if (!media.webkitCurrentPlaybackTargetIsWireless)
return;
shouldBeTrue("mediaController.controls.airplayButton.enabled");
shouldBeTrue("mediaController.controls.airplayButton.on");
shouldBeFalse("mediaController.controls.muteButton.enabled");
shouldBeFalse("mediaController.controls.autoHideController.fadesWhileIdle");
debug("");
container.remove();
media.remove();
finishJSTest();
}
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>