Bug 1338312 - browser.sessions.getRecentlyClosed returns incorrect information for tabs in closed windows. r=aswan, a=gchang
authorBob Silverberg <bsilverberg@mozilla.com>
Wed, 22 Feb 2017 08:56:28 -0500
changeset 359450 f024cf09cb2c192de90cf309ceea52da84455530
parent 359449 4851173666d03c2be1e2d72705650c69cfc35dfb
child 359451 faa3b0ea01237c74a055568f3bd82b1b3f371cb4
push id10805
push userryanvm@gmail.com
push dateFri, 24 Feb 2017 18:25:19 +0000
treeherdermozilla-aurora@329442feed24 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan, gchang
bugs1338312
milestone53.0a2
Bug 1338312 - browser.sessions.getRecentlyClosed returns incorrect information for tabs in closed windows. r=aswan, a=gchang
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
@@ -713,18 +713,19 @@ ExtensionTabManager.prototype = {
       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;
+      let entry = entries[entries.length - 1];
+      result.url = entry.url;
+      result.title = entry.title;
       if (tab.image) {
         result.favIconUrl = tab.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();
+});