Friday, December 2, 2011

Test Sample

This test is to ensure that Mouse-lock can only be applied if the window is in focus. Believe it or not it is my first Mochitest. It was put together using other tests. Thinking of it as my first I thought it might be good to document it. Below is a snapshot of the event.

SimpleTest.waitForExplicitFinish();
var windowObjectReference = null; // global variable
var pointer = navigator.pointer;

var canvas = document.getElementById("canvas");

canvas.mozRequestFullScreen();
document.addEventListener("mozfullscreenchange", function (e) {
if (document.mozFullScreen) {
if (document.mozFullScreenElement === canvas) {
// Mouse should not be lock because the window is not in focus
if(windowObjectReference == null || windowObjectReference.closed || )
/* if the pointer to the window object in memory does not exist
or if such pointer exists but the window was closed */
{
windowObjectReference = window.open("http://www.spreadfirefox.com/",
"PromoteFirefoxWindowName", "resizable=yes,scrollbars=yes,status=yes");
/* then create it. The new window will be created and
will be brought on top of any other window. */
}
window.blur();//Sets the main window out of focus.
pointer.lock(canvas);
isnot(pointer.islocked(), true, "Mouse should only be locked if the window is in focus");
window.focus();
pointer.lock(canvas);
is(pointer.islocked(), true, "Mouse pointer should be locked");
}
SimpleTest.finish();
}
else {
canvas.mozRequestFullScreen();
}
}, false);

No comments:

Post a Comment