content/svg/content/test/test_SVGLengthList.xhtml
author Cameron McCormack <cam@mcc.id.au>
Mon, 05 Mar 2012 10:38:03 +1100
changeset 88593 a19f6fd4f6f2db4af1be3d44221f3200bf367d84
parent 86942 298a762dc5524ad3c0554b3fc5cc2b293a5de1e3
child 100854 cad2a6ac68ca231ab797a992503f8bca261fc974
permissions -rw-r--r--
Bug 731813 - Do not attempt to serialize SVG attributes for mutation events if they do not exist. r=jwatt,bzbarsky

<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=515116
-->
<head>
  <title>Tests specific to SVGLengthList</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="MutationEventChecker.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=515116">Mozilla Bug 515116</a>
<p id="display"></p>
<div id="content" style="display:none;">
<svg id="svg" xmlns="http://www.w3.org/2000/svg" width="100" height="100">
  <text id="text" x="10cm 20cm 30mc"/>
</svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[

SimpleTest.waitForExplicitFinish();

/*
This file runs a series of SVGLengthList specific tests. Generic SVGXxxList
tests can be found in test_SVGxxxList.xhtml. Anything that can be generalized
to other list types belongs there.
*/

function run_tests()
{
  document.getElementById('svg').pauseAnimations();

  var text = document.getElementById("text");
  var lengths = text.x.baseVal;

  is(lengths.numberOfItems, 0, 'Checking numberOfItems');

  // Test mutation events
  // --- Initialization
  eventChecker = new MutationEventChecker;
  eventChecker.watchAttr(text, "x");
  eventChecker.expect("modify");
  text.textContent = "abc";
  text.setAttribute("x", "10 20 30");
  is(lengths.numberOfItems, 3, 'Checking numberOfItems');
  // -- Actual changes
  eventChecker.expect("modify modify modify modify modify");
  lengths[0].value = 8;
  lengths[0].valueInSpecifiedUnits = 9;
  lengths[0].valueAsString = "10";
  lengths[0].convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_CM);
  lengths[0].newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_MM, 11);
  // -- Redundant changes
  eventChecker.expect("modify");
  lengths[0].valueAsString = "10";
  eventChecker.expect("");
  lengths[0].value = 10;
  lengths[0].valueInSpecifiedUnits = 10;
  lengths[0].valueAsString = "10";
  lengths[0].convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_NUMBER);
  lengths[0].newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_NUMBER, 10);
  // -- Attribute removal
  eventChecker.expect("remove");
  text.removeAttribute("x");
  // -- Non-existent attribute removal
  eventChecker.expect("");
  text.removeAttribute("x");
  text.removeAttributeNS(null, "x");
  eventChecker.finish();

  SimpleTest.finish();
}

window.addEventListener("load", run_tests, false);

]]>
</script>
</pre>
</body>
</html>