Bug 1770005 - Add select and autocomplete dropdowns to browserRequest window. r=mkmelin
authorMartin Giger <martin@humanoids.be>
Fri, 20 May 2022 13:00:25 +0300
changeset 35787 9400a0f6772d73739d683cd109cf23907c41ba45
parent 35786 9cdf8b7551efe2567b252afbc016d53a8a36dee5
child 35788 7cd77158c7f3716a9b12bb261d42f609a7801b65
push id19940
push usermkmelin@iki.fi
push dateFri, 20 May 2022 10:04:12 +0000
treeherdercomm-central@9400a0f6772d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1770005
Bug 1770005 - Add select and autocomplete dropdowns to browserRequest window. r=mkmelin Differential Revision: https://phabricator.services.mozilla.com/D146730
mail/base/content/browserRequest.js
mail/base/content/browserRequest.xhtml
mail/base/jar.mn
mail/base/test/browser/browser.ini
mail/base/test/browser/browser_browserRequestWindow.js
mail/base/test/browser/browser_formPickers.js
--- a/mail/base/content/browserRequest.js
+++ b/mail/base/content/browserRequest.js
@@ -1,16 +1,45 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var { MailE10SUtils } = ChromeUtils.import(
   "resource:///modules/MailE10SUtils.jsm"
 );
 
+/* Magic global things the <browser> and its entourage of logic expect. */
+var PopupNotifications = {
+  show(browser, id, message) {
+    console.warn(
+      "Not showing popup notification",
+      id,
+      "with the message",
+      message
+    );
+  },
+};
+
+var gBrowser = {
+  get selectedBrowser() {
+    return document.getElementById("requestFrame");
+  },
+  _getAndMaybeCreateDateTimePickerPanel() {
+    return this.selectedBrowser.dateTimePicker;
+  },
+  get webNavigation() {
+    return this.selectedBrowser.webNavigation;
+  },
+};
+
+function getBrowser() {
+  return gBrowser.selectedBrowser;
+}
+
+/* Logic to actually run the login process and window contents */
 var reporterListener = {
   _isBusy: false,
 
   QueryInterface: ChromeUtils.generateQI([
     "nsIWebProgressListener",
     "nsISupportsWeakReference",
   ]),
 
--- a/mail/base/content/browserRequest.xhtml
+++ b/mail/base/content/browserRequest.xhtml
@@ -5,39 +5,52 @@
  -->
 
 <?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/messenger.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/tabmail.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/searchBox.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/browserRequest.css" type="text/css"?>
 
-<!DOCTYPE window>
+<!DOCTYPE window [
+<!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd">
+%brandDTD;
+<!ENTITY % messengerDTD SYSTEM "chrome://messenger/locale/messenger.dtd">
+%messengerDTD;
+]>
 <window id="browserRequest"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         buttons=","
         onload="loadRequestedUrl()"
         onclose="reportUserClosed()"
         title=""
         width="800"
         height="500"
         orient="vertical">
+  <popupset id="mainPopupSet">
+#define BROWSER_POPUPS_ONLY
+#include ../../base/content/mainPopupSet.inc.xhtml
+  </popupset>
 
   <script src="chrome://global/content/globalOverlay.js"/>
   <script src="chrome://global/content/editMenuOverlay.js"/>
+  <script src="chrome://messenger/content/viewZoomOverlay.js"/>
   <script src="chrome://messenger/content/browserRequest.js"/>
 
   <html:link rel="localization" href="messenger/messenger.ftl"/>
 
   <keyset id="mainKeyset">
     <key id="key_close" key="w" modifiers="accel" oncommand="cancelRequest()"/>
     <key id="key_close2"  keycode="VK_ESCAPE" oncommand="cancelRequest()"/>
   </keyset>
 
   <!-- Use the same styling and semantics as content tabs. -->
   <html:div id="header" class="contentTabAddress">
     <html:img id="security-icon" class="contentTabSecurity" />
     <html:input id="headerMessage" class="contentTabUrlInput themeableSearchBox"
                 readonly="readonly">
     </html:input>
   </html:div>
-  <browser type="content" src="about:blank" id="requestFrame" flex="1"/>
+  <browser type="content" src="about:blank" id="requestFrame" flex="1"
+           autocompletepopup="PopupAutoComplete"
+           selectmenulist="ContentSelectDropdown"
+           datetimepicker="DateTimePickerPanel"/>
 </window>
--- a/mail/base/jar.mn
+++ b/mail/base/jar.mn
@@ -14,17 +14,17 @@ messenger.jar:
     content/messenger/aboutDialog-appUpdater.js     (content/aboutDialog-appUpdater.js)
     content/messenger/aboutDialog.css               (content/aboutDialog.css)
     content/messenger/aboutDialog.js                (content/aboutDialog.js)
 *   content/messenger/aboutDialog.xhtml             (content/aboutDialog.xhtml)
     content/messenger/aboutMessage.js               (content/aboutMessage.js)
 *   content/messenger/aboutMessage.xhtml            (content/aboutMessage.xhtml)
     content/messenger/aboutRights.xhtml             (content/aboutRights.xhtml)
     content/messenger/browserRequest.js             (content/browserRequest.js)
-    content/messenger/browserRequest.xhtml          (content/browserRequest.xhtml)
+*   content/messenger/browserRequest.xhtml          (content/browserRequest.xhtml)
     content/messenger/commandglue.js                (content/commandglue.js)
     content/messenger/commonDialog.xhtml            (content/commonDialog.xhtml)
     content/messenger/compactFoldersDialog.js       (content/compactFoldersDialog.js)
     content/messenger/compactFoldersDialog.xhtml    (content/compactFoldersDialog.xhtml)
     content/messenger/customElements.js             (content/customElements.js)
     content/messenger/customizeToolbar.js           (content/customizeToolbar.js)
     content/messenger/customizeToolbar.xhtml        (content/customizeToolbar.xhtml)
     content/messenger/dialogShadowDom.js            (content/dialogShadowDom.js)
--- a/mail/base/test/browser/browser.ini
+++ b/mail/base/test/browser/browser.ini
@@ -6,16 +6,17 @@ prefs =
   mail.spotlight.firstRunDone=true
   mail.winsearch.firstRunDone=true
   mailnews.database.global.indexer.enabled=false
   mailnews.start_page.override_url=about:blank
   mailnews.start_page.url=about:blank
 subsuite = thunderbird
 support-files = files/**
 
+[browser_browserRequestWindow.js]
 [browser_formPickers.js]
 tags = webextensions
 [browser_interactionTelemetry.js]
 [browser_linkHandler.js]
 [browser_mailContext.js]
 tags = contextmenu webextensions
 [browser_menulist.js]
 skip-if = os == 'mac'
new file mode 100644
--- /dev/null
+++ b/mail/base/test/browser/browser_browserRequestWindow.js
@@ -0,0 +1,75 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* import-globals-from ../../content/browserRequest.js */
+
+/**
+ * Open the browserRequest window.
+ *
+ * @returns {{cancelledPromise: Promise, requestWindow: DOMWindow}}
+ */
+async function openBrowserRequestWindow() {
+  let onCancelled;
+  let cancelledPromise = new Promise(resolve => {
+    onCancelled = resolve;
+  });
+  let requestWindow = await new Promise(resolve => {
+    Services.ww.openWindow(
+      null,
+      "chrome://messenger/content/browserRequest.xhtml",
+      null,
+      "chrome,private,centerscreen,width=980,height=750",
+      {
+        url:
+          "http://mochi.test:8888/browser/comm/mail/base/test/browser/files/sampleContent.html",
+        cancelled() {
+          onCancelled();
+        },
+        loaded(window, webProgress) {
+          resolve(window);
+        },
+      }
+    );
+  });
+  return { cancelledPromise, requestWindow };
+}
+
+add_task(async function test_urlBar() {
+  let { requestWindow, cancelledPromise } = await openBrowserRequestWindow();
+
+  let browser = requestWindow.getBrowser();
+  await BrowserTestUtils.browserLoaded(browser);
+  ok(browser, "Got a browser from global getBrowser function");
+
+  let urlBar = requestWindow.document.getElementById("headerMessage");
+  is(urlBar.value, browser.currentURI.spec, "Initial page is shown in URL bar");
+
+  let redirect = BrowserTestUtils.browserLoaded(browser);
+  BrowserTestUtils.loadURI(browser, "about:blank");
+  await redirect;
+  is(urlBar.value, "about:blank", "URL bar value follows browser");
+
+  const closeEvent = new Event("close");
+  requestWindow.dispatchEvent(closeEvent);
+  await BrowserTestUtils.closeWindow(requestWindow);
+  await cancelledPromise;
+});
+
+add_task(async function test_cancelWithEsc() {
+  let { requestWindow, cancelledPromise } = await openBrowserRequestWindow();
+
+  EventUtils.synthesizeKey("VK_ESCAPE", {}, requestWindow);
+  await cancelledPromise;
+});
+
+add_task(async function test_cancelWithAccelW() {
+  let { requestWindow, cancelledPromise } = await openBrowserRequestWindow();
+
+  EventUtils.synthesizeKey(
+    "w",
+    { [AppConstants.platform == "macosx" ? "metaKey" : "ctrlKey"]: true },
+    requestWindow
+  );
+  await cancelledPromise;
+});
--- a/mail/base/test/browser/browser_formPickers.js
+++ b/mail/base/test/browser/browser_formPickers.js
@@ -312,8 +312,29 @@ add_task(async function testExtensionMes
     "formpickers_mochi_test-messageDisplayAction-toolbarbutton"
   );
   await checkABrowser(browser);
   panel.hidePopup();
 
   await extension.unload();
   await BrowserTestUtils.closeWindow(messageWindow);
 });
+
+add_task(async function testBrowserRequestWindow() {
+  let requestWindow = await new Promise(resolve => {
+    Services.ww.openWindow(
+      null,
+      "chrome://messenger/content/browserRequest.xhtml",
+      null,
+      "chrome,private,centerscreen,width=980,height=750",
+      {
+        url: TEST_DOCUMENT_URL,
+        cancelled() {},
+        loaded(window, webProgress) {
+          resolve(window);
+        },
+      }
+    );
+  });
+
+  await checkABrowser(requestWindow.document.getElementById("requestFrame"));
+  await BrowserTestUtils.closeWindow(requestWindow);
+});