Bug 1653392 - Basic tab modal print UI test r=emalysz,sfoster
☠☠ backed out by 4a5520ecb075 ☠ ☠
authorMark Striemer <mstriemer@mozilla.com>
Fri, 24 Jul 2020 15:33:15 +0000
changeset 542080 7fac5bd02bb3c962c2b68ea682877772ddd98268
parent 542079 9f8b675f0f6bcb72c974a913572afb04d9258b69
child 542081 3a145ddbf34a6c2dc9515eb8100aef16aff6ae22
push id122620
push usermstriemer@mozilla.com
push dateFri, 24 Jul 2020 16:49:23 +0000
treeherderautoland@7fac5bd02bb3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemalysz, sfoster
bugs1653392
milestone80.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1653392 - Basic tab modal print UI test r=emalysz,sfoster Differential Revision: https://phabricator.services.mozilla.com/D84245
toolkit/components/printing/tests/browser.ini
toolkit/components/printing/tests/browser_modal_print.js
toolkit/components/printing/tests/head.js
--- a/toolkit/components/printing/tests/browser.ini
+++ b/toolkit/components/printing/tests/browser.ini
@@ -1,8 +1,16 @@
+[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
   file_page_change_print_original_2.html
 skip-if = os == "mac"
 
 [browser_preview_print_simplify_non_article.js]
 support-files =
new file mode 100644
--- /dev/null
+++ b/toolkit/components/printing/tests/browser_modal_print.js
@@ -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();
+  });
+});
new file mode 100644
--- /dev/null
+++ b/toolkit/components/printing/tests/head.js
@@ -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;
+  }
+}