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

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: Align with review comments 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>Checks SVGLength - converting from px to all other unit types</title>
fs 2016/08/25 10:16:51 'SVGLength, converting from 'px' to other units (d
Shanmuga Pandi 2016/08/26 07:35:18 Done.
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 <p></p>
fs 2016/08/25 10:16:51 Per below we don't need this.
Shanmuga Pandi 2016/08/26 07:35:18 Done.
6 <body> 6 <script>
7 <p id="description"></p> 7 function calculateDPI() {
8 <div id="console"></div> 8 // Crude hack to determine the DPI, instead of hardcoding our 96 dpi here.
fs 2016/08/25 10:16:51 Actually, I think hardcoding 96 is exactly what we
Shanmuga Pandi 2016/08/26 07:35:18 Done.
9 <script src="script-tests/SVGLength-px.js"></script> 9 var divElement = document.createElement("div");
10 </body> 10 divElement.setAttribute("style", "height: 1in");
11 </html> 11 var pElement = document.querySelector("p");
12 pElement.appendChild(divElement);
13 var cssPixelsPerInch = divElement.offsetHeight;
14 pElement.removeChild(divElement);
15
16 // Crude hack to make this test pass with Opera/Mac
17 if (navigator.userAgent.indexOf("Opera") != -1) {
18 if (navigator.userAgent.indexOf("Macintosh") != -1) {
19 cssPixelsPerInch = 72;
20 }
21 }
22
23 return cssPixelsPerInch;
24 }
25
26 test(function() {
fs 2016/08/25 10:16:51 It'd probably make sense to split this into severa
Shanmuga Pandi 2016/08/26 07:35:18 Done.
27 var cssPixelsPerInch = calculateDPI();
28 var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg") ;
29 var length = svgElement.createSVGLength();
30
31 // Set value to be 2px
32 length.valueAsString = "2px";
33 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX);
34 assert_equals(length.value, 2);
35 assert_equals(length.valueInSpecifiedUnits, 2);
36 assert_equals(length.valueAsString, "2px");
37
38 // Convert from px to unitless
39 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_NUMBER);
40 assert_equals(length.valueAsString, "2");
41 assert_equals(length.value, 2);
42 assert_equals(length.valueInSpecifiedUnits, 2);
43 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_NUMBER);
44
45 // Reset to 2px
46 length.valueAsString = "2px";
47
48 // 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
49 assert_throws(null, function() { length.convertToSpecifiedUnits(SVGLength.SVG_ LENGTHTYPE_PERCENTAGE); });
fs 2016/08/25 10:16:51 NotSupportedError
Shanmuga Pandi 2016/08/26 07:35:18 Done.
50 assert_equals(length.valueAsString, "2px");
51 assert_equals(length.value, 2);
52 assert_equals(length.valueInSpecifiedUnits, 2);
53 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX);
54
55 // Reset to 2px
56 length.valueAsString = "2px";
57
58 // 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
59 assert_throws(null, function() { length.convertToSpecifiedUnits(SVGLength.SVG_ LENGTHTYPE_EMS); });
fs 2016/08/25 10:16:51 NotSupportedError
60 assert_equals(length.valueAsString, "2px");
61 assert_equals(length.value, 2);
62 assert_equals(length.valueInSpecifiedUnits, 2);
63 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX);
64
65 // Reset to 2px
66 length.valueAsString = "2px";
67
68 // 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
69 assert_throws(null, function() { length.convertToSpecifiedUnits(SVGLength.SVG_ LENGTHTYPE_EXS); });
fs 2016/08/25 10:16:52 NotSupportedError
70 assert_equals(length.valueAsString, "2px");
71 assert_equals(length.value, 2);
72 assert_equals(length.valueInSpecifiedUnits, 2);
73 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX);
74
75 // Reset to 2px
76 length.valueAsString = "2px";
77
78 // Convert from px to cm
79 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_CM);
80 referenceValue = Number(2 * 2.54 / cssPixelsPerInch).toFixed(7);
81 assert_equals(length.valueAsString, referenceValue + "cm");
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_CM);
85
86 // Reset to 2px
87 length.valueAsString = "2px";
88
89 // Convert from px to mm
90 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_MM);
91 referenceValue = Number(2 * 25.4 / cssPixelsPerInch).toFixed(6);
92 assert_equals(length.valueAsString, referenceValue + "mm");
93 assert_equals(length.valueInSpecifiedUnits.toFixed(6), referenceValue);
94 assert_equals(length.value.toFixed(1), "2.0");
95 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_MM);
96
97 // Reset to 2px
98 length.valueAsString = "2px";
99
100 // Convert from px to in
101 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_IN);
102 referenceValue = Number(2 / cssPixelsPerInch).toFixed(7);
103 assert_equals(length.valueAsString, referenceValue + "in");
104 assert_equals(length.valueInSpecifiedUnits.toFixed(7), referenceValue);
105 assert_equals(length.value.toFixed(1), "2.0");
106 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_IN);
107
108 // Reset to 2px
109 length.valueAsString = "2px";
110
111 // Convert from px to pt
112 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PT);
113 referenceValue = Number(2 / cssPixelsPerInch * 72);
114 assert_equals(length.valueAsString, referenceValue + "pt");
115 assert_equals(length.valueInSpecifiedUnits, referenceValue);
116 assert_equals(length.value.toFixed(1), "2.0");
117 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PT);
118
119 // Reset to 2px
120 length.valueAsString = "2px";
121
122 // Convert from px to pc
123 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PC);
124 referenceValue = Number(2 / cssPixelsPerInch * 6).toFixed(3);
125 // Don't check valueAsString here, it's unreliable across browsers.
126 assert_equals(length.valueInSpecifiedUnits.toFixed(3), referenceValue);
127 assert_equals(length.value.toFixed(1), "2.0");
128 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PC);
129 });
130 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698