Bug 1619057 - Expand mailing lists even if browser.compose.onBeforeSend listener returns nothing. r=mkmelin a=rjl
authorGeoff Lankow <geoff@darktrojan.net>
Fri, 17 Apr 2020 20:25:18 +1200
changeset 38720 9ef0d5ece977ce41a31434d4f4f45debed785a4c
parent 38719 da0a04cfc0497609fe596b2ba2ea7d8400e1dcda
child 38721 9c50eec1c6cd684f60741ecf1100eb429bf0508a
push id400
push userclokep@gmail.com
push dateMon, 04 May 2020 18:56:09 +0000
reviewersmkmelin, rjl
bugs1619057
Bug 1619057 - Expand mailing lists even if browser.compose.onBeforeSend listener returns nothing. r=mkmelin a=rjl
mail/components/extensions/parent/ext-compose.js
mail/components/extensions/test/browser/browser_ext_compose_onBeforeSend.js
--- a/mail/components/extensions/parent/ext-compose.js
+++ b/mail/components/extensions/parent/ext-compose.js
@@ -241,37 +241,43 @@ class ComposeEventTracker extends EventE
 
     composeWindow.ToggleWindowLock(true);
 
     let results = await this.emit(
       "compose-before-send",
       composeWindow,
       getComposeDetails(composeWindow, this.extension)
     );
+    let didSetDetails = false;
     if (results) {
       for (let result of results) {
         if (!result) {
           continue;
         }
         if (result.cancel) {
           composeWindow.ToggleWindowLock(false);
           return;
         }
         if (result.details) {
           await setComposeDetails(
             composeWindow,
             result.details,
             this.extension
           );
-          composeWindow.GetComposeDetails();
-          composeWindow.expandRecipients();
+          didSetDetails = true;
         }
       }
     }
 
+    if (didSetDetails) {
+      // Load the new details into gMsgCompose.compFields for sending.
+      composeWindow.GetComposeDetails();
+    }
+    // Calling getComposeDetails collapses mailing lists. Expand them again.
+    composeWindow.expandRecipients();
     composeWindow.ToggleWindowLock(false);
     composeWindow.CompleteGenericSendMessage(msgType);
   }
 }
 
 this.compose = class extends ExtensionAPI {
   getAPI(context) {
     function getComposeTab(tabId) {
--- a/mail/components/extensions/test/browser/browser_ext_compose_onBeforeSend.js
+++ b/mail/components/extensions/test/browser/browser_ext_compose_onBeforeSend.js
@@ -508,16 +508,53 @@ add_task(async function testListExpansio
       );
       browser.test.assertEq(
         "Test",
         listener7.details.subject,
         "listener7 subject correct"
       );
       browser.compose.onBeforeSend.removeListener(listener7);
 
+      // Return nothing from the listener. The mailing list should be expanded.
+
+      createdWindowPromise = waitForEvent("onCreated");
+      await browser.compose.beginNew({
+        to: [{ id: list, type: "mailingList" }],
+        subject: "Test",
+      });
+      createdWindow = await createdWindowPromise;
+      browser.test.assertEq("messageCompose", createdWindow.type);
+
+      await checkWindow({
+        to: ["Holmes and Watson <Tenants221B>"],
+        subject: "Test",
+      });
+
+      [tab] = await browser.tabs.query({ windowId: createdWindow.id });
+
+      let listener8 = (tab, details) => {
+        listener8.tab = tab;
+        listener8.details = details;
+      };
+      browser.compose.onBeforeSend.addListener(listener8);
+      await beginSend();
+      browser.test.assertEq(tab.id, listener8.tab.id, "listener8 was fired");
+      browser.test.assertEq(1, listener8.details.to.length);
+      browser.test.assertEq(
+        "Holmes and Watson <Tenants221B>",
+        listener8.details.to[0],
+        "listener8 recipient correct"
+      );
+      browser.test.assertEq(
+        "Test",
+        listener8.details.subject,
+        "listener8 subject correct"
+      );
+      browser.compose.onBeforeSend.removeListener(listener8);
+
       await browser.addressBooks.delete(addressBook);
       browser.test.notifyPass("finished");
     },
     manifest: { permissions: ["addressBooks", "compose"] },
   });
 
   extension.onMessage("beginSend", async () => {
     let composeWindows = [...Services.wm.getEnumerator("msgcompose")];
@@ -547,21 +584,30 @@ add_task(async function testListExpansio
     "list in unchanged field was expanded"
   );
   is(
     sentMessage7.bccList,
     "Sherlock Holmes <sherlock@bakerstreet.invalid>, John Watson <john@bakerstreet.invalid>",
     "list in changed field was expanded"
   );
 
+  ok(outboxMessages.hasMoreElements());
+  let sentMessage8 = outboxMessages.getNext();
+  is(sentMessage8.subject, "Test", "subject was not changed");
+  is(
+    sentMessage8.recipients,
+    "Sherlock Holmes <sherlock@bakerstreet.invalid>, John Watson <john@bakerstreet.invalid>",
+    "list in unchanged field was expanded"
+  );
+
   ok(!outboxMessages.hasMoreElements());
 
   await new Promise(resolve => {
     outbox.deleteMessages(
-      toXPCOMArray([sentMessage7], Ci.nsIMutableArray),
+      toXPCOMArray([sentMessage7, sentMessage8], Ci.nsIMutableArray),
       null,
       true,
       false,
       { OnStopCopy: resolve },
       false
     );
   });
 });