blob: 841452facc19fddbfe1f1090c6281a82f726724b [file] [log] [blame]
<!DOCTYPE html>
<title>Document#exitFullscreen() vs. Element#requestFullscreen()</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../trusted-click.js"></script>
<div id="log"></div>
<div id="parent"><div></div></div>
<script>
// Adapted from https://github.com/web-platform-tests/wpt/pull/4250
// TODO(foolip): Remove this test when the above is imported and passing.
async_test(t => {
const parent = document.getElementById("parent");
document.onfullscreenchange = t.step_func(() => {
// We are now in fullscreen, so exiting requires a resize but requesting
// does not.
assert_equals(document.fullscreenElement, parent, "fullscreenElement after fullscreenchange event");
trusted_click(t, () => {
// Request fullscreen on another element, to avoid any synchronous
// short-circuiting on document.fullscreenElement.requestFullscreen(),
// which used to be in the spec. Also request both before and after the
// exit. The first request will be applied at the next microtask
// checkpoint and events queued for the following animation frame task.
// That will race with the exit resize, but by the second fullscreenchange
// event fullscreenElement must be null. The second request is ignored due
// to the pending exit and doesn't result in any events.
let fullscreenchanges = 0;
document.onfullscreenchange = t.step_func(() => {
fullscreenchanges++;
if (fullscreenchanges == 2) {
assert_equals(document.fullscreenElement, null);
// Expect no more fullscreenchange events.
document.onfullscreenchange = t.unreached_func("third fullscreenchange event");
requestAnimationFrame(t.step_func_done());
}
});
const child = parent.firstChild;
child.requestFullscreen();
assert_equals(document.fullscreenElement, parent, "fullscreenElement after first requestFullscreen()");
document.exitFullscreen();
assert_equals(document.fullscreenElement, parent, "fullscreenElement after exitFullscreen()");
child.requestFullscreen();
assert_equals(document.fullscreenElement, parent, "fullscreenElement after second requestFullscreen()");
}, parent);
});
document.onfullscreenerror = t.unreached_func("fullscreenerror event");
trusted_request(t, parent);
});
</script>