Bug 1160556 - Recollect session history data when the page title changes r=Gijs
authorTim Taubert <ttaubert@mozilla.com>
Tue, 05 May 2015 16:00:12 +0200
changeset 273762 d6e5fb263125dd6001cef011000b3a70cac8fc5f
parent 273761 f392bbb834961737b529b3b9253466a45e116a12
child 273763 d4e4b4b55b5c723591323b708b0c1007ef971b94
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1160556
milestone40.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 1160556 - Recollect session history data when the page title changes r=Gijs
browser/components/sessionstore/content/content-sessionStore.js
browser/components/sessionstore/test/browser.ini
browser/components/sessionstore/test/browser_page_title.js
browser/components/sessionstore/test/head.js
--- a/browser/components/sessionstore/content/content-sessionStore.js
+++ b/browser/components/sessionstore/content/content-sessionStore.js
@@ -260,31 +260,38 @@ let SessionHistoryListener = {
     // a delay.
     docShell.QueryInterface(Ci.nsIWebNavigation).sessionHistory.
       addSHistoryListener(this);
 
     // Collect data if we start with a non-empty shistory.
     if (!SessionHistory.isEmpty(docShell)) {
       this.collect();
     }
+
+    // Listen for page title changes.
+    addEventListener("DOMTitleChanged", this);
   },
 
   uninit: function () {
     let sessionHistory = docShell.QueryInterface(Ci.nsIWebNavigation).sessionHistory;
     if (sessionHistory) {
       sessionHistory.removeSHistoryListener(this);
     }
   },
 
   collect: function () {
     if (docShell) {
       MessageQueue.push("history", () => SessionHistory.collect(docShell));
     }
   },
 
+  handleEvent(event) {
+    this.collect();
+  },
+
   onFrameTreeCollected: function () {
     this.collect();
   },
 
   onFrameTreeReset: function () {
     this.collect();
   },
 
--- a/browser/components/sessionstore/test/browser.ini
+++ b/browser/components/sessionstore/test/browser.ini
@@ -83,16 +83,17 @@ skip-if = buildapp == 'mulet'
 [browser_formdata_format.js]
 [browser_formdata_xpath.js]
 [browser_frametree.js]
 [browser_frame_history.js]
 [browser_global_store.js]
 [browser_history_persist.js]
 [browser_label_and_icon.js]
 [browser_merge_closed_tabs.js]
+[browser_page_title.js]
 [browser_pageStyle.js]
 [browser_privatetabs.js]
 [browser_replace_load.js]
 [browser_restore_redirect.js]
 [browser_scrollPositions.js]
 [browser_sessionHistory.js]
 # Disabled because of bug 1077581
 skip-if = e10s
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser_page_title.js
@@ -0,0 +1,38 @@
+"use strict";
+
+const URL = "data:text/html,<title>initial title</title>";
+
+add_task(function* () {
+  // Create a new tab.
+  let tab = gBrowser.addTab(URL);
+  yield promiseBrowserLoaded(tab.linkedBrowser);
+
+  // Remove the tab.
+  yield promiseRemoveTab(tab);
+
+  // Check the title.
+  let [{state: {entries}}] = JSON.parse(ss.getClosedTabData(window));
+  is(entries[0].title, "initial title", "correct title");
+});
+
+add_task(function* () {
+  // Create a new tab.
+  let tab = gBrowser.addTab(URL);
+  let browser = tab.linkedBrowser;
+  yield promiseBrowserLoaded(browser);
+
+  // Flush to ensure we collected the initial title.
+  TabState.flush(browser);
+
+  // Set a new title.
+  yield ContentTask.spawn(browser, null, function* () {
+    content.document.title = "new title";
+  });
+
+  // Remove the tab.
+  yield promiseRemoveTab(tab);
+
+  // Check the title.
+  let [{state: {entries}}] = JSON.parse(ss.getClosedTabData(window));
+  is(entries[0].title, "new title", "correct title");
+});
--- a/browser/components/sessionstore/test/head.js
+++ b/browser/components/sessionstore/test/head.js
@@ -523,11 +523,13 @@ const FORM_HELPERS = [
   "getFileNameArray", "setFileNameArray",
 ];
 
 for (let name of FORM_HELPERS) {
   let msg = "ss-test:" + name;
   this[name] = (browser, data) => sendMessage(browser, msg, data);
 }
 
+// Removes the given tab immediately and returns a promise that resolves when
+// all pending status updates (messages) of the closing tab have been received.
 function promiseRemoveTab(tab) {
   return BrowserTestUtils.removeTab(tab);
 }