gecko-dev/dom/html/test/file_fullscreen-esc-context...

101 строка
3.1 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=910532
Verify that an ESC key press canceling the context menu
won't exit DOM fullscreen.
-->
<head>
<meta charset="UTF-8">
<title>Text for bug 910532</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="file_fullscreen-utils.js"></script>
<style>
body:-moz-full-screen {
background-color: red;
}
</style>
</head>
<body>
<script type="application/javascript">
const Ci = SpecialPowers.Ci;
SimpleTest.requestFlakyTimeout("We need to wait a small time to confirm " +
"that the first ESC key does not exit fullscreen.");
function ok(condition, msg) {
opener.ok(condition, "[esc-context-menu] " + msg);
}
function is(a, b, msg) {
opener.is(a, b, "[esc-context-menu] " + msg);
}
var contextMenu;
var escapeSent = 0;
function sendEscape() {
escapeSent++;
synthesizeKey("VK_ESCAPE", {});
}
function begin() {
// Copy from browser/base/content/test/general/test_contextmenu.html
var chromeWin = SpecialPowers.wrap(window)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow)
.QueryInterface(Ci.nsIDOMChromeWindow);
contextMenu = chromeWin.document.getElementById("contentAreaContextMenu");
ok(contextMenu, "Got context menu XUL");
addFullscreenChangeContinuation("enter", fullscreenEntered);
SpecialPowers.pushPrefEnv({"set":[["full-screen-api.approval-required", false]]}, function() {
document.body.mozRequestFullScreen();
});
}
function finish() {
opener.nextTest();
}
function fullscreenEntered(event) {
ok(document.mozFullScreen, "Should have entered fullscreen mode");
is(document.mozFullScreenElement, document.body, "FSE should be doc");
contextMenu.addEventListener("popupshown", contextMenuOpened, false);
is(contextMenu.state, "closed", "Should not have opened context menu");
synthesizeMouseAtCenter(document.body, {type: 'contextmenu', button: 2});
}
function contextMenuOpened(event) {
contextMenu.removeEventListener("popupshown", contextMenuOpened);
is(contextMenu.state, "open", "Should have opened context menu");
addFullscreenChangeContinuation("exit", fullscreenExited);
contextMenu.addEventListener("popuphidden", contextMenuClosed, false);
sendEscape();
}
function contextMenuClosed(event) {
is(contextMenu.state, "closed", "Should have closed context menu");
setTimeout(function () {
ok(document.mozFullScreen, "Should still be in fullscreen mode");
sendEscape();
}, 100);
}
function fullscreenExited(event) {
is(escapeSent, 2, "Only the second escape should exit fullscreen");
ok(!document.mozFullScreen, "Should have left fullscreen mode");
finish();
}
</script>
</body>
</html>