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.junit.Test;
21 import org.junit.runner.RunWith;
22
23
24
25
26
27
28
29
30 @RunWith(BrowserRunner.class)
31 public class SVGTest extends WebDriverTestCase {
32
33
34
35
36
37 @Test
38 @Alerts("svgElem")
39 public void getAttribute() throws Exception {
40 final String html = DOCTYPE_HTML
41 + "<html><body>\n"
42 + "<script>\n"
43 + LOG_TITLE_FUNCTION
44 + "try {\n"
45 + " var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');\n"
46 + " svg.setAttribute('id', 'svgElem');\n"
47 + " document.body.appendChild(svg);\n"
48 + " log(document.getElementById('svgElem').getAttribute('id'));\n"
49 + "} catch(e) { logEx(e); }\n"
50 + "</script></body></html>";
51
52 loadPageVerifyTitle2(html);
53 }
54
55
56
57
58
59 @Test
60 @Alerts("clicked")
61 public void triggerEvent() throws Exception {
62 final String html = DOCTYPE_HTML
63 + "<html>\n"
64 + "<head>\n"
65 + "<script>\n"
66 + LOG_TITLE_FUNCTION
67 + " function init() {\n"
68 + " try {\n"
69 + " var rect = document.getElementById('rect');\n"
70 + " rect.addEventListener('click', function() { log('clicked') });\n"
71
72 + " var e = document.createEvent('MouseEvents');\n"
73 + " e.initEvent('click', true, false);\n"
74 + " document.getElementById('rect').dispatchEvent(e);\n"
75 + " } catch(e) { logEx(e); }\n"
76 + " }\n"
77 + "</script>\n"
78 + "</head>\n"
79 + "<body onload='init()'>\n"
80 + "<svg xmlns='http://www.w3.org/2000/svg' version='1.1'>\n"
81 + " <rect id='rect' width='300' height='100' />\n"
82 + "</svg>\n"
83 + "</body>\n"
84 + "</html>";
85
86 loadPageVerifyTitle2(html);
87 }
88 }