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 SVGTextElementTest extends WebDriverTestCase {
28
29
30
31
32 @Test
33 @Alerts("function SVGTextElement() { [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.SVGTextElement);\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 SVGTextElement]", "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 + " <text id='myId' x='0' y='4' fill='orange'>HtmlUnit is great!</text>\n"
70 + "</svg>\n"
71 + "</body></html>";
72
73 loadPageVerifyTitle2(html);
74 }
75
76
77
78
79 @Test
80 @Alerts({"[object SVGTextElement]", "117.3"})
81 @HtmlUnitNYI(CHROME = {"[object SVGTextElement]", "180.0"},
82 EDGE = {"[object SVGTextElement]", "180.0"},
83 FF = {"[object SVGTextElement]", "180.0"},
84 FF_ESR = {"[object SVGTextElement]", "180.0"})
85 public void getComputedTextLength() throws Exception {
86 final String html = DOCTYPE_HTML
87 + "<html><head>\n"
88 + "<script>\n"
89 + LOG_TITLE_FUNCTION
90 + " function test() {\n"
91 + " if (window.SVGTextElement) {\n"
92 + " var text = document.getElementById('myId');\n"
93 + " log(text);\n"
94 + " var length = text.getComputedTextLength();\n"
95 + " log(length.toFixed(1));\n"
96 + " }\n"
97 + " }\n"
98 + "</script>\n"
99 + "</head><body onload='test()'>\n"
100 + "<svg width='100%' height='100%' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'>\n"
101 + " <text id='myId' x='0' y='4' fill='orange'>HtmlUnit is great!</text>\n"
102 + "</svg>\n"
103 + "</body></html>";
104
105 loadPageVerifyTitle2(html);
106 }
107 }