Bug 1338312 - browser.sessions.getRecentlyClosed returns incorrect information for tabs in closed windows, r?aswan
MozReview-Commit-ID: FrUhiR9Q9aV
--- 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();
+});