2011-10-31 22:11:09 -07:00
<!DOCTYPE HTML>
2011-09-04 13:40:18 -07:00
< html >
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=545812
Test DOM full-screen API.
-->
< head >
< title > Test for Bug 545812< / title >
2011-09-04 13:40:18 -07:00
< script type = "application/javascript" src = "/tests/SimpleTest/EventUtils.js" > < / script >
2011-11-07 15:58:48 -08:00
< script type = "application/javascript" src = "/tests/SimpleTest/SimpleTest.js" > < / script >
2012-10-08 15:21:57 -07:00
< script type = "application/javascript" src = "file_fullscreen-utils.js" > < / script >
2011-09-04 13:40:18 -07:00
< style >
2011-10-31 22:11:09 -07:00
body {
background-color: black;
2011-09-04 13:40:18 -07:00
}
< / style >
< / head >
2012-03-20 16:21:15 -07:00
< body >
2011-09-04 13:40:18 -07:00
< script type = "application/javascript" >
/** Test for Bug 545812 **/
function ok(condition, msg) {
2011-12-06 13:59:39 -08:00
opener.ok(condition, "[fullscreen] " + msg);
2011-09-04 13:40:18 -07:00
}
function is(a, b, msg) {
2011-12-06 13:59:39 -08:00
opener.is(a, b, "[fullscreen] " + msg);
2011-09-04 13:40:18 -07:00
}
/*
< html >
< body onload = 'document.body.mozRequestFullScreen();' >
2011-10-31 22:11:09 -07:00
< iframe id = 'inner-frame' > < / iframe >
2011-09-04 13:40:18 -07:00
< / body >
< / html >
*/
2011-11-07 15:58:48 -08:00
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>";
2011-09-04 13:40:18 -07:00
var iframe = null;
var outOfDocElement = null;
var inDocElement = null;
2011-10-31 22:11:09 -07:00
var container = null;
2011-09-04 13:40:18 -07:00
var button = null;
2012-10-08 15:21:57 -07:00
2011-11-01 17:02:47 -07:00
2011-09-04 13:40:18 -07:00
function sendMouseClick(element) {
synthesizeMouseAtCenter(element, {});
}
2011-10-31 22:11:09 -07:00
function fullScreenElement() {
return document.getElementById('full-screen-element');
}
2012-10-08 15:21:57 -07:00
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.");
2014-08-12 05:30:59 -07:00
ok(document.mozFullScreenElement.matches(":-moz-full-screen"), "4. FSE should match :-moz-full-screen");
2012-10-08 15:21:57 -07:00
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");
2013-02-25 17:59:33 -08:00
iframe.allowFullscreen = true;
2012-10-08 15:21:57 -07:00
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 {
2014-08-12 05:30:59 -07:00
ok(n.matches(":-moz-full-screen-ancestor"), "Ancestor " + n + " should match :-moz-full-screen-ancestor")
2012-10-08 15:21:57 -07:00
n = n.parentNode;
2014-08-12 05:30:59 -07:00
} while (n & & n.matches);
2012-10-08 15:21:57 -07:00
// Remove full-screen ancestor element from document, verify it stops being reported as current FSE.
2015-01-05 11:49:04 -08:00
addFullscreenChangeContinuation("exit", exit_to_arg_test_1);
2012-10-08 15:21:57 -07:00
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.");
}
2015-01-05 11:49:04 -08:00
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();
ok(!document.mozFullScreen, "Should have left full-screen mode.");
}
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();
ok(!document.mozFullScreen, "Should have left full-screen mode.");
}
2012-10-08 15:21:57 -07:00
function exit4(event) {
2015-01-05 11:49:04 -08:00
ok(!document.mozFullScreen, "38. Should be back in non-full-screen mode (fifth time)");
2015-02-19 08:53:01 -08:00
SpecialPowers.pushPrefEnv({"set":[["full-screen-api.allow-trusted-requests-only", true]]}, function() {
addFullscreenErrorContinuation(error2);
fullScreenElement().mozRequestFullScreen();
});
2012-10-08 15:21:57 -07:00
}
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();
ok(!document.mozFullScreen, "Should have left full-screen mode.");
2011-09-04 13:40:18 -07:00
}
2012-10-08 15:21:57 -07:00
function exit5(event) {
ok(!document.mozFullScreen, "Should have left full-screen mode (last time).");
2015-02-19 08:53:01 -08:00
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();
});
2012-10-08 15:21:57 -07:00
}
function error3(event) {
ok(!document.mozFullScreen, "Should still be in normal mode, because pref is not enabled.");
2015-02-19 08:53:01 -08:00
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();
});
2012-10-08 15:21:57 -07:00
}
2011-09-04 13:40:18 -07:00
2012-03-20 16:21:15 -07:00
function begin() {
2012-10-08 15:21:57 -07:00
addFullscreenChangeContinuation("enter", enter1);
2012-03-20 16:21:15 -07:00
fullScreenElement().mozRequestFullScreen();
2011-11-07 15:58:48 -08:00
}
2011-09-04 13:40:18 -07:00
< / script >
< / pre >
2011-10-31 22:11:09 -07:00
< div id = "full-screen-element" > < / div >
2011-09-04 13:40:18 -07:00
< / body >
< / html >