Bug 1329971 - tab objects returned by sessions.getRecentlyClosed are missing some data, r=kmag
authorBob Silverberg <bsilverberg@mozilla.com>
Wed, 11 Jan 2017 09:14:58 -0500
changeset 376255 97e7ffeacda1eeaa7269415a2fd8fe6ffd4d5df4
parent 376254 20abab774cd1356eaa21cfb8ea53480c31bcf05c
child 376256 39b8a7d708e58ea56d5f1baf570d1605f130d323
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1329971
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1329971 - tab objects returned by sessions.getRecentlyClosed are missing some data, r=kmag MozReview-Commit-ID: GB3Xaxg8HRf
browser/components/extensions/ext-utils.js
browser/components/extensions/test/browser/browser-common.ini
browser/components/extensions/test/browser/browser_ext_sessions_getRecentlyClosed_tabs.js
--- a/browser/components/extensions/ext-utils.js
+++ b/browser/components/extensions/ext-utils.js
@@ -705,16 +705,25 @@ ExtensionTabManager.prototype = {
       windowId: WindowManager.getId(window),
       selected: false,
       highlighted: false,
       active: false,
       pinned: false,
       incognito: Boolean(tab.state && tab.state.isPrivate),
     };
 
+    if (this.hasTabPermission(tab)) {
+      let entries = tab.state ? tab.state.entries : tab.entries;
+      result.url = entries[0].url;
+      result.title = entries[0].title;
+      if (tab.image) {
+        result.favIconUrl = tab.image;
+      }
+    }
+
     return result;
   },
 
   getTabs(window) {
     return Array.from(window.gBrowser.tabs)
                 .filter(tab => !tab.closing)
                 .map(tab => this.convert(tab));
   },
--- a/browser/components/extensions/test/browser/browser-common.ini
+++ b/browser/components/extensions/test/browser/browser-common.ini
@@ -58,16 +58,17 @@ support-files =
 [browser_ext_popup_corners.js]
 [browser_ext_popup_sendMessage.js]
 [browser_ext_popup_shutdown.js]
 [browser_ext_runtime_openOptionsPage.js]
 [browser_ext_runtime_openOptionsPage_uninstall.js]
 [browser_ext_runtime_setUninstallURL.js]
 [browser_ext_sessions_getRecentlyClosed.js]
 [browser_ext_sessions_getRecentlyClosed_private.js]
+[browser_ext_sessions_getRecentlyClosed_tabs.js]
 [browser_ext_sessions_restore.js]
 [browser_ext_simple.js]
 [browser_ext_tab_runtimeConnect.js]
 [browser_ext_tabs_audio.js]
 [browser_ext_tabs_captureVisibleTab.js]
 [browser_ext_tabs_create.js]
 [browser_ext_tabs_create_invalid_url.js]
 [browser_ext_tabs_detectLanguage.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/browser/browser_ext_sessions_getRecentlyClosed_tabs.js
@@ -0,0 +1,96 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+function expectedTabInfo(tab, window) {
+  let browser = tab.linkedBrowser;
+  return {
+    url: browser.currentURI.spec,
+    title: browser.contentTitle,
+    favIconUrl: window.gBrowser.getIcon(tab),
+  };
+}
+
+function checkTabInfo(expected, actual) {
+  for (let prop in expected) {
+    is(actual[prop], expected[prop], `Expected value found for ${prop} of tab object.`);
+  }
+}
+
+add_task(async function test_sessions_get_recently_closed_tabs() {
+  async function background() {
+    browser.test.onMessage.addListener(async msg => {
+      if (msg == "check-sessions") {
+        let recentlyClosed = await browser.sessions.getRecentlyClosed();
+        browser.test.sendMessage("recentlyClosed", recentlyClosed);
+      }
+    });
+  }
+
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      permissions: ["sessions", "tabs"],
+    },
+    background,
+  });
+
+  let win = await BrowserTestUtils.openNewBrowserWindow();
+  await BrowserTestUtils.loadURI(win.gBrowser.selectedBrowser, "about:addons");
+  await BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser);
+  let expectedTabs = [];
+  let tab = win.gBrowser.selectedTab;
+  expectedTabs.push(expectedTabInfo(tab, win));
+
+  for (let url of ["about:robots", "about:mozilla"]) {
+    tab = await BrowserTestUtils.openNewForegroundTab(win.gBrowser, url);
+    expectedTabs.push(expectedTabInfo(tab, win));
+  }
+
+  await extension.startup();
+
+  // Test with a closed tab.
+  await BrowserTestUtils.removeTab(tab);
+
+  extension.sendMessage("check-sessions");
+  let recentlyClosed = await extension.awaitMessage("recentlyClosed");
+  let tabInfo = recentlyClosed[0].tab;
+  let expectedTab = expectedTabs.pop();
+  checkTabInfo(expectedTab, tabInfo);
+
+  // Test with a closed window containing tabs.
+  await BrowserTestUtils.closeWindow(win);
+
+  extension.sendMessage("check-sessions");
+  recentlyClosed = await extension.awaitMessage("recentlyClosed");
+  let tabInfos = recentlyClosed[0].window.tabs;
+  is(tabInfos.length, 2, "Expected number of tabs in closed window.");
+  for (let x = 0; x < tabInfos.length; x++) {
+    checkTabInfo(expectedTabs[x], tabInfos[x]);
+  }
+
+  await extension.unload();
+
+  // Test without tabs permission.
+  extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      permissions: ["sessions"],
+    },
+    background,
+  });
+
+  await extension.startup();
+
+  extension.sendMessage("check-sessions");
+  recentlyClosed = await extension.awaitMessage("recentlyClosed");
+  tabInfos = recentlyClosed[0].window.tabs;
+  is(tabInfos.length, 2, "Expected number of tabs in closed window.");
+  for (let tabInfo of tabInfos) {
+    for (let prop in expectedTabs[0]) {
+      is(undefined,
+         tabInfo[prop],
+         `${prop} of tab object is undefined without tabs permission.`);
+    }
+  }
+
+  await extension.unload();
+});