/* localfont versions include a bogus local ref followed by a valid url */
markAlocalfirst: "local(bogus-markA), url(" + kBaseFontURL + "markA.woff" + ")",
markBlocalfirst: "local(bogus-markB), url(" + kBaseFontURL + "markB.woff" + ")",
markClocalfirst: "local(bogus-markC), url(" + kBaseFontURL + "markC.woff" + ")",
markDlocalfirst: "local(bogus-markD), url(" + kBaseFontURL + "markD.woff" + ")",
};
function familyName(name, i) {
return "test" + i + "-" + name;
}
function fontFaceRule(name, fontdata, ft) { var desc = [];
desc.push("font-family: " + name); var srckey = fontdata.src + ft;
desc.push("src: " + mapFontURLs[srckey]);
for (var d in fontdata.descriptors) {
desc.push(mapDescriptorNames[d] + ": " + fontdata.descriptors[d]);
}
return "@font-face { " + desc.join(";") + " }";
}
function clearRules(sheetIndex) { var sheet = document.styleSheets[sheetIndex];
while(sheet.cssRules.length > 0) {
sheet.deleteRule(0);
}
}
function clearAllRulesAndFonts() {
clearRules(kSheetFonts);
clearRules(kSheetStyles);
document.fonts.clear();
}
function addStyleRulesAndText(testdata, i) {
// add style rules for testcontent var sheet = document.styleSheets[kSheetStyles];
while(sheet.cssRules.length > 0) {
sheet.deleteRule(0);
} var rule = []; var family = familyName(testdata.fonts[0].family, i);
rule.push("#testcontent { font-family: " + family);
if ("style" in testdata) {
for (s in testdata.style) {
rule.push(s + ": " + testdata.style[s]);
}
}
rule.push("}");
sheet.insertRule(rule.join("; "), 0);
var content = document.getElementById("testcontent");
content.innerHTML = testdata.content;
content.offsetHeight;
}
// work arounds
function getFonts() {
if ("forEach" in document.fonts) {
return document.fonts;
}
return Array.from(document.fonts);
}
function getSize() {
if ("size" in document.fonts) {
return document.fonts.size;
}
return getFonts().length;
}
function getReady() {
if (typeof(document.fonts.ready) == "function") {
return document.fonts.ready();
}
return document.fonts.ready;
}
function setTimeoutPromise(aDelay) {
return new Promise(function(aResolve, aReject) {
setTimeout(aResolve, aDelay);
});
}
function addFontFaceRules(testdata, i, ft) { var sheet = document.styleSheets[kSheetFonts]; var createdFonts = [];
testdata.fonts.forEach(function(f) { var n = sheet.cssRules.length; var fn = familyName(f.family, i);
sheet.insertRule(fontFaceRule(fn, f, ft), n); var newfont; var fonts = getFonts();
try {
fonts.forEach(function(font) { newfont = font; });
createdFonts.push({family: fn, data: f, font: newfont});
} catch (e) {
console.log(e);
}
});
return createdFonts;
}
function addDocumentFonts(testdata, i, ft) { var createdFonts = [];
testdata.fonts.forEach(function(fd) { var fn = familyName(fd.family, i); var srckey = fd.src + ft; var f = new FontFace(fn, mapFontURLs[srckey], fd.descriptors);
document.fonts.add(f);
createdFonts.push({family: fn, data: fd, font: f});
});
return createdFonts;
}
var q = Promise.resolve();
function runTests() {
function setupTests() {
setup({explicit_done: true});
}
function checkFontsBeforeLoad(name, testdata, fd) {
test(function() {
assert_equals(document.fonts.status, "loaded", "before initializing test, no fonts should be loading - found: " + document.fonts.status); var size = getSize();
assert_equals(size, testdata.fonts.length, "fonts where not added to the font set object"); var i = 0;
fonts = getFonts();
fonts.forEach(function(ff) {
assert_equals(ff.status, "unloaded", "added fonts should be in unloaded state");
});
}, name + " before load");
}
function checkFontsAfterLoad(name, testdata, fd, afterTimeout) {
test(function() {
assert_equals(document.fonts.status, "loaded", "after ready promise resolved, no fonts should be loading"); var i = 0;
fd.forEach(function(f) {
assert_true(f.font instanceof FontFace, "font needs to be an instance of FontFace object");
if (f.data.loaded) {
assert_equals(f.font.status, "loaded", "font not loaded - font " + i + " " + f.data.src + " "
+ JSON.stringify(f.data.descriptors) + " for content " + testdata.content);
} else {
assert_equals(f.font.status, "unloaded", "font loaded - font " + i + " " + f.data.src + " "
+ JSON.stringify(f.data.descriptors) + " for content " + testdata.content);
}
i++;
});
}, name + " after load" + (afterTimeout ? " and timeout" : ""));
}
function testFontLoads(testdata, i, name, fd) {
checkFontsBeforeLoad(name, testdata, fd);
addStyleRulesAndText(testdata, i);
var ready = getReady();
return ready.then(function() {
checkFontsAfterLoad(name, testdata, fd, false);
}).then(function() {
return setTimeoutPromise(0).then(function() {
checkFontsAfterLoad(name, testdata, fd, true);
});
}).then(function() { var ar = getReady();
return ar.then(function() {
test(function() {
assert_equals(document.fonts.status, "loaded", "after ready promise fulfilled once, fontset should not be loading"); var fonts = getFonts();
fonts.forEach(function(f) {
assert_not_equals(f.status, "loading", "after ready promise fulfilled once, no font should be loading");
});
}, name + " test done check");
});
}).then(function() {
clearAllRulesAndFonts();
});
}
function testUnicodeRangeFontFace(testdata, i, ft) { var name = "TEST " + i + " " + testdata.test + " (@font-face rules)" + (ft != "" ? " " + ft : ft);
var fd = addFontFaceRules(testdata, i, ft);
return testFontLoads(testdata, i, name, fd);
}
function testUnicodeRangeDocumentFonts(testdata, i, ft) { var name = "TEST " + i + " " + testdata.test + " (document.fonts)" + (ft != "" ? " " + ft : ft);
var fd = addDocumentFonts(testdata, i, ft);
return testFontLoads(testdata, i, name, fd);
}
if ("fonts" in document) {
runTests();
} else {
test(function() {
assert_true(true, "CSS Font Loading API is not enabled.");
}, "CSS Font Loading API is not enabled");
}
</script>
</body>
</html>
Messung V0.5
¤ Dauer der Verarbeitung: 0.3 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.