1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
setup({explicit_done : true});
var styleValidTests = {
'weight': [
'bold',
'700',
'900',
'850',
'850.3',
'calc(100 + 300)',
'calc(0.2 + 205.5)',
'calc(0 - 100)',
'calc(200 + 801)',
],
'stretch': ['51%', '199%', 'calc(10% + 20%)', '0%'],
'style' : [ 'normal', 'italic', 'oblique', 'oblique 50deg', 'oblique -90deg', 'oblique 90deg',
'oblique calc(90deg + 20deg)', 'oblique calc(30deg + 20deg)' ]
};
var styleInvalidTests = {
'weight': ['100 400'],
'stretch': ['100% 110%', '100% 150%', 'calc(1 + 10%)'],
'style' : [ 'normal 10deg', 'italic 10deg', 'oblique -91deg', 'oblique 91deg' ]
};
function testParseStyle() {
for (validStyleTestCategory of Object.keys(styleValidTests)) {
for (validStyleTest of styleValidTests[validStyleTestCategory]) {
test(
function() {
assert_true(
CSS.supports('font-' + validStyleTestCategory, validStyleTest));
},
'Valid value ' + validStyleTest + ' for font property ' +
validStyleTestCategory + ' used for styling.')
}
}
for (invalidStyleTestCategory of Object.keys(styleInvalidTests)) {
for (invalidStyleTest of styleInvalidTests[invalidStyleTestCategory]) {
test(
function() {
assert_false(CSS.supports(
'font-' + invalidStyleTestCategory, invalidStyleTest));
},
'Invalid value ' + invalidStyleTest + ' for font property ' +
invalidStyleTestCategory + ' used for styling.')
}
}
}
var faceTests = {
'weight': [
['100', '100'], ['700', '700'], ['900', '900'], ['bold', 'bold'],
['normal', 'normal'], ['100 400', '100 400'], ['100 101.5', '100 101.5'],
['999.8 999.9', '999.8 999.9'],
[ '500 400', '500 400']
],
'stretch': [
['0%', '0%'],
['calc(0% - 10%)', 'calc(-10%)' ],
['100%', '100%'],
['110%', '110%'],
['111.5%', '111.5%'],
[ "50% 200%", "50% 200%" ],
[ "0.1% 1%", "0.1% 1%" ],
[ "900% 901%", "900% 901%" ],
['ultra-condensed', 'ultra-condensed'],
['ultra-expanded', 'ultra-expanded'],
],
'style' : [
[ "normal", "normal" ],
[ "italic", "italic" ],
[ "oblique", "oblique" ],
[ "oblique 10deg", "oblique 10deg" ],
[ "oblique 10deg 20deg", "oblique 10deg 20deg" ]
]
};
var faceInvalidTests = {
'weight': [
'0',
'0.9',
'-100 200',
'100 -200',
'100 1001',
'1001',
'1000.5',
'100 200 300',
'a',
'a b c',
],
'stretch': [
'-0.5%', '-1%', '60% 70% 80%', 'a%', 'a b c', '0.1',
'-60% 80%', 'ultra-expannnned', '50% 0'
],
'style' : [ 'oblique 100deg', 'oblique italic', 'oblique -91deg', 'oblique 0',
'oblique 10', 'iiitalic', '90deg', '11', 'italic 90deg' ]
};
function testParseFace() {
for (var theProperty of Object.keys(faceTests)) {
for (var faceTest of faceTests[theProperty]) {
test(
() => {
var fontFace = new FontFace('testfont', 'url()');
assert_equals(fontFace[theProperty], 'normal');
fontFace[theProperty] = faceTest[0];
assert_equals(fontFace[theProperty], faceTest[1]);
},
'Valid value ' + faceTest[0] + ' matches ' + faceTest[1] + ' for ' +
theProperty + ' in @font-face.');
}
}
for (var theProperty of Object.keys(faceInvalidTests)) {
for (var faceTest of faceInvalidTests[theProperty]) {
test(
() => {
var fontFace = new FontFace('testfont', 'url()');
assert_throws_dom('SyntaxError', () => {
fontFace[theProperty] = faceTest;
}, 'Value must not be accepted as weight value.');
},
'Value ' + faceTest + ' must not be accepted as ' + theProperty +
' in @font-face.')
}
}
}
window.addEventListener('load', function() {
testParseStyle();
testParseFace();
done();
});
</script>
</body>
</html>
|