Bug 1425358 - Wait for all tab titles to be displayed in Tabs.jsm before taking screenshots. r?mattn draft
authorJared Wein <jwein@mozilla.com>
Thu, 14 Dec 2017 16:59:46 -0600
changeset 712214 d9d49d5cd925b49a9f4dd34b1ca9bed784b3c445
parent 709018 e30c06a1074c2455f47e0bafb9bb84ec1a09d682
child 743998 db8cdb1ba1e987b02ac0cbe4f926b0e241772171
push id93275
push userbmo:jaws@mozilla.com
push dateFri, 15 Dec 2017 20:16:18 +0000
reviewersmattn
bugs1425358
milestone59.0a1
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",