blob: a783101ab3379224f10c5915003120aa61dbdc7d [file] [log] [blame]
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>window.enablePixelTesting = true;</script>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<svg id="svg" xmlns="http://www.w3.org/2000/svg" width="200" height="200">
<text id="text1" x="500 1000 1500" y="50"> ABC </text>
</svg>
<p id="description"></p>
<div id="console"></div>
<script type="text/javascript">
<![CDATA[
description("This is a test of the simple SVGLengthList API parts.");
if (window.testRunner)
testRunner.dumpAsText();
var text1 = document.getElementById("text1");
// Spec: The object referenced by animVal will always be distinct from the one referenced by baseVal, even when the attribute is not animated.
shouldBeTrue("text1.x.baseVal != text1.x.animVal");
shouldBe("text1.x.baseVal.numberOfItems", "3");
shouldBe("text1.x.animVal.numberOfItems", "3");
shouldBe("text1.x.baseVal.getItem(0).value", "500");
shouldBe("text1.x.baseVal.getItem(1).value", "1000");
shouldBe("text1.x.baseVal.getItem(2).value", "1500");
debug("");
debug("Test uncommon arguments for initialize()");
shouldThrow("text1.x.baseVal.initialize(30)");
shouldThrow("text1.x.baseVal.initialize('aString')");
shouldThrow("text1.x.baseVal.initialize(text1)");
shouldThrow("text1.x.baseVal.initialize(null)");
debug("");
debug("Test uncommon arguments for getItem()");
shouldThrow("text1.x.baseVal.getItem(30)");
shouldBe("text1.x.baseVal.getItem('aString')", "text1.x.baseVal.getItem(0)");
shouldBe("text1.x.baseVal.getItem(text1)", "text1.x.baseVal.getItem(0)");
shouldBe("text1.x.baseVal.getItem(null)", "text1.x.baseVal.getItem(0)");
debug("");
debug("Test uncommon arguments for insertItemBefore()");
shouldThrow("text1.x.baseVal.insertItemBefore(30)");
shouldThrow("text1.x.baseVal.insertItemBefore('aString')");
shouldThrow("text1.x.baseVal.insertItemBefore(text1)");
shouldThrow("text1.x.baseVal.insertItemBefore(null)");
shouldBe("text1.x.baseVal.insertItemBefore(text1.x.baseVal.getItem(1), 'aString')", "text1.x.baseVal.getItem(0)");
shouldBeEqualToString("text1.x.baseVal.removeItem(2).toString()", "[object SVGLength]");
shouldBe("text1.x.baseVal.numberOfItems", "3");
shouldBe("text1.x.baseVal.getItem(0).value", "1000");
shouldBe("text1.x.baseVal.getItem(1).value", "500");
shouldBe("text1.x.baseVal.getItem(2).value", "1500");
shouldBeEqualToString("text1.getAttribute('x')", "1000 500 1500");
shouldBe("text1.x.baseVal.insertItemBefore(text1.x.baseVal.getItem(1), text1)", "text1.x.baseVal.getItem(0)");
shouldBeEqualToString("text1.x.baseVal.removeItem(2).toString()", "[object SVGLength]");
shouldBe("text1.x.baseVal.numberOfItems", "3");
shouldBe("text1.x.baseVal.getItem(0).value", "500");
shouldBe("text1.x.baseVal.getItem(1).value", "1000");
shouldBe("text1.x.baseVal.getItem(2).value", "1500");
shouldBeEqualToString("text1.getAttribute('x')", "500 1000 1500");
shouldBe("text1.x.baseVal.insertItemBefore(text1.x.baseVal.getItem(1), null)", "text1.x.baseVal.getItem(0)");
shouldBeEqualToString("text1.x.baseVal.removeItem(2).toString()", "[object SVGLength]");
shouldBe("text1.x.baseVal.numberOfItems", "3");
shouldBe("text1.x.baseVal.getItem(0).value", "1000");
shouldBe("text1.x.baseVal.getItem(1).value", "500");
shouldBe("text1.x.baseVal.getItem(2).value", "1500");
shouldBeEqualToString("text1.getAttribute('x')", "1000 500 1500");
shouldBe("text1.x.baseVal.insertItemBefore(text1.x.baseVal.getItem(1), 0)", "text1.x.baseVal.getItem(0)");
shouldBeEqualToString("text1.x.baseVal.removeItem(2).toString()", "[object SVGLength]");
shouldBe("text1.x.baseVal.numberOfItems", "3");
shouldBe("text1.x.baseVal.getItem(0).value", "500");
shouldBe("text1.x.baseVal.getItem(1).value", "1000");
shouldBe("text1.x.baseVal.getItem(2).value", "1500");
shouldBeEqualToString("text1.getAttribute('x')", "500 1000 1500");
shouldThrow("text1.x.baseVal.insertItemBefore(30, 0)");
shouldThrow("text1.x.baseVal.insertItemBefore('aString', 0)");
shouldThrow("text1.x.baseVal.insertItemBefore(text1, 0)");
shouldThrow("text1.x.baseVal.insertItemBefore(null, 0)");
debug("");
debug("Set x='1 2 3 4' for text1");
shouldBeUndefined("text1.setAttribute('x', '1 2 3 4')");
debug("");
debug("Test edge cases for insertItemBefore()");
shouldBe("text1.x.baseVal.insertItemBefore(text1.x.baseVal.getItem(3), 3)", "text1.x.baseVal.getItem(3)");
shouldBeEqualToString("text1.x.baseVal.removeItem(4).toString()", "[object SVGLength]");
shouldBeEqualToString("text1.getAttribute('x')", "1 2 3 4");
shouldBe("text1.x.baseVal.insertItemBefore(text1.x.baseVal.getItem(1), 5)", "text1.x.baseVal.getItem(4)");
shouldBeEqualToString("text1.x.baseVal.removeItem(1).toString()", "[object SVGLength]");
shouldBeEqualToString("text1.getAttribute('x')", "1 3 4 2");
shouldBe("text1.x.baseVal.insertItemBefore(text1.x.baseVal.getItem(1), 0)", "text1.x.baseVal.getItem(0)");
shouldBeEqualToString("text1.x.baseVal.removeItem(2).toString()", "[object SVGLength]");
shouldBeEqualToString("text1.getAttribute('x')", "3 1 4 2");
debug("");
debug("Set x='1 2 3 4' for text1");
shouldBeUndefined("text1.setAttribute('x', '1 2 3 4')");
shouldBe("text1.x.baseVal.numberOfItems", "4");
shouldBe("text1.x.baseVal.getItem(0).value", "1");
shouldBe("text1.x.baseVal.getItem(1).value", "2");
shouldBe("text1.x.baseVal.getItem(2).value", "3");
shouldBe("text1.x.baseVal.getItem(3).value", "4");
shouldBeEqualToString("text1.getAttribute('x')", "1 2 3 4");
debug("");
debug("Test uncommon arguments for replaceItem()");
shouldThrow("text1.x.baseVal.replaceItem(30)");
shouldThrow("text1.x.baseVal.replaceItem('aString')");
shouldThrow("text1.x.baseVal.replaceItem(text1)");
shouldThrow("text1.x.baseVal.replaceItem(null)");
shouldThrow("text1.x.baseVal.replaceItem(30, 0)");
shouldThrow("text1.x.baseVal.replaceItem('aString', 0)");
shouldThrow("text1.x.baseVal.replaceItem(text1, 0)");
shouldThrow("text1.x.baseVal.replaceItem(null, 0)");
shouldBe("text1.x.baseVal.replaceItem(text1.x.baseVal.getItem(0), 0)", "text1.x.baseVal.getItem(0)");
shouldBe("text1.x.baseVal.numberOfItems", "4");
shouldBe("text1.x.baseVal.getItem(0).value", "1");
shouldBe("text1.x.baseVal.getItem(1).value", "2");
shouldBe("text1.x.baseVal.getItem(2).value", "3");
shouldBe("text1.x.baseVal.getItem(3).value", "4");
shouldBeEqualToString("text1.getAttribute('x')", "1 2 3 4");
shouldBe("text1.x.baseVal.replaceItem(text1.x.baseVal.getItem(0), 'aString')", "text1.x.baseVal.getItem(0)");
shouldBe("text1.x.baseVal.numberOfItems", "4");
shouldBe("text1.x.baseVal.getItem(0).value", "1");
shouldBe("text1.x.baseVal.getItem(1).value", "2");
shouldBe("text1.x.baseVal.getItem(2).value", "3");
shouldBe("text1.x.baseVal.getItem(3).value", "4");
shouldBeEqualToString("text1.getAttribute('x')", "1 2 3 4");
shouldBe("text1.x.baseVal.replaceItem(text1.x.baseVal.getItem(0), text1)", "text1.x.baseVal.getItem(0)");
shouldBe("text1.x.baseVal.numberOfItems", "4");
shouldBeEqualToString("text1.getAttribute('x')", "1 2 3 4");
debug("");
debug("Set x='1 2 3 4' for text1");
shouldBeUndefined("text1.setAttribute('x', '1 2 3 4')");
debug("");
debug("Test edge cases for replaceItem()");
shouldBe("text1.x.baseVal.replaceItem(text1.x.baseVal.getItem(3), 3)", "text1.x.baseVal.getItem(3)");
shouldBe("text1.x.baseVal.numberOfItems", "4");
shouldBeEqualToString("text1.getAttribute('x')", "1 2 3 4");
shouldBe("text1.x.baseVal.replaceItem(text1.x.baseVal.getItem(1), 3)", "text1.x.baseVal.getItem(3)");
shouldBeEqualToString("text1.x.baseVal.removeItem(1).toString()", "[object SVGLength]");
shouldBe("text1.x.baseVal.numberOfItems", "3");
shouldBeEqualToString("text1.getAttribute('x')", "1 3 2");
shouldThrow("text1.x.baseVal.replaceItem(text1.x.baseVal.getItem(3), 4)");
debug("");
debug("Set x='1 2 3 4' for text1");
shouldBeUndefined("text1.setAttribute('x', '1 2 3 4')");
debug("");
debug("Test overlapping edge cases for replaceItem()");
var item = text1.x.baseVal.getItem(3);
shouldBe("text1.x.baseVal.replaceItem(text1.x.baseVal.getItem(0), 3)", "text1.x.baseVal.getItem(3)");
shouldBeEqualToString("text1.x.baseVal.removeItem(0).toString()", "[object SVGLength]");
shouldBe("text1.x.baseVal.numberOfItems", "3");
item = text1.x.baseVal.getItem(2);
item.newValueSpecifiedUnits(item.unitType, item.value * 2);
shouldBe("text1.x.baseVal.getItem(2).value", "2");
shouldBe("text1.x.baseVal.replaceItem(text1.x.baseVal.getItem(0), 2)", "text1.x.baseVal.getItem(2)");
shouldBeEqualToString("text1.x.baseVal.removeItem(0).toString()", "[object SVGLength]");
shouldBe("text1.x.baseVal.numberOfItems", "2");
item = text1.x.baseVal.getItem(1);
item.newValueSpecifiedUnits(item.unitType, item.value * 2);
shouldBe("text1.x.baseVal.getItem(1).value", "4");
shouldBe("text1.x.baseVal.replaceItem(text1.x.baseVal.getItem(0), 1)", "text1.x.baseVal.getItem(1)");
shouldBeEqualToString("text1.x.baseVal.removeItem(1).toString()", "[object SVGLength]");
shouldBe("text1.x.baseVal.numberOfItems", "1");
item = text1.x.baseVal.getItem(0);
item.newValueSpecifiedUnits(item.unitType, item.value * 2);
shouldBe("text1.x.baseVal.getItem(0).value", "6");
shouldBe("text1.x.baseVal.replaceItem(text1.x.baseVal.getItem(0), 0)", "text1.x.baseVal.getItem(0)");
shouldBe("text1.x.baseVal.numberOfItems", "1");
debug("");
debug("Set x='1 2 3 4' for text1");
shouldBeUndefined("text1.setAttribute('x', '1 2 3 4')");
debug("");
debug("Test uncommon arguments for removeItem()");
shouldThrow("text1.x.baseVal.removeItem(30)");
shouldBe("text1.x.baseVal.removeItem(0).value", "1");
shouldBe("text1.x.baseVal.numberOfItems", "3");
shouldBe("text1.x.baseVal.getItem(0).value", "2");
shouldBe("text1.x.baseVal.getItem(1).value", "3");
shouldBe("text1.x.baseVal.getItem(2).value", "4");
shouldBeEqualToString("text1.getAttribute('x')", "2 3 4");
shouldBe("text1.x.baseVal.removeItem(text1).value", "2");
shouldBe("text1.x.baseVal.numberOfItems", "2");
shouldBe("text1.x.baseVal.getItem(0).value", "3");
shouldBe("text1.x.baseVal.getItem(1).value", "4");
shouldBeEqualToString("text1.getAttribute('x')", "3 4");
debug("");
debug("Test uncommon arguments for appendItem()");
shouldThrow("text1.x.baseVal.appendItem(30)");
shouldThrow("text1.x.baseVal.appendItem('aString')");
shouldThrow("text1.x.baseVal.appendItem(text1)");
shouldThrow("text1.x.baseVal.appendItem(null)");
debug("");
debug("Testing animVal clear throws");
shouldThrow("text1.x.animVal.clear()");
shouldBeUndefined("text1.x.baseVal.clear()");
]]>
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>