1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.html;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.BrowserRunner;
19 import org.htmlunit.junit.annotation.Alerts;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.openqa.selenium.WebDriver;
23 import org.openqa.selenium.htmlunit.HtmlUnitDriver;
24
25
26
27
28
29
30
31 @RunWith(BrowserRunner.class)
32 public class HtmlSvgTest extends WebDriverTestCase {
33
34
35
36
37 @Test
38 @Alerts("[object SVGSVGElement]")
39 public void simpleScriptable() throws Exception {
40 final String html = DOCTYPE_HTML
41 + "<html><head>\n"
42 + "<script>\n"
43 + LOG_TITLE_FUNCTION
44 + " function test() {\n"
45 + " log(document.getElementById('myId'));\n"
46 + " }\n"
47 + "</script>\n"
48 + "</head><body onload='test()'>\n"
49 + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n"
50 + " </svg>\n"
51 + "</body></html>";
52
53 final WebDriver driver = loadPageVerifyTitle2(html);
54 if (driver instanceof HtmlUnitDriver) {
55 final HtmlPage page = (HtmlPage) getEnclosedPage();
56 assertTrue(HtmlSvg.class.isInstance(page.getElementById("myId")));
57 }
58 }
59
60
61
62
63 @Test
64 @Alerts("false")
65 public void style() throws Exception {
66 final String html = DOCTYPE_HTML
67 + "<html><body>\n"
68 + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n"
69 + " </svg>\n"
70 + "<script>\n"
71 + LOG_TITLE_FUNCTION
72 + " log(document.getElementById('myId').style == undefined);\n"
73 + "</script>\n"
74 + "</body></html>";
75
76 loadPageVerifyTitle2(html);
77 }
78
79
80
81
82 @Test
83 @Alerts({"function", "function"})
84 public void functions() throws Exception {
85 final String html = DOCTYPE_HTML
86 + "<html><body>\n"
87 + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n"
88 + " </svg>\n"
89 + "<script>\n"
90 + LOG_TITLE_FUNCTION
91 + " var svg = document.getElementById('myId');\n"
92 + " log(typeof svg.getScreenCTM);\n"
93 + " log(typeof svg.createSVGMatrix);\n"
94 + "</script>\n"
95 + "</body></html>";
96
97 loadPageVerifyTitle2(html);
98 }
99
100
101
102
103 @Test
104 @Alerts("[object SVGMatrix]")
105 public void getScreenCTM() throws Exception {
106 final String html = DOCTYPE_HTML
107 + "<html><body>\n"
108 + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n"
109 + " </svg>\n"
110 + "<script>\n"
111 + LOG_TITLE_FUNCTION
112 + " var svg = document.getElementById('myId');\n"
113 + " try {\n"
114 + " log(svg.getScreenCTM());\n"
115 + " } catch(e) { logEx(e); }\n"
116 + "</script>\n"
117 + "</body></html>";
118
119 loadPageVerifyTitle2(html);
120 }
121 }