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.BrowserRunner;
19 import org.htmlunit.junit.annotation.Alerts;
20 import org.htmlunit.junit.annotation.HtmlUnitNYI;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23
24
25
26
27
28
29 @RunWith(BrowserRunner.class)
30 public class SVGTextElementTest extends WebDriverTestCase {
31
32
33
34
35 @Test
36 @Alerts("function SVGTextElement() { [native code] }")
37 public void simpleScriptable() throws Exception {
38 final String html = DOCTYPE_HTML
39 + "<html><head>\n"
40 + "<script>\n"
41 + LOG_TITLE_FUNCTION
42 + " function test() {\n"
43 + " log(window.SVGTextElement);\n"
44 + " }\n"
45 + "</script>\n"
46 + "</head><body onload='test()'>\n"
47 + "</body></html>";
48
49 loadPageVerifyTitle2(html);
50 }
51
52
53
54
55 @Test
56 @Alerts({"[object SVGTextElement]", "true"})
57 public void getComputedTextLengthAvailable() throws Exception {
58 final String html = DOCTYPE_HTML
59 + "<html><head>\n"
60 + "<script>\n"
61 + LOG_TITLE_FUNCTION
62 + " function test() {\n"
63 + " if (window.SVGPathElement) {\n"
64 + " var text = document.getElementById('myId');\n"
65 + " log(text);\n"
66 + " log(text.getComputedTextLength() > 0);\n"
67 + " }\n"
68 + " }\n"
69 + "</script>\n"
70 + "</head><body onload='test()'>\n"
71 + "<svg width='100%' height='100%' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'>\n"
72 + " <text id='myId' x='0' y='4' fill='orange'>HtmlUnit is great!</text>\n"
73 + "</svg>\n"
74 + "</body></html>";
75
76 loadPageVerifyTitle2(html);
77 }
78
79
80
81
82 @Test
83 @Alerts({"[object SVGTextElement]", "117.3"})
84 @HtmlUnitNYI(CHROME = {"[object SVGTextElement]", "180.0"},
85 EDGE = {"[object SVGTextElement]", "180.0"},
86 FF = {"[object SVGTextElement]", "180.0"},
87 FF_ESR = {"[object SVGTextElement]", "180.0"})
88 public void getComputedTextLength() throws Exception {
89 final String html = DOCTYPE_HTML
90 + "<html><head>\n"
91 + "<script>\n"
92 + LOG_TITLE_FUNCTION
93 + " function test() {\n"
94 + " if (window.SVGTextElement) {\n"
95 + " var text = document.getElementById('myId');\n"
96 + " log(text);\n"
97 + " var length = text.getComputedTextLength();\n"
98 + " log(length.toFixed(1));\n"
99 + " }\n"
100 + " }\n"
101 + "</script>\n"
102 + "</head><body onload='test()'>\n"
103 + "<svg width='100%' height='100%' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'>\n"
104 + " <text id='myId' x='0' y='4' fill='orange'>HtmlUnit is great!</text>\n"
105 + "</svg>\n"
106 + "</body></html>";
107
108 loadPageVerifyTitle2(html);
109 }
110 }