mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-06 00:55:37 +00:00
Bug 690989 - Work around fullscreenchange events sometimes being dispatched before fullscreen transition completes on Linux. r=smaug
This commit is contained in:
parent
aff5207df8
commit
9ac7e3719d
@ -243,6 +243,7 @@ MOCHITEST_FILES = \
|
||||
test_bug677463.html \
|
||||
test_bug682886.html \
|
||||
test_bug717819.html \
|
||||
file_fullscreen-utils.js \
|
||||
file_fullscreen-api.html \
|
||||
file_fullscreen-api-keys.html \
|
||||
test_fullscreen-api.html \
|
||||
|
@ -9,6 +9,7 @@ Test that restricted key pressed drop documents out of DOM full-screen mode.
|
||||
<head>
|
||||
<title>Test for Bug 545812</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
<script type="application/javascript" src="file_fullscreen-utils.js"></script>
|
||||
<style>
|
||||
body {
|
||||
background-color: black;
|
||||
@ -51,7 +52,6 @@ function checkKeyEffect() {
|
||||
if (gKeyTestIndex < keyList.length) {
|
||||
setTimeout(testNextKey, 0);
|
||||
} else {
|
||||
document.mozCancelFullScreen();
|
||||
opener.nextTest();
|
||||
}
|
||||
}
|
||||
@ -59,8 +59,8 @@ function checkKeyEffect() {
|
||||
function testTrustedKeyEvents() {
|
||||
document.body.focus();
|
||||
gKeyReceived = false;
|
||||
addFullscreenChangeContinuation("exit", checkKeyEffect);
|
||||
synthesizeKey(gKeyName, {});
|
||||
setTimeout(checkKeyEffect, 0);
|
||||
}
|
||||
|
||||
function testScriptInitiatedKeyEvents() {
|
||||
@ -92,7 +92,7 @@ function testScriptInitiatedKeyEvents() {
|
||||
|
||||
function testNextKey() {
|
||||
if (!document.mozFullScreen) {
|
||||
document.addEventListener("mozfullscreenchange", reallyTestNextKey, false);
|
||||
addFullscreenChangeContinuation("enter", reallyTestNextKey);
|
||||
document.body.mozRequestFullScreen();
|
||||
}
|
||||
else {
|
||||
@ -101,8 +101,6 @@ function testNextKey() {
|
||||
}
|
||||
|
||||
function reallyTestNextKey() {
|
||||
document.removeEventListener("mozfullscreenchange", reallyTestNextKey, false);
|
||||
|
||||
ok(document.mozFullScreen, "Must be in full-screen mode");
|
||||
|
||||
gKeyName = keyList[gKeyTestIndex].code;
|
||||
|
@ -10,6 +10,7 @@ Test DOM full-screen API.
|
||||
<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;
|
||||
@ -43,9 +44,7 @@ var outOfDocElement = null;
|
||||
var inDocElement = null;
|
||||
var container = null;
|
||||
var button = null;
|
||||
var fullScreenChangeCount = 0;
|
||||
var fullscreendenied = false;
|
||||
var fullScreenErrorRun = false;
|
||||
|
||||
|
||||
function sendMouseClick(element) {
|
||||
synthesizeMouseAtCenter(element, {});
|
||||
@ -59,181 +58,165 @@ function fullScreenElement() {
|
||||
return document.getElementById('full-screen-element');
|
||||
}
|
||||
|
||||
function fullScreenChange(event) {
|
||||
switch (fullScreenChangeCount) {
|
||||
case 0: {
|
||||
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.mozMatchesSelector(":-moz-full-screen"), "4. FSE should match :-moz-full-screen");
|
||||
var fse = fullScreenElement();
|
||||
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.");
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
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.mozAllowFullScreen = true;
|
||||
document.body.appendChild(iframe);
|
||||
iframe.src = iframeContents;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
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.
|
||||
document.mozCancelFullScreen();
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
ok(!document.mozFullScreen, "16. Should have left full-screen when removing FSE ancestor.");
|
||||
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");
|
||||
|
||||
fullScreenElement().mozRequestFullScreen();
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
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.
|
||||
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);
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
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");
|
||||
var f =
|
||||
function(e) {
|
||||
document.removeEventListener("mozfullscreenerror", f, false);
|
||||
ok(!document.mozFullScreen, "31. Requests for full-screen from not-in-doc elements should fail.");
|
||||
fullScreenErrorRun = true;
|
||||
|
||||
container = document.createElement("div");
|
||||
inDocElement = document.createElement("div");
|
||||
container.appendChild(inDocElement);
|
||||
fullScreenElement().appendChild(container);
|
||||
|
||||
inDocElement.mozRequestFullScreen();
|
||||
};
|
||||
document.addEventListener("mozfullscreenerror", f, false);
|
||||
outOfDocElement.mozRequestFullScreen();
|
||||
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
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");
|
||||
ok(fullScreenErrorRun, "34. Should have run fullscreenerror handler from previous case.");
|
||||
is(document.mozFullScreenElement, inDocElement, "35. FSE should be inDocElement.");
|
||||
|
||||
var n = container;
|
||||
do {
|
||||
ok(n.mozMatchesSelector(":-moz-full-screen-ancestor"), "Ancestor " + n + " should match :-moz-full-screen-ancestor")
|
||||
n = n.parentNode;
|
||||
} while (n && n.mozMatchesSelector);
|
||||
|
||||
// Remove full-screen ancestor element from document, verify it stops being reported as current FSE.
|
||||
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.");
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
ok(!document.mozFullScreen, "38. Should be back in non-full-screen mode (third time)");
|
||||
setRequireTrustedContext(true);
|
||||
fullscreendenied = false;
|
||||
fullScreenElement().mozRequestFullScreen();
|
||||
|
||||
setTimeout(
|
||||
function() {
|
||||
ok(fullscreendenied, "Request for fullscreen should have been denied because calling context isn't trusted");
|
||||
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);
|
||||
sendMouseClick(button);
|
||||
}, 0);
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
ok(document.mozFullScreen, "Moved to full-screen after mouse click");
|
||||
document.mozCancelFullScreen();
|
||||
ok(document.mozFullScreen, "Should still be in full-screen mode, because calling context isn't trusted.");
|
||||
setRequireTrustedContext(false);
|
||||
document.mozCancelFullScreen();
|
||||
ok(!document.mozFullScreen, "Should have left full-screen mode.");
|
||||
break;
|
||||
}
|
||||
case 9: {
|
||||
ok(!document.mozFullScreen, "Should have left full-screen mode (last time).");
|
||||
|
||||
SpecialPowers.setBoolPref("full-screen-api.enabled", false);
|
||||
is(document.mozFullScreenEnabled, false, "document.mozFullScreenEnabled should be false if full-screen-api.enabled is false");
|
||||
fullscreendenied = false;
|
||||
fullScreenElement().mozRequestFullScreen();
|
||||
setTimeout(
|
||||
function() {
|
||||
ok(!document.mozFullScreen, "Should still be in normal mode, because pref is not enabled.");
|
||||
|
||||
SpecialPowers.setBoolPref("full-screen-api.enabled", true);
|
||||
is(document.mozFullScreenEnabled, true, "document.mozFullScreenEnabled should be true if full-screen-api.enabled is true");
|
||||
|
||||
iframe = document.createElement("iframe");
|
||||
fullScreenElement().appendChild(iframe);
|
||||
iframe.src = iframeContents;
|
||||
ok(!document.mozFullScreen, "Should still be in normal mode, because iframe did not have mozallowfullscreen attribute.");
|
||||
fullScreenElement().removeChild(iframe);
|
||||
iframe = null;
|
||||
|
||||
// Set timeout for calling finish(), so that any pending "mozfullscreenchange" events
|
||||
// would have a chance to fire.
|
||||
setTimeout(function(){opener.nextTest();}, 0);
|
||||
}, 0);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
ok(false, "Should not receive any more fullscreenchange events!");
|
||||
}
|
||||
}
|
||||
fullScreenChangeCount++;
|
||||
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.mozMatchesSelector(":-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.");
|
||||
}
|
||||
|
||||
document.addEventListener("mozfullscreenerror", function(){fullscreendenied=true;}, false);
|
||||
document.addEventListener("mozfullscreenchange", fullScreenChange, false);
|
||||
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.mozAllowFullScreen = 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.mozMatchesSelector(":-moz-full-screen-ancestor"), "Ancestor " + n + " should match :-moz-full-screen-ancestor")
|
||||
n = n.parentNode;
|
||||
} while (n && n.mozMatchesSelector);
|
||||
|
||||
// Remove full-screen ancestor element from document, verify it stops being reported as current FSE.
|
||||
addFullscreenChangeContinuation("exit", exit4);
|
||||
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 exit4(event) {
|
||||
ok(!document.mozFullScreen, "38. Should be back in non-full-screen mode (third time)");
|
||||
setRequireTrustedContext(true);
|
||||
|
||||
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();
|
||||
ok(document.mozFullScreen, "Should still be in full-screen mode, because calling context isn't trusted.");
|
||||
setRequireTrustedContext(false);
|
||||
document.mozCancelFullScreen();
|
||||
ok(!document.mozFullScreen, "Should have left full-screen mode.");
|
||||
}
|
||||
|
||||
function exit5(event) {
|
||||
ok(!document.mozFullScreen, "Should have left full-screen mode (last time).");
|
||||
|
||||
SpecialPowers.setBoolPref("full-screen-api.enabled", false);
|
||||
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.setBoolPref("full-screen-api.enabled", true);
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ 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="file_fullscreen-utils.js"></script>
|
||||
<style>
|
||||
body {
|
||||
background-color: black;
|
||||
@ -29,10 +30,6 @@ function is(a, b, msg) {
|
||||
opener.is(a, b, "[denied] " + msg);
|
||||
}
|
||||
|
||||
var fullscreendenied = false;
|
||||
|
||||
document.addEventListener("mozfullscreenerror", function(){fullscreendenied=true;}, false);
|
||||
|
||||
var gotFullScreenChange = false;
|
||||
|
||||
function begin() {
|
||||
@ -46,46 +43,42 @@ function begin() {
|
||||
// Request full-screen from a non trusted context (this script isn't a user
|
||||
// generated event!).
|
||||
SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only", true);
|
||||
fullscreendenied = false;
|
||||
document.body.mozRequestFullScreen();
|
||||
setTimeout(
|
||||
addFullscreenErrorContinuation(
|
||||
function() {
|
||||
ok(!document.mozFullScreen, "Should not grant request in non-trusted context");
|
||||
ok(fullscreendenied, "Request in non-trusted event handler should be denied");
|
||||
// Test requesting full-screen mode in a long-running user-generated event handler.
|
||||
// The request in the key handler should not be granted.
|
||||
window.addEventListener("keypress", keyHandler, false);
|
||||
synthesizeKey("VK_A", {});
|
||||
}, 0);
|
||||
});
|
||||
document.body.mozRequestFullScreen();
|
||||
}
|
||||
|
||||
function keyHandler(event) {
|
||||
window.removeEventListener("keypress", keyHandler, false);
|
||||
|
||||
|
||||
// Busy loop until 2s has passed. We should then be past the 1 second threshold, and so
|
||||
// our request for full-screen mode should be rejected.
|
||||
var end = (new Date()).getTime() + 2000;
|
||||
while ((new Date()).getTime() < end) {
|
||||
; // Wait...
|
||||
}
|
||||
fullscreendenied = false;
|
||||
document.body.mozRequestFullScreen();
|
||||
setTimeout(
|
||||
addFullscreenErrorContinuation(
|
||||
function() {
|
||||
ok(fullscreendenied, "Request in long running event handler should be denied");
|
||||
ok(!document.mozFullScreen, "Should not grant request in long-running event handler.");
|
||||
|
||||
|
||||
// Disable the requirement for trusted contexts only, so the tests are easier
|
||||
// to write.
|
||||
SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only", false);
|
||||
|
||||
SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only", false);
|
||||
|
||||
// Create an iframe without a mozallowfullscreen attribute, whose contents requests
|
||||
// full-screen. The request should be denied, and we should not receive a fullscreenchange
|
||||
// event in this document.
|
||||
var iframe = document.createElement("iframe");
|
||||
iframe.src = "file_fullscreen-denied-inner.html";
|
||||
document.body.appendChild(iframe);
|
||||
}, 0);
|
||||
});
|
||||
document.body.mozRequestFullScreen();
|
||||
}
|
||||
|
||||
function finish() {
|
||||
|
@ -10,6 +10,8 @@ exit DOM full-screen mode.
|
||||
<head>
|
||||
<title>Test for Bug 700764</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, div:-moz-full-screen {
|
||||
background-color: red;
|
||||
@ -35,14 +37,12 @@ function finish() {
|
||||
function fullscreenchange1(event) {
|
||||
ok(document.mozFullScreen, "Should have entered full-screen mode");
|
||||
is(document.mozFullScreenElement, document.body, "FSE should be doc");
|
||||
document.removeEventListener("mozfullscreenchange", fullscreenchange1, false);
|
||||
document.addEventListener("mozfullscreenchange", fullscreenchange2, false);
|
||||
addFullscreenChangeContinuation("exit", fullscreenchange2);
|
||||
ok(!document.getElementById("subdoc").contentWindow.escKeySent, "Should not yet have sent ESC key press.");
|
||||
document.getElementById("subdoc").contentWindow.startTest();
|
||||
}
|
||||
|
||||
function fullscreenchange2(event) {
|
||||
document.removeEventListener("mozfullscreenchange", fullscreenchange2, false);
|
||||
ok(document.getElementById("subdoc").contentWindow.escKeySent, "Should have sent ESC key press.");
|
||||
ok(!document.getElementById("subdoc").contentWindow.escKeyReceived, "ESC key press to exit should not be delivered.");
|
||||
ok(!document.mozFullScreen, "Should have left full-screen mode on ESC key press");
|
||||
@ -50,7 +50,7 @@ function fullscreenchange2(event) {
|
||||
}
|
||||
|
||||
function begin() {
|
||||
document.addEventListener("mozfullscreenchange", fullscreenchange1, false);
|
||||
addFullscreenChangeContinuation("enter", fullscreenchange1);
|
||||
document.body.mozRequestFullScreen();
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ Test plugins with 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="file_fullscreen-utils.js"></script>
|
||||
<style>
|
||||
body:-moz-full-screen, div:-moz-full-screen {
|
||||
background-color: red;
|
||||
@ -80,29 +81,26 @@ function startTest() {
|
||||
if (isMacOs) {
|
||||
// Running on MacOS, all plugins are effectively windowless, request for full-screen should be granted.
|
||||
// Continue test in the (mac-specific) "mozfullscreenchange" handler.
|
||||
document.addEventListener("mozfullscreenchange", macFullScreenChange, false);
|
||||
return;
|
||||
addFullscreenChangeContinuation("enter", macFullScreenChange1);
|
||||
} else {
|
||||
// Non-MacOS, request should be denied, carry on the test after receiving error event.
|
||||
document.addEventListener("mozfullscreenerror", nonMacTest, false);
|
||||
addFullscreenErrorContinuation(nonMacTest);
|
||||
}
|
||||
}
|
||||
|
||||
function nonMacTest() {
|
||||
document.removeEventListener("mozfullscreenerror", nonMacTest, false);
|
||||
ok(!document.mozFullScreen, "Request for full-screen with focused windowed plugin should be denied.");
|
||||
|
||||
// Focus a regular html element, and re-request full-screen, request should be granted.
|
||||
e("windowless-plugin").focus();
|
||||
document.addEventListener("mozfullscreenchange", nonMacTest2, false);
|
||||
addFullscreenChangeContinuation("enter", nonMacTest2);
|
||||
document.body.mozRequestFullScreen();
|
||||
}
|
||||
|
||||
function nonMacTest2() {
|
||||
document.removeEventListener("mozfullscreenchange", nonMacTest2, false);
|
||||
ok(document.mozFullScreen, "Request for full-screen with non-plugin focused should be granted.");
|
||||
// Focus a windowed plugin, full-screen should be revoked.
|
||||
document.addEventListener("mozfullscreenchange", nonMacTest3, false);
|
||||
addFullscreenChangeContinuation("exit", nonMacTest3);
|
||||
e("windowed-plugin").focus();
|
||||
}
|
||||
|
||||
@ -120,36 +118,27 @@ function createWindowedPlugin() {
|
||||
return p;
|
||||
}
|
||||
|
||||
function macFullScreenChange(event) {
|
||||
switch (fullScreenChangeCount) {
|
||||
case 0: {
|
||||
ok(document.mozFullScreen, "Requests for full-screen with focused windowed plugins should be granted on MacOS");
|
||||
|
||||
// Create a new windowed plugin, and add that to the document. Should *not* exit full-screen mode on MacOS.
|
||||
windowedPlugin = createWindowedPlugin();
|
||||
document.body.appendChild(windowedPlugin);
|
||||
|
||||
// Focus windowed plugin. Should not exit full-screen mode on MacOS.
|
||||
windowedPlugin.focus();
|
||||
|
||||
setTimeout(
|
||||
function() {
|
||||
ok(document.mozFullScreen, "Adding & focusing a windowed plugin to document should not cause full-screen to exit on MacOS.");
|
||||
document.mozCancelFullScreen();
|
||||
}, 0);
|
||||
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
ok(!document.mozFullScreen, "Should have left full-screen mode after calling document.mozCancelFullScreen().");
|
||||
opener.nextTest();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
ok(false, "Should not receive any more fullscreenchange events!");
|
||||
}
|
||||
}
|
||||
fullScreenChangeCount++;
|
||||
function macFullScreenChange1(event) {
|
||||
ok(document.mozFullScreen, "Requests for full-screen with focused windowed plugins should be granted on MacOS");
|
||||
|
||||
// Create a new windowed plugin, and add that to the document. Should *not* exit full-screen mode on MacOS.
|
||||
windowedPlugin = createWindowedPlugin();
|
||||
document.body.appendChild(windowedPlugin);
|
||||
|
||||
// Focus windowed plugin. Should not exit full-screen mode on MacOS.
|
||||
windowedPlugin.focus();
|
||||
|
||||
setTimeout(
|
||||
function() {
|
||||
ok(document.mozFullScreen, "Adding & focusing a windowed plugin to document should not cause full-screen to exit on MacOS.");
|
||||
addFullscreenChangeContinuation("exit", macFullScreenChange2);
|
||||
document.mozCancelFullScreen();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function macFullScreenChange2(event) {
|
||||
ok(!document.mozFullScreen, "Should have left full-screen mode after calling document.mozCancelFullScreen().");
|
||||
opener.nextTest();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
@ -19,6 +19,8 @@ Tests:
|
||||
<head>
|
||||
<title>Test for Bug 700764</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>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@ -36,18 +38,28 @@ Tests:
|
||||
|
||||
function ok(condition, msg) {
|
||||
opener.ok(condition, "[rollback] " + msg);
|
||||
if (!condition) {
|
||||
opener.finish();
|
||||
}
|
||||
}
|
||||
|
||||
function is(a, b, msg) {
|
||||
opener.is(a, b, "[rollback] " + msg);
|
||||
if (a != b) {
|
||||
opener.finish();
|
||||
}
|
||||
}
|
||||
|
||||
function addListener(type, f) {
|
||||
document.addEventListener("mozfullscreen" + type, f, false);
|
||||
function enterFullscreen(element, callback) {
|
||||
addFullscreenChangeContinuation("enter", callback);
|
||||
element.focus();
|
||||
element.mozRequestFullScreen();
|
||||
}
|
||||
|
||||
function removeListener(type, f) {
|
||||
document.removeEventListener("mozfullscreen" + type, f, false);
|
||||
function revertFullscreen(doc, callback) {
|
||||
ok(doc.mozFullScreenElement != null, "Should only exit fullscreen on a fullscreen doc");
|
||||
addFullscreenChangeContinuation("exit", callback, doc);
|
||||
doc.mozCancelFullScreen();
|
||||
}
|
||||
|
||||
function e(id) {
|
||||
@ -60,67 +72,52 @@ function requestFullscreen(element) {
|
||||
}
|
||||
|
||||
function begin() {
|
||||
addListener("change", change1);
|
||||
e("fse").mozRequestFullScreen();
|
||||
enterFullscreen(e("fse"), change1);
|
||||
}
|
||||
|
||||
function change1() {
|
||||
removeListener("change", change1);
|
||||
addListener("error", error1);
|
||||
is(document.mozFullScreenElement, e("fse"), "Body should be FSE");
|
||||
|
||||
// Request full-screen from element not descendent from current FSE.
|
||||
addFullscreenErrorContinuation(error1);
|
||||
requestFullscreen(e("non-fse"));
|
||||
}
|
||||
|
||||
function error1() {
|
||||
removeListener("error", error1);
|
||||
addListener("change", change2);
|
||||
is(document.mozFullScreenElement, e("fse"), "FSE should not change");
|
||||
var iframe = e("subdoc");
|
||||
requestFullscreen(iframe.contentDocument.body);
|
||||
enterFullscreen(iframe.contentDocument.body, change2);
|
||||
}
|
||||
|
||||
function change2() {
|
||||
removeListener("change", change2);
|
||||
var iframe = e("subdoc");
|
||||
is(document.mozFullScreenElement, iframe, "Subdoc container should be FSE.");
|
||||
is(iframe.contentDocument.mozFullScreenElement, iframe.contentDocument.body, "Subdoc body should be FSE in subdoc");
|
||||
addListener("change", change3);
|
||||
iframe.contentDocument.mozCancelFullScreen();
|
||||
revertFullscreen(document, change3);
|
||||
}
|
||||
|
||||
function change3() {
|
||||
removeListener("change", change3);
|
||||
is(document.mozFullScreenElement, e("fse"), "FSE should rollback to FSE.");
|
||||
addListener("change", change4);
|
||||
document.mozCancelFullScreen();
|
||||
revertFullscreen(document, change4);
|
||||
}
|
||||
|
||||
function change4() {
|
||||
removeListener("change", change4);
|
||||
is(document.mozFullScreenElement, null, "Should have left full-screen entirely");
|
||||
addListener("change", change5);
|
||||
requestFullscreen(e("fse"));
|
||||
enterFullscreen(e("fse"), change5);
|
||||
}
|
||||
|
||||
function change5() {
|
||||
removeListener("change", change5);
|
||||
addListener("change", change6);
|
||||
is(document.mozFullScreenElement, e("fse"), "FSE should be e('fse')");
|
||||
requestFullscreen(e("fse-inner"));
|
||||
enterFullscreen(e("fse-inner"), change6);
|
||||
}
|
||||
|
||||
function change6() {
|
||||
removeListener("change", change6);
|
||||
addListener("change", change7);
|
||||
addFullscreenChangeContinuation("exit", change7);
|
||||
var element = e('fse-inner');
|
||||
is(document.mozFullScreenElement, element, "FSE should be e('fse-inner')");
|
||||
element.parentNode.removeChild(element);
|
||||
}
|
||||
|
||||
function change7() {
|
||||
removeListener("change", change7);
|
||||
is(document.mozFullScreenElement, null, "Should have fully exited full-screen mode when removed FSE from doc");
|
||||
opener.nextTest();
|
||||
}
|
||||
|
104
content/html/content/test/file_fullscreen-utils.js
Normal file
104
content/html/content/test/file_fullscreen-utils.js
Normal file
@ -0,0 +1,104 @@
|
||||
// Remember the window size in non-fullscreen mode.
|
||||
var normalSize = new function() {
|
||||
this.w = window.outerWidth;
|
||||
this.h = window.outerHeight;
|
||||
}();
|
||||
|
||||
// Returns true if the window occupies the entire screen.
|
||||
// Note this only returns true once the transition from normal to
|
||||
// fullscreen mode is complete.
|
||||
function inFullscreenMode() {
|
||||
return window.outerWidth == window.screen.width &&
|
||||
window.outerHeight == window.screen.height;
|
||||
}
|
||||
|
||||
// Returns true if the window is in normal mode, i.e. non fullscreen mode.
|
||||
// Note this only returns true once the transition from fullscreen back to
|
||||
// normal mode is complete.
|
||||
function inNormalMode() {
|
||||
return window.outerWidth == normalSize.w &&
|
||||
window.outerHeight == normalSize.h;
|
||||
}
|
||||
|
||||
function ok(condition, msg) {
|
||||
opener.ok(condition, "[rollback] " + msg);
|
||||
if (!condition) {
|
||||
opener.finish();
|
||||
}
|
||||
}
|
||||
|
||||
// On Linux we sometimes receive fullscreenchange events before the window
|
||||
// has finished transitioning to fullscreen. This can cause problems and
|
||||
// test failures, so work around it on Linux until we can get a proper fix.
|
||||
const workAroundFullscreenTransition = navigator.userAgent.indexOf("Linux") != -1;
|
||||
|
||||
// Adds a listener that will be called once a fullscreen transition
|
||||
// is complete. When type==='enter', callback is called when we've
|
||||
// received a fullscreenchange event, and the fullscreen transition is
|
||||
// complete. When type==='exit', callback is called when we've
|
||||
// received a fullscreenchange event and the window dimensions match
|
||||
// the window dimensions when the window opened (so don't resize the
|
||||
// window while running your test!). inDoc is the document which
|
||||
// the listeners are added on, if absent, the listeners are added to
|
||||
// the current document.
|
||||
function addFullscreenChangeContinuation(type, callback, inDoc) {
|
||||
var doc = inDoc || document;
|
||||
var listener = null;
|
||||
if (type === "enter") {
|
||||
// when entering fullscreen, ensure we don't call 'callback' until the
|
||||
// enter transition is complete.
|
||||
listener = function(event) {
|
||||
doc.removeEventListener("mozfullscreenchange", listener, false);
|
||||
if (!workAroundFullscreenTransition) {
|
||||
callback(event);
|
||||
return;
|
||||
}
|
||||
if (!inFullscreenMode()) {
|
||||
opener.todo(false, "fullscreenchange before entering fullscreen complete! " +
|
||||
" window.fullScreen=" + window.fullScreen +
|
||||
" normal=(" + normalSize.w + "," + normalSize.h + ")" +
|
||||
" outerWidth=" + window.outerWidth + " width=" + window.screen.width +
|
||||
" outerHeight=" + window.outerHeight + " height=" + window.screen.height);
|
||||
setTimeout(function(){listener(event);}, 100);
|
||||
return;
|
||||
}
|
||||
setTimeout(function(){callback(event)}, 0);
|
||||
};
|
||||
} else if (type === "exit") {
|
||||
listener = function(event) {
|
||||
doc.removeEventListener("mozfullscreenchange", listener, false);
|
||||
if (!workAroundFullscreenTransition) {
|
||||
callback(event);
|
||||
return;
|
||||
}
|
||||
if (!document.mozFullScreenElement && !inNormalMode()) {
|
||||
opener.todo(false, "fullscreenchange before exiting fullscreen complete! " +
|
||||
" window.fullScreen=" + window.fullScreen +
|
||||
" normal=(" + normalSize.w + "," + normalSize.h + ")" +
|
||||
" outerWidth=" + window.outerWidth + " width=" + window.screen.width +
|
||||
" outerHeight=" + window.outerHeight + " height=" + window.screen.height);
|
||||
// 'document' (*not* 'doc') has no fullscreen element, so we're trying
|
||||
// to completely exit fullscreen mode. Wait until the transition
|
||||
// to normal mode is complete before calling callback.
|
||||
setTimeout(function(){listener(event);}, 100);
|
||||
return;
|
||||
}
|
||||
opener.info("[rollback] Exited fullscreen");
|
||||
setTimeout(function(){callback(event);}, 0);
|
||||
};
|
||||
} else {
|
||||
throw "'type' must be either 'enter', or 'exit'.";
|
||||
}
|
||||
doc.addEventListener("mozfullscreenchange", listener, false);
|
||||
}
|
||||
|
||||
// Calls |callback| when the next fullscreenerror is dispatched to inDoc||document.
|
||||
function addFullscreenErrorContinuation(callback, inDoc) {
|
||||
var doc = inDoc || document;
|
||||
var listener = function(event) {
|
||||
doc.removeEventListener("mozfullscreenerror", listener, false);
|
||||
setTimeout(function(){callback(event);}, 0);
|
||||
};
|
||||
doc.addEventListener("mozfullscreenerror", listener, false);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user