Bug 1385548 - Part 4: Add new test for tab modals created from a WebExtensions options_ui page. draft
authorLuca Greco <lgreco@mozilla.com>
Tue, 19 Sep 2017 18:30:22 +0200
changeset 667055 e65bc2cd702f20c6ad7a247541c6785ef6f25702
parent 667054 8129757327935c43713dbbf06a2523ac41ef2846
child 732285 2f65d5df7ecc8d00a6acfec1f797079840e53d54
push id80600
push userluca.greco@alcacoop.it
push dateTue, 19 Sep 2017 16:57:34 +0000
bugs1385548
milestone57.0a1
Bug 1385548 - Part 4: Add new test for tab modals created from a WebExtensions options_ui page. MozReview-Commit-ID: BUExkEQLkuR
browser/components/extensions/test/browser/browser-common.ini
browser/components/extensions/test/browser/browser_ext_optionsPage_modals.js
--- a/browser/components/extensions/test/browser/browser-common.ini
+++ b/browser/components/extensions/test/browser/browser-common.ini
@@ -85,16 +85,17 @@ skip-if = os == 'mac' # Bug 1374749 will
 [browser_ext_incognito_views.js]
 [browser_ext_incognito_popup.js]
 [browser_ext_lastError.js]
 [browser_ext_menus.js]
 [browser_ext_omnibox.js]
 skip-if = debug || asan # Bug 1354681
 [browser_ext_openPanel.js]
 [browser_ext_optionsPage_browser_style.js]
+[browser_ext_optionsPage_modals.js]
 [browser_ext_optionsPage_privileges.js]
 [browser_ext_pageAction_context.js]
 [browser_ext_pageAction_contextMenu.js]
 [browser_ext_pageAction_popup.js]
 [browser_ext_pageAction_popup_resize.js]
 [browser_ext_pageAction_simple.js]
 [browser_ext_pageAction_telemetry.js]
 [browser_ext_pageAction_title.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/browser/browser_ext_optionsPage_modals.js
@@ -0,0 +1,101 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+add_task(async function test_tab_options_modals() {
+  function backgroundScript() {
+    browser.runtime.openOptionsPage();
+  }
+
+  function optionsScript() {
+    browser.test.onMessage.addListener(async (msg) => {
+      if (msg !== "options-ui-alert") {
+        return;
+      }
+
+      try {
+        alert("WebExtensions OptionsUI Page Modal");
+
+        browser.test.notifyPass("options-ui-modals");
+      } catch (error) {
+        browser.test.log(`Error: ${error} :: ${error.stack}`);
+        browser.test.notifyFail("options-ui-modals");
+      }
+    });
+
+    browser.test.sendMessage("options-ui-loaded");
+  }
+
+  const ID = "options_modals@tests.mozilla.org";
+  let extension = ExtensionTestUtils.loadExtension({
+    useAddonManager: "temporary",
+
+    manifest: {
+      applications: {gecko: {id: ID}},
+      "permissions": ["tabs"],
+      "options_ui": {
+        "page": "options.html",
+      },
+    },
+    files: {
+      "options.html": `<!DOCTYPE html>
+        <html>
+          <head>
+            <meta charset="utf-8">
+            <script src="options.js" type="text/javascript"></script>
+          </head>
+        </html>`,
+      "options.js": optionsScript,
+    },
+    background: backgroundScript,
+  });
+
+  let webpageTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com/");
+
+  await extension.startup();
+
+  await extension.awaitMessage("options-ui-loaded");
+
+  let aboutAddonsBrowser = gBrowser.selectedBrowser;
+  let aboutAddonsTab = gBrowser.selectedTab;
+
+  Assert.equal(aboutAddonsBrowser.currentURI.spec, "about:addons",
+               "Expect the about:addons tab to be selected");
+
+  const onceTabModalOpened = new Promise(resolve => {
+    aboutAddonsBrowser.addEventListener("DOMWillOpenModalDialog", function onModalDialog(event) {
+      if (Cu.isCrossProcessWrapper(event.target)) {
+        // This event fires in both the content and chrome processes. We
+        // want to ignore the one in the content process.
+        return;
+      }
+
+      aboutAddonsBrowser.removeEventListener("DOMWillOpenModalDialog", onModalDialog, true);
+      resolve();
+    }, true);
+  });
+
+  info("Select the previous tab");
+
+  extension.sendMessage("options-ui-alert");
+
+  await onceTabModalOpened;
+
+  let stack = aboutAddonsBrowser.parentNode;
+  let dialogs = stack.getElementsByTagName("tabmodalprompt");
+
+  Assert.equal(dialogs.length, 1, "Expect a tab modal opened for the about addons tab");
+
+  info("Close the tab modal prompt");
+  dialogs[0].onButtonClick(0);
+
+  await extension.awaitFinish("options-ui-modals");
+
+  Assert.equal(stack.getElementsByTagName("tabmodalprompt").length, 0,
+               "Expect the tab modal to be closed");
+
+  await BrowserTestUtils.removeTab(aboutAddonsTab);
+  await BrowserTestUtils.removeTab(webpageTab);
+
+  await extension.unload();
+});