Bug 1425358 - Wait for all tab titles to be displayed in Tabs.jsm before taking screenshots. r=MattN
☠☠ backed out by 8643a82e172d ☠ ☠
authorJared Wein <jwein@mozilla.com>
Thu, 14 Dec 2017 16:59:46 -0600
changeset 396557 fd98493f58fa4c5c9d55558c0d623fbc2ac9f3e6
parent 396556 a8c870edc43dc60f36b4b7cab9dd5cb52e824341
child 396558 eb72a70b524f7434a307df720019efa7442a6554
push id57043
push usermozilla@noorenberghe.ca
push dateFri, 15 Dec 2017 17:12:20 +0000
treeherderautoland@fd98493f58fa [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
@@ -10,30 +10,32 @@ const {classes: Cc, interfaces: Ci, util
 
 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>`;
 
 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 Promise.all(allTabTitlesDisplayed(browserWindow));
       },
     },
 
     fourPinned: {
       selectors: ["#tabbrowser-tabs"],
       async applyConfig() {
         fiveTabsHelper();
         let browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
@@ -48,19 +50,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 Promise.all(allTabTitlesDisplayed(browserWindow));
       },
     },
 
     twoPinnedWithOverflow: {
       selectors: ["#tabbrowser-tabs"],
       async applyConfig() {
         fiveTabsHelper();
 
@@ -100,27 +104,55 @@ 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 Promise.all(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) {
+    let tabTitleLoaded = () => {
+      let spec = tab.linkedBrowser &&
+                 tab.linkedBrowser.documentURI &&
+                 tab.linkedBrowser.documentURI.spec;
+      return spec ? tab.label == specToTitleMap[spec] : false;
+    };
+    let promise =
+      TestUtils.waitForCondition(tabTitleLoaded, `Tab should be showing ${tab.label}`);
+    tabTitlePromises.push(promise);
+  }
+
+  return 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",