Bug 1144450 - Part 5: Fix/add tests for not firing loadingdone/loadingerror when adding an already-loaded/error FontFace to a FontFaceSet. r=jdaggett
authorCameron McCormack <cam@mcc.id.au>
Tue, 24 Mar 2015 19:34:32 +1100
changeset 264092 6a83dc07c6c85c23ff81271dfdd620307163f0b9
parent 264091 fabd2ae326921bddf114f4f5f025b43525128c44
child 264093 0d377a96684ffe46395284f7bd470dc83c0c8bae
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdaggett
bugs1144450
milestone39.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 1144450 - Part 5: Fix/add tests for not firing loadingdone/loadingerror when adding an already-loaded/error FontFace to a FontFaceSet. r=jdaggett
layout/style/test/test_font_loading_api.html
--- a/layout/style/test/test_font_loading_api.html
+++ b/layout/style/test/test_font_loading_api.html
@@ -610,17 +610,18 @@ function runTest() {
         .then(function() {
           document.fonts.clear();
           return document.fonts.ready;
         });
 
   }).then(function() {
 
     // (TEST 29) Test that a loadingdone and a loadingerror event is dispatched
-    // when a FontFace with status "error" is added to the FontFaceSet.
+    // when a FontFace that eventually becomes status "error" is added to the
+    // FontFaceSet.
     var face;
     var awaitEvents = new Promise(function(aResolve, aReject) {
 
       var onloadingdoneTriggered = false, loadingdoneDispatched = false;
       var onloadingerrorTriggered = false, loadingerrorDispatched = false;
 
       function check() {
         if (onloadingdoneTriggered && loadingdoneDispatched &&
@@ -652,35 +653,37 @@ function runTest() {
       }
       document.fonts.addEventListener("loadingerror", errorListener);
       document.fonts.onloadingerror = function(aEvent) {
         onloadingerrorTriggered = true;
         check();
       };
     });
 
-    face = new FontFace("test", new ArrayBuffer(0));
+    face = new FontFace("test", "url(x)");
+    face.load();
+    is(face.status, "loading", "FontFace should have status \"loading\" (TEST 29)");
+    document.fonts.add(face);
 
     return face.loaded
       .then(function() {
         ok(false, "the FontFace should not load (TEST 29)");
       }, function(aError) {
         is(face.status, "error", "FontFace should have status \"error\" (TEST 29)");
-        document.fonts.add(face);
         return awaitEvents;
       })
       .then(function() {
         document.fonts.clear();
         return document.fonts.ready;
       });
 
   }).then(function() {
 
     // (TEST 30) Test that a loadingdone event is dispatched when a FontFace
-    // with status "loaded" is added to the FontFaceSet.
+    // that eventually becomes status "loaded" is added to the FontFaceSet.
     var face;
     var awaitEvents = new Promise(function(aResolve, aReject) {
 
       var onloadingdoneTriggered = false, loadingdoneDispatched = false;
 
       function check() {
         if (onloadingdoneTriggered && loadingdoneDispatched) {
           document.fonts.onloadingdone = null;
@@ -696,22 +699,24 @@ function runTest() {
       document.fonts.addEventListener("loadingdone", doneListener);
       document.fonts.onloadingdone = function(aEvent) {
         is(aEvent.fontfaces[0], face, "the CSSFontFaceLoadEvent should have a fontfaces array with the FontFace in it (TEST 30)");
         onloadingdoneTriggered = true;
         check();
       };
     });
 
-    face = new FontFace("test", fontData);
+    face = new FontFace("test", "url(BitPattern.woff)");
+    face.load();
+    is(face.status, "loading", "FontFace should have status \"loading\" (TEST 30)");
+    document.fonts.add(face);
 
     return face.loaded
       .then(function() {
         is(face.status, "loaded", "FontFace should have status \"loaded\" (TEST 30)");
-        document.fonts.add(face);
         return awaitEvents;
       })
       .then(function() {
         document.fonts.clear();
       });
 
   }).then(function() {
 
@@ -739,24 +744,25 @@ function runTest() {
       document.fonts.onloadingdone = function(aEvent) {
         is(aEvent.fontfaces[0], face, "the CSSFontFaceLoadEvent should have a fontfaces array with the FontFace in it (TEST 31)");
         onloadingdoneTriggered = true;
         check();
       };
     });
 
     face = new FontFace("test", "url(BitPattern.woff)");
+    is(face.status, "unloaded", "FontFace should have status \"unloaded\" (TEST 31)");
+    document.fonts.add(face);
 
     return face.load()
         .then(function() {
-          is(face.status, "loaded", "FontFace should have status \"loaded\" (TEST 31)");
-          document.fonts.add(face);
           return awaitEvents;
         })
         .then(function() {
+          is(face.status, "loaded", "FontFace should have status \"loaded\" (TEST 31)");
           document.fonts.clear();
           return document.fonts.ready;
         });
 
   }).then(function() {
 
     // (TEST 32) Test that pending restyles prevent document.fonts.status
     // from becoming loaded.
@@ -860,16 +866,73 @@ function runTest() {
     Object.keys(defaultValues).forEach(function(aDesc) {
       is(face[aDesc], defaultValues[aDesc], "FontFace should return default value for " + aDesc + " (TEST 34)");
     });
 
     style.textContent = "";
 
   }).then(function() {
 
+    // (TEST 35) Test that no loadingdone event is dispatched when a FontFace
+    // with "loaded" status is added to a "loaded" FontFaceSet.
+    var gotLoadingDone = false;
+    document.fonts.onloadingdone = function(aEvent) {
+      gotLoadingDone = true;
+    };
+
+    is(document.fonts.status, "loaded", "document.fonts.status should have status \"loaded\" (TEST 35)");
+    var face = new FontFace("test", fontData);
+
+    return face.loaded
+      .then(function() {
+        is(face.status, "loaded", "FontFace should have status \"loaded\" (TEST 35)");
+        document.fonts.add(face);
+        is(document.fonts.status, "loaded", "document.fonts.status should still have status \"loaded\" (TEST 35)");
+        return document.fonts.ready;
+      })
+      .then(function() {
+        ok(!gotLoadingDone, "loadingdone event should not be dispatched (TEST 35)");
+        document.fonts.onloadingdone = null;
+        document.fonts.clear();
+      });
+
+  }).then(function() {
+
+    // (TEST 36) Test that no loadingdone or loadingerror event is dispatched
+    // when a FontFace with "error" status is added to a "loaded" FontFaceSet.
+    var gotLoadingDone = false, gotLoadingError = false;
+    document.fonts.onloadingdone = function(aEvent) {
+      gotLoadingDone = true;
+    };
+    document.fonts.onloadingerror = function(aEvent) {
+      gotLoadingError = true;
+    };
+
+    is(document.fonts.status, "loaded", "document.fonts.status should have status \"loaded\" (TEST 36)");
+    var face = new FontFace("test", new ArrayBuffer(0));
+
+    return face.loaded
+      .then(function() {
+        ok(false, "FontFace should not have loaded (TEST 36)");
+      }, function() {
+        is(face.status, "error", "FontFace should have status \"error\" (TEST 36)");
+        document.fonts.add(face);
+        is(document.fonts.status, "loaded", "document.fonts.status should still have status \"loaded\" (TEST 36)");
+        return document.fonts.ready;
+      })
+      .then(function() {
+        ok(!gotLoadingDone, "loadingdone event should not be dispatched (TEST 36)");
+        ok(!gotLoadingError, "loadingerror event should not be dispatched (TEST 36)");
+        document.fonts.onloadingdone = null;
+        document.fonts.onloadingerror = null;
+        document.fonts.clear();
+      });
+
+  }).then(function() {
+
     // (TEST LAST) Test that a pending style sheet load prevents
     // document.fonts.status from being set to "loaded".
 
     // First, add a FontFace to document.fonts that will load soon.
     var face = new FontFace("test", "url(BitPattern.woff)");
     face.load();
     document.fonts.add(face);