summaryrefslogtreecommitdiffstats
path: root/dom/smil/test/test_smilTextZoom.xhtml
blob: 5f65bd778e3bf0203409b8373d8b6251f7205f49 (plain)
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
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Test for SMIL Animation Behavior with textZoom</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="smilTestUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content">
  <svg xmlns="http://www.w3.org/2000/svg" width="300px" height="200px"
       onload="this.pauseAnimations()">
    <text y="100px" x="0px" style="font-size: 5px">
      abc
      <animate attributeName="font-size" attributeType="CSS" fill="freeze"
               from="20px" to="40px" begin="1s" dur="1s"/>
    </text>
    <rect y="100px" x="50px" style="stroke-width: 5px">
      <animate attributeName="stroke-width" attributeType="CSS" fill="freeze"
               from="20px" to="40px" begin="1s" dur="1s"/>
    </rect>
  </svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();

// Helper function
function verifyStyle(aNode, aPropertyName, aExpectedVal)
{
  var computedVal = SMILUtil.getComputedStyleSimple(aNode, aPropertyName);

  // Bug 1379908: The computed value of stroke-* properties should be
  // serialized with px units, but currently Gecko and Servo don't do that
  // when animating these values.
  if ('stroke-width' == aPropertyName) {
    var expectedVal = SMILUtil.stripPx(aExpectedVal);
    var unitlessComputedVal = SMILUtil.stripPx(computedVal);
    is(unitlessComputedVal, expectedVal, "computed value of " + aPropertyName);
    return;
  }
  is(computedVal, aExpectedVal, "computed value of " + aPropertyName);
}

function main()
{
  // Start out pause
  var svg = SMILUtil.getSVGRoot();
  ok(svg.animationsPaused(), "should be paused by <svg> load handler");
  is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");

  // Set text zoom to 2x
  var origTextZoom =  SpecialPowers.getTextZoom(window);
  SpecialPowers.setTextZoom(window, 2);

  try {
    // Verify computed style values at various points during animation.
    // * Correct behavior is for the computed values of 'font-size' to be
    // the same as their corresponding specified values, since text zoom
    // should not affect SVG text elements.
    // * I also include tests for an identical animation of the "stroke-width"
    // property, which should _not_ be affected by textZoom.
    var text = document.getElementsByTagName("text")[0];
    var rect = document.getElementsByTagName("rect")[0];

    verifyStyle(text, "font-size",    "5px");
    verifyStyle(rect, "stroke-width", "5px");
    svg.setCurrentTime(1);
    verifyStyle(text, "font-size",    "20px");
    verifyStyle(rect, "stroke-width", "20px");
    svg.setCurrentTime(1.5);
    verifyStyle(text, "font-size",    "30px");
    verifyStyle(rect, "stroke-width", "30px");
    svg.setCurrentTime(2);
    verifyStyle(text, "font-size",    "40px");
    verifyStyle(rect, "stroke-width", "40px");
    svg.setCurrentTime(3);
    verifyStyle(text, "font-size",    "40px");
    verifyStyle(rect, "stroke-width", "40px");
  } catch (e) {
    // If anything goes wrong, make sure we restore textZoom before bubbling
    // the exception upwards, so that we don't mess up subsequent tests.
    SpecialPowers.setTextZoom(window, origTextZoom);

    throw e;
  }

  // We're done! Restore original text-zoom before finishing
  SpecialPowers.setTextZoom(window, origTextZoom);
  SimpleTest.finish();
}

window.addEventListener("load", main);
]]>
</script>
</pre>
</body>
</html>