/**
* hitEventLoop is called when we want to check something but we can't rely on
* an event or a specific number of event loop hiting.
* This method can be called by specifying a condition, a test (using SimpleTest
* API), how many times the event loop has to be hit and what to call next.
* If times < 0, the event loop will be hit as long as the condition isn't
* true or the test doesn't time out.
*/
function hitEventLoop(condition, test, times) {
return new Promise(function(resolve, reject) {
function doMagic() {
if (condition() || times == 0) {
test();
resolve();
return;
}
times--;
setTimeout(doMagic, 0);
}
doMagic();
});
}
function checkChangeIsDisabled(aWindow) {
// We want to check that nothing has changed. Having a high value would take
// too much time. Worse thing that could happen is random green. var hits = 5;
function getProp(propName) {
return window[propName + "Getter"].call(aWindow);
}
var originalWidth = getProp("innerWidth"); var originalHeight = getProp("innerHeight");
var originalX = getProp("screenX"); var originalY = getProp("screenY");
var oWidth = getProp("outerWidth"); var oHeight = getProp("outerHeight");
function changeTest() {
is(getProp("innerWidth"), originalWidth, "Window width shouldn't have changed");
is(getProp("innerHeight"), originalHeight, "Window height shouldn't have changed");
is(getProp("screenX"), originalX, "Window x position shouldn't have changed");
is(getProp("screenY"), originalY, "Window y position shouldn't have changed");
is(getProp("outerWidth"), oWidth, "Window outerWidth shouldn't have changed");
is(getProp("outerHeight"), oHeight, "Window outerHeight shouldn't have changed");
}
/**
* Size changes.
*/ var newWidth = getNewWidth(aWindow); var newHeight = getNewHeight(aWindow);
// We did a lot of changes. Now, we are going to wait and see if something
// happens.
// NOTE: if this happens to fail, you will have to check manually which
// operation has been accepted.
return hitEventLoop(changeCondition, changeTest, hits);
}
function checkChangeIsEnabled(aWindow, aNext)
{
info(`checkChangeIsEnabled start`);
// Something should happen. We are not going to go to the next test until
// it does. var hits = -1;
function sizeChangeTest() {
isnot(aWindow.outerWidth, prevWidth, "Window width should have changed");
isnot(aWindow.outerHeight, prevHeight, "Window height should have changed");
function posChangeCondition() {
// With GTK, sometimes, only one dimension changes.
if (navigator.platform.includes('Linux')) {
return aWindow.screenX != prevX || aWindow.screenY != prevY;
}
return aWindow.screenX != prevX && aWindow.screenY != prevY;
}
function posChangeTest() {
// With GTK, sometimes, only one dimension changes.
if (navigator.platform.includes('Linux')) {
// With GTK, sometimes, aWindow.screenX changes during two calls.
// So we call it once and save the returned value. var x = aWindow.screenX; var y = aWindow.screenY;
if (x != prevX) {
isnot(x, prevX, "Window x position should have changed");
}
if (y != prevY) {
isnot(y, prevY, "Window y position should have changed");
}
} else {
isnot(aWindow.screenX, prevX, "Window x position should have changed");
isnot(aWindow.screenY, prevY, "Window y position should have changed");
}
function outerChangeTest() {
isnot(aWindow.outerWidth, oWidth, "Window outerWidth should have changed");
isnot(aWindow.outerHeight, oHeight, "Window outerHeight should have changed");
}
SpecialPowers.pushPrefEnv({ "set": [["dom.disable_window_move_resize", false]]},
function() {
SimpleTest.waitForFocus(function() {
if (screen.width <= 200 || screen.height <= 200) {
todo(false, "The screen needs to be bigger than 200px*200px to run this test.");
SimpleTest.finish();
return;
}
backValues();
// The current window can't change it's own size and position.
checkChangeIsDisabled(window).then(function() {
info(`Change was disabled`);
// We create a window and check that it can change its own size and position.
// However, passing size/position parameters to window.open should work. var w = window.open("file_resize_move_windows_1.html", '', 'width=170,height=170,screenX=65,screenY=65');
SimpleTest.waitForFocus(function() {
w.check(function() {
// The current window can change the size and position of the created one.
checkChangeIsEnabled(w, function() {
w.close();
// If we call window.open with an empty string as a third parameter,
// by default, it will create a new tab instead of a new window.
// In that case, we shouldn't allow the caller to change the size/position.
w = window.open("file_resize_move_windows_2.html", '', '');
SimpleTest.waitForFocus(function() {
w.check(function() {
// The current window can't change the size and position of the new tab.
checkChangeIsDisabled(w).then(function() {
w.close();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.