summaryrefslogtreecommitdiffstats
path: root/dom/svg/test/test_animLengthObjectIdentity.xhtml
blob: b4bce755b9eb58b61cbd64f344e79ebb11983b5f (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
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=508496
-->
<head>
  <title>Test for object identity of SVG animated lengths</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=506856">Mozilla Bug 508496</a>
<p id="display"></p>
<div id="content" style="display: none">
<svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px"
     onload="this.pauseAnimations()">
  <circle cx="-100" cy="-100" r="15" fill="blue" id="circle">
    <animate attributeName="cx" from="0" to="100" dur="4s" begin="1s; 10s"
      fill="freeze" id="animate"/>
  </circle>
</svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[
/** Test object identity of animated lengths **/

/* Global Variables */
const svgns = "http://www.w3.org/2000/svg";
var svg = document.getElementById("svg");
var circle = document.getElementById("circle");

SimpleTest.waitForExplicitFinish();

function main() {
  ok(svg.animationsPaused(), "should be paused by <svg> load handler");
  is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");

  var animLength = circle.cx;
  ok(animLength === circle.cx,
    "Got different SVGAnimatedLength objects at startup");

  var baseVal = circle.cx.baseVal;
  ok(baseVal === circle.cx.baseVal,
    "Got different baseVal SVGLength objects at startup");

  var animVal = circle.cx.animVal;
  ok(animVal === circle.cx.animVal,
    "Got different animVal SVGLength objects at startup");

  var animate = document.getElementById("animate");
  if (animate && animate.targetElement) {
    // Sample mid-way through the animation
    svg.setCurrentTime(5);

    ok(animLength === circle.cx,
      "Got different SVGAnimatedLength objects during animation");
    ok(baseVal === circle.cx.baseVal,
      "Got different baseVal SVGLength objects during animation");
    ok(animVal === circle.cx.animVal,
      "Got different animVal SVGLength objects during animation");
  }

  // Drop all references to the tear off objects
  var oldValue = circle.cx.animVal.value; // Just a float, not an object ref
  animLength = null;
  baseVal = null;
  animVal = null;
  SpecialPowers.gc();

  // The tearoff objects should no longer exist and we should create new ones.
  // If somehow, the tearoff objects have died and yet not been removed from the
  // hashmap we'll end up in all sorts of trouble when we try to access them.
  // So in the following, we're not really interested in the value, just that we
  // don't crash.
  is(circle.cx.animVal.value, oldValue,
    "Unexpected result accessing new(?) length object.");

  SimpleTest.finish();
}

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