Bug 1460423 - "New Tab" tab label is empty after restore previous session if restoring about:blank or new tabs set to "Blank Page" r=mikedeboer
authorEd Lee <edilee@mozilla.com>
Wed, 17 Oct 2018 11:16:38 +0000
changeset 500184 b2156ede19a58ae592cb36dece61f66e691bf54f
parent 500183 79444293ad73024fec1b8363de9a304737f5c098
child 500185 bbff80c1200f8031eb67e785a87f79dc5c71c2b9
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1460423
milestone64.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 1460423 - "New Tab" tab label is empty after restore previous session if restoring about:blank or new tabs set to "Blank Page" r=mikedeboer Differential Revision: https://phabricator.services.mozilla.com/D8750
browser/base/content/tabbrowser.js
browser/components/sessionstore/SessionStore.jsm
browser/components/sessionstore/test/browser_tab_label_during_restore.js
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -1200,17 +1200,22 @@ window._gBrowser = {
     let state = Object.assign({}, aTab._sharingState);
     return {
       camera: !!state.camera,
       microphone: !!state.microphone,
       screen: state.screen && state.screen.replace("Paused", ""),
     };
   },
 
-  setInitialTabTitle(aTab, aTitle, aOptions) {
+  setInitialTabTitle(aTab, aTitle, aOptions = {}) {
+    // Convert some non-content title (actually a url) to human readable title
+    if (!aOptions.isContentTitle && isBlankPageURL(aTitle)) {
+      aTitle = this.tabContainer.emptyTabTitle;
+    }
+
     if (aTitle) {
       if (!aTab.getAttribute("label")) {
         aTab._labelIsInitialTitle = true;
       }
 
       this._setTabLabel(aTab, aTitle, aOptions);
     }
   },
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -2762,17 +2762,17 @@ var SessionStoreInternal = {
 
     let activePageData = tabData.entries[tabData.index - 1] || null;
 
     // If the page has a title, set it.
     if (activePageData) {
       if (activePageData.title &&
           activePageData.title != activePageData.url) {
         win.gBrowser.setInitialTabTitle(tab, activePageData.title, { isContentTitle: true });
-      } else if (activePageData.url != "about:blank") {
+      } else {
         win.gBrowser.setInitialTabTitle(tab, activePageData.url);
       }
     }
 
     // Restore the tab icon.
     if ("image" in tabData) {
       win.gBrowser.setIcon(tab, tabData.image, undefined, tabData.iconLoadingPrincipal);
       TabStateCache.update(browser, { image: null, iconLoadingPrincipal: null });
--- a/browser/components/sessionstore/test/browser_tab_label_during_restore.js
+++ b/browser/components/sessionstore/test/browser_tab_label_during_restore.js
@@ -15,16 +15,17 @@ add_task(async function() {
     ],
   });
 
   const BACKUP_STATE = SessionStore.getBrowserState();
   const REMOTE_URL = "http://www.example.com/";
   const ABOUT_ROBOTS_URI = "about:robots";
   const ABOUT_ROBOTS_TITLE = "Gort! Klaatu barada nikto!";
   const NO_TITLE_URL = "data:text/plain,foo";
+  const EMPTY_TAB_TITLE = gBrowser.tabContainer.emptyTabTitle;
 
   function observeLabelChanges(tab, expectedLabels) {
     let seenLabels = [tab.label];
     function TabAttrModifiedListener(event) {
       if (event.detail.changed.some(attr => attr == "label")) {
         seenLabels.push(tab.label);
       }
     }
@@ -39,33 +40,35 @@ add_task(async function() {
   let browserLoadedPromise = BrowserTestUtils.firstBrowserLoaded(window, false);
   await promiseBrowserState({
     windows: [{
       tabs: [
         { entries: [{ url: REMOTE_URL, triggeringPrincipal_base64 }] },
         { entries: [{ url: ABOUT_ROBOTS_URI, triggeringPrincipal_base64 }] },
         { entries: [{ url: REMOTE_URL, triggeringPrincipal_base64 }] },
         { entries: [{ url: NO_TITLE_URL, triggeringPrincipal_base64 }] },
+        { entries: [{ url: "about:blank", triggeringPrincipal_base64 }] },
       ],
     }],
   });
-  let [tab1, tab2, tab3, tab4] = gBrowser.tabs;
+  let [tab1, tab2, tab3, tab4, tab5] = gBrowser.tabs;
   is(gBrowser.selectedTab, tab1, "first tab is selected");
 
   await browserLoadedPromise;
   const REMOTE_TITLE = tab1.linkedBrowser.contentTitle;
   is(tab1.linkedBrowser.currentURI.spec, REMOTE_URL, "correct URL loaded in first tab");
   is(typeof REMOTE_TITLE, "string", "content title is a string");
   isnot(REMOTE_TITLE.length, 0, "content title isn't empty");
   isnot(REMOTE_TITLE, REMOTE_URL, "content title is different from the URL");
   is(tab1.label, REMOTE_TITLE, "first tab displays content title");
   ok(document.title.startsWith(REMOTE_TITLE), "title bar displays content title");
   ok(tab2.hasAttribute("pending"), "second tab is pending");
   ok(tab3.hasAttribute("pending"), "third tab is pending");
   ok(tab4.hasAttribute("pending"), "fourth tab is pending");
+  is(tab5.label, EMPTY_TAB_TITLE, "fifth tab dislpays empty tab title");
 
   info("selecting the second tab");
   // The fix for bug 1364127 caused about: pages' initial tab titles to show
   // their about: URIs until their actual page titles are known, e.g.
   // "about:addons" -> "Add-ons Manager". This is bug 1371896. Previously,
   // about: pages' initial tab titles were blank until the page title was known.
   let finishObservingLabelChanges = observeLabelChanges(tab2, [ABOUT_ROBOTS_URI, ABOUT_ROBOTS_TITLE]);
   browserLoadedPromise = BrowserTestUtils.browserLoaded(tab2.linkedBrowser, false, ABOUT_ROBOTS_URI);
@@ -93,26 +96,27 @@ add_task(async function() {
   is(document.title, document.getElementById("bundle_brand").getString("brandFullName"),
      "title bar doesn't display content title since page doesn't have one");
   finishObservingLabelChanges();
 
   info("restoring the modified browser state");
   gBrowser.selectedTab = tab3;
   await TabStateFlusher.flushWindow(window);
   await promiseBrowserState(SessionStore.getBrowserState());
-  [tab1, tab2, tab3, tab4] = gBrowser.tabs;
+  [tab1, tab2, tab3, tab4, tab5] = gBrowser.tabs;
   is(tab3, gBrowser.selectedTab, "third tab is selected after restoring");
   ok(document.title.startsWith(REMOTE_TITLE), "title bar displays content title");
   ok(tab1.hasAttribute("pending"), "first tab is pending after restoring");
   ok(tab2.hasAttribute("pending"), "second tab is pending after restoring");
   is(tab2.label, ABOUT_ROBOTS_TITLE, "second tab displays content title");
   ok(!tab3.hasAttribute("pending"), "third tab is not pending after restoring");
   is(tab3.label, REMOTE_TITLE, "third tab displays content title in pending state");
   ok(tab4.hasAttribute("pending"), "fourth tab is pending after restoring");
   is(tab4.label, NO_TITLE_URL, "fourth tab displays URL");
+  is(tab5.label, EMPTY_TAB_TITLE, "fifth tab still displays empty tab title");
 
   info("selecting the first tab");
   finishObservingLabelChanges = observeLabelChanges(tab1, [REMOTE_TITLE]);
   let tabContentRestored = TestUtils.topicObserved("sessionstore-debug-tab-restored");
   gBrowser.selectedTab = tab1;
   ok(document.title.startsWith(REMOTE_TITLE), "title bar displays content title");
   await tabContentRestored;
   ok(!tab1.hasAttribute("pending"), "first tab isn't pending anymore");