1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.svg;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.annotation.Alerts;
19 import org.htmlunit.junit.annotation.HtmlUnitNYI;
20 import org.junit.jupiter.api.Test;
21
22
23
24
25
26
27 public class SVGTextPathElementTest extends WebDriverTestCase {
28
29
30
31
32 @Test
33 @Alerts("function SVGTextPathElement() { [native code] }")
34 public void simpleScriptable() throws Exception {
35 final String html = DOCTYPE_HTML
36 + "<html><head>\n"
37 + "<script>\n"
38 + LOG_TITLE_FUNCTION
39 + " function test() {\n"
40 + " log(window.SVGTextPathElement);\n"
41 + " }\n"
42 + "</script>\n"
43 + "</head><body onload='test()'>\n"
44 + "</body></html>";
45
46 loadPageVerifyTitle2(html);
47 }
48
49
50
51
52 @Test
53 @Alerts({"[object SVGTextPathElement]", "true"})
54 public void getComputedTextLengthAvailable() throws Exception {
55 final String html = DOCTYPE_HTML
56 + "<html><head>\n"
57 + "<script>\n"
58 + LOG_TITLE_FUNCTION
59 + " function test() {\n"
60 + " if (window.SVGPathElement) {\n"
61 + " var text = document.getElementById('myId');\n"
62 + " log(text);\n"
63 + " log(text.getComputedTextLength() > 0);\n"
64 + " }\n"
65 + " }\n"
66 + "</script>\n"
67 + "</head><body onload='test()'>\n"
68 + "<svg width='100%' height='100%' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'>\n"
69 + " <defs>\n"
70 + " <path id='myTextPath' d='M 50,100 Q 150,50 250,100' />\n"
71 + " </defs>\n"
72 + " <text fill='steelblue' font-size='20'>\n"
73 + " <textPath id='myId' xlink:href='#myTextPath'>Heho</textPath>\n"
74 + " </text>\n"
75 + "</svg>\n"
76 + "</body></html>";
77
78 loadPageVerifyTitle2(html);
79 }
80
81
82
83
84 @Test
85 @Alerts({"[object SVGTextPathElement]", "43.3"})
86 @HtmlUnitNYI(CHROME = {"[object SVGTextPathElement]", "40.0"},
87 EDGE = {"[object SVGTextPathElement]", "40.0"},
88 FF = {"[object SVGTextPathElement]", "40.0"},
89 FF_ESR = {"[object SVGTextPathElement]", "40.0"})
90 public void getComputedTextLength() throws Exception {
91 final String html = DOCTYPE_HTML
92 + "<html><head>\n"
93 + "<script>\n"
94 + LOG_TITLE_FUNCTION
95 + " function test() {\n"
96 + " if (window.SVGTextElement) {\n"
97 + " var text = document.getElementById('myId');\n"
98 + " log(text);\n"
99 + " var length = text.getComputedTextLength();\n"
100 + " log(length.toFixed(1));\n"
101 + " }\n"
102 + " }\n"
103 + "</script>\n"
104 + "</head><body onload='test()'>\n"
105 + "<svg width='100%' height='100%' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'>\n"
106 + " <defs>\n"
107 + " <path id='myTextPath' d='M 50,100 Q 150,50 250,100' />\n"
108 + " </defs>\n"
109 + " <text fill='steelblue' font-size='20'>\n"
110 + " <textPath id='myId' xlink:href='#myTextPath'>Heho</textPath>\n"
111 + " </text>\n"
112 + "</svg>\n"
113 + "</body></html>";
114
115 loadPageVerifyTitle2(html);
116 }
117 }