blob: d157ec72d42a8da7b857399e747e0f68ec8d198a [file] [log] [blame]
<html>
<head>
<style>
#valid_normal {
font-feature-settings: normal;
}
#valid_value_1 {
font-feature-settings: "dlig" 1;
}
#valid_value_2 {
font-feature-settings: "swsh" 2;
}
#valid_value_on {
font-feature-settings: "smcp" on;
}
#valid_value_off {
font-feature-settings: "liga" off;
}
#valid_value_omit {
font-feature-settings: "c2sc";
}
#valid_valuelist {
font-feature-settings: "tnum", 'hist';
}
#valid_singlequote {
font-feature-settings: 'PKRN';
}
#valid_unusual_tag {
font-feature-settings: "!@#$";
}
#valid_tag_space {
font-feature-settings: "a bc";
}
#valid_composite {
font-feature-settings: "dlig" 1, 'smcp' on, 'lig ' off;
}
#invalid_ident {
font-feature-settings: dlig;
}
#invalid_cases {
font-feature-settings: dlig, DLIG, DLig;
}
#invalid_1 {
font-feature-settings: 1;
}
#invalid_off {
font-feature-settings: off;
}
#invalid_normal_duplicate {
font-feature-settings: normal, normal;
}
#invalid_normal_list {
font-feature-settings: normal, aaaa;
}
#invalid_longer_ident {
font-feature-settings: aaaaa;
}
#invalid_longer_quote {
font-feature-settings: "aaaaa";
}
#invalid_negative {
font-feature-settings: aaaa -1;
}
#invalid_float {
font-feature-settings: aaaa 1.5;
}
#invalid_missing_comma {
font-feature-settings: aaaa "bbbb";
}
#invalid_missing_comma_ident {
font-feature-settings: aaaa bbbb;
}
#invalid_comma {
font-feature-settings: ,;
}
#invalid_ending_comma {
font-feature-settings: aaaa,;
}
#invalid_beginning_comma {
font-feature-settings: ,aaaa;
}
#invalid_on {
font-feature-settings: aaaa, on;
}
#invalid_0 {
font-feature-settings: "aaaa" 1, "bbbb", 0;
}
#invalid_composite {
font-feature-settings: aaaaa on, dlig on, PKRN -1;
}
</style>
<style>
@font-face {
font-feature-settings: 'liga';
}
@font-face {
font-feature-settings: aaaaa;
}
</style>
<script src="../resources/js-test-pre.js"></script>
</head>
<body>
<div id="valid_normal"></div>
<div id="valid_value_1"></div>
<div id="valid_value_2"></div>
<div id="valid_value_on"></div>
<div id="valid_value_off"></div>
<div id="valid_value_omit"></div>
<div id="valid_valuelist"></div>
<div id="valid_singlequote"></div>
<div id="valid_unusual_tag"></div>
<div id="valid_tag_space"></div>
<div id="valid_composite"></div>
<div id="invalid_ident"></div>
<div id="invalid_cases"></div>
<div id="invalid_1"></div>
<div id="invalid_off"></div>
<div id="invalid_normal_duplicate"></div>
<div id="invalid_normal_list"></div>
<div id="invalid_longer_ident"></div>
<div id="invalid_longer_quote"></div>
<div id="invalid_negative"></div>
<div id="invalid_float"></div>
<div id="invalid_missing_comma"></div>
<div id="invalid_missing_comma_ident"></div>
<div id="invalid_comma"></div>
<div id="invalid_ending_comma"></div>
<div id="invalid_beginning_comma"></div>
<div id="invalid_on"></div>
<div id="invalid_0"></div>
<div id="outer" style="font-feature-settings: 'dlig';">
<div id="inner"></div>
</div>
<p id="description"></p>
<div id="console"></div>
<script>
description('Test parsing of the CSS3 font-feature-settings property.');
function canonicalize(fontFeatureSettingsString) {
var pieces = fontFeatureSettingsString.split(", ");
var lowered = pieces.map(function(piece) {
return piece.toLowerCase();
});
var sorted = lowered.sort();
return sorted.join(", ");
}
function parseResultOf(id) {
var element = document.getElementById(id);
return window.getComputedStyle(element)['font-feature-settings'];
}
debug('- Tests valid inputs.');
shouldBeEqualToString('canonicalize(parseResultOf("valid_normal"))', canonicalize("normal"));
shouldBeEqualToString('canonicalize(parseResultOf("valid_value_1"))', canonicalize("'dlig' 1"));
shouldBeEqualToString('canonicalize(parseResultOf("valid_value_2"))', canonicalize("'swsh' 2"));
shouldBeEqualToString('canonicalize(parseResultOf("valid_value_on"))', canonicalize("'smcp' 1"));
shouldBeEqualToString('canonicalize(parseResultOf("valid_value_off"))', canonicalize("'liga' 0"));
shouldBeEqualToString('canonicalize(parseResultOf("valid_value_omit"))', canonicalize("'c2sc' 1"));
shouldBeEqualToString('canonicalize(parseResultOf("valid_valuelist"))', canonicalize("'tnum' 1, 'hist' 1"));
shouldBeEqualToString('canonicalize(parseResultOf("valid_singlequote"))', canonicalize("'PKRN' 1"));
shouldBeEqualToString('canonicalize(parseResultOf("valid_unusual_tag"))', canonicalize("'!@#$' 1"));
shouldBeEqualToString('canonicalize(parseResultOf("valid_tag_space"))', canonicalize("'a bc' 1"));
shouldBeEqualToString('canonicalize(parseResultOf("valid_composite"))', canonicalize("'dlig' 1, 'smcp' 1, 'lig ' 0"));
debug('- Tests invalid inputs. Results should be "normal".');
shouldBe('parseResultOf("invalid_ident")', '"normal"');
shouldBe('parseResultOf("invalid_cases")', '"normal"');
shouldBe('parseResultOf("invalid_1")', '"normal"');
shouldBe('parseResultOf("invalid_off")', '"normal"');
shouldBe('parseResultOf("invalid_normal_duplicate")', '"normal"');
shouldBe('parseResultOf("invalid_normal_list")', '"normal"');
shouldBe('parseResultOf("invalid_longer_ident")', '"normal"');
shouldBe('parseResultOf("invalid_longer_quote")', '"normal"');
shouldBe('parseResultOf("invalid_negative")', '"normal"');
shouldBe('parseResultOf("invalid_float")', '"normal"');
shouldBe('parseResultOf("invalid_missing_comma")', '"normal"');
shouldBe('parseResultOf("invalid_missing_comma_ident")', '"normal"');
shouldBe('parseResultOf("invalid_comma")', '"normal"');
shouldBe('parseResultOf("invalid_ending_comma")', '"normal"');
shouldBe('parseResultOf("invalid_beginning_comma")', '"normal"');
shouldBe('parseResultOf("invalid_on")', '"normal"');
shouldBe('parseResultOf("invalid_0")', '"normal"');
debug('- Tests inherit.');
shouldBeEqualToString('canonicalize(parseResultOf("outer"))', canonicalize("'dlig' 1"));
shouldBeEqualToString('canonicalize(parseResultOf("inner"))', canonicalize("'dlig' 1"));
debug('- Tests @font-face.');
var fontFaceRuleValid = document.styleSheets[1].cssRules[0].style['font-feature-settings'];
var fontFaceRuleInvalid = document.styleSheets[1].cssRules[1].style['font-feature-settings'];
shouldBeEqualToString('canonicalize(fontFaceRuleValid)', canonicalize("'liga' 1"));
shouldBeEqualToString('fontFaceRuleInvalid', "");
</script>
<script src="../resources/js-test-post.js"></script>
</body>
</html>