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

Side by Side Diff: third_party/WebKit/LayoutTests/svg/dom/SVGLength-px.html

Issue 2271223002: Convert LayoutTests/svg/dom/SVGLength*.html js-tests.js tests to testharness.js based tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moved length to local Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 1 <!DOCTYPE HTML>
2 <html> 2 <title>SVGLength, converting from 'px' to other units (detached)</title>
3 <head> 3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/js-test.js"></script> 4 <script src="../../resources/testharnessreport.js"></script>
5 </head> 5 <script>
6 <body> 6 var cssPixelsPerInch = 96;
7 <p id="description"></p> 7 setup(function() {
8 <div id="console"></div> 8 window.svgElement = document.createElementNS("http://www.w3.org/2000/svg", "sv g");
9 <script src="script-tests/SVGLength-px.js"></script> 9 });
10 </body> 10
11 </html> 11 test(function() {
12 var length = svgElement.createSVGLength();
13 length.valueAsString = "2px";
14 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_NUMBER);
15 assert_equals(length.valueAsString, "2");
16 assert_equals(length.value, 2);
17 assert_equals(length.valueInSpecifiedUnits, 2);
18 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_NUMBER);
19 }, document.title + ", unitless");
20
21 test(function() {
22 var length = svgElement.createSVGLength();
23 length.valueAsString = "2px";
24 // Try converting from px to percentage, should fail as the SVGLength is not a ssociated with a SVGSVGElement, and thus no viewport information is available.
25 assert_throws("NotSupportedError", function() { length.convertToSpecifiedUnits (SVGLength.SVG_LENGTHTYPE_PERCENTAGE); });
26 assert_equals(length.valueAsString, "2px");
27 assert_equals(length.value, 2);
28 assert_equals(length.valueInSpecifiedUnits, 2);
29 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX);
30 }, document.title + ", percentage");
31
32 test(function() {
33 var length = svgElement.createSVGLength();
34 length.valueAsString = "2px";
35 // Try converting from px to ems, should fail as the SVGLength is not associat ed with a SVGSVGElement, and thus no font-size information is available.
36 assert_throws("NotSupportedError", function() { length.convertToSpecifiedUnits (SVGLength.SVG_LENGTHTYPE_EMS); });
37 assert_equals(length.valueAsString, "2px");
38 assert_equals(length.value, 2);
39 assert_equals(length.valueInSpecifiedUnits, 2);
40 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX);
41 }, document.title + ", ems");
42
43 test(function() {
44 var length = svgElement.createSVGLength();
45 length.valueAsString = "2px";
46 // Try converting from px to exs, should fail as the SVGLength is not associat ed with a SVGSVGElement, and thus no font-size information is available.
47 assert_throws("NotSupportedError", function() { length.convertToSpecifiedUnits (SVGLength.SVG_LENGTHTYPE_EXS); });
48 assert_equals(length.valueAsString, "2px");
49 assert_equals(length.value, 2);
50 assert_equals(length.valueInSpecifiedUnits, 2);
51 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX);
52 }, document.title + ", exs");
53
54 test(function() {
55 var length = svgElement.createSVGLength();
56 length.valueAsString = "2px";
57 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_CM);
58 var referenceValue = Number(2 * 2.54 / cssPixelsPerInch).toFixed(7);
59 assert_equals(length.valueAsString, referenceValue + "cm");
60 assert_equals(length.valueInSpecifiedUnits.toFixed(7), referenceValue);
61 assert_equals(length.value.toFixed(1), "2.0");
62 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_CM);
63 }, document.title + ", cm");
64
65 test(function() {
66 var length = svgElement.createSVGLength();
67 length.valueAsString = "2px";
68 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_MM);
69 var referenceValue = Number(2 * 25.4 / cssPixelsPerInch).toFixed(6);
70 assert_equals(length.valueAsString, referenceValue + "mm");
71 assert_equals(length.valueInSpecifiedUnits.toFixed(6), referenceValue);
72 assert_equals(length.value.toFixed(1), "2.0");
73 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_MM);
74 }, document.title + ", mm");
75
76 test(function() {
77 var length = svgElement.createSVGLength();
78 length.valueAsString = "2px";
79 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_IN);
80 var referenceValue = Number(2 / cssPixelsPerInch).toFixed(7);
81 assert_equals(length.valueAsString, referenceValue + "in");
82 assert_equals(length.valueInSpecifiedUnits.toFixed(7), referenceValue);
83 assert_equals(length.value.toFixed(1), "2.0");
84 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_IN);
85 }, document.title + ", in");
86
87 test(function() {
88 var length = svgElement.createSVGLength();
89 length.valueAsString = "2px";
90 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PT);
91 var referenceValue = Number(2 / cssPixelsPerInch * 72);
92 assert_equals(length.valueAsString, referenceValue + "pt");
93 assert_equals(length.valueInSpecifiedUnits, referenceValue);
94 assert_equals(length.value.toFixed(1), "2.0");
95 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PT);
96 }, document.title + ", pt");
97
98 test(function() {
99 var length = svgElement.createSVGLength();
100 length.valueAsString = "2px";
101 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PC);
102 var referenceValue = Number(2 / cssPixelsPerInch * 6).toFixed(3);
103 // Don't check valueAsString here, it's unreliable across browsers.
104 assert_equals(length.valueInSpecifiedUnits.toFixed(3), referenceValue);
105 assert_equals(length.value.toFixed(1), "2.0");
106 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PC);
107 }, document.title + ", pc");
108 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698