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

Unified Diff: third_party/WebKit/LayoutTests/svg/text/text-rect-precision.html

Issue 2260763002: Convert LayoutTests/svg/text/* 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, 4 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
Index: third_party/WebKit/LayoutTests/svg/text/text-rect-precision.html
diff --git a/third_party/WebKit/LayoutTests/svg/text/text-rect-precision.html b/third_party/WebKit/LayoutTests/svg/text/text-rect-precision.html
index ea8a29ba2f892c0b3ccdbf95eb7034fea69c0739..b8bf650c6a436e7afc2c76c04909e8311a18d323 100644
--- a/third_party/WebKit/LayoutTests/svg/text/text-rect-precision.html
+++ b/third_party/WebKit/LayoutTests/svg/text/text-rect-precision.html
@@ -1,56 +1,48 @@
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
- <script src="../../resources/js-test.js"></script>
-</head>
-<body>
- <svg style="position: absolute; top: 10px; left: 10px; width: 500px; height: 300px;">
- <g>
- <text id="test" x="0" y="50" font-size="25" fill="#000" text-rendering="geometricPrecision">Sphinx of black quartz, judge my vow.</text>
- </g>
- <g>
- <text id="measure" x="0" y="150" fill="#000" text-rendering="geometricPrecision" xml:space="preserve">&nbsp;</text>
- </g>
- </svg>
+<!DOCTYPE html>
+<title>The width of text element is similar to the sum of the width of all characters.</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<svg style="position: absolute; top: 10px; left: 10px; width: 500px; height: 300px;">
+ <g>
+ <text id="test" x="0" y="50" font-size="25" fill="#000" text-rendering="geometricPrecision">Sphinx of black quartz, judge my vow.</text>
+ </g>
+ <g>
+ <text id="measure" x="0" y="150" fill="#000" text-rendering="geometricPrecision" xml:space="preserve">&nbsp;</text>
+ </g>
+</svg>
<script>
+function measureText(testElement) {
+ var measureElement = document.getElementById('measure');
+ measureElement.setAttribute('font-size', testElement.getAttribute('font-size'));
+ var str = testElement.firstChild.nodeValue;
- function measureText(testElement)
- {
- var measureElement = document.getElementById('measure');
- measureElement.setAttribute('font-size', testElement.getAttribute('font-size'));
- var str = testElement.firstChild.nodeValue;
-
- var characterWidths = {};
- var width = 0;
- for (var i = 0; i < str.length; i++) {
- var c = str[i];
- var w = characterWidths[c];
- if (!w) {
- measureElement.firstChild.nodeValue = c;
- w = measureElement.getBoundingClientRect().width;
- characterWidths[c] = w;
- }
- width += w;
- }
- return width;
- }
+ var characterWidths = {};
+ var width = 0;
+ for (var i = 0; i < str.length; i++) {
+ var c = str[i];
+ var w = characterWidths[c];
+ if (!w) {
+ measureElement.firstChild.nodeValue = c;
+ w = measureElement.getBoundingClientRect().width;
+ characterWidths[c] = w;
+ }
+ width += w;
+ }
+ return width;
+}
- var el = document.getElementById('test');
- var elementWidth = el.getBoundingClientRect().width;
- var textWidth = measureText(el);
- // This tolerance value is made up but our goal is to ensure that the
- // sum of individual glyph widths is roughly similar to the total element
- // width.
- var glyphOverflowTolerance = Math.min(elementWidth, textWidth) / 2;
- if (elementWidth > textWidth) {
- // The sum of individual character widths will include the glyph
- // overflow of each character separately and therefore the total element
- // width should be smaller.
- testFailed('Width of text element is ' + elementWidth + ', expected the sum of individual character widths, ' + textWidth + ', to be larger.');
- } else if (Math.abs(elementWidth - textWidth) > glyphOverflowTolerance) {
- testFailed('Width of text element is ' + elementWidth + ', expected the sum of individal character widths, ' + textWidth + ', to be similar.');
- } else {
- testPassed('Width of text element is similar to the sum of the width of all characters.');
- }
-</script>
-</body>
-</html>
+test(function() {
+ var element = document.getElementById('test');
+ var elementWidth = element.getBoundingClientRect().width;
+ var textWidth = measureText(element);
+ // This tolerance value is made up but our goal is to ensure that the
+ // sum of individual glyph widths is roughly similar to the total element
+ // width.
+ var glyphOverflowTolerance = Math.min(elementWidth, textWidth) / 2;
+ // The sum of individual character widths will include the glyph
+ // overflow of each character separately and therefore the total element
+ // width should be smaller.
+ assert_less_than_equal(elementWidth, textWidth);
+ assert_less_than_equal(Math.abs(elementWidth - textWidth), glyphOverflowTolerance);
+});
+</script>

Powered by Google App Engine
This is Rietveld 408576698