chromium/third_party/blink/web_tests/fast/css/fontface-properties.html

<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-display: block;
  /* 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"');
    shouldBeEqualToString('ahemFace.display', 'block');

    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');
    shouldBeEqualToString('defaultFace.display', 'auto');

    debug('');
    constructedFace = new FontFace('constructedFace', 'local(bar)', {
        'style': 'oblique',
        'weight': 'bold',
        'unicodeRange': 'U+100-1FF, U+ABCD',
        'variant': 'small-caps',
        'featureSettings': "'liga' 0",
        'display': 'optional'
    });
    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');
    shouldBeEqualToString('constructedFace.display', 'optional');

    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";
    modifiedFace.display = 'fallback';
    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", "liga" 0');
    shouldBeEqualToString('modifiedFace.display', 'fallback');

    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");
    shouldThrow("face.display = 123");
    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>