Bug 1813303 - Test. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D168375
This commit is contained in:
Emilio Cobos Álvarez
2023-02-01 23:27:01 +00:00
parent f5613692c6
commit 7070212c9e
5 changed files with 182 additions and 138 deletions

View File

@@ -121,7 +121,13 @@ skip-if = os == 'mac' && os_version == '10.15' # macosx1014/15 due to 1550078
[test_largemenu.html]
skip-if = os == 'linux' && !debug # Bug 1207174
[test_maximized_persist.xhtml]
support-files = window_maximized_persist.xhtml
support-files =
window_maximized_persist.xhtml
file_maximized_persist.js
[test_maximized_persist_with_no_titlebar.xhtml]
support-files =
window_maximized_persist_with_no_titlebar.xhtml
file_maximized_persist.js
[test_navigate_persist.html]
support-files = window_navigate_persist.html
[test_menu.xhtml]

View File

@@ -0,0 +1,139 @@
SimpleTest.waitForExplicitFinish();
const WIDTH = 300;
const HEIGHT = 300;
let gWindow;
function promiseMessage(msg) {
info(`wait for message "${msg}"`);
return new Promise(resolve => {
function listener(evt) {
info(`got message "${evt.data}"`);
if (evt.data == msg) {
window.removeEventListener("message", listener);
resolve();
}
}
window.addEventListener("message", listener);
});
}
function openWindow(features = "") {
return window.browsingContext.topChromeWindow.openDialog(
gWindow,
"_blank",
"chrome,dialog=no,all," + features,
window
);
}
function checkWindow(msg, win, sizemode, width, height) {
is(win.windowState, sizemode, "sizemode should match " + msg);
if (sizemode == win.STATE_NORMAL) {
is(win.innerWidth, width, "width should match " + msg);
is(win.innerHeight, height, "height should match " + msg);
}
}
function todoCheckWindow(msg, win, sizemode) {
todo_is(win.windowState, sizemode, "sizemode should match " + msg);
}
// Persistence of "sizemode" is delayed to 500ms after it's changed.
// See SIZE_PERSISTENCE_TIMEOUT in nsWebShellWindow.cpp.
// We wait for 1000ms to ensure that it is actually persisted.
// We can also wait for condition that XULStore does have the value
// set, but that way we cannot test the cases where we don't expect
// persistence to happen.
function waitForSizeModePersisted() {
return new Promise(resolve => {
setTimeout(resolve, 1000);
});
}
async function changeSizeMode(func) {
let promiseSizeModeChange = promiseMessage("sizemodechange");
func();
await promiseSizeModeChange;
await waitForSizeModePersisted();
}
async function runTest(aWindow) {
gWindow = aWindow;
let win = openWindow();
await SimpleTest.promiseFocus(win);
// Check the default state.
const chrome_url = win.location.href;
checkWindow("when open initially", win, win.STATE_NORMAL, WIDTH, HEIGHT);
const widthDiff = win.outerWidth - win.innerWidth;
const heightDiff = win.outerHeight - win.innerHeight;
// Maximize the window.
await changeSizeMode(() => win.maximize());
checkWindow("after maximize window", win, win.STATE_MAXIMIZED);
win.close();
// Open a new window to check persisted sizemode.
win = openWindow();
await SimpleTest.promiseFocus(win);
checkWindow("when reopen to maximized", win, win.STATE_MAXIMIZED);
// Restore the window.
if (win.windowState == win.STATE_MAXIMIZED) {
await changeSizeMode(() => win.restore());
}
checkWindow("after restore window", win, win.STATE_NORMAL, WIDTH, HEIGHT);
win.close();
// Open a new window again to check persisted sizemode.
win = openWindow();
await SimpleTest.promiseFocus(win);
checkWindow("when reopen to normal", win, win.STATE_NORMAL, WIDTH, HEIGHT);
// And maximize the window again for next test.
await changeSizeMode(() => win.maximize());
win.close();
// Open a new window again with centerscreen which shouldn't revert
// the persisted sizemode.
win = openWindow("centerscreen");
await SimpleTest.promiseFocus(win);
checkWindow("when open with centerscreen", win, win.STATE_MAXIMIZED);
win.close();
// Linux doesn't seem to persist sizemode across opening window
// with specified size, so mark it expected fail for now.
let todo = navigator.platform.includes("Linux");
let checkWindowMayFail = todo ? todoCheckWindow : checkWindow;
// Open a new window with size specified.
win = openWindow("width=400,height=400");
await SimpleTest.promiseFocus(win);
checkWindow("when reopen with size", win, win.STATE_NORMAL, 400, 400);
await waitForSizeModePersisted();
win.close();
// Open a new window without size specified.
// The window opened before should not change persisted sizemode.
win = openWindow();
await SimpleTest.promiseFocus(win);
checkWindowMayFail("when reopen without size", win, win.STATE_MAXIMIZED);
win.close();
// Open a new window with sizing synchronously.
win = openWindow();
win.resizeTo(500 + widthDiff, 500 + heightDiff);
await SimpleTest.promiseFocus(win);
checkWindow("when sized synchronously", win, win.STATE_NORMAL, 500, 500);
await waitForSizeModePersisted();
win.close();
// Open a new window without any sizing.
// The window opened before should not change persisted sizemode.
win = openWindow();
await SimpleTest.promiseFocus(win);
checkWindowMayFail("when reopen without sizing", win, win.STATE_MAXIMIZED);
win.close();
// Clean up the XUL store for the given window.
Services.xulStore.removeDocument(chrome_url);
SimpleTest.finish();
}

View File

@@ -2,146 +2,11 @@
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Window Open Test"
onload="runTest()"
onload="runTest('window_maximized_persist.xhtml')"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<script class="testbody" type="application/javascript"><![CDATA[
SimpleTest.waitForExplicitFinish();
const WIDTH = 300;
const HEIGHT = 300;
function promiseMessage(msg) {
info(`wait for message "${msg}"`);
return new Promise(resolve => {
function listener(evt) {
info(`got message "${evt.data}"`);
if (evt.data == msg) {
window.removeEventListener("message", listener);
resolve();
}
}
window.addEventListener("message", listener);
});
}
function openWindow(features = "") {
return window.browsingContext.topChromeWindow.openDialog(
"window_maximized_persist.xhtml",
"_blank", "chrome,dialog=no,all," + features, window);
}
function checkWindow(msg, win, sizemode, width, height) {
is(win.windowState, sizemode, "sizemode should match " + msg);
if (sizemode == win.STATE_NORMAL) {
is(win.innerWidth, width, "width should match " + msg);
is(win.innerHeight, height, "height should match " + msg);
}
}
function todoCheckWindow(msg, win, sizemode) {
todo_is(win.windowState, sizemode, "sizemode should match " + msg);
}
// Persistence of "sizemode" is delayed to 500ms after it's changed.
// See SIZE_PERSISTENCE_TIMEOUT in nsWebShellWindow.cpp.
// We wait for 1000ms to ensure that it is actually persisted.
// We can also wait for condition that XULStore does have the value
// set, but that way we cannot test the cases where we don't expect
// persistence to happen.
function waitForSizeModePersisted() {
return new Promise(resolve => {
setTimeout(resolve, 1000);
});
}
async function changeSizeMode(func) {
let promiseSizeModeChange = promiseMessage("sizemodechange");
func();
await promiseSizeModeChange;
await waitForSizeModePersisted();
}
async function runTest() {
let win = openWindow();
await SimpleTest.promiseFocus(win);
// Check the default state.
const chrome_url = win.location.href;
checkWindow("when open initially", win, win.STATE_NORMAL, WIDTH, HEIGHT);
const widthDiff = win.outerWidth - win.innerWidth;
const heightDiff = win.outerHeight - win.innerHeight;
// Maximize the window.
await changeSizeMode(() => win.maximize());
checkWindow("after maximize window", win, win.STATE_MAXIMIZED);
win.close();
// Open a new window to check persisted sizemode.
win = openWindow();
await SimpleTest.promiseFocus(win);
checkWindow("when reopen to maximized", win, win.STATE_MAXIMIZED);
// Restore the window.
if (win.windowState == win.STATE_MAXIMIZED) {
await changeSizeMode(() => win.restore());
}
checkWindow("after restore window", win, win.STATE_NORMAL, WIDTH, HEIGHT);
win.close();
// Open a new window again to check persisted sizemode.
win = openWindow();
await SimpleTest.promiseFocus(win);
checkWindow("when reopen to normal", win, win.STATE_NORMAL, WIDTH, HEIGHT);
// And maximize the window again for next test.
await changeSizeMode(() => win.maximize());
win.close();
// Open a new window again with centerscreen which shouldn't revert
// the persisted sizemode.
win = openWindow("centerscreen");
await SimpleTest.promiseFocus(win);
checkWindow("when open with centerscreen", win, win.STATE_MAXIMIZED);
win.close();
// Linux doesn't seem to persist sizemode across opening window
// with specified size, so mark it expected fail for now.
let todo = navigator.platform.includes('Linux');
let checkWindowMayFail = todo ? todoCheckWindow : checkWindow;
// Open a new window with size specified.
win = openWindow("width=400,height=400");
await SimpleTest.promiseFocus(win);
checkWindow("when reopen with size", win, win.STATE_NORMAL, 400, 400);
await waitForSizeModePersisted();
win.close();
// Open a new window without size specified.
// The window opened before should not change persisted sizemode.
win = openWindow();
await SimpleTest.promiseFocus(win);
checkWindowMayFail("when reopen without size", win, win.STATE_MAXIMIZED);
win.close();
// Open a new window with sizing synchronously.
win = openWindow();
win.resizeTo(500 + widthDiff, 500 + heightDiff);
await SimpleTest.promiseFocus(win);
checkWindow("when sized synchronously", win, win.STATE_NORMAL, 500, 500);
await waitForSizeModePersisted();
win.close();
// Open a new window without any sizing.
// The window opened before should not change persisted sizemode.
win = openWindow();
await SimpleTest.promiseFocus(win);
checkWindowMayFail("when reopen without sizing", win, win.STATE_MAXIMIZED);
win.close();
// Clean up the XUL store for the given window.
Services.xulStore.removeDocument(chrome_url);
SimpleTest.finish();
}
]]></script>
<script src="file_maximized_persist.js"/>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Window Open Test"
onload="runTest('window_maximized_persist_with_no_titlebar.xhtml')"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<script src="file_maximized_persist.js"/>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</window>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window title="Window Open Test"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
height="300"
width="300"
sizemode="normal"
chromemargin="0,2,2,2"
id="window"
persist="height width sizemode">
<script type="application/javascript"><![CDATA[
window.addEventListener("sizemodechange", evt => {
window.arguments[0].postMessage("sizemodechange", "*");
});
]]></script>
</window>