Bug 1587673 - glodaList tab mode should be considered a mailTab for WebExtensions. r=mkmelin a=jorgk THUNDERBIRD_70_0b4_BUILD1 THUNDERBIRD_70_0b4_RELEASE
authorGeoff Lankow <geoff@darktrojan.net>
Thu, 10 Oct 2019 16:58:16 +1300
changeset 36701 629a054c868f3ee7dc7acb8af608e079865258c4
parent 36700 e822d43d62ee6ab63c1a42809ecb5f62c379db2e
child 36702 49806deb60adaabb0922368f8c1854701cedb90a
push id394
push userclokep@gmail.com
push dateMon, 21 Oct 2019 20:22:01 +0000
reviewersmkmelin, jorgk
bugs1587673
Bug 1587673 - glodaList tab mode should be considered a mailTab for WebExtensions. r=mkmelin a=jorgk
mail/components/extensions/parent/ext-mail.js
mail/components/extensions/parent/ext-mailTabs.js
mail/components/extensions/parent/ext-messageDisplay.js
mail/components/extensions/test/browser/browser_ext_mailTabs.js
--- a/mail/components/extensions/parent/ext-mail.js
+++ b/mail/components/extensions/parent/ext-mail.js
@@ -801,17 +801,17 @@ class TabmailTab extends Tab {
 
   /** Returns the tabmail element for the tab. */
   get tabmail() {
     return this.browser.ownerDocument.getElementById("tabmail");
   }
 
   /** Returns true if this tab is a 3-pane tab. */
   get mailTab() {
-    return this.nativeTab.mode.type == "folder";
+    return ["folder", "glodaList"].includes(this.nativeTab.mode.name);
   }
 
   /** Returns the tab index. */
   get index() {
     return this.tabmail.tabInfo
       .filter(info => getTabBrowser(info))
       .indexOf(this.nativeTab);
   }
--- a/mail/components/extensions/parent/ext-mailTabs.js
+++ b/mail/components/extensions/parent/ext-mailTabs.js
@@ -46,29 +46,34 @@ function convertMailTab(tab, context) {
     sortType: null,
     sortOrder: null,
     layout: LAYOUTS[Services.prefs.getIntPref("mail.pane_config.dynamic")],
     folderPaneVisible: null,
     messagePaneVisible: null,
   };
 
   let nativeTab = tab.nativeTab;
-  let { folderDisplay } = nativeTab;
-  if (folderDisplay.view.displayedFolder) {
+  let { folderDisplay, mode } = nativeTab;
+  if (mode.name == "folder" && folderDisplay.view.displayedFolder) {
     let { folderPaneVisible, messagePaneVisible } = nativeTab.mode.persistTab(
       nativeTab
     );
+    mailTabObject.folderPaneVisible = folderPaneVisible;
+    mailTabObject.messagePaneVisible = messagePaneVisible;
+  } else if (mode.name == "glodaList") {
+    mailTabObject.folderPaneVisible = false;
+    mailTabObject.messagePaneVisible = true;
+  }
+  if (mode.name == "glodaList" || folderDisplay.view.displayedFolder) {
     mailTabObject.sortType = SORT_TYPE_MAP.get(
       folderDisplay.view.primarySortType
     );
     mailTabObject.sortOrder = SORT_ORDER_MAP.get(
       folderDisplay.view.primarySortOrder
     );
-    mailTabObject.folderPaneVisible = folderPaneVisible;
-    mailTabObject.messagePaneVisible = messagePaneVisible;
   }
   if (context.extension.hasPermission("accountsRead")) {
     mailTabObject.displayedFolder = convertFolder(
       folderDisplay.displayedFolder
     );
   }
   return mailTabObject;
 }
@@ -181,16 +186,17 @@ this.mailTabs = class extends ExtensionA
               context
             ),
             tab => convertMailTab(tab, context)
           );
         },
 
         async update(tabId, args) {
           let tab = getTabOrActive(tabId);
+          let { nativeTab } = tab;
           let window = tab.window;
 
           let {
             displayedFolder,
             layout,
             folderPaneVisible,
             messagePaneVisible,
             sortOrder,
@@ -198,80 +204,85 @@ this.mailTabs = class extends ExtensionA
           } = args;
 
           if (displayedFolder && extension.hasPermission("accountsRead")) {
             let uri = folderPathToURI(
               displayedFolder.accountId,
               displayedFolder.path
             );
             if (tab.active) {
-              let treeView = Cu.getGlobalForObject(tab.nativeTab)
-                .gFolderTreeView;
+              let treeView = Cu.getGlobalForObject(nativeTab).gFolderTreeView;
               let folder = MailServices.folderLookup.getFolderForURL(uri);
               if (folder) {
                 treeView.selectFolder(folder);
               } else {
                 throw new ExtensionError(
                   `Folder "${displayedFolder.path}" for account ` +
                     `"${displayedFolder.accountId}" not found.`
                 );
               }
             } else {
-              tab.nativeTab.folderDisplay.showFolderUri(uri);
+              nativeTab.folderDisplay.showFolderUri(uri);
             }
           }
 
           if (sortType) {
             // Change "foo" to "byFoo".
             sortType = "by" + sortType[0].toUpperCase() + sortType.substring(1);
             if (
               sortType in Ci.nsMsgViewSortType &&
               sortOrder &&
               sortOrder in Ci.nsMsgViewSortOrder
             ) {
-              tab.nativeTab.folderDisplay.view.sort(
+              nativeTab.folderDisplay.view.sort(
                 Ci.nsMsgViewSortType[sortType],
                 Ci.nsMsgViewSortOrder[sortOrder]
               );
             }
           }
 
           // Layout applies to all folder tabs.
           if (layout) {
             Services.prefs.setIntPref(
               "mail.pane_config.dynamic",
               LAYOUTS.indexOf(layout)
             );
           }
 
-          if (typeof folderPaneVisible == "boolean") {
+          if (
+            typeof folderPaneVisible == "boolean" &&
+            nativeTab.mode.name == "folder"
+          ) {
             if (tab.active) {
               let document = window.document;
               let folderPaneSplitter = document.getElementById(
                 "folderpane_splitter"
               );
               folderPaneSplitter.setAttribute(
                 "state",
                 folderPaneVisible ? "open" : "collapsed"
               );
             } else {
-              tab.nativeTab.folderDisplay.folderPaneVisible = folderPaneVisible;
+              nativeTab.folderDisplay.folderPaneVisible = folderPaneVisible;
             }
           }
 
-          if (typeof messagePaneVisible == "boolean") {
+          if (
+            typeof messagePaneVisible == "boolean" &&
+            nativeTab.mode.name == "folder"
+          ) {
             if (tab.active) {
               if (messagePaneVisible == window.IsMessagePaneCollapsed()) {
                 window.MsgToggleMessagePane();
               }
             } else {
-              tab.nativeTab.messageDisplay._visible = messagePaneVisible;
+              nativeTab.messageDisplay._visible = messagePaneVisible;
               if (!messagePaneVisible) {
                 // Prevent the messagePane from showing if a message is selected.
-                tab.nativeTab.folderDisplay._aboutToSelectMessage = true;
+                nativeTab.folderDisplay._aboutToSelectMessage = true;
               }
             }
           }
         },
 
         async getSelectedMessages(tabId) {
           if (!extension.hasPermission("messagesRead")) {
             throw new ExtensionError(
--- a/mail/components/extensions/parent/ext-messageDisplay.js
+++ b/mail/components/extensions/parent/ext-messageDisplay.js
@@ -30,17 +30,19 @@ this.messageDisplay = class extends Exte
         }).api(),
         async getDisplayedMessage(tabId) {
           let tab = tabManager.get(tabId);
           let displayedMessage = null;
 
           if (tab instanceof TabmailTab) {
             if (
               tab.active &&
-              ["folder", "message"].includes(tab.nativeTab.mode.name)
+              ["folder", "glodaList", "message"].includes(
+                tab.nativeTab.mode.name
+              )
             ) {
               displayedMessage = tab.nativeTab.messageDisplay.displayedMessage;
             }
           } else if (tab.nativeTab.gMessageDisplay) {
             displayedMessage = tab.nativeTab.gMessageDisplay.displayedMessage;
           }
 
           return convertMessage(displayedMessage, extension);
--- a/mail/components/extensions/test/browser/browser_ext_mailTabs.js
+++ b/mail/components/extensions/test/browser/browser_ext_mailTabs.js
@@ -485,8 +485,69 @@ add_task(async function test_background_
   await extension.startup();
   extension.sendMessage(account.key);
   await extension.awaitFinish("mailTabs");
   await extension.unload();
 
   tabmail.closeOtherTabs(tabmail.tabModes.folder.tabs[0]);
   window.gFolderTreeView.selectFolder(rootFolder);
 });
+
+add_task(async function test_glodaList_tab() {
+  async function background() {
+    let mailTabs = await browser.mailTabs.query({});
+    browser.test.assertEq(2, mailTabs.length);
+
+    let [tab] = await browser.mailTabs.query({ active: true });
+    browser.test.assertTrue(!tab.folderPaneVisible);
+    browser.test.assertTrue(tab.messagePaneVisible);
+
+    // This should have no effect, and it certainly shouldn't throw.
+    await browser.mailTabs.update({
+      folderPaneVisible: true,
+      messagePaneVisible: false,
+    });
+
+    await new Promise(resolve => {
+      browser.test.onMessage.addListener(function listener(...args) {
+        browser.test.onMessage.removeListener(listener);
+        resolve(args);
+      });
+      browser.test.sendMessage("checkRealLayout", {
+        folderPaneVisible: false,
+        messagePaneVisible: true,
+      });
+    });
+
+    [tab] = await browser.mailTabs.query({ active: true });
+    browser.test.assertEq(2, mailTabs.length);
+    browser.test.assertTrue(!tab.folderPaneVisible);
+    browser.test.assertTrue(tab.messagePaneVisible);
+
+    browser.test.notifyPass("mailTabs");
+  }
+
+  let tabmail = document.getElementById("tabmail");
+  tabmail.openTab("glodaList", { collection: { items: [] } });
+
+  let extension = ExtensionTestUtils.loadExtension({
+    background,
+    manifest: { permissions: ["accountsRead", "messagesRead"] },
+  });
+
+  extension.onMessage("checkRealLayout", expected => {
+    is(
+      document.getElementById("messagepaneboxwrapper").collapsed,
+      !expected.messagePaneVisible
+    );
+    is(
+      document.getElementById("folderPaneBox").collapsed,
+      !expected.folderPaneVisible
+    );
+    extension.sendMessage();
+  });
+
+  await extension.startup();
+  await extension.awaitFinish("mailTabs");
+  await extension.unload();
+
+  tabmail.closeOtherTabs(tabmail.tabModes.folder.tabs[0]);
+});