Bug 746885 part 3 - Change pointer lock tests to always run on a domain with fullscreen-approved permissions. r=smaug

This commit is contained in:
Chris Pearce 2012-05-09 09:48:27 +12:00
Родитель c10533ca2d
Коммит ad84909722
4 изменённых файлов: 98 добавлений и 9 удалений

Просмотреть файл

@ -15,6 +15,7 @@ include $(topsrcdir)/config/rules.mk
_TEST_FILES = \
test_pointerlock-api.html \
pointerlock_utils.js \
file_approval.html \
file_pointerlock-api.html \
file_pointerlockerror.html \
file_escapeKey.html \

Просмотреть файл

@ -0,0 +1,66 @@
<!DOCTYPE HTML>
<html>
<!--https://bugzilla.mozilla.org/show_bug.cgi?id=746885-->
<head>
<title>Bug 746885</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="pointerlock_utils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=746885">
Mozilla Bug 746885
</a>
<div id="div"></div>
<pre id="test">
<script type="text/javascript">
/*
* Test for Bug 746885
* When requesting pointer lock on a domain that doesn't have fullscreen
* permission, the pointer lock request should be delayed until approval
* has been granted.
*/
SimpleTest.waitForExplicitFinish();
// Ensure fullscreen won't be automatically granted for this document's domain.
SpecialPowers.removeFullscreenAllowed(document);
var div = document.getElementById("div");
var isApproved = false;
document.addEventListener("mozpointerlockchange",
function (e) {
is(isApproved, true, "Should only receive mozpointerlockchange when we've been approved for fullscreen.");
document.mozCancelFullScreen();
}, false);
function approveFullscreen() {
isApproved = true;
SpecialPowers.setFullscreenAllowed(document);
}
document.addEventListener("mozfullscreenchange", function(e) {
if (document.mozFullScreenElement === div) {
// First entered fullscreen. Request pointer lock...
div.mozRequestPointerLock();
// ... But only approve fullscreen after a delay, giving the pointer
// lock request time to run if it were going to. Note we need two timeouts
// here to because if we were to fail and the pointer lock request were to
// succeed without approval, we'd need to give it time to run, and time for
// its asynchronously dispatched mozpointerlockchange to run.
setTimeout(function(){ setTimeout(approveFullscreen, 0); }, 0);
} else {
SimpleTest.finish();
}
}, false);
function start() {
div.mozRequestFullScreen();
}
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -19,10 +19,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
<script type="application/javascript">
/**
* Pointer Lock tests for bug 633602. These depend on the fullscreen api
* which doesn't work well on all platforms when run in an iframe, even
* when allowing fullscreen on the iframe. To get around this, all tests
* are run in a child window, which can go fullscreen. This method is
* borrowed from content/html/content/test/test_fullscreen-api.html.
* which doesn't work when run in the mochitests' iframe, since the
* mochitests' iframe doesn't have a mozallowfullscreen attribute. To get
* around this, all tests are run in a child window, which can go fullscreen.
* This method is borrowed from content/html/content/test/test_fullscreen-api.html.
**/
SimpleTest.waitForExplicitFinish();
@ -33,10 +33,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
// Disable the requirement for trusted contexts only, so the tests are easier to write.
SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only", false);
// Grant "fullscreen" permission on the test domain. This means fullscreen will be
// automatically approved, so pointer lock in the tests will be too.
SpecialPowers.setFullscreenAllowed(document);
// Run the tests which go full-screen in new window, as Mochitests
// normally run in an iframe, which by default will not have the
// mozallowfullscreen attribute set, so full-screen won't work.
var gTestFiles = [
"file_approval.html",
"file_screenClientXYConst.html",
"file_childIframe.html",
"file_doubleLock.html",
@ -63,15 +68,22 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
const isWinXP = navigator.userAgent.indexOf("Windows NT 5.1") != -1;
const isOSXLion = navigator.userAgent.indexOf("Mac OS X 10.7") != -1;
function finish() {
SpecialPowers.clearUserPref("full-screen-api.enabled");
SpecialPowers.clearUserPref("full-screen-api.allow-trusted-requests-only");
SpecialPowers.removeFullscreenAllowed(document)
SimpleTest.finish();
}
function nextTest() {
if (isWinXP) {
todo(false, "Can't reliably run full-screen tests on Windows XP due to bug 704010");
SimpleTest.finish();
finish();
return;
}
if (isOSXLion) {
todo(false, "Can't reliably run full-screen tests on OS X Lion, see bug 744125");
SimpleTest.finish();
finish();
return;
}
if (gTestWindow) {
@ -85,9 +97,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
gTestWindow = window.open(gTestFiles[gTestIndex], "", "width=500,height=500");
gTestIndex++;
} else {
SpecialPowers.clearUserPref("full-screen-api.enabled");
SpecialPowers.clearUserPref("full-screen-api.allow-trusted-requests-only");
SimpleTest.finish();
finish();
}
}

Просмотреть файл

@ -1070,4 +1070,16 @@ SpecialPowersAPI.prototype = {
.frameLoader
.messageManager);
},
setFullscreenAllowed: function(document) {
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
var uri = this.getDocumentURIObject(document);
pm.add(uri, "fullscreen", Ci.nsIPermissionManager.ALLOW_ACTION);
},
removeFullscreenAllowed: function(document) {
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
var uri = this.getDocumentURIObject(document);
pm.remove(uri.host, "fullscreen");
}
};