blob: 4d0231c98f736b7d0db927bb7327d6a008ff18db [file] [log] [blame]
<html>
<head>
<script src="../../resources/js-test.js"></script>
<style>
@font-face {
font-family: TestFont1;
src: local('Courier New'), local('Cousine-Regular');
}
@font-face {
font-family: TestFont2;
src: url(../../resources/Ahem.ttf);
unicode-range: u+61-7a; /* 'a'-'z' */
}
@font-face {
font-family: TestFont3;
src: url(data:application/x-truetype-font,) format("truetype");
}
@font-face {
font-family: TestFont4;
src: url(data:application/xml,) format("svg");
}
</style>
<script>
description('Test load events for fonts.loadFont() with multiple font families.');
window.jsTestIsAsync = true;
function runTests() {
document.fonts.addEventListener('loading', onLoading);
document.fonts.addEventListener('loadingdone', onLoadingDone);
document.fonts.addEventListener('loadingerror', onLoadingError);
document.fonts.ready.then(finish);
document.fonts.load('10px TestFont1, TestFont2, TestFont3, TestFont4', 'abc').catch(function() {});
}
var event;
var firedEvents = [];
function onLoading(e) {
firedEvents.push(e.type);
}
function onLoadingDone(e) {
firedEvents.push(e.type);
event = e;
shouldBe("event.fontfaces.length", "2");
shouldBeEqualToString("event.fontfaces[0].status", "loaded");
shouldBeEqualToString("event.fontfaces[1].status", "loaded");
loadedFonts = e.fontfaces.map(function(face){return face.family;}).sort();
shouldBe('loadedFonts', "['TestFont1', 'TestFont2']");
shouldBeTrue("document.fonts.check('10px TestFont1')");
shouldBeTrue("document.fonts.check('10px TestFont2')");
shouldBeTrue("document.fonts.check('10px TestFont1, TestFont2')");
shouldBeTrue("document.fonts.check('10px Times')");
shouldBeTrue("document.fonts.check('10px TestFont1, Times')");
}
function onLoadingError(e) {
firedEvents.push(e.type);
event = e;
shouldBe("event.fontfaces.length", "2");
shouldBeEqualToString("event.fontfaces[0].status", "error");
shouldBeEqualToString("event.fontfaces[1].status", "error");
failedFonts = e.fontfaces.map(function(face){return face.family;}).sort();
shouldBe('failedFonts', "['TestFont3', 'TestFont4']");
shouldBeFalse("document.fonts.check('10px TestFont3')");
shouldBeFalse("document.fonts.check('10px TestFont4')");
shouldBeFalse("document.fonts.check('10px TestFont4, Times')");
}
function finish() {
shouldBe("firedEvents", "['loading', 'loadingdone', 'loadingerror']");
finishJSTest();
}
if (document.fonts)
runTests();
else {
testFailed('document.fonts does not exist');
finishJSTest();
}
</script>
</head>
<body>
</body>
</html>