Bug 1366870 - Part 1: Add test for about: pages' initial tab titles. r=dao, a=jcristau
authorChris Peterson <cpeterson@mozilla.com>
Mon, 29 May 2017 14:58:57 -0700
changeset 413967 b0b8389788b67f223cb92b11092edc0a31e6bca5
parent 413966 ca6fb91beb0dd5ba95a5619c4fb6ea8737a1bc78
child 413968 ea9a39406ec791128dfbbd54b5ecd8762ac21b7f
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao, jcristau
bugs1366870, 1364127, 1371896
milestone55.0
Bug 1366870 - Part 1: Add test for about: pages' initial tab titles. r=dao, a=jcristau This test case documents the current behavior of about: pages's initial tab titles. 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. This test case uses the about:robots page because its title is not localized, which makes testing easier. MozReview-Commit-ID: JGaRciaZUEC
browser/components/sessionstore/test/browser_tab_label_during_restore.js
--- a/browser/components/sessionstore/test/browser_tab_label_during_restore.js
+++ b/browser/components/sessionstore/test/browser_tab_label_during_restore.js
@@ -1,24 +1,29 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
+"use strict";
+
 /**
  * Test that we don't do unnecessary tab label changes while restoring a tab.
  */
 
 add_task(async function() {
   await SpecialPowers.pushPrefEnv({
     "set": [
       ["browser.sessionstore.restore_on_demand", true],
       ["browser.sessionstore.restore_tabs_lazily", true],
     ]
   });
+
   const BACKUP_STATE = SessionStore.getBrowserState();
   const TEST_URL = "http://example.com/";
+  const ABOUT_ROBOTS_URI = "about:robots";
+  const ABOUT_ROBOTS_TITLE = "Gort! Klaatu barada nikto!";
 
   function observeLabelChanges(tab) {
     info("observing tab label changes. initial label: " + tab.label);
     let labelChangeCount = 0;
     function TabAttrModifiedListener(event) {
       if (event.detail.changed.some(attr => { return attr == "label" })) {
         info("tab label change: " + tab.label);
         labelChangeCount++;
@@ -32,58 +37,78 @@ add_task(async function() {
   }
 
   info("setting test browser state");
   let browserLoadedPromise = BrowserTestUtils.firstBrowserLoaded(window, false);
   await promiseBrowserState({
     windows: [{
       tabs: [
         { entries: [{ url: TEST_URL }] },
+        { entries: [{ url: ABOUT_ROBOTS_URI }] },
         { entries: [{ url: TEST_URL }] },
       ]
     }]
   });
-  let [firstTab, secondTab] = gBrowser.tabs;
+  let [firstTab, secondTab, thirdTab] = gBrowser.tabs;
   is(gBrowser.selectedTab, firstTab, "first tab is selected");
 
   await browserLoadedPromise;
   const CONTENT_TITLE = firstTab.linkedBrowser.contentTitle;
   is(firstTab.linkedBrowser.currentURI.spec, TEST_URL, "correct URL loaded in first tab");
   is(typeof CONTENT_TITLE, "string", "content title is a string");
   isnot(CONTENT_TITLE.length, 0, "content title isn't empty");
   isnot(CONTENT_TITLE, TEST_URL, "content title is different from the URL");
   is(firstTab.label, CONTENT_TITLE, "first tab displays content title");
   ok(document.title.startsWith(CONTENT_TITLE), "title bar displays content title");
   ok(secondTab.hasAttribute("pending"), "second tab is pending");
-  is(secondTab.label, TEST_URL, "second tab displays URL as its title");
+  // 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.
+  is(secondTab.label, ABOUT_ROBOTS_URI, "second tab displays URI as its initial title");
+  ok(thirdTab.hasAttribute("pending"), "third tab is pending");
+  is(thirdTab.label, TEST_URL, "third tab displays URI as its initial title");
 
   info("selecting the second tab");
   let checkLabelChangeCount = observeLabelChanges(secondTab);
-  browserLoadedPromise = BrowserTestUtils.browserLoaded(secondTab.linkedBrowser, false, TEST_URL);
+  browserLoadedPromise = BrowserTestUtils.browserLoaded(secondTab.linkedBrowser, false, ABOUT_ROBOTS_URI);
   gBrowser.selectedTab = secondTab;
   await browserLoadedPromise;
   ok(!secondTab.hasAttribute("pending"), "second tab isn't pending anymore");
-  is(secondTab.label, CONTENT_TITLE, "second tab displays content title");
+  is(secondTab.label, ABOUT_ROBOTS_TITLE, "second tab displays content title");
+  ok(document.title.startsWith(ABOUT_ROBOTS_TITLE), "title bar displays content title");
+  checkLabelChangeCount(1); // ABOUT_ROBOTS_URI -> ABOUT_ROBOTS_TITLE
+
+  info("selecting the third tab");
+  checkLabelChangeCount = observeLabelChanges(thirdTab);
+  browserLoadedPromise = BrowserTestUtils.browserLoaded(thirdTab.linkedBrowser, false, TEST_URL);
+  gBrowser.selectedTab = thirdTab;
+  await browserLoadedPromise;
+  ok(!thirdTab.hasAttribute("pending"), "third tab isn't pending anymore");
+  is(thirdTab.label, CONTENT_TITLE, "third tab displays content title");
   ok(document.title.startsWith(CONTENT_TITLE), "title bar displays content title");
-  checkLabelChangeCount(1);
+  checkLabelChangeCount(1); // TEST_URL -> CONTENT_TITLE
 
   info("restoring the modified browser state");
   await TabStateFlusher.flushWindow(window);
   await promiseBrowserState(SessionStore.getBrowserState());
-  [firstTab, secondTab] = gBrowser.tabs;
-  is(secondTab, gBrowser.selectedTab, "second tab is selected after restoring");
+  [firstTab, secondTab, thirdTab] = gBrowser.tabs;
+  is(thirdTab, gBrowser.selectedTab, "third tab is selected after restoring");
   ok(document.title.startsWith(CONTENT_TITLE), "title bar displays content title");
   ok(firstTab.hasAttribute("pending"), "first tab is pending after restoring");
   is(firstTab.label, CONTENT_TITLE, "first tab displays content title in pending state");
+  ok(secondTab.hasAttribute("pending"), "second tab is pending after restoring");
+  is(secondTab.label, ABOUT_ROBOTS_TITLE, "second tab displays content title");
+  ok(!thirdTab.hasAttribute("pending"), "third tab is not pending after restoring");
+  is(thirdTab.label, CONTENT_TITLE, "third tab displays content title in pending state");
 
   info("selecting the first tab");
   checkLabelChangeCount = observeLabelChanges(firstTab);
   let tabContentRestored = TestUtils.topicObserved("sessionstore-debug-tab-restored");
   gBrowser.selectedTab = firstTab;
   ok(document.title.startsWith(CONTENT_TITLE), "title bar displays content title");
   await tabContentRestored;
   ok(!firstTab.hasAttribute("pending"), "first tab isn't pending anymore");
   checkLabelChangeCount(0);
   is(firstTab.label, CONTENT_TITLE, "first tab displays content title after restoring content");
 
   await promiseBrowserState(BACKUP_STATE);
 });
-