dom/smil/test/test_smilCSSFontStretchRelative.xhtml

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/smil/test/test_smilCSSFontStretchRelative.xhtml	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     1.4 +<html xmlns="http://www.w3.org/1999/xhtml">
     1.5 +<head>
     1.6 +  <title>Test for Animation Behavior on CSS Properties</title>
     1.7 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.8 +  <script type="text/javascript" src="smilTestUtils.js"></script>
     1.9 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.10 +</head>
    1.11 +<body>
    1.12 +<p id="display"></p>
    1.13 +<div id="content" style="display: none">
    1.14 +<svg id="svg" xmlns="http://www.w3.org/2000/svg">
    1.15 +</svg>
    1.16 +</div>
    1.17 +<pre id="test">
    1.18 +<script class="testbody" type="text/javascript">
    1.19 +<![CDATA[
    1.20 +/* This testcase verifies that animated values of "wider" and "narrower" for
    1.21 +   "font-stretch" have the expected effect, across all possible inherited
    1.22 +   values of the property.
    1.23 +   XXXdholbert Currently, we don't support animating relative values of
    1.24 +   font-stretch, so most of the tests here use todo_is() rather than is().
    1.25 +*/
    1.26 +
    1.27 +SimpleTest.waitForExplicitFinish();
    1.28 +
    1.29 +const gPropertyName="font-stretch";
    1.30 +
    1.31 +// List of non-relative font-stretch values, from smallest to largest
    1.32 +const gFontStretchValues = [
    1.33 +  "ultra-condensed",
    1.34 +  "extra-condensed",
    1.35 +  "condensed",
    1.36 +  "semi-condensed",
    1.37 +  "normal",
    1.38 +  "semi-expanded",
    1.39 +  "expanded",
    1.40 +  "extra-expanded",
    1.41 +  "ultra-expanded"
    1.42 +];
    1.43 +
    1.44 +function testFontStretchValue(baseValue, narrowerStep, widerStep)
    1.45 +{
    1.46 +  var svg = SMILUtil.getSVGRoot();
    1.47 +  var gElem = document.createElementNS(SVG_NS, "g");
    1.48 +  gElem.setAttribute("style", "font-stretch: " + baseValue);
    1.49 +  svg.appendChild(gElem);
    1.50 +
    1.51 +  var textElem = document.createElementNS(SVG_NS, "text");
    1.52 +  gElem.appendChild(textElem);
    1.53 +
    1.54 +  var animElem = document.createElementNS(SVG_NS, "set");
    1.55 +  animElem.setAttribute("attributeName", gPropertyName);
    1.56 +  animElem.setAttribute("attributeType", "CSS");
    1.57 +  animElem.setAttribute("begin", "0s");
    1.58 +  animElem.setAttribute("dur", "indefinite");
    1.59 +  textElem.appendChild(animElem);
    1.60 +
    1.61 +  // CHECK EFFECT OF 'narrower'
    1.62 +  // NOTE: Using is() instead of todo_is() for ultra-condensed, since
    1.63 +  // 'narrower' has no effect on that value.
    1.64 +  var myIs = (baseValue == "ultra-condensed" ? is : todo_is);
    1.65 +  animElem.setAttribute("to", "narrower");
    1.66 +  SMILUtil.getSVGRoot().setCurrentTime(1.0); // Force a resample
    1.67 +  myIs(SMILUtil.getComputedStyleSimple(textElem, gPropertyName), narrowerStep,
    1.68 +       "checking effect of 'narrower' on inherited value '" + baseValue + "'");
    1.69 +
    1.70 +  // CHECK EFFECT OF 'wider'
    1.71 +  // NOTE: using is() instead of todo_is() for ultra-expanded, since
    1.72 +  // 'wider' has no effect on that value.
    1.73 +  myIs = (baseValue == "ultra-expanded" ? is : todo_is);
    1.74 +  animElem.setAttribute("to", "wider");
    1.75 +  SMILUtil.getSVGRoot().setCurrentTime(1.0); // Force a resample
    1.76 +  myIs(SMILUtil.getComputedStyleSimple(textElem, gPropertyName), widerStep,
    1.77 +          "checking effect of 'wider' on inherited value '" + baseValue + "'");
    1.78 +
    1.79 +  // Removing animation should clear animated effects
    1.80 +  textElem.removeChild(animElem);
    1.81 +  svg.removeChild(gElem);
    1.82 +}
    1.83 +
    1.84 +function main()
    1.85 +{
    1.86 +  var valuesList = gFontStretchValues;
    1.87 +  for (var baseIdx in valuesList) {
    1.88 +    // 'narrower' and 'wider' are expected to shift us by one slot, but not
    1.89 +    // past the ends of the list of possible values.
    1.90 +    var narrowerIdx = Math.max(baseIdx - 1, 0);
    1.91 +    var widerIdx =    Math.min(baseIdx + 1, valuesList.length - 1);
    1.92 +
    1.93 +    testFontStretchValue(valuesList[baseIdx],
    1.94 +                         valuesList[narrowerIdx], valuesList[widerIdx]);
    1.95 +  }
    1.96 +
    1.97 +  SimpleTest.finish();
    1.98 +}
    1.99 +
   1.100 +window.addEventListener("load", main, false);
   1.101 +]]>
   1.102 +</script>
   1.103 +</pre>
   1.104 +</body>
   1.105 +</html>

mercurial