mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-09-10 11:54:40 +00:00
156 lines
4.7 KiB
HTML
156 lines
4.7 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Test for race conditions of Fullscreen API</title>
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<script src="/tests/SimpleTest/EventUtils.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
|
|
function Deferred() {
|
|
this.promise = new Promise(resolve => {
|
|
this.resolve = resolve;
|
|
});
|
|
}
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
// XXX This actually exposes a true race condition, but it could rarely
|
|
// happen in real world, because it only happens when requestFullscreen
|
|
// is called immediately after exiting fullscreen in certain condition,
|
|
// and in real life, requestFullscreen can only be called inside a user
|
|
// event handler. But we want to fix this race condition at some point,
|
|
// via queuing all exiting request as well as entering request together
|
|
// which we may eventually need to do for bug 1188256.
|
|
SimpleTest.requestFlakyTimeout(
|
|
"Need to wait for potential fullscreen transition");
|
|
addLoadEvent(function () {
|
|
SpecialPowers.pushPrefEnv({
|
|
"set": [["full-screen-api.allow-trusted-requests-only", false]]
|
|
}, next);
|
|
});
|
|
|
|
const OPEN_WINDOW_FUNCS = [
|
|
function openNewTab() {
|
|
return window.open("about:blank");
|
|
},
|
|
function openNewWindow() {
|
|
return window.open("about:blank", "", "width=300,height=200");
|
|
}
|
|
];
|
|
|
|
const ACTION_FUNCS = [
|
|
function navigate(win) {
|
|
info("About to navigate to another page");
|
|
var deferred = new Deferred();
|
|
win.location = "data:text/html,<html>";
|
|
setTimeout(() => {
|
|
SimpleTest.waitForFocus(() => {
|
|
ok(!win.fullScreen, "The window should no longer be in fullscreen");
|
|
win.close();
|
|
deferred.resolve();
|
|
}, win);
|
|
}, 0);
|
|
return deferred.promise;
|
|
},
|
|
function closeWindow(win) {
|
|
info("About to close the window");
|
|
win.close();
|
|
return Promise.resolve();
|
|
},
|
|
function exitFullscreen(win) {
|
|
info("About to cancel fullscreen");
|
|
var deferred = new Deferred();
|
|
function listener() {
|
|
win.removeEventListener("mozfullscreenchange", listener);
|
|
ok(!win.document.mozFullScreen, "Should exit fullscreen");
|
|
ok(!win.fullScreen, "The window should no longer be in fullscreen");
|
|
win.close();
|
|
deferred.resolve();
|
|
}
|
|
win.addEventListener("mozfullscreenchange", listener);
|
|
win.document.mozCancelFullScreen();
|
|
return deferred.promise;
|
|
},
|
|
function exitAndClose(win) {
|
|
info("About to cancel fullscreen and close the window");
|
|
win.document.mozCancelFullScreen();
|
|
win.close();
|
|
return Promise.resolve();
|
|
}
|
|
];
|
|
|
|
function* testGenerator() {
|
|
for (var openWinFunc of OPEN_WINDOW_FUNCS) {
|
|
for (var actionFunc of ACTION_FUNCS) {
|
|
info(`Testing ${openWinFunc.name}, ${actionFunc.name}`);
|
|
yield { openWinFunc: openWinFunc, actionFunc: actionFunc };
|
|
}
|
|
}
|
|
}
|
|
|
|
function runTest(test) {
|
|
var win = test.openWinFunc();
|
|
return new Promise(resolve => {
|
|
SimpleTest.waitForFocus(resolve, win, true);
|
|
}).then(() => {
|
|
return new Promise((resolve, reject) => {
|
|
var retried = false;
|
|
function listener(evt) {
|
|
if (!retried && evt.type == "mozfullscreenerror") {
|
|
todo(false, "Failed to enter fullscreen, but try again");
|
|
retried = true;
|
|
SimpleTest.waitForFocus(() => {
|
|
win.document.documentElement.mozRequestFullScreen();
|
|
}, win, true);
|
|
return;
|
|
}
|
|
win.removeEventListener("mozfullscreenchange", listener);
|
|
win.removeEventListener("mozfullscreenerror", listener);
|
|
is(evt.type, "mozfullscreenchange", "Should get fullscreenchange");
|
|
ok(win.document.mozFullScreen, "Should have entered fullscreen");
|
|
ok(win.fullScreen, "The window should be in fullscreen");
|
|
test.actionFunc(win).then(resolve);
|
|
}
|
|
if (win.fullScreen) {
|
|
todo(false, "Should not open in fullscreen mode");
|
|
win.close();
|
|
reject();
|
|
return;
|
|
}
|
|
info("About to enter fullscreen");
|
|
win.addEventListener("mozfullscreenchange", listener);
|
|
win.addEventListener("mozfullscreenerror", listener);
|
|
win.document.documentElement.mozRequestFullScreen();
|
|
});
|
|
}).then(() => {
|
|
ok(win.closed, "The window should have been closed");
|
|
});
|
|
}
|
|
|
|
var tests = testGenerator();
|
|
|
|
function next() {
|
|
var test = tests.next().value;
|
|
if (test) {
|
|
runTest(test).catch(() => {
|
|
return new Promise(resolve => {
|
|
SimpleTest.waitForFocus(resolve);
|
|
}).then(() => runTest(test));
|
|
}).catch(() => {
|
|
ok(false, "Fail to run test " +
|
|
`${test.openWinFunc.name}, ${test.actionFunc.name}`);
|
|
}).then(() => {
|
|
setTimeout(() => SimpleTest.waitForFocus(next), 1000);
|
|
});
|
|
} else {
|
|
SimpleTest.finish();
|
|
return;
|
|
}
|
|
}
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|