blob: 01d2a4aa757939d654845834e1bc71a2e70c3c57 [file] [log] [blame]
<script src="../../../resources/js-test-pre.js"></script>
<script src="../resources/media-controls-loader.js" type="text/javascript"></script>
<body>
<style type="text/css" media="screen">
video, #host {
position: absolute;
top: 0;
left: 0;
}
video {
width: 800px;
height: 240px;
}
</style>
<video src="../../content/test.mp4" controls></video>
<div id="host"></div>
<script type="text/javascript">
window.jsTestIsAsync = true;
description("Testing the <code>PlacardSupport</code> behavior when playing media through AirPlay.");
const container = document.querySelector("div#host");
const media = document.querySelector("video");
const mediaController = createControls(container, media, null);
media.addEventListener("canplay", makeAirPlayAvailable);
function makeAirPlayAvailable()
{
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);
enterAirPlay();
}
function enterAirPlay()
{
media.addEventListener("webkitcurrentplaybacktargetiswirelesschanged", currentPlaybackTargetIsWirelessChanged);
media.webkitShowPlaybackTargetPicker();
}
function currentPlaybackTargetIsWirelessChanged(event)
{
if (!media.webkitCurrentPlaybackTargetIsWireless)
return;
shouldBe("mediaController.controls.placard", "mediaController.controls.airplayPlacard");
shouldBeTrue("mediaController.controls.children.includes(mediaController.controls.airplayPlacard)");
debug("");
container.remove();
media.remove();
finishJSTest();
}
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>