Bug 1629023 - Return a tab object from compose.begin* functions. r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Fri, 17 Apr 2020 10:45:51 +1200
changeset 29334 756d8f7c911959eedf4ecbee51b7e3b3c31f0f99
parent 29333 01f1041e43c58555469932a4c2d2461e1504b10c
child 29335 2a1b8d8994d0e6874590f5e23e391400b4b6a4ef
push id17315
push usergeoff@darktrojan.net
push dateSat, 18 Apr 2020 00:20:24 +0000
treeherdercomm-central@756d8f7c9119 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1629023
Bug 1629023 - Return a tab object from compose.begin* functions. r=mkmelin
mail/components/extensions/parent/ext-compose.js
mail/components/extensions/test/browser/browser_ext_compose_begin.js
--- a/mail/components/extensions/parent/ext-compose.js
+++ b/mail/components/extensions/parent/ext-compose.js
@@ -48,17 +48,17 @@ async function openComposeWindow(related
   function waitForWindow() {
     return new Promise(resolve => {
       function observer(subject, topic, data) {
         if (
           subject.location.href ==
           "chrome://messenger/content/messengercompose/messengercompose.xhtml"
         ) {
           Services.obs.removeObserver(observer, "chrome-document-loaded");
-          resolve();
+          resolve(subject.ownerGlobal);
         }
       }
       Services.obs.addObserver(observer, "chrome-document-loaded");
     });
   }
 
   // ForwardInline is totally broken, see bug 1513824.
   if (type == Ci.nsIMsgCompType.ForwardInline) {
@@ -309,44 +309,57 @@ this.compose = class extends ExtensionAP
             };
 
             this.eventTracker.on("compose-before-send", listener);
             return () => {
               this.eventTracker.off("compose-before-send", listener);
             };
           },
         }).api(),
-        beginNew(details) {
-          return openComposeWindow(
+        async beginNew(details) {
+          let composeWindow = await openComposeWindow(
             null,
             Ci.nsIMsgCompType.New,
             details,
             extension
           );
+          return tabManager.convert(composeWindow);
         },
-        beginReply(messageId, replyType, details) {
+        async beginReply(messageId, replyType, details) {
           let type = Ci.nsIMsgCompType.Reply;
           if (replyType == "replyToList") {
             type = Ci.nsIMsgCompType.ReplyToList;
           } else if (replyType == "replyToAll") {
             type = Ci.nsIMsgCompType.ReplyAll;
           }
-          return openComposeWindow(messageId, type, details, extension);
+          let composeWindow = await openComposeWindow(
+            messageId,
+            type,
+            details,
+            extension
+          );
+          return tabManager.convert(composeWindow);
         },
-        beginForward(messageId, forwardType, details) {
+        async beginForward(messageId, forwardType, details) {
           let type = Ci.nsIMsgCompType.ForwardInline;
           if (forwardType == "forwardAsAttachment") {
             type = Ci.nsIMsgCompType.ForwardAsAttachment;
           } else if (
             forwardType === null &&
             Services.prefs.getIntPref("mail.forward_message_mode") == 0
           ) {
             type = Ci.nsIMsgCompType.ForwardAsAttachment;
           }
-          return openComposeWindow(messageId, type, details, extension);
+          let composeWindow = await openComposeWindow(
+            messageId,
+            type,
+            details,
+            extension
+          );
+          return tabManager.convert(composeWindow);
         },
         getComposeDetails(tabId) {
           let tab = getComposeTab(tabId);
           return getComposeDetails(tab.nativeTab, extension);
         },
         setComposeDetails(tabId, details) {
           let tab = getComposeTab(tabId);
           return setComposeDetails(tab.nativeTab, details, extension);
--- a/mail/components/extensions/test/browser/browser_ext_compose_begin.js
+++ b/mail/components/extensions/test/browser/browser_ext_compose_begin.js
@@ -42,17 +42,21 @@ add_task(async function testIdentity() {
           args: [{ identityId: nonDefaultIdentity.id }],
           isDefault: false,
         },
       ];
       for (let func of funcs) {
         browser.test.log(func.name);
         for (let test of tests) {
           browser.test.log(JSON.stringify(test.args));
-          await browser.compose[func.name](...func.args.concat(test.args));
+          let tab = await browser.compose[func.name](
+            ...func.args.concat(test.args)
+          );
+          browser.test.assertEq("object", typeof tab);
+          browser.test.assertEq("number", typeof tab.id);
           browser.test.sendMessage("checkIdentity", test.isDefault);
           await new Promise(resolve => {
             browser.test.onMessage.addListener(function listener() {
               browser.test.onMessage.removeListener(listener);
               resolve();
             });
           });
         }