Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Unified Diff: LayoutTests/fast/svg/svgangle.html

Issue 303263008: [SVG2] Add support for the 'turn' unit in <angle>. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: compilefix :P Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | LayoutTests/svg/css/svg-angle-turn.svg » ('j') | Source/core/svg/SVGAngle.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/fast/svg/svgangle.html
diff --git a/LayoutTests/fast/svg/svgangle.html b/LayoutTests/fast/svg/svgangle.html
new file mode 100644
index 0000000000000000000000000000000000000000..c599ac24bd92723a8489e641249e172ac4b4435b
--- /dev/null
+++ b/LayoutTests/fast/svg/svgangle.html
@@ -0,0 +1,170 @@
+<!doctype html>
+<title>SVGAngle tests</title>
+<script src=../../resources/testharness.js></script>
+<script src=../../resources/testharnessreport.js></script>
+<div id="testcontainer">
+<svg width="1" height="1" visibility="hidden">
+<defs><marker/></defs>
+</svg>
+</div>
+<div id=log></div>
+<script>
+var svg = document.querySelector("svg");
+var marker = document.querySelector("marker");
+var EPSILON = Math.pow(2, -8);
+var angles = [ 10, 0, 360, 500, 90, 180, 45, 25.9, 145, 270, 0.5, 0.2, 1.37, 3.14159 /* Math.PI */, 0.523599 /* Math.PI/6 */ ];
+var units = {
+ "" : 1,
+ "deg": 2,
+ "rad": 3,
+ "grad": 4,
+ "turn": 5
+};
+var unitconstants = {
+ "UNKNOWN" : 0,
+ "UNSPECIFIED": 1,
+ "DEG": 2,
+ "RAD": 3,
+ "GRAD": 4,
+ "TURN": 5
+};
+
+function convertTo(value, unit, outunit) {
+ switch(unit) {
+ case "":
+ case "deg":
+ switch(outunit) {
+ case "":
+ case "deg":
+ return value;
+ case "rad":
+ return value*(Math.PI/180);
+ case "grad":
+ return value*(400/360);
+ case "turn":
+ return value/360;
+ }
+ case "rad":
+ switch(outunit) {
+ case "":
+ case "deg":
+ return value * 180 / Math.PI;
+ case "rad":
+ return value;
+ case "grad":
+ return value * 180 / Math.PI * 400 / 360;
+ case "turn":
+ return value / (2 * Math.PI);
+ }
+ case "grad":
+ switch(outunit) {
+ case "":
+ case "deg":
+ return value * 360 / 400;
+ case "rad":
+ return value * Math.PI * 2 / 400;
+ case "grad":
+ return value;
+ case "turn":
+ return value / 400;
+ }
+ case "turn":
+ switch(outunit) {
+ case "":
+ case "deg":
+ return value * 360;
+ case "rad":
+ return value * Math.PI * 2;
+ case "grad":
+ return value * 400;
+ case "turn":
+ return value;
+ }
+ }
+}
+
+function createAngle(valuestr) {
+ var angle = svg.createSVGAngle();
+ try {
+ angle.valueAsString = valuestr;
+ }
+ catch(e) {
+ throw e;
fs 2014/06/03 15:52:48 Nit: Looks having no try-catch block would give th
+ }
+ return angle;
+}
+
+for(var unit in units) {
+ test(function() {
+ var result = undefined;
+ try {
+ var a = createAngle(47 + unit);
+ result = a.unitType;
+ }
+ catch(e) {}
fs 2014/06/03 15:52:48 Nit: AFAIK, the harness will catch exceptions (and
Erik Dahlström (inactive) 2014/06/04 09:28:21 Yes, the output from failures looked (much) cleane
fs 2014/06/04 11:21:14 Yepp, I can see that. Ok.
+ assert_equals(result, units[unit]);
+ }, "SVGAngle(47" + unit + ").unitType");
+}
+
+for(var constant in unitconstants) {
+ var str = "SVG_ANGLETYPE_" + constant;
+ test(function() {
+ assert_exists(SVGAngle, str, "");
+ }, "SVGAngle." + str);
+}
+
+angles.forEach(function(angle) {
+ for(var unit in units) {
+ var anglestr = angle + unit;
+ var ref;
+ try {
+ ref = createAngle(anglestr);
+ }
+ catch(e) {
+ continue;
+ }
+
+ test(function() {
+ assert_approx_equals(angle, ref.valueInSpecifiedUnits, EPSILON);
+ }, "SVGAngle(" + anglestr + ").valueInSpecifiedUnits");
+
+ try {
+ marker.setAttribute("orient", anglestr);
+
+ test(function() {
+ assert_equals(marker.orientAngle.baseVal.valueAsString, anglestr);
+ }, "orient=\"" + anglestr + "\".valueAsString");
+
+ test(function() {
+ assert_approx_equals(marker.orientAngle.baseVal.value, convertTo(angle, unit, "deg"), EPSILON);
+ }, "orient=\"" + anglestr + "\".value");
+ }
+ finally {
+ marker.removeAttribute("orient");
+ }
+
+ for (var otherunit in units) {
+ test(function() {
+ var a = createAngle(anglestr);
+ try {
+ a.convertToSpecifiedUnits(units[otherunit]);
+ }
+ catch(e) {}
+ assert_approx_equals(a.valueInSpecifiedUnits, convertTo(angle, unit, otherunit), EPSILON);
+ }, "SVGAngle(" + anglestr + ").convertToSpecifiedUnits(" + units[otherunit] + " /*" + (otherunit ? otherunit : "unspecified") + "*/)");
+
+ test(function() {
+ var result = "";
+ try {
+ var a = createAngle(47 + otherunit);
+ a.newValueSpecifiedUnits(units[unit], angle);
+ result = a.valueAsString;
+ }
+ catch(e) {
+ }
+ assert_equals(result, ref.valueAsString);
+ }, "newValueSpecifiedUnits(" + units[unit] + ", " + angle + ")" );
+ };
+ }
+});
+</script>
« no previous file with comments | « no previous file | LayoutTests/svg/css/svg-angle-turn.svg » ('j') | Source/core/svg/SVGAngle.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698