mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-09-10 11:54:40 +00:00
261 lines
10 KiB
HTML
261 lines
10 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=545812
|
|
|
|
Test DOM full-screen API.
|
|
|
|
-->
|
|
<head>
|
|
<title>Test for Bug 545812</title>
|
|
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<script type="application/javascript" src="file_fullscreen-utils.js"></script>
|
|
<style>
|
|
body {
|
|
background-color: black;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<script type="application/javascript">
|
|
|
|
/** Test for Bug 545812 **/
|
|
|
|
function ok(condition, msg) {
|
|
opener.ok(condition, "[fullscreen] " + msg);
|
|
}
|
|
|
|
function is(a, b, msg) {
|
|
opener.is(a, b, "[fullscreen] " + msg);
|
|
}
|
|
|
|
/*
|
|
<html>
|
|
<body onload='document.body.mozRequestFullScreen();'>
|
|
<iframe id='inner-frame'></iframe>
|
|
</body>
|
|
</html>
|
|
*/
|
|
var iframeContents = "data:text/html;charset=utf-8,<html><body onload%3D'parent.SimpleTest.waitForFocus(function(){document.body.mozRequestFullScreen();});'><iframe id%3D'inner-frame'><%2Fiframe><%2Fbody><%2Fhtml>";
|
|
|
|
var iframe = null;
|
|
var outOfDocElement = null;
|
|
var inDocElement = null;
|
|
var container = null;
|
|
var button = null;
|
|
|
|
|
|
function sendMouseClick(element) {
|
|
synthesizeMouseAtCenter(element, {});
|
|
}
|
|
|
|
function fullScreenElement() {
|
|
return document.getElementById('full-screen-element');
|
|
}
|
|
|
|
function enter1(event) {
|
|
ok(document.mozFullScreen, "1. Should be in full-screen mode (first time)");
|
|
is(event.target, document, "2. Event target should be full-screen document #1");
|
|
is(document.mozFullScreenElement, fullScreenElement(), "3. Full-screen element should be div element.");
|
|
ok(document.mozFullScreenElement.matches(":-moz-full-screen"), "4. FSE should match :-moz-full-screen");
|
|
var fse = fullScreenElement();
|
|
addFullscreenChangeContinuation("exit", exit1);
|
|
fse.parentNode.removeChild(fse);
|
|
is(document.mozFullScreenElement, null, "5. Full-screen element should be null after removing.");
|
|
ok(!document.mozFullScreen, "6. Should have left full-screen mode when we remove full-screen element");
|
|
document.body.appendChild(fse);
|
|
ok(!document.mozFullScreen, "7. Should not return to full-screen mode when re-adding former FSE");
|
|
is(document.mozFullScreenElement, null, "8. Full-screen element should still be null after re-adding former FSE.");
|
|
}
|
|
|
|
function exit1(event) {
|
|
ok(!document.mozFullScreen, "9. Should have left full-screen mode (first time)");
|
|
is(event.target, document, "10. Event target should be full-screen document #2");
|
|
is(document.mozFullScreenElement, null, "11. Full-screen element should be null.");
|
|
iframe = document.createElement("iframe");
|
|
iframe.allowFullscreen = true;
|
|
addFullscreenChangeContinuation("enter", enter2);
|
|
document.body.appendChild(iframe);
|
|
iframe.src = iframeContents;
|
|
}
|
|
|
|
function enter2(event) {
|
|
ok(document.mozFullScreen, "12. Should be back in full-screen mode (second time)");
|
|
is(event.target, document, "13. Event target should be full-screen document #3");
|
|
is(document.mozFullScreenElement, iframe, "14. Full-screen element should be iframe element.");
|
|
is(iframe.contentDocument.mozFullScreenElement, iframe.contentDocument.body, "15. Full-screen element in subframe should be body");
|
|
|
|
// The iframe's body is full-screen. Cancel full-screen in the subdocument to return
|
|
// the full-screen element to the previous full-screen element. This causes
|
|
// a fullscreenchange event.
|
|
addFullscreenChangeContinuation("exit", exit2);
|
|
document.mozCancelFullScreen();
|
|
}
|
|
|
|
function exit2(event) {
|
|
ok(!document.mozFullScreen, "16. Should have left full-screen when canceling fullscreen in ancestor document.");
|
|
is(document.mozFullScreenElement, null, "17. Full-screen element should have rolled back.");
|
|
is(iframe.contentDocument.mozFullScreenElement, null, "18. Full-screen element in subframe should be null");
|
|
|
|
addFullscreenChangeContinuation("enter", enter3);
|
|
fullScreenElement().mozRequestFullScreen();
|
|
}
|
|
|
|
function enter3(event) {
|
|
ok(document.mozFullScreen, "19. Should be back in full-screen mode (second time)");
|
|
is(event.target, document, "20. Event target should be full-screen document #3");
|
|
is(document.mozFullScreenElement, fullScreenElement(), "21. Full-screen element should be div.");
|
|
|
|
// Transplant the FSE into subdoc. Should exit full-screen.
|
|
addFullscreenChangeContinuation("exit", exit3);
|
|
var _innerFrame = iframe.contentDocument.getElementById("inner-frame");
|
|
var fse = fullScreenElement();
|
|
_innerFrame.contentDocument.body.appendChild(fse);
|
|
ok(!document.mozFullScreen, "22. Should exit full-screen after transplanting FSE");
|
|
is(document.mozFullScreenElement, null, "23. Full-screen element transplanted, should be null.");
|
|
is(iframe.contentDocument.mozFullScreenElement, null, "24. Full-screen element in outer frame should be null.");
|
|
is(_innerFrame.contentDocument.mozFullScreenElement, null, "25. Full-screen element in inner frame should be null.");
|
|
ok(!iframe.contentDocument.mozFullScreen, "26. Outer frame should not acquire full-screen status.");
|
|
ok(!_innerFrame.contentDocument.mozFullScreen, "27. Inner frame should not acquire full-screen status.");
|
|
|
|
document.body.appendChild(fse);
|
|
}
|
|
|
|
function exit3(event) {
|
|
ok(!document.mozFullScreen, "28. Should be back in non-full-screen mode (second time)");
|
|
is(event.target, document, "29. Event target should be full-screen document #4");
|
|
is(document.mozFullScreenElement, null, "30. Full-screen element should be null.");
|
|
document.body.removeChild(iframe);
|
|
iframe = null;
|
|
|
|
// Do a request out of document. It should be denied.
|
|
// Continue test in the following mozfullscreenerror handler.
|
|
outOfDocElement = document.createElement("div");
|
|
addFullscreenErrorContinuation(error1);
|
|
outOfDocElement.mozRequestFullScreen();
|
|
}
|
|
|
|
function error1(event) {
|
|
ok(!document.mozFullScreen, "31. Requests for full-screen from not-in-doc elements should fail.");
|
|
container = document.createElement("div");
|
|
inDocElement = document.createElement("div");
|
|
container.appendChild(inDocElement);
|
|
fullScreenElement().appendChild(container);
|
|
|
|
addFullscreenChangeContinuation("enter", enter4);
|
|
inDocElement.mozRequestFullScreen();
|
|
}
|
|
|
|
function enter4(event) {
|
|
ok(document.mozFullScreen, "32. Should still be in full-screen mode (third time)");
|
|
is(event.target, document, "33. Event target should be full-screen document #5");
|
|
is(document.mozFullScreenElement, inDocElement, "35. FSE should be inDocElement.");
|
|
|
|
var n = container;
|
|
do {
|
|
ok(n.matches(":-moz-full-screen-ancestor"), "Ancestor " + n + " should match :-moz-full-screen-ancestor")
|
|
n = n.parentNode;
|
|
} while (n && n.matches);
|
|
|
|
// Remove full-screen ancestor element from document, verify it stops being reported as current FSE.
|
|
addFullscreenChangeContinuation("exit", exit_to_arg_test_1);
|
|
container.parentNode.removeChild(container);
|
|
ok(!document.mozFullScreen, "36. Should exit full-screen mode after removing full-screen element ancestor from document");
|
|
is(document.mozFullScreenElement, null, "37. Should not have a full-screen element again.");
|
|
}
|
|
|
|
function exit_to_arg_test_1(event) {
|
|
ok(!document.mozFullScreen, "Should have left full-screen mode (third time).");
|
|
addFullscreenChangeContinuation("enter", enter_from_arg_test_1);
|
|
var threw = false;
|
|
try {
|
|
fullScreenElement().mozRequestFullScreen(123);
|
|
} catch (e) {
|
|
threw = true;
|
|
// trigger normal fullscreen so that we continue
|
|
fullScreenElement().mozRequestFullScreen();
|
|
}
|
|
ok(!threw, "mozRequestFullScreen with bogus arg (123) shouldn't throw exception");
|
|
}
|
|
|
|
function enter_from_arg_test_1(event) {
|
|
ok(document.mozFullScreen, "Should have entered full-screen after calling with bogus (ignored) argument (fourth time)");
|
|
addFullscreenChangeContinuation("exit", exit_to_arg_test_2);
|
|
document.mozCancelFullScreen();
|
|
}
|
|
|
|
function exit_to_arg_test_2(event) {
|
|
ok(!document.mozFullScreen, "Should have left full-screen mode (fourth time).");
|
|
addFullscreenChangeContinuation("enter", enter_from_arg_test_2);
|
|
var threw = false;
|
|
try {
|
|
fullScreenElement().mozRequestFullScreen({ vrDisplay: null });
|
|
} catch (e) {
|
|
threw = true;
|
|
// trigger normal fullscreen so that we continue
|
|
fullScreenElement().mozRequestFullScreen();
|
|
}
|
|
ok(!threw, "mozRequestFullScreen with { vrDisplay: null } shouldn't throw exception");
|
|
}
|
|
|
|
function enter_from_arg_test_2(event) {
|
|
ok(document.mozFullScreen, "Should have entered full-screen after calling with vrDisplay null argument (fifth time)");
|
|
addFullscreenChangeContinuation("exit", exit4);
|
|
document.mozCancelFullScreen();
|
|
}
|
|
|
|
function exit4(event) {
|
|
ok(!document.mozFullScreen, "38. Should be back in non-full-screen mode (fifth time)");
|
|
SpecialPowers.pushPrefEnv({"set":[["full-screen-api.allow-trusted-requests-only", true]]}, function() {
|
|
addFullscreenErrorContinuation(error2);
|
|
fullScreenElement().mozRequestFullScreen();
|
|
});
|
|
}
|
|
|
|
function error2(event) {
|
|
ok(!document.mozFullScreen, "Should still be in normal mode, because calling context isn't trusted.");
|
|
button = document.createElement("button");
|
|
button.onclick = function(){fullScreenElement().mozRequestFullScreen();}
|
|
fullScreenElement().appendChild(button);
|
|
addFullscreenChangeContinuation("enter", enter5);
|
|
sendMouseClick(button);
|
|
}
|
|
|
|
function enter5(event) {
|
|
ok(document.mozFullScreen, "Moved to full-screen after mouse click");
|
|
addFullscreenChangeContinuation("exit", exit5);
|
|
document.mozCancelFullScreen();
|
|
}
|
|
|
|
function exit5(event) {
|
|
ok(!document.mozFullScreen, "Should have left full-screen mode (last time).");
|
|
SpecialPowers.pushPrefEnv({
|
|
"set":[["full-screen-api.allow-trusted-requests-only", false],
|
|
["full-screen-api.enabled", false]]}, function() {
|
|
is(document.mozFullScreenEnabled, false, "document.mozFullScreenEnabled should be false if full-screen-api.enabled is false");
|
|
addFullscreenErrorContinuation(error3);
|
|
fullScreenElement().mozRequestFullScreen();
|
|
});
|
|
}
|
|
|
|
function error3(event) {
|
|
ok(!document.mozFullScreen, "Should still be in normal mode, because pref is not enabled.");
|
|
|
|
SpecialPowers.pushPrefEnv({"set":[["full-screen-api.enabled", true]]}, function() {
|
|
is(document.mozFullScreenEnabled, true, "document.mozFullScreenEnabled should be true if full-screen-api.enabled is true");
|
|
opener.nextTest();
|
|
});
|
|
}
|
|
|
|
function begin() {
|
|
addFullscreenChangeContinuation("enter", enter1);
|
|
fullScreenElement().mozRequestFullScreen();
|
|
}
|
|
|
|
</script>
|
|
</pre>
|
|
<div id="full-screen-element"></div>
|
|
</body>
|
|
</html>
|