blob: a0663983319c5b07da0014bc425b53ecf5857c33 [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">
<polyline id="poly1" stroke="green" points="0 0 100 0 100 100 0 100"/>
</svg>
<p id="description"></p>
<div id="console"></div>
<script type="text/javascript">
<![CDATA[
description("This is a test of the simple SVGPointList API parts.");
if (window.testRunner)
testRunner.dumpAsText();
// Extend String prototype, to offer a function, that formats the points attribute in the same way across browsers
String.prototype.formatPointsAttribute = function() {
return this.replace(/,/g, " "); // Remove Firefox commas
}
function dumpPoint(point) {
return "x=" + point.x.toFixed(0) + " y=" + point.y.toFixed(0);
}
var svg = document.getElementById("svg");
var poly1 = document.getElementById("poly1");
shouldBe("poly1.points.numberOfItems", "4");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
var point;
debug("");
debug("Creating point x=200 y=100");
shouldBeEqualToString("(point = svg.createSVGPoint()).toString()", "[object SVGPoint]");
shouldBe("point.x = 200", "200");
shouldBe("point.y = 100", "100");
debug("");
debug("Test uncommon arguments for initialize()");
shouldBe("poly1.points.initialize(point)", "point");
shouldBe("poly1.points.numberOfItems", "1");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=200 y=100");
shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "200 100");
shouldThrow("poly1.points.initialize(poly1)");
shouldThrow("poly1.points.initialize(0)");
shouldThrow("poly1.points.initialize('aString')");
debug("");
debug("Reset points attribute to 0 0 100 0 100 100 0 100");
shouldBeUndefined("poly1.setAttribute('points', '0 0 100 0 100 100 0 100')");
shouldBe("poly1.points.numberOfItems", "4");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
debug("");
debug("Test uncommon arguments for getItem()");
shouldThrow("poly1.points.getItem(30)");
shouldBe("poly1.points.getItem('aString')", "poly1.points.getItem(0)");
shouldBe("poly1.points.getItem(poly1)", "poly1.points.getItem(0)");
shouldBe("poly1.points.getItem(null)", "poly1.points.getItem(0)");
debug("");
debug("Test uncommon arguments for insertItemBefore()");
shouldThrow("poly1.points.insertItemBefore(30)");
shouldThrow("poly1.points.insertItemBefore('aString')");
shouldThrow("poly1.points.insertItemBefore(poly1)");
shouldThrow("poly1.points.insertItemBefore(null)");
shouldBeEqualToString("dumpPoint(poly1.points.insertItemBefore(poly1.points.getItem(1), 'aString'))", "x=100 y=0");
shouldBe("poly1.points.numberOfItems", "4");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=100 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=0 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "100 0 0 0 100 100 0 100");
shouldBeEqualToString("dumpPoint(poly1.points.insertItemBefore(poly1.points.getItem(1), poly1))", "x=0 y=0");
shouldBe("poly1.points.numberOfItems", "4");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
shouldBeEqualToString("dumpPoint(poly1.points.insertItemBefore(poly1.points.getItem(1), null))", "x=100 y=0");
shouldBe("poly1.points.numberOfItems", "4");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=100 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=0 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "100 0 0 0 100 100 0 100");
shouldBeEqualToString("dumpPoint(poly1.points.insertItemBefore(poly1.points.getItem(1), 0))", "x=0 y=0");
shouldBe("poly1.points.numberOfItems", "4");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
shouldThrow("poly1.points.insertItemBefore(30, 0)");
shouldThrow("poly1.points.insertItemBefore('aString', 0)");
shouldThrow("poly1.points.insertItemBefore(poly1, 0)");
shouldThrow("poly1.points.insertItemBefore(null, 0)");
debug("");
debug("Test uncommon arguments for replaceItem()");
shouldThrow("poly1.points.replaceItem(30)");
shouldThrow("poly1.points.replaceItem('aString')");
shouldThrow("poly1.points.replaceItem(poly1)");
shouldThrow("poly1.points.replaceItem(null, 0)");
shouldThrow("poly1.points.replaceItem('aString', 0)");
shouldThrow("poly1.points.replaceItem(poly1, 0)");
shouldThrow("poly1.points.replaceItem(1, 0)");
debug("");
debug("Test uncommon arguments for replaceItem() and xml-dom synchronization");
shouldBe("poly1.points.numberOfItems", "4");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
shouldBeEqualToString("dumpPoint(poly1.points.replaceItem(poly1.points.getItem(0), 0))", "x=0 y=0");
shouldBe("poly1.points.numberOfItems", "4");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
shouldBeEqualToString("dumpPoint(poly1.points.replaceItem(poly1.points.getItem(0), 'aString'))", "x=0 y=0");
shouldBe("poly1.points.numberOfItems", "4");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
shouldBeEqualToString("dumpPoint(poly1.points.replaceItem(poly1.points.getItem(0), poly1))", "x=0 y=0");
shouldBe("poly1.points.numberOfItems", "4");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
shouldBeEqualToString("dumpPoint(poly1.points.replaceItem(poly1.points.getItem(0), null))", "x=0 y=0");
shouldBe("poly1.points.numberOfItems", "4");
shouldBeEqualToString("poly1.getAttribute('points')", "0 0 100 0 100 100 0 100");
debug("");
debug("Reset points attribute to 0 0 100 0 100 100 0 100");
shouldBeUndefined("poly1.setAttribute('points', '0 0 100 0 100 100 0 100')");
debug("");
debug("Test uncommon arguments for removeItem()");
shouldThrow("poly1.points.removeItem(30)");
shouldBeEqualToString("dumpPoint(poly1.points.removeItem('aString'))", "x=0 y=0");
shouldBe("poly1.points.numberOfItems", "3");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=100 y=0");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=100");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=100 y=0");
shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "100 0 100 100 0 100");
shouldBeEqualToString("dumpPoint(poly1.points.removeItem(poly1))", "x=100 y=0");
shouldBe("poly1.points.numberOfItems", "2");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=100 y=100");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=0 y=100");
shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "100 100 0 100");
shouldBeEqualToString("dumpPoint(poly1.points.removeItem(null))", "x=100 y=100");
shouldBe("poly1.points.numberOfItems", "1");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=100");
shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 100");
debug("");
debug("Test uncommon arguments for appendItem()");
shouldThrow("poly1.points.appendItem(30)");
shouldThrow("poly1.points.appendItem('aString')");
shouldThrow("poly1.points.appendItem(poly1)");
shouldThrow("poly1.points.appendItem(null)");
shouldBeEqualToString("dumpPoint(poly1.points.appendItem(point))", "x=200 y=100");
shouldBe("poly1.points.numberOfItems", "2");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=100");
shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=200 y=100");
shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 100 200 100");
]]>
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>