Bug 1385548 - Part 2: Add new test for tab modals created from a WebExtensions options_ui page. r=kmag
authorLuca Greco <lgreco@mozilla.com>
Tue, 19 Sep 2017 18:30:22 +0200
changeset 435965 a4de1a9d965add037872c11a11eac026158be657
parent 435964 f42d24d8aa41eac04c0cbcc196072251fd3cd5b1
child 435966 4bf0f40c6755b92ab878a4c0a523499b2180a2e4
push id8114
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 16:33:21 +0000
treeherdermozilla-beta@73e0d89a540f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1385548
milestone58.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 1385548 - Part 2: Add new test for tab modals created from a WebExtensions options_ui page. r=kmag 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
@@ -88,16 +88,17 @@ skip-if = (os == 'win' && !debug) # bug 
 [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,94 @@
+/* -*- 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() {
+    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");
+    }
+  }
+
+  let extension = ExtensionTestUtils.loadExtension({
+    useAddonManager: "temporary",
+
+    manifest: {
+      "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,
+  });
+
+  await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:addons");
+
+  await extension.startup();
+
+  const onceModalOpened = new Promise(resolve => {
+    const aboutAddonsBrowser = gBrowser.selectedBrowser;
+
+    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("Wait the options_ui modal to be opened");
+  await onceModalOpened;
+
+  const optionsBrowser = gBrowser.selectedBrowser.contentDocument
+                                 .getElementById("addon-options");
+
+  let stack;
+
+  // For remote extensions, the stack that contains the tabmodalprompt elements
+  // is the parent of the extensions options_ui browser element, otherwise it would
+  // be the parent of the currently selected tabbrowser's browser.
+  if (optionsBrowser.isRemoteBrowser) {
+    stack = optionsBrowser.parentNode;
+  } else {
+    stack = gBrowser.selectedBrowser.parentNode;
+  }
+
+  let dialogs = stack.querySelectorAll("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.querySelectorAll("tabmodalprompt").length, 0,
+               "Expect the tab modal to be closed");
+
+  await BrowserTestUtils.removeTab(gBrowser.selectedTab);
+
+  await extension.unload();
+});