Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / svg / custom / acid3-test-77.html
blobe01892eb98ba5409e985015f35f0f057cf46780e
1 <!--
2 // test 77: external SVG fonts, from Erik Dahlstrom
3 //
4 // SVGFonts are described here[3], and the relevant DOM methods
5 // used in the test are defined here[4].
6 //
7 // Note that in order to be more predictable the svg should be
8 // visible, so that clause "For non-rendering environments, the
9 // user agent shall make reasonable assumptions about glyph
10 // metrics." doesn't influence the results. We use 'opacity:0'
11 // to hide the SVG, but arguably it's still a "rendering
12 // environment".
14 // The font-size 4000 was chosen because that matches the
15 // unitsPerEm value in the svgfont, which makes it easy to check
16 // the glyph advances since they will then be exactly what was
17 // specified in the svgfont.
19 // [3] http://www.w3.org/TR/SVG11/fonts.html
20 // [4] http://www.w3.org/TR/SVG11/text.html#InterfaceSVGTextContentElement
21 -->
23 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
24 <html>
25 <head>
26 <script src="../../resources/js-test.js"></script>
27 </head>
28 <body>
29 <p id="description"></p>
30 <div id="console"></div>
31 <script>
32 description("Acid3 test 77, checking text metric functionality");
34 window.jsTestIsAsync = true;
35 if (window.testRunner)
36 testRunner.waitUntilDone();
38 var text;
39 var iframe;
41 function startTest() {
42 iframe = document.createElement("iframe");
43 iframe.onload = fontLoaded;
44 iframe.src = "resources/Acid3Font-loader.svg";
45 document.documentElement.appendChild(iframe);
48 var fontLoaded = function() {
49 var svg = iframe.getSVGDocument().documentElement;
50 text = iframe.getSVGDocument().getElementsByTagName('text')[0];
51 text.textContent = "abc";
52 text.setAttribute("y", "1em");
53 text.setAttribute("font-size", "4000");
54 executeTest();
57 function executeTest() {
58 // The font-size 4000 was chosen because that matches the unitsPerEm value in the svgfont,
59 // which makes it easy to check the glyph advances since they will then be exactly what was specified in the svgfont.
60 shouldBe("text.getNumberOfChars()", "3");
61 shouldBe("text.getComputedTextLength()", "4711+42+23");
62 shouldBe("text.getSubStringLength(0,1)", "42");
63 shouldBe("text.getSubStringLength(0,2)", "42+23");
64 shouldBe("text.getSubStringLength(1,1)", "23");
65 shouldBe("text.getSubStringLength(1,0)", "0");
66 shouldBe("text.getSubStringLength(1, 3)", "4734");
67 shouldBe("text.getSubStringLength(0, 4)", "4776");
68 shouldThrow("text.getSubStringLength(3, 0)");
69 shouldThrow("text.getSubStringLength(-17, 20)");
70 shouldBe("text.getStartPositionOfChar(0).x", "0");
71 shouldBe("text.getStartPositionOfChar(1).x", "42");
72 shouldBe("text.getStartPositionOfChar(2).x", "42+23");
73 shouldBe("text.getStartPositionOfChar(0).y", "4000");
74 shouldThrow("text.getEndPositionOfChar(-1)");
75 shouldThrow("text.getEndPositionOfChar(4)");
76 shouldBe("text.getEndPositionOfChar(0).x", "42");
77 shouldBe("text.getEndPositionOfChar(1).x", "42+23");
78 shouldBe("text.getEndPositionOfChar(2).x", "42+23+4711");
79 shouldThrow("text.getEndPositionOfChar(-17)");
80 shouldThrow("text.getEndPositionOfChar(4)");
82 finishJSTest();
85 startTest();
86 </script>
87 </body>
88 </html>