blob: 66ca02c9cac0fb9c46a09f31d11ce2679e12895f [file] [log] [blame]
<html>
<head>
<script src="../../resources/js-test.js"></script>
<style>
@font-face {
font-family: 'Ahem';
src: url(../../resources/Ahem.ttf);
font-style: italic;
font-weight: 300;
unicode-range: U+0-3FF;
font-variant: small-caps;
-webkit-font-feature-settings: "dlig" 1;
/* font-stretch property is not supported */
}
</style>
<script>
description('Test getting/setting FontFace properties.');
function getDocumentFontFaces() {
var faces = [];
document.fonts.forEach(function(face) { faces.push(face); });
return faces;
}
function runTests() {
window.jsTestIsAsync = true;
ahemFace = getDocumentFontFaces()[0];
shouldBeEqualToString('ahemFace.family', 'Ahem');
shouldBeEqualToString('ahemFace.style', 'italic');
shouldBeEqualToString('ahemFace.weight', '300');
shouldBeEqualToString('ahemFace.unicodeRange', 'U+0-3FF');
shouldBeEqualToString('ahemFace.variant', 'small-caps');
shouldBeEqualToString('ahemFace.featureSettings', "'dlig' 1");
debug('');
defaultFace = new FontFace('defaultFace', 'local(foo)');
shouldBeEqualToString('defaultFace.family', 'defaultFace');
shouldBeEqualToString('defaultFace.style', 'normal');
shouldBeEqualToString('defaultFace.weight', 'normal');
shouldBeEqualToString('defaultFace.stretch', 'normal');
shouldBeEqualToString('defaultFace.unicodeRange', 'U+0-10FFFF');
shouldBeEqualToString('defaultFace.variant', 'normal');
shouldBeEqualToString('defaultFace.featureSettings', 'normal');
debug('');
constructedFace = new FontFace('constructedFace', 'local(bar)', {
'style': 'oblique',
'weight': 'bold',
'unicodeRange': 'U+100-1FF, U+ABCD',
'variant': 'small-caps',
'featureSettings': "'liga' 0"
});
shouldBeEqualToString('constructedFace.family', 'constructedFace');
shouldBeEqualToString('constructedFace.style', 'oblique');
shouldBeEqualToString('constructedFace.weight', 'bold');
shouldBeEqualToString('constructedFace.unicodeRange', 'U+100-1FF, U+ABCD');
shouldBeEqualToString('constructedFace.variant', 'small-caps');
shouldBeEqualToString('constructedFace.featureSettings', "'liga' 0");
debug('');
modifiedFace = new FontFace('unmodified', 'local(baz)');
modifiedFace.family = 'modified';
modifiedFace.style = 'italic';
modifiedFace.weight = 900;
modifiedFace.unicodeRange = 'U+0-3FF';
modifiedFace.variant = 'small-caps';
modifiedFace.featureSettings = "'dlig' 1, 'liga' 0";
shouldBeEqualToString('modifiedFace.family', 'modified');
shouldBeEqualToString('modifiedFace.style', 'italic');
shouldBeEqualToString('modifiedFace.weight', '900');
shouldBeEqualToString('modifiedFace.unicodeRange', 'U+0-3FF');
shouldBeEqualToString('modifiedFace.variant', 'small-caps');
shouldBeEqualToString('modifiedFace.featureSettings', "'dlig' 1, 'liga' 0");
debug('');
face = new FontFace('test', 'local(foo)');
shouldThrow("face.style = ''");
shouldThrow("face.weight = 'a'");
shouldThrow("face.unicodeRange = 'U+'");
shouldThrow("face.variant = '???'");
shouldThrow("face.featureSettings = null");
promise1 = face.loaded;
promise2 = face.load();
promise3 = face.loaded;
shouldBeTrue('promise1 === promise2');
shouldBeTrue('promise1 === promise3');
promise1.then(
function() {
debug('FAIL: Expected NetworkError');
}).catch(function(err) {
shouldBeEqualToString('"' + err.message + '"' , 'A network error occurred.');
}).then(finishJSTest);
}
if (document.fonts)
runTests();
else {
testFailed('document.fonts does not exist');
}
</script>
</head>
<body>
</body>
</html>