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 147
|
<!DOCTYPE html>
<meta charset="UTF-8">
<title>CSS Text Test: computed value of 'tab-size'</title>
<!--
Issue 463: [css-text] The computed value and animation type of tab-size
https://github.com/w3c/csswg-drafts/issues/463
-->
<link rel="author" title="Gérard Talbot" href="http://www.gtalbot.org/BrowserBugsSection/css21testsuite/">
<link rel="help" href="https://www.w3.org/TR/css-text-3/#tab-size-property">
<meta content="This test checks that the computed value of 'tab-size' is a number when it is specified as such or is a length (absolute or relative) when it is specified as such." name="assert">
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
div#target
{
font-family: Ahem;
font-size: 20px;
}
</style>
<div id="target">A</div>
<div id="log"></div>
<script>
function startTesting()
{
var targetElement = document.getElementById("target");
function verifyComputedStyle(property_name, specified_value, expected_value, description)
{
test(function()
{
targetElement.style.setProperty(property_name, "initial");
/*
The purpose of setting the property to its initial value
is to act as a fallback value in case the specified value
fails. Since we are running 11 consecutive tests on the
same element, then it is necessary to 'reset' its property
to an initial value.
*/
targetElement.style.setProperty(property_name, specified_value);
assert_equals(getComputedStyle(targetElement)[property_name], expected_value);
}, description);
}
function compareValueCloseTo(property_name, specified_value, epsilon, expected_value, description)
{
test(function()
{
targetElement.style.setProperty(property_name, "initial");
targetElement.style.setProperty(property_name, specified_value);
var computedSpecifiedValue = parseFloat(getComputedStyle(targetElement)[property_name]);
assert_true(isFinite(computedSpecifiedValue)); /* We can not accept NaN as value */
targetElement.style.setProperty(property_name, expected_value);
var computedExpectedValue = parseFloat(getComputedStyle(targetElement)[property_name]);
assert_array_approx_equals(computedSpecifiedValue, computedExpectedValue, epsilon);
} , description);
}
verifyComputedStyle("tab-size", "4", "4", "testing tab-size: 4");
/* verifyComputedStyle(property_name, initial_value, specified_value, expected_value, description) */
/* absolute length units: in, cm, mm, pt, pc, Q, px */
verifyComputedStyle("tab-size", "0.5in", "48px", "testing tab-size: 0.5in");
verifyComputedStyle("tab-size", "2.54cm", "96px", "testing tab-size: 2.54cm");
verifyComputedStyle("tab-size", "25.4mm", "96px", "testing tab-size: 25.4mm");
verifyComputedStyle("tab-size", "18pt", "24px", "testing tab-size: 18pt");
verifyComputedStyle("tab-size", "5pc", "80px", "testing tab-size: 5pc");
verifyComputedStyle("tab-size", "101.6Q", "96px", "testing tab-size: 101.6Q");
verifyComputedStyle("tab-size", "7px", "7px", "testing tab-size: 7px");
/* verifyComputedStyle(property_name, specified_value, expected_value, description) */
/* relative length units: em, ex, rem */
verifyComputedStyle("tab-size", "1em", "20px", "testing tab-size: 1em");
/* compareValueCloseTo(property_name, specified_value, epsilon, expected_value, description) */
compareValueCloseTo("tab-size", "2ex", 0.001, "32px", "testing tab-size: 2ex");
/*
For this sub-test, we set the tolerance precision (epsilon)
to (0.001 === 1 thousandth).
*/
verifyComputedStyle("tab-size", "3rem", "48px", "testing tab-size: 3rem");
/*
NOT tested are: vw, vh, vmin, vmax and ch units
verifyComputedStyle("tab-size", "4vw", "?px", "testing tab-size: 4vw");
verifyComputedStyle("tab-size", "5vh", "?px", "testing tab-size: 5vh");
verifyComputedStyle("tab-size", "6vmin", "?px", "testing tab-size: 6vmin");
verifyComputedStyle("tab-size", "7vmax", "?px", "testing tab-size: 7vmax");
verifyComputedStyle("tab-size", "8ch", "?px", "testing tab-size: 8ch");
*/
}
startTesting();
</script>
|