Bug 1338312 - browser.sessions.getRecentlyClosed returns incorrect information for tabs in closed windows, r=aswan
authorBob Silverberg <bsilverberg@mozilla.com>
Tue, 14 Feb 2017 15:23:46 -0500
changeset 390763 e2b89b2e9dd7a651b2085dcddfcd024285d62a7a
parent 390762 e3aead1e9d17e8268314fade1a65f2d8aa6a34d4
child 390764 a59d9440cef9735733df18b62e4d6b18eabf5474
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1338312
milestone54.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 1338312 - browser.sessions.getRecentlyClosed returns incorrect information for tabs in closed windows, r=aswan MozReview-Commit-ID: FrUhiR9Q9aV
browser/components/extensions/ext-utils.js
browser/components/extensions/test/browser/browser_ext_sessions_getRecentlyClosed.js
--- a/browser/components/extensions/ext-utils.js
+++ b/browser/components/extensions/ext-utils.js
@@ -539,18 +539,19 @@ class Tab extends TabBase {
       highlighted: false,
       active: false,
       pinned: false,
       incognito: Boolean(tabData.state && tabData.state.isPrivate),
     };
 
     if (extension.tabManager.hasTabPermission(tabData)) {
       let entries = tabData.state ? tabData.state.entries : tabData.entries;
-      result.url = entries[0].url;
-      result.title = entries[0].title;
+      let entry = entries[entries.length - 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.js
+++ b/browser/components/extensions/test/browser/browser_ext_sessions_getRecentlyClosed.js
@@ -90,8 +90,41 @@ add_task(function* test_sessions_get_rec
 
   // test with filter
   extension.sendMessage("check-sessions", {maxResults: 2});
   recentlyClosed = yield extension.awaitMessage("recentlyClosed");
   checkRecentlyClosed(recentlyClosed.filter(onlyNewItemsFilter), 2, currentWindowId);
 
   yield extension.unload();
 });
+
+add_task(function* test_sessions_get_recently_closed_navigated() {
+  function background() {
+    browser.sessions.getRecentlyClosed({maxResults: 1}).then(recentlyClosed => {
+      let tab = recentlyClosed[0].window.tabs[0];
+      browser.test.assertEq("http://example.com/", tab.url,
+        "Tab in closed window has the expected url.");
+      browser.test.assertTrue(tab.title.includes("mochitest index"),
+        "Tab in closed window has the expected title.");
+      browser.test.notifyPass("getRecentlyClosed with navigation");
+    });
+  }
+
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      permissions: ["sessions", "tabs"],
+    },
+    background,
+  });
+
+  // Test with a window with navigation history.
+  let win = yield BrowserTestUtils.openNewBrowserWindow();
+  for (let url of ["about:robots", "about:mozilla", "http://example.com/"]) {
+    yield BrowserTestUtils.loadURI(win.gBrowser.selectedBrowser, url);
+    yield BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser);
+  }
+
+  yield BrowserTestUtils.closeWindow(win);
+
+  yield extension.startup();
+  yield extension.awaitFinish();
+  yield extension.unload();
+});