Bug 1606506 - Fix _title and _url properties tabs that don't have a browser; r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 01 Jan 2020 11:30:20 +1300
changeset 37848 fca52e027551658d7d7388706eb184d69aeb5071
parent 37847 9a43763d30c8c557d63048c1453d561075ac1f99
child 37849 c64b9c77d53db301191794fee8d5cd863639ad65
push id397
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:16:13 +0000
reviewersmkmelin
bugs1606506
Bug 1606506 - Fix _title and _url properties tabs that don't have a browser; r=mkmelin
mail/components/extensions/parent/ext-mail.js
mail/components/extensions/test/browser/browser_ext_windows_types.js
--- a/mail/components/extensions/parent/ext-mail.js
+++ b/mail/components/extensions/parent/ext-mail.js
@@ -651,16 +651,29 @@ class Tab extends TabBase {
 
   /** Returns the frame loader for the tab. */
   get frameLoader() {
     // If we don't have a frameLoader yet, just return a dummy with no width and
     // height.
     return super.frameLoader || { lazyWidth: 0, lazyHeight: 0 };
   }
 
+  /** Returns the current URL of this tab, without permission checks. */
+  get _url() {
+    return this.browser ? this.browser.currentURI.spec : null;
+  }
+
+  /** Returns the current title of this tab, without permission checks. */
+  get _title() {
+    if (this.browser && this.browser.contentTitle) {
+      return this.browser.contentTitle;
+    }
+    return this.nativeTab.label;
+  }
+
   /** Returns the favIcon, without permission checks. */
   get _favIconUrl() {
     return null;
   }
 
   /** Returns the last accessed time. */
   get lastAccessed() {
     return 0;
@@ -726,21 +739,16 @@ class Tab extends TabBase {
     return this.active;
   }
 
   /** Returns the loading status of the tab. */
   get status() {
     return "complete";
   }
 
-  /** Returns the title of the tab, without permission checks. */
-  get _title() {
-    return this.nativeTab.ownerDocument.title;
-  }
-
   /** Returns the width of the tab. */
   get width() {
     return this.frameLoader.lazyWidth;
   }
 
   /** Returns the native window object of the tab. */
   get window() {
     return this.nativeTab;
--- a/mail/components/extensions/test/browser/browser_ext_windows_types.js
+++ b/mail/components/extensions/test/browser/browser_ext_windows_types.js
@@ -28,16 +28,20 @@ add_task(async () => {
       let createdWindow = await createdWindowPromise;
       browser.test.assertEq("addressBook", createdWindow.type);
 
       let windowDetail = await browser.windows.get(createdWindow.id, {
         populate: true,
       });
       browser.test.assertEq("addressBook", windowDetail.type);
       browser.test.assertEq(1, windowDetail.tabs.length);
+      // These three properties should not be present, but not fail either.
+      browser.test.assertEq(undefined, windowDetail.tabs[0].favIconUrl);
+      browser.test.assertEq(undefined, windowDetail.tabs[0].title);
+      browser.test.assertEq(undefined, windowDetail.tabs[0].url);
 
       let removedWindowPromise = waitForEvent("onRemoved");
       await browser.addressBooks.closeUI();
       await removedWindowPromise;
 
       // Message compose window.
 
       createdWindowPromise = waitForEvent("onCreated");
@@ -45,16 +49,20 @@ add_task(async () => {
       createdWindow = await createdWindowPromise;
       browser.test.assertEq("messageCompose", createdWindow.type);
 
       windowDetail = await browser.windows.get(createdWindow.id, {
         populate: true,
       });
       browser.test.assertEq("messageCompose", windowDetail.type);
       browser.test.assertEq(1, windowDetail.tabs.length);
+      // These three properties should not be present, but not fail either.
+      browser.test.assertEq(undefined, windowDetail.tabs[0].favIconUrl);
+      browser.test.assertEq(undefined, windowDetail.tabs[0].title);
+      browser.test.assertEq(undefined, windowDetail.tabs[0].url);
 
       removedWindowPromise = waitForEvent("onRemoved");
       await browser.tabs.remove(windowDetail.tabs[0].id);
       await removedWindowPromise;
 
       // Message display window.
 
       createdWindowPromise = waitForEvent("onCreated");
@@ -62,25 +70,29 @@ add_task(async () => {
       createdWindow = await createdWindowPromise;
       browser.test.assertEq("messageDisplay", createdWindow.type);
 
       windowDetail = await browser.windows.get(createdWindow.id, {
         populate: true,
       });
       browser.test.assertEq("messageDisplay", windowDetail.type);
       browser.test.assertEq(1, windowDetail.tabs.length);
+      // These three properties should not be present, but not fail either.
+      browser.test.assertEq(undefined, windowDetail.tabs[0].favIconUrl);
+      browser.test.assertEq(undefined, windowDetail.tabs[0].title);
+      browser.test.assertEq(undefined, windowDetail.tabs[0].url);
 
       removedWindowPromise = waitForEvent("onRemoved");
       browser.test.sendMessage("closeMessage");
       await removedWindowPromise;
 
       browser.test.notifyPass();
     },
     manifest: {
-      permissions: ["addressBooks"],
+      permissions: ["addressBooks", "tabs"],
     },
   });
 
   let account = createAccount();
   addIdentity(account);
   let rootFolder = account.incomingServer.rootFolder;
   rootFolder.createSubfolder("test1", null);
   let subFolders = {};