1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.svg;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.html.DomElement;
19 import org.htmlunit.html.HtmlPage;
20 import org.htmlunit.html.HtmlScript;
21 import org.htmlunit.junit.BrowserRunner;
22 import org.htmlunit.junit.annotation.Alerts;
23 import org.htmlunit.junit.annotation.HtmlUnitNYI;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.openqa.selenium.WebDriver;
27 import org.openqa.selenium.htmlunit.HtmlUnitDriver;
28
29
30
31
32
33
34
35
36 @RunWith(BrowserRunner.class)
37 public class SvgScriptTest extends WebDriverTestCase {
38
39
40
41
42 @Test
43 @Alerts("[object SVGScriptElement]")
44 public void simpleScriptable() throws Exception {
45 final String html = DOCTYPE_HTML
46 + "<html><head>\n"
47 + "<script>\n"
48 + LOG_TITLE_FUNCTION
49 + " function test() {\n"
50 + " log(document.getElementById('myId'));\n"
51 + " }\n"
52 + "</script>\n"
53 + "</head><body onload='test()'>\n"
54 + " <svg xmlns='http://www.w3.org/2000/svg' version='1.1'>\n"
55 + " <script id='myId'></script>\n"
56 + " </svg>\n"
57 + "</body></html>";
58
59 final WebDriver driver = loadPageVerifyTitle2(html);
60 if (driver instanceof HtmlUnitDriver) {
61 final HtmlPage page = (HtmlPage) getEnclosedPage();
62 assertType(getExpectedAlerts()[0], page.getElementById("myId"));
63 }
64 }
65
66 private void assertType(final String expectedAlert, final DomElement element) {
67 if ("[object SVGScriptElement]".equals(expectedAlert)) {
68 assertTrue(SvgScript.class.isInstance(element));
69 }
70 else {
71 assertTrue(HtmlScript.class.isInstance(element));
72 }
73 }
74
75
76
77
78 @Test
79 @Alerts({"[object SVGScriptElement]", "[object HTMLScriptElement]"})
80 @HtmlUnitNYI(CHROME = {"[object SVGScriptElement]", "[object SVGScriptElement]"},
81 EDGE = {"[object SVGScriptElement]", "[object SVGScriptElement]"},
82 FF = {"[object SVGScriptElement]", "[object SVGScriptElement]"},
83 FF_ESR = {"[object SVGScriptElement]", "[object SVGScriptElement]"})
84 public void htmlOrSvg() throws Exception {
85 final String html = "<svg xmlns='http://www.w3.org/2000/svg' version='1.1'>\n"
86 + "<script id='id1'>\n"
87 + LOG_TITLE_FUNCTION
88 + " function test() {\n"
89 + " log(document.getElementById('id1'));\n"
90 + " log(document.getElementById('id2'));\n"
91 + " }\n"
92 + "</script>\n"
93 + "<body onload='test()'>\n"
94 + " <script id='id2'></script>\n"
95 + "</body>\n"
96 + "</svg>";
97
98 final WebDriver driver = loadPageVerifyTitle2(html);
99 if (driver instanceof HtmlUnitDriver) {
100 final HtmlPage page = (HtmlPage) getEnclosedPage();
101 assertType(getExpectedAlerts()[0], page.getElementById("id1"));
102 assertType(getExpectedAlerts()[1], page.getElementById("id2"));
103 }
104 }
105 }