Bug 1144977 - Part 2: Tests. r=jdaggett
authorCameron McCormack <cam@mcc.id.au>
Fri, 27 Mar 2015 21:05:22 +1100
changeset 264943 7a7b97047c76a98b40049fcd8280809da2820521
parent 264942 cfe959cdfb212d2e0e890cf1bdfe8d391a583fc4
child 264944 447a722809972ac41d5465ffdfcbb6584076fdc2
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
bugs1144977
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 1144977 - Part 2: Tests. 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
@@ -924,16 +924,186 @@ function runTest() {
         ok(!gotLoadingError, "loadingerror event should not be dispatched (TEST 36)");
         document.fonts.onloadingdone = null;
         document.fonts.onloadingerror = null;
         document.fonts.clear();
       });
 
   }).then(function() {
 
+    // (TEST 37) Test that a FontFace only has one loadingdone event dispatched
+    // at the FontFaceSet containing it.
+
+    var events = [], face, face2;
+
+    document.fonts.onloadingdone = function(e) {
+      events.push(e);
+    };
+    document.fonts.onloadingerror = function(e) {
+      events.push(e);
+    };
+
+    is(document.fonts.status, "loaded", "document.fonts.status should have status \"loaded\" (TEST 37)");
+
+    face = new FontFace("test", "url(BitPattern.woff)");
+    face.load();
+    document.fonts.add(face);
+    is(document.fonts.status, "loading", "document.fonts.status should have status \"loading\" after first font added (TEST 37)");
+
+    return face.loaded
+      .then(function() {
+        is(document.fonts.status, "loaded", "document.fonts.status should have status \"loaded\" after first font loaded (TEST 37)");
+        is(face.status, "loaded", "first FontFace should have status \"loaded\" (TEST 37)");
+
+        face2 = new FontFace("test2", "url(BitPattern.woff)");
+        face2.load();
+        document.fonts.add(face2);
+        is(document.fonts.status, "loading", "document.fonts.status should have status \"loading\" after second font added (TEST 37)");
+
+        return face2.loaded;
+      }).then(function() {
+        is(document.fonts.status, "loaded", "document.fonts.status should have status \"loaded\" after second font loaded (TEST 37)");
+        is(face2.status, "loaded", "second FontFace should have status \"loaded\" (TEST 37)");
+
+        is(events.length, 2, "should receive two events (TEST 37)");
+
+        is(events[0].type, "loadingdone", "first event should be \"loadingdone\" (TEST 37)");
+        is(events[0].fontfaces.length, 1, "first event should have 1 FontFace (TEST 37)");
+        is(events[0].fontfaces[0], face, "first event should have the first FontFace");
+
+        is(events[1].type, "loadingdone", "second event should be \"loadingdone\" (TEST 37)");
+        is(events[1].fontfaces.length, 1, "second event should only have 1 FontFace (TEST 37)");
+        is(events[1].fontfaces[0], face2, "second event should have the second FontFace (TEST 37)");
+
+        document.fonts.onloadingdone = null;
+        document.fonts.onloadingerror = null;
+        document.fonts.clear();
+        return document.fonts.ready;
+      });
+
+  }).then(function() {
+
+    // (TEST 38) Test that a FontFace only has one loadingerror event dispatched
+    // at the FontFaceSet containing it.
+
+    var events = [], face, face2;
+
+    document.fonts.onloadingdone = function(e) {
+      events.push(e);
+    };
+    document.fonts.onloadingerror = function(e) {
+      events.push(e);
+    };
+
+    is(document.fonts.status, "loaded", "document.fonts.status should have status \"loaded\" (TEST 38)");
+
+    face = new FontFace("test", "url(x)");
+    face.load();
+    document.fonts.add(face);
+    is(document.fonts.status, "loading", "document.fonts.status should have status \"loading\" after first font added (TEST 38)");
+
+    return face.loaded
+      .then(function() {
+        ok(false, "first FontFace should not load (TEST 38)");
+      }, function() {
+        is(document.fonts.status, "loaded", "document.fonts.status should have status \"loaded\" after first font failed to load (TEST 38)");
+        is(face.status, "error", "first FontFace should have status \"error\" (TEST 38)");
+
+        face2 = new FontFace("test2", "url(x)");
+        face2.load();
+        document.fonts.add(face2);
+        is(document.fonts.status, "loading", "document.fonts.status should have status \"loading\" after second font added (TEST 38)");
+
+        return face2.loaded;
+      }).then(function() {
+        ok(false, "second FontFace should not load (TEST 38)");
+      }, function() {
+        is(document.fonts.status, "loaded", "document.fonts.status should have status \"loaded\" after second font failed to load (TEST 38)");
+        is(face2.status, "error", "second FontFace should have status \"error\" (TEST 38)");
+
+        is(events.length, 4, "should receive four events (TEST 38)");
+
+        is(events[0].type, "loadingdone", "first event should be \"loadingdone\" (TEST 38)");
+        is(events[0].fontfaces.length, 0, "first event should have no FontFaces (TEST 38)");
+
+        is(events[1].type, "loadingerror", "second event should be \"loadingerror\" (TEST 38)");
+        is(events[1].fontfaces.length, 1, "second event should have 1 FontFace (TEST 38)");
+        is(events[1].fontfaces[0], face, "second event should have the first FontFace");
+
+        is(events[2].type, "loadingdone", "third event should be \"loadingdone\" (TEST 38)");
+        is(events[2].fontfaces.length, 0, "third event should have no FontFaces (TEST 38)");
+
+        is(events[3].type, "loadingerror", "third event should be \"loadingerror\" (TEST 38)");
+        is(events[3].fontfaces.length, 1, "third event should only have 1 FontFace (TEST 38)");
+        is(events[3].fontfaces[0], face2, "third event should have the second FontFace");
+
+        document.fonts.onloadingdone = null;
+        document.fonts.onloadingerror = null;
+        document.fonts.clear();
+        return document.fonts.ready;
+      });
+
+  }).then(function() {
+
+    // (TEST 39) Test that a FontFace for an @font-face rule only has one
+    // loadingdone event dispatched at the FontFaceSet containing it.
+
+    var style = document.querySelector("style");
+    var ruleText = "@font-face { font-family: test; src: url(BitPattern.woff); } " +
+                   "@font-face { font-family: test2; src: url(BitPattern.woff?2); }";
+
+    style.textContent = ruleText;
+
+    var all = Array.from(document.fonts);
+    var events = [];
+
+    document.fonts.onloadingdone = function(e) {
+      events.push(e);
+    };
+    document.fonts.onloadingerror = function(e) {
+      events.push(e);
+    };
+
+    is(document.fonts.status, "loaded", "document.fonts.status should have status \"loaded\" (TEST 39)");
+
+    all[0].load();
+    is(document.fonts.status, "loading", "document.fonts.status should have status \"loading\" after first font loading (TEST 39)");
+
+    return document.fonts.ready
+      .then(function() {
+        is(document.fonts.status, "loaded", "document.fonts.status should have status \"loaded\" after first font loaded (TEST 39)");
+        is(all[0].status, "loaded", "first FontFace should have status \"loaded\" (TEST 39)");
+        is(all[1].status, "unloaded", "second FontFace should have status \"unloaded\" (TEST 39)");
+
+        all[1].load();
+        is(document.fonts.status, "loading", "document.fonts.status should have status \"loading\" after second font loading (TEST 39)");
+
+        return document.fonts.ready;
+      }).then(function() {
+        is(document.fonts.status, "loaded", "document.fonts.status should have status \"loaded\" after second font loaded (TEST 39)");
+        is(all[1].status, "loaded", "second FontFace should have status \"loaded\" (TEST 39)");
+
+        is(events.length, 2, "should receive two events (TEST 39)");
+
+        is(events[0].type, "loadingdone", "first event should be \"loadingdone\" (TEST 39)");
+        is(events[0].fontfaces.length, 1, "first event should have 1 FontFace (TEST 39)");
+        is(events[0].fontfaces[0], all[0], "first event should have the first FontFace");
+
+        is(events[1].type, "loadingdone", "second event should be \"loadingdone\" (TEST 39)");
+        is(events[1].fontfaces.length, 1, "second event should only have 1 FontFace (TEST 39)");
+        is(events[1].fontfaces[0], all[1], "second event should have the second FontFace (TEST 39)");
+
+        document.fonts.onloadingdone = null;
+        document.fonts.onloadingerror = null;
+        document.fonts.clear();
+        return document.fonts.ready;
+      });
+
+  }).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);