Bug 931445 part 2 - Use util code from fullscreen tests to improve robustness of pointerlock tests. r=smaug

MozReview-Commit-ID: HYTy2Y6VG0G

--HG--
extra : source : 613205ba7a9fd609e27f6065fb9ea1574f8385a3
This commit is contained in:
Xidorn Quan 2016-05-23 09:03:32 +10:00
Родитель 3c0b0350d3
Коммит 1c7060be1f
16 изменённых файлов: 180 добавлений и 170 удалений

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

@ -108,6 +108,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
secondMove.mozMovementY = e.mozMovementY;
parent.removeEventListener("mousemove", secondMoveChild);
addFullscreenChangeContinuation("exit", function() {
runTests();
SimpleTest.finish();
});
document.exitFullscreen();
};
@ -118,21 +122,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
}
}, false);
document.addEventListener("mozpointerlockerror", function () {
document.exitFullscreen();
}, false);
document.addEventListener("fullscreenchange", function (e) {
if (document.fullscreenElement === parent) {
parent.mozRequestPointerLock();
}
else {
runTests();
SimpleTest.finish();
}
}, false);
function start() {
addFullscreenChangeContinuation("enter", function() {
parent.mozRequestPointerLock();
});
parent.requestFullscreen();
}
</script>

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

@ -40,6 +40,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
document.addEventListener("mozpointerlockchange", function (e) {
if (document.mozPointerLockElement === div) {
if (numberOfLocks === 2) {
addFullscreenChangeContinuation("exit", function() {
runTests();
SimpleTest.finish();
});
document.exitFullscreen();
}
else {
@ -49,18 +53,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
}
}, false);
document.addEventListener("fullscreenchange", function (e) {
if (document.fullscreenElement === div) {
div.mozRequestPointerLock();
}
else {
runTests();
SimpleTest.finish();
}
}, false);
function start() {
console.log('started');
addFullscreenChangeContinuation("enter", function() {
div.mozRequestPointerLock();
});
div.requestFullscreen();
}
</script>

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

@ -29,12 +29,11 @@
, pointerUnLocked = false;
function start() {
document.addEventListener("fullscreenchange", enteredFullscreen);
addFullscreenChangeContinuation("enter", enteredFullscreen);
div.requestFullscreen();
}
function enteredFullscreen(e) {
document.removeEventListener("fullscreenchange", enteredFullscreen);
is(document.fullscreenElement, div, "Element #div should entered fullscreen");
ok(!document.mozPointerLockElement, "Pointer shouldn't have been locked");
document.addEventListener("mozpointerlockchange", lockedPointer);
@ -45,7 +44,7 @@
document.removeEventListener("mozpointerlockchange", lockedPointer);
is(document.mozPointerLockElement, div, "Pointer should have been locked on #div");
document.addEventListener("mozpointerlockchange", unlockedPointer);
document.addEventListener("fullscreenchange", leavedFullscreen);
addFullscreenChangeContinuation("exit", leavedFullscreen);
SimpleTest.executeSoon(() => synthesizeKey("VK_ESCAPE", {}));
}
@ -61,7 +60,6 @@
}
function leavedFullscreen() {
document.removeEventListener("fullscreenchange", leavedFullscreen);
ok(!exitedFullscreen, "Shouldn't have exited fullscreen before");
ok(!document.fullscreenElement, "Should have exited fullscreen now");
exitedFullscreen = true;

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

@ -65,6 +65,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
totalMovementY = divCenterHeight + ((divCenterHeight / 2) * 3);
div.removeEventListener("mousemove", secondMoveListener, false);
addFullscreenChangeContinuation("exit", function() {
info("Got fullscreenchange for exiting");
runTests();
SimpleTest.finish();
});
document.exitFullscreen();
}
@ -84,20 +89,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
}
}, false);
document.addEventListener("fullscreenchange", function() {
if (document.fullscreenElement === div) {
info("Got fullscreenchange for entering");
div.mozRequestPointerLock();
}
else {
info("Got fullscreenchange for exiting");
runTests();
SimpleTest.finish();
}
}, false);
function start() {
info("Requesting fullscreen on parent");
addFullscreenChangeContinuation("enter", function() {
info("Got fullscreenchange for entering");
div.mozRequestPointerLock();
});
div.requestFullscreen();
}
</script>

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

@ -41,21 +41,19 @@
elemWasLocked = true;
document.mozExitPointerLock();
} else {
addFullscreenChangeContinuation("exit", function() {
ok(elemWasLocked, "Expected SVG elem to become locked.");
SimpleTest.finish();
});
document.exitFullscreen();
}
}, false);
document.addEventListener("fullscreenchange", function (e) {
if (document.fullscreenElement === elem) {
elem.mozRequestPointerLock();
} else {
ok(elemWasLocked, "Expected SVG elem to become locked.");
SimpleTest.finish();
}
}, false);
function start() {
elem = document.getElementById("svg-elem");
addFullscreenChangeContinuation("enter", function() {
elem.mozRequestPointerLock();
});
elem.requestFullscreen();
}
</script>

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

@ -83,35 +83,21 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
secondMove.mozMovementY = e.mozMovementY;
div.removeEventListener("mousemove", moveMouseAgain, false);
document.exitFullscreen();
};
function fullscreenchange() {
if (document.fullscreenElement === div) {
info("Got fullscreenchange for entering");
var screenX = window.screenX;
var screenY = window.screenY;
if (screenX != 0 || screenY != 0) {
todo(screenX == 0 && screenY == 0,
"We should only receive fullscreenchange once we've finished fullscreen transition");
setTimeout(fullscreenchange, 250);
return;
}
info("Finish waiting for fullscreenchange");
div.addEventListener("mousemove", moveMouse, false);
synthesizeMouseAtCenter(div, {type: "mousemove"}, window);
}
else {
addFullscreenChangeContinuation("exit", function() {
info("Got fullscreenchange for exiting");
runTests();
SimpleTest.finish();
}
}
document.addEventListener("fullscreenchange", fullscreenchange, false);
});
document.exitFullscreen();
};
function start() {
info("Requesting fullscreen on parent");
addFullscreenChangeContinuation("enter", function() {
info("Got fullscreenchange for entering");
div.addEventListener("mousemove", moveMouse, false);
synthesizeMouseAtCenter(div, {type: "mousemove"}, window);
});
div.requestFullscreen();
}
</script>

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

@ -49,30 +49,26 @@
document.addEventListener("mozpointerlockchange", function (e) {
if (document.mozPointerLockElement === parentDiv) {
parentDivLocked = true;
addFullscreenChangeContinuation("enter", function() {
pointerLocked = !!document.mozPointerLockElement;
addFullscreenChangeContinuation("exit", function() {
addFullscreenChangeContinuation("exit", function() {
runTests();
SimpleTest.finish();
});
document.exitFullscreen();
});
document.exitFullscreen();
});
childDiv.requestFullscreen();
}
}, false);
document.addEventListener("fullscreenchange", function() {
if (document.fullscreenElement === parentDiv) {
if (parentDivFullScreen === true) {
document.exitFullscreen();
} else {
parentDivFullScreen = true;
parentDiv.mozRequestPointerLock();
}
}
else if (document.fullscreenElement === childDiv) {
pointerLocked = !!document.mozPointerLockElement;
document.exitFullscreen();
}
else {
runTests();
SimpleTest.finish();
}
}, false);
function start() {
addFullscreenChangeContinuation("enter", function() {
parentDivFullScreen = true;
parentDiv.mozRequestPointerLock();
});
parentDiv.requestFullscreen();
}
</script>

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

@ -52,24 +52,21 @@
document.addEventListener("mozpointerlockerror", function (e) {
prefDisabled = true;
document.exitFullscreen();
}, false);
document.addEventListener("fullscreenchange", function (e) {
if (document.fullscreenElement === div) {
SpecialPowers.setBoolPref("full-screen-api.pointer-lock.enabled",
true );
div.mozRequestPointerLock();
}
else {
addFullscreenChangeContinuation("exit", function() {
SpecialPowers.setBoolPref("full-screen-api.pointer-lock.enabled",
true );
runTests();
SimpleTest.finish();
}
});
document.exitFullscreen();
}, false);
function start() {
addFullscreenChangeContinuation("enter", function() {
SpecialPowers.setBoolPref("full-screen-api.pointer-lock.enabled",
true );
div.mozRequestPointerLock();
});
div.requestFullscreen();
}
</script>

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

@ -79,25 +79,23 @@
} else {
info("Got mozpointerlockchange for exiting");
pointerUnlocked = true;
addFullscreenChangeContinuation("exit", function() {
info("Got fullscreenchange for exiting");
runTests();
SimpleTest.finish();
});
document.exitFullscreen();
}
}, false);
document.addEventListener("fullscreenchange", function(e) {
if (document.fullscreenElement === div) {
info("Got fullscreenchange for entering");
hasRequestPointerLock = "mozRequestPointerLock" in div;
div.mozRequestPointerLock();
} else {
info("Got fullscreenchange for exiting");
runTests();
SimpleTest.finish();
}
}, false);
function start() {
div = document.getElementById("div");
info("Requesting fullscreen on parent");
addFullscreenChangeContinuation("enter", function() {
info("Got fullscreenchange for entering");
hasRequestPointerLock = "mozRequestPointerLock" in div;
div.mozRequestPointerLock();
});
div.requestFullscreen();
}
</script>

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

@ -51,7 +51,7 @@ function checkPointerLockElement(elem) {
}
function start() {
listenOneDocEvent("fullscreenchange", enteredFullscreen);
addFullscreenChangeContinuation("enter", enteredFullscreen);
document.documentElement.requestFullscreen();
}
@ -82,7 +82,7 @@ function lockedPointerOnInner() {
function unlockedPointerFromInner() {
checkPointerLockElement(null);
listenOneDocEvent("fullscreenchange", exitedFullscreen);
addFullscreenChangeContinuation("exit", exitedFullscreen);
document.exitFullscreen();
}

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

@ -171,6 +171,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
child.removeEventListener("mousemove", childMoveTest);
SimpleTest.executeSoon(function () {
info("Exit fullscreen");
addFullscreenChangeContinuation("exit", function() {
info("Got fullscreenchange for exiting");
runTests();
SimpleTest.finish();
});
document.exitFullscreen();
});
}
@ -188,19 +193,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
}
}, false);
document.addEventListener("fullscreenchange", function (e) {
if (document.fullscreenElement === parent) {
info("Got fullscreenchange for entering");
parent.mozRequestPointerLock();
} else {
info("Got fullscreenchange for exiting");
runTests();
SimpleTest.finish();
}
}, false);
function start() {
info("Requesting fullscreen on parent");
addFullscreenChangeContinuation("enter", function() {
info("Got fullscreenchange for entering");
parent.mozRequestPointerLock();
});
parent.requestFullscreen();
}
</script>

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

@ -82,6 +82,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
clientY: e.clientY
};
addFullscreenChangeContinuation("exit", function() {
info("Got fullscreenchange for exiting");
runTests();
SimpleTest.finish();
});
document.exitFullscreen();
}
@ -98,35 +103,17 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
}
}, false);
function fullscreenchange() {
var screenX = window.screenX;
var screenY = window.screenY;
if (document.fullscreenElement === div) {
function start() {
div = document.getElementById("div");
info("Requesting fullscreen on parent");
addFullscreenChangeContinuation("enter", function() {
info("Got fullscreenchange for entering");
if (screenX != 0 || screenY != 0) {
todo(screenX == 0 && screenY == 0,
"We should only receive fullscreenchange once we've finished fullscreen transition " +
"window.screenX=" + screenX + " window.screenY=" + screenY);
setTimeout(fullscreenchange, 250);
return;
}
info("Finish waiting for fullscreenchange");
synthesizeNativeMouseMove(div, 0, 0, () => {
div.addEventListener("mousemove", moveUnlocked, false);
divRect = div.getBoundingClientRect();
synthesizeNativeMouseMove(div, divRect.width / 2, divRect.height / 2);
});
} else {
info("Got fullscreenchange for exiting");
runTests();
SimpleTest.finish();
}
}
document.addEventListener("fullscreenchange", fullscreenchange, false);
function start() {
div = document.getElementById("div");
info("Requesting fullscreen on parent");
});
div.requestFullscreen();
}
</script>

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

@ -137,23 +137,20 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602
synthesizeMouseAtCenter(child, { type: "mousemove" }, window);
}
else {
addFullscreenChangeContinuation("exit", function() {
runTests();
SimpleTest.finish();
});
document.exitFullscreen();
}
}, false);
document.addEventListener("fullscreenchange", function() {
if (document.fullscreenElement === parent) {
parent.mozRequestPointerLock();
}
else {
runTests();
SimpleTest.finish();
}
}, false);
function start() {
parent = document.getElementById("parent");
child = document.getElementById("child");
addFullscreenChangeContinuation("enter", function() {
parent.mozRequestPointerLock();
});
parent.requestFullscreen();
}
</script>

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

@ -48,20 +48,18 @@
document.addEventListener("mozpointerlockchange", function (e) {
if (document.mozPointerLockElement === div) {
divPointerLock = true;
addFullscreenChangeContinuation("exit", function() {
runTests();
SimpleTest.finish();
});
document.exitFullscreen();
}
}, false);
document.addEventListener("fullscreenchange", function() {
if (document.fullscreenElement === div) {
input.focus();
} else {
runTests();
SimpleTest.finish();
}
}, false);
function start() {
addFullscreenChangeContinuation("enter", function() {
input.focus();
});
div.requestFullscreen();
}
</script>

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

@ -22,4 +22,4 @@ support-files =
[test_pointerlock-api.html]
tags = fullscreen
skip-if = buildapp == 'b2g' || toolkit == 'android' || os == 'linux' || os == 'win' # B2G - window.open focus issues using fullscreen. Linux/Win: Bug 931445
skip-if = buildapp == 'b2g' || toolkit == 'android' || os == 'win' # B2G - window.open focus issues using fullscreen. Win: Bug 931445

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

@ -48,3 +48,73 @@ addLoadEvent(function() {
}
});
// 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(win) {
return win.innerWidth == win.screen.width &&
win.innerHeight == win.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(win) {
return win.innerWidth == win.normalSize.w &&
win.innerHeight == win.normalSize.h;
}
// 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 topWin = doc.defaultView.top;
// Remember the window size in non-fullscreen mode.
if (!topWin.normalSize) {
topWin.normalSize = {
w: window.innerWidth,
h: window.innerHeight
};
}
function checkCondition() {
if (type == "enter") {
return inFullscreenMode(topWin);
} else if (type == "exit") {
// If we just revert the state to a previous fullscreen state,
// the window won't back to the normal mode. Hence we check
// fullscreenElement first here. Note that we need to check
// the fullscreen element of the outmost document here instead
// of the current one.
return topWin.document.fullscreenElement || inNormalMode(topWin);
} else {
throw "'type' must be either 'enter', or 'exit'.";
}
}
function invokeCallback(event) {
// Use async call after a paint to workaround unfinished fullscreen
// change even when the window size has changed on Linux.
requestAnimationFrame(() => setTimeout(() => callback(event), 0), 0);
}
function onFullscreenChange(event) {
doc.removeEventListener("fullscreenchange", onFullscreenChange, false);
if (checkCondition()) {
invokeCallback(event);
return;
}
function onResize() {
if (checkCondition()) {
topWin.removeEventListener("resize", onResize, false);
invokeCallback(event);
}
}
topWin.addEventListener("resize", onResize, false);
}
doc.addEventListener("fullscreenchange", onFullscreenChange, false);
}