Bug 1375546 - Fix sessions.getRecentlyClosed to consider the current tab history index, r=mikedeboer,mixedpuppy
authorBob Silverberg <bsilverberg@mozilla.com>
Tue, 19 Sep 2017 16:05:33 -0400
changeset 435470 ae7f9f3bbec21bcecdf98fcae2312a34f9008eb2
parent 435469 83afa692da84387ded48b42f36f05911a4cbadb0
child 435471 db6679f42d980c1267971a6102459ae9501c32eb
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer, mixedpuppy
bugs1375546
milestone58.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 1375546 - Fix sessions.getRecentlyClosed to consider the current tab history index, r=mikedeboer,mixedpuppy If the back button is used to navigate a tab backwards in its history, and then the tab is closed, the current implementation of sessions.getRecentlyClosed does not take this into account and just uses the last item in the tab history for the values returned for the tab. This patch fixes this by using the values for the current position of the tab in its history. MozReview-Commit-ID: LcgtA5FqVWi
browser/components/extensions/ext-browser.js
browser/components/extensions/test/browser/browser_ext_sessions_getRecentlyClosed_tabs.js
--- a/browser/components/extensions/ext-browser.js
+++ b/browser/components/extensions/ext-browser.js
@@ -660,17 +660,20 @@ class Tab extends TabBase {
       active: false,
       pinned: false,
       incognito: Boolean(tabData.state && tabData.state.isPrivate),
       lastAccessed: tabData.state ? tabData.state.lastAccessed : tabData.lastAccessed,
     };
 
     if (extension.tabManager.hasTabPermission(tabData)) {
       let entries = tabData.state ? tabData.state.entries : tabData.entries;
-      let entry = entries[entries.length - 1];
+      let lastTabIndex = tabData.state ? tabData.state.index : tabData.index;
+      // We need to take lastTabIndex - 1 because the index in the tab data is
+      // 1-based rather than 0-based.
+      let entry = entries[lastTabIndex - 1];
       result.url = entry.url;
       result.title = entry.title;
       if (tabData.image) {
         result.favIconUrl = tabData.image;
       }
     }
 
     return result;
--- a/browser/components/extensions/test/browser/browser_ext_sessions_getRecentlyClosed_tabs.js
+++ b/browser/components/extensions/test/browser/browser_ext_sessions_getRecentlyClosed_tabs.js
@@ -33,18 +33,29 @@ add_task(async function test_sessions_ge
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       permissions: ["sessions", "tabs"],
     },
     background,
   });
 
   let win = await BrowserTestUtils.openNewBrowserWindow();
-  await BrowserTestUtils.loadURI(win.gBrowser.selectedBrowser, "about:mozilla");
-  await BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser);
+  let tabBrowser = win.gBrowser.selectedBrowser;
+  for (let url of ["about:robots", "about:mozilla", "about:config"]) {
+    await BrowserTestUtils.loadURI(tabBrowser, url);
+    await BrowserTestUtils.browserLoaded(tabBrowser, false, url);
+  }
+
+  // Ensure that getRecentlyClosed returns correct results after the back
+  // button has been used.
+  let goBackPromise = BrowserTestUtils.waitForLocationChange(
+    win.gBrowser, "about:mozilla");
+  tabBrowser.goBack();
+  await goBackPromise;
+
   let expectedTabs = [];
   let tab = win.gBrowser.selectedTab;
   // Because there is debounce logic in ContentLinkHandler.jsm to reduce the
   // favicon loads, we have to wait some time before checking that icon was
   // stored properly. If that page doesn't have favicon links, let it timeout.
   try {
     await BrowserTestUtils.waitForCondition(() => {
       return gBrowser.getIcon(tab) != null;