blob: f86ef6c707dc47159d6d6ae73821f27bf26290cf [file] [log] [blame]
<script src="../../../resources/js-test-pre.js"></script>
<script src="../resources/media-controls-loader.js" type="text/javascript"></script>
<script src="../resources/media-controls-utils.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"></video>
<div id="host"></div>
<script type="text/javascript">
window.jsTestIsAsync = true;
description("Testing the <code>PlacardSupport</code> behavior when playing media through AirPlay in fullscreen.");
const container = document.querySelector("div#host");
const media = document.querySelector("video");
const mediaController = createControls(container, media, null);
const button = document.body.appendChild(document.createElement("div"));
media.addEventListener("canplay", enterFullscreen);
function enterFullscreen()
{
media.addEventListener(media.webkitPresentationMode ? "webkitpresentationmodechanged" : "webkitfullscreenchange", makeAirPlayAvailable);
button.setAttribute("style", "position: absolute; left: 0; top: 0;");
button.innerText = "Enter fullscreen";
button.addEventListener("click", () => media.webkitEnterFullscreen());
pressOnElement(button);
}
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();
button.remove();
media.remove();
finishJSTest();
}
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>