Bug 1536764 - Allow WebExt experiments to use MessageListTracker. r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Thu, 21 Mar 2019 11:52:50 +1300
changeset 26145 83230ef727a3
parent 26144 fc995375f444
child 26146 1aba8edbbfa2
push id15695
push usermozilla@jorgk.com
push dateFri, 22 Mar 2019 17:34:54 +0000
treeherdercomm-central@83230ef727a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1536764
Bug 1536764 - Allow WebExt experiments to use MessageListTracker. r=mkmelin
mail/components/extensions/parent/ext-mail.js
mail/components/extensions/test/xpcshell/test_ext_experiments.js
--- a/mail/components/extensions/parent/ext-mail.js
+++ b/mail/components/extensions/parent/ext-mail.js
@@ -1273,16 +1273,20 @@ class MessageManager {
 
   convert(msgHdr) {
     return convertMessage(msgHdr, this.extension);
   }
 
   get(id) {
     return messageTracker.getMessage(id);
   }
+
+  startMessageList(messageList) {
+    return messageListTracker.startList(messageList, this.extension);
+  }
 }
 
 extensions.on("startup", (type, extension) => { // eslint-disable-line mozilla/balanced-listeners
   if (extension.hasPermission("accountsRead")) {
     defineLazyGetter(extension, "folderManager", () => new FolderManager(extension));
   }
   if (extension.hasPermission("messagesRead")) {
     defineLazyGetter(extension, "messageManager", () => new MessageManager(extension));
--- a/mail/components/extensions/test/xpcshell/test_ext_experiments.js
+++ b/mail/components/extensions/test/xpcshell/test_ext_experiments.js
@@ -34,16 +34,26 @@ add_task(async function test_managers() 
       let subject = await browser.testapi.testCanGetMessage(testMessage.id);
       browser.test.assertEq(testMessage.subject, subject);
 
       let convertedMessage = await browser.testapi.testCanConvertMessage();
       browser.test.log(JSON.stringify(convertedMessage));
       browser.test.assertEq(testMessage.id, convertedMessage.id);
       browser.test.assertEq(testMessage.subject, convertedMessage.subject);
 
+      let messageList = await browser.testapi.testCanStartMessageList();
+      browser.test.assertEq(36, messageList.id.length);
+      browser.test.assertEq(4, messageList.messages.length);
+      browser.test.assertEq(testMessage.subject, messageList.messages[0].subject);
+
+      messageList = await browser.messages.continueList(messageList.id);
+      browser.test.assertEq(null, messageList.id);
+      browser.test.assertEq(1, messageList.messages.length);
+      browser.test.assertTrue(testMessage.subject != messageList.messages[0].subject);
+
       browser.test.notifyPass("finished");
     },
     files: {
       "schema.json": JSON.stringify([{
         namespace: "testapi",
         functions: [{
           name: "testCanGetFolder",
           type: "function",
@@ -65,16 +75,21 @@ add_task(async function test_managers() 
             name: "messageId",
             type: "integer",
           }],
         }, {
           name: "testCanConvertMessage",
           type: "function",
           async: true,
           parameters: [],
+        }, {
+          name: "testCanStartMessageList",
+          type: "function",
+          async: true,
+          parameters: [],
         }],
       }]),
       "implementation.js": `
         var { ExtensionCommon } = ChromeUtils.import("resource://gre/modules/ExtensionCommon.jsm");
         var { MailServices } = ChromeUtils.import("resource:///modules/MailServices.jsm");
         var testapi = class extends ExtensionCommon.ExtensionAPI {
           getAPI(context) {
             return {
@@ -91,16 +106,20 @@ add_task(async function test_managers() 
                   let realMessage = context.extension.messageManager.get(messageId);
                   return realMessage.subject;
                 },
                 async testCanConvertMessage() {
                   let realFolder = [...MailServices.accounts.allFolders.enumerate()].find(f => f.name == "test1");
                   let realMessage = realFolder.messages.getNext();
                   return context.extension.messageManager.convert(realMessage);
                 },
+                async testCanStartMessageList() {
+                  let realFolder = [...MailServices.accounts.allFolders.enumerate()].find(f => f.name == "test1");
+                  return context.extension.messageManager.startMessageList(realFolder.messages);
+                },
               },
             };
           }
         };
       `,
     },
     manifest: {
       permissions: ["accountsRead", "messagesRead"],
@@ -111,12 +130,14 @@ add_task(async function test_managers() 
             scopes: ["addon_parent"],
             paths: [["testapi"]],
             script: "implementation.js",
           },
         },
       },
     },
   });
+  Services.prefs.setIntPref("extensions.webextensions.messagesPerPage", 4);
   await extension.startup();
   await extension.awaitFinish("finished");
   await extension.unload();
+  Services.prefs.clearUserPref("extensions.webextensions.messagesPerPage");
 });