Bug 1425358 - Wait for all tab titles to be displayed in Tabs.jsm before taking screenshots. r=MattN
authorJared Wein <jwein@mozilla.com>
Thu, 14 Dec 2017 16:59:46 -0600
changeset 396569 956979c14336ad83d3dcd530f931fe9184d73efd
parent 396568 ed12e55558f7c2cdd6c08d186c4fcc7b9aa72ec3
child 396570 f78151ce20f1627659e178d84387448510a38724
push id33098
push userncsoregi@mozilla.com
push dateSat, 16 Dec 2017 09:35:50 +0000
treeherdermozilla-central@c7b126878814 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1425358
milestone59.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 1425358 - Wait for all tab titles to be displayed in Tabs.jsm before taking screenshots. r=MattN MozReview-Commit-ID: G4gDBezgdEd
browser/tools/mozscreenshots/mozscreenshots/extension/configurations/Tabs.jsm
--- a/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/Tabs.jsm
+++ b/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/Tabs.jsm
@@ -5,35 +5,36 @@
 "use strict";
 
 this.EXPORTED_SYMBOLS = ["Tabs"];
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 const CUST_TAB = "chrome://browser/skin/customize.svg";
 const PREFS_TAB = "chrome://browser/skin/settings.svg";
-const DEFAULT_FAVICON_TAB = `data:text/html,<meta charset="utf-8">
-<title>No favicon</title>`;
+const DEFAULT_FAVICON_TAB = `data:text/html,<meta%20charset="utf-8"><title>No%20favicon</title>`;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/Timer.jsm");
+Cu.import("resource://testing-common/TestUtils.jsm");
 
 this.Tabs = {
   init(libDir) {},
 
   configurations: {
     fiveTabs: {
       selectors: ["#tabbrowser-tabs"],
       async applyConfig() {
         fiveTabsHelper();
         let browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
         hoverTab(browserWindow.gBrowser.tabs[3]);
         await new Promise((resolve, reject) => {
           setTimeout(resolve, 3000);
         });
+        await allTabTitlesDisplayed(browserWindow);
       },
     },
 
     fourPinned: {
       selectors: ["#tabbrowser-tabs"],
       async applyConfig() {
         fiveTabsHelper();
         let browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
@@ -48,19 +49,21 @@ this.Tabs = {
         browserWindow.gBrowser.selectTabAtIndex(5);
         hoverTab(browserWindow.gBrowser.tabs[2]);
         // also hover the new tab button
         let newTabButton = browserWindow.document.getAnonymousElementByAttribute(browserWindow.
                            gBrowser.tabContainer, "class", "tabs-newtab-button");
         hoverTab(newTabButton);
         browserWindow.gBrowser.tabs[browserWindow.gBrowser.tabs.length - 1].
                       setAttribute("beforehovered", true);
+
         await new Promise((resolve, reject) => {
           setTimeout(resolve, 3000);
         });
+        await allTabTitlesDisplayed(browserWindow);
       },
     },
 
     twoPinnedWithOverflow: {
       selectors: ["#tabbrowser-tabs"],
       async applyConfig() {
         fiveTabsHelper();
 
@@ -100,27 +103,57 @@ this.Tabs = {
            inBackground: true,
            replace: true,
            triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal()
         });
         browserWindow.gBrowser.pinTab(browserWindow.gBrowser.tabs[1]);
         browserWindow.gBrowser.pinTab(browserWindow.gBrowser.tabs[2]);
         browserWindow.gBrowser.selectTabAtIndex(3);
         hoverTab(browserWindow.gBrowser.tabs[5]);
+
         await new Promise((resolve, reject) => {
           setTimeout(resolve, 3000);
         });
+        await allTabTitlesDisplayed(browserWindow);
       },
     },
   },
 };
 
 
 /* helpers */
 
+async function allTabTitlesDisplayed(browserWindow) {
+  let specToTitleMap = {
+    "about:home": "New Tab",
+    "about:newtab": "New Tab",
+    "about:addons": "Add-ons Manager",
+  };
+  specToTitleMap[PREFS_TAB] = "browser/skin/settings.svg";
+  specToTitleMap[CUST_TAB] = "browser/skin/customize.svg";
+  specToTitleMap[DEFAULT_FAVICON_TAB] = "No favicon";
+
+  let tabTitlePromises = [];
+  for (let tab of browserWindow.gBrowser.tabs) {
+    function tabTitleLoaded(spec) {
+      return () => {
+        return spec ? tab.label == specToTitleMap[spec] : false;
+      };
+    }
+    let spec = tab.linkedBrowser &&
+               tab.linkedBrowser.documentURI &&
+               tab.linkedBrowser.documentURI.spec;
+    let promise =
+      TestUtils.waitForCondition(tabTitleLoaded(spec), `Tab (${spec}) should be showing "${specToTitleMap[spec]}". Got "${tab.label}"`);
+    tabTitlePromises.push(promise);
+  }
+
+  return Promise.all(tabTitlePromises);
+}
+
 function fiveTabsHelper() {
   // some with no favicon and some with. Selected tab in middle.
   closeAllButOneTab("about:addons");
 
   let browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
   browserWindow.gBrowser.loadTabs([
     "about:addons",
     "about:home",