Bug 1144977 - Part 2: Tests. r=jdaggett

This commit is contained in:
Cameron McCormack 2015-03-27 21:05:22 +11:00
parent 286cfffcba
commit 2d72d42a60

View File

@ -927,6 +927,176 @@ function runTest() {
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