Bug 1653392 - Basic tab modal print UI test r=emalysz,sfoster

Differential Revision: https://phabricator.services.mozilla.com/D84245
This commit is contained in:
Mark Striemer 2020-07-24 15:33:15 +00:00
Родитель c30a3a2200
Коммит e63a1303ef
3 изменённых файлов: 149 добавлений и 0 удалений

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

@ -1,3 +1,11 @@
[DEFAULT]
support-files =
head.js
[browser_modal_print.js]
support-files =
simplifyArticleSample.html
[browser_page_change_print_original.js]
support-files =
file_page_change_print_original_1.html

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

@ -0,0 +1,69 @@
function assertExpectedPrintPage(helper) {
let printBrowser = helper.win.getSourceBrowser();
is(
printBrowser,
gBrowser.selectedBrowser,
"The current browser is being printed"
);
is(
printBrowser.currentURI.spec,
PrintHelper.defaultTestPageUrl,
"The URL of the browser is the one we expect"
);
}
add_task(async function testModalPrintDialog() {
await PrintHelper.withTestPage(async helper => {
helper.assertDialogHidden();
await helper.startPrint();
helper.assertDialogVisible();
// Check that we're printing the right page.
assertExpectedPrintPage(helper);
// Close the dialog with Escape.
await helper.withClosingFn(() => {
EventUtils.synthesizeKey("VK_ESCAPE", {}, helper.win);
});
helper.assertDialogHidden();
});
});
add_task(async function testPrintMultiple() {
await PrintHelper.withTestPage(async helper => {
helper.assertDialogHidden();
// First print as usual.
await helper.startPrint();
helper.assertDialogVisible();
assertExpectedPrintPage(helper);
// Trigger the command a few more times, verify the overlay still exists.
await helper.startPrint();
await helper.startPrint();
await helper.startPrint();
helper.assertDialogVisible();
// Verify it's still the correct page.
assertExpectedPrintPage(helper);
});
});
add_task(async function testCancelButton() {
await PrintHelper.withTestPage(async helper => {
helper.assertDialogHidden();
await helper.startPrint();
helper.assertDialogVisible();
let cancelButton = helper.doc.querySelector("button[name=cancel]");
ok(cancelButton, "Got the cancel button");
info(helper.doc.body.innerHTML + "\n");
await helper.withClosingFn(() =>
EventUtils.synthesizeMouseAtCenter(cancelButton, {}, helper.win)
);
helper.assertDialogHidden();
});
});

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

@ -0,0 +1,72 @@
class PrintHelper {
static withTestPage(testFn) {
SpecialPowers.pushPrefEnv({
set: [["print.tab_modal.enabled", true]],
});
return BrowserTestUtils.withNewTab(
this.defaultTestPageUrl,
async browser => {
await testFn(new PrintHelper(browser));
SpecialPowers.popPrefEnv();
}
);
}
static get defaultTestPageUrl() {
const testPath = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"http://example.com"
);
return testPath + "simplifyArticleSample.html";
}
constructor(browser) {
this.browser = browser;
}
async startPrint() {
document.getElementById("cmd_print").doCommand();
let dialog = await TestUtils.waitForCondition(() => this._dialogs[0]);
await dialog._ready;
}
async withClosingFn(closeFn) {
let closed = this._dialogs[0]._closed;
await closeFn();
await closed;
}
assertDialogHidden() {
is(this._dialogs.length, 0, "There are no print dialogs");
}
assertDialogVisible() {
is(this._dialogs.length, 1, "There is one print dialog");
BrowserTestUtils.is_visible(this._dialogs[0], "The dialog is visible");
}
get _container() {
return this.browser.ownerGlobal.gBrowser.getBrowserContainer(this.browser);
}
get _dialogs() {
return this._container.querySelectorAll(".printDialogContainer");
}
get _printBrowser() {
let dialogs = this._dialogs;
is(dialogs.length, 1, "There's one dialog");
let frame = dialogs[0].querySelector(".dialogFrame");
ok(frame, "Found the print dialog frame");
return frame;
}
get doc() {
return this._printBrowser.contentDocument;
}
get win() {
return this._printBrowser.contentWindow;
}
}