Bug 1399443 - wait for font pickers to populate asynchronously in test-font-chooser.js. r=jorgk
authoraceman <acelists@atlas.sk>
Wed, 13 Sep 2017 23:42:53 +0200
changeset 29707 ca41eb0d202f0e9b58a89e866113fd6479d12f72
parent 29706 6f8f477a33c77f8742ab2e3a03c6c7119ab3103d
child 29708 95c5d61a2c34bc781256c1dd7c4e7573cfb5f86a
push id378
push userclokep@gmail.com
push dateMon, 13 Nov 2017 18:45:35 +0000
reviewersjorgk
bugs1399443
Bug 1399443 - wait for font pickers to populate asynchronously in test-font-chooser.js. r=jorgk
mail/test/mozmill/pref-window/test-font-chooser.js
--- a/mail/test/mozmill/pref-window/test-font-chooser.js
+++ b/mail/test/mozmill/pref-window/test-font-chooser.js
@@ -13,47 +13,43 @@
 var MODULE_NAME = "test-font-chooser";
 
 var RELATIVE_ROOT = "../shared-modules";
 var MODULE_REQUIRES = ["folder-display-helpers", "window-helpers",
                        "pref-window-helpers"];
 
 Components.utils.import("resource://gre/modules/Services.jsm");
 
-// We can't initialize them h because the global scope is read far too
-// early.
-var Cc, Ci;
-
 var gFontEnumerator;
 
 // We'll test with Western. Unicode has issues on Windows (bug 550443).
 var kLanguage = "x-western";
 
 // A list of fonts present on the computer for each font type.
 var gRealFontLists = {};
 
 // A list of font types to consider
 var kFontTypes = ["serif", "sans-serif", "monospace"];
 
 function setupModule(module) {
-  let fdh = collector.getModule("folder-display-helpers");
-  fdh.installInto(module);
-  let wh = collector.getModule("window-helpers");
-  wh.installInto(module);
-  let pwh = collector.getModule("pref-window-helpers");
-  pwh.installInto(module);
+  for (let lib of MODULE_REQUIRES) {
+    collector.getModule(lib).installInto(module);
+  }
 
-  Cc = Components.classes;
-  Ci = Components.interfaces;
+  let finished = false;
+  buildFontList().then(() => finished = true, Cu.reportError);
+  mc.waitFor(() => finished, "Timeout waiting for font enumeration to complete.");
+}
 
-  gFontEnumerator = Cc["@mozilla.org/gfx/fontenumerator;1"]
-                      .createInstance(Ci.nsIFontEnumerator);
+async function buildFontList() {
+  gFontEnumerator = Components.classes["@mozilla.org/gfx/fontenumerator;1"]
+                      .createInstance(Components.interfaces.nsIFontEnumerator);
   for (let fontType of kFontTypes) {
     gRealFontLists[fontType] =
-      gFontEnumerator.EnumerateFonts(kLanguage, fontType, {});
+      await gFontEnumerator.EnumerateFontsAsync(kLanguage, fontType);
     if (gRealFontLists[fontType].length == 0)
       throw new Error("No fonts found for language " + kLanguage +
                       " and font type " + fontType + ".");
   }
 }
 
 function assert_fonts_equal(aDescription, aExpected, aActual) {
   if (aExpected != aActual)
@@ -77,16 +73,21 @@ function _verify_fonts_displayed(aSerif,
     assert_fonts_equal("display pane", displayPaneExpected, displayPaneActual);
   }
 
   // Bring up the preferences window.
   open_pref_window("paneDisplay", verify_display_pane);
 
   // Now verify the advanced dialog.
   function verify_advanced(fontc) {
+    // The font pickers are populated async so we need to wait for it.
+    for (let fontElemId of ["serif", "sans-serif", "monospace"]) {
+      fontc.waitFor(() => fontc.e(fontElemId).value != "",
+                    "Timeout waiting for font picker " + fontElemId + " to populate.");
+    }
     assert_fonts_equal("serif", aSerif, fontc.e("serif").value);
     assert_fonts_equal("sans-serif", aSansSerif, fontc.e("sans-serif").value);
     assert_fonts_equal("monospace", aMonospace, fontc.e("monospace").value);
   }
 
   // Now open the advanced dialog.
   plan_for_modal_dialog("FontsDialog", verify_advanced);
   // XXX This would have been better done from within the prefs dialog, but
@@ -113,17 +114,17 @@ function test_font_name_displayed() {
     // name for each font.
     let standardFamily = gFontEnumerator.getStandardFamilyName(fontList[0]);
     Services.prefs.setCharPref("font.name." + fontType + "." + kLanguage,
                                standardFamily);
     expected[fontType] = standardFamily;
   }
 
   let fontTypes = kFontTypes.map(fontType => expected[fontType]);
-  _verify_fonts_displayed.apply(null, fontTypes);
+  _verify_fonts_displayed(...fontTypes);
 }
 
 // Fonts definitely not present on a computer -- we simply use UUIDs. These
 // should be kept in sync with the ones in *-prefs.js.
 var kFakeFonts = {
   "serif": "bc7e8c62-0634-467f-a029-fe6abcdf1582",
   "sans-serif": "419129aa-43b7-40c4-b554-83d99b504b89",
   "monospace": "348df6e5-e874-4d21-ad4b-359b530a33b7",
@@ -160,10 +161,10 @@ function test_font_name_not_present() {
     expected[fontType] = fonts[1];
 
     // Set font.name to be the fake font. font.name-list is handled by
     // wrapper.py.
     Services.prefs.setCharPref("font.name." + fontType + "." + kLanguage, fakeFont);
   }
 
   let fontTypes = kFontTypes.map(fontType => expected[fontType]);
-  _verify_fonts_displayed.apply(null, fontTypes);
+  _verify_fonts_displayed(...fontTypes);
 }