1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.html;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.annotation.Alerts;
19 import org.junit.jupiter.api.Test;
20
21
22
23
24
25
26
27 public class HTMLBaseElementTest extends WebDriverTestCase {
28
29
30
31
32 @Test
33 @Alerts({"http://www.foo.com/images/", "§§URL§§", "", "_blank"})
34 public void hrefAndTarget() throws Exception {
35 final String html = DOCTYPE_HTML
36 + "<html>\n"
37 + " <head>\n"
38 + " <base id='b1' href='http://www.foo.com/images/' />\n"
39 + " <base id='b2' target='_blank' />\n"
40 + " <script>\n"
41 + LOG_TITLE_FUNCTION
42 + " function test() {\n"
43 + " log(document.getElementById('b1').href);\n"
44 + " log(document.getElementById('b2').href);\n"
45 + " log(document.getElementById('b1').target);\n"
46 + " log(document.getElementById('b2').target);\n"
47 + " }\n"
48 + " </script>\n"
49 + " </head>\n"
50 + " <body onload='test()'>foo</body>\n"
51 + "</html>";
52
53 expandExpectedAlertsVariables(URL_FIRST);
54 loadPageVerifyTitle2(html);
55 }
56
57
58
59
60 @Test
61 @Alerts({"[object HTMLBaseElement]", "function HTMLBaseElement() { [native code] }"})
62 public void type() throws Exception {
63 final String html = DOCTYPE_HTML
64 + "<html><head>\n"
65 + "<script>\n"
66 + LOG_TITLE_FUNCTION
67 + " function test() {\n"
68 + " var elem = document.getElementById('b1');\n"
69 + " try {\n"
70 + " log(elem);\n"
71 + " log(HTMLBaseElement);\n"
72 + " } catch(e) { logEx(e); }\n"
73 + " }\n"
74 + "</script>\n"
75 + "</head>\n"
76 + "<body onload='test()'>\n"
77 + " <base id='b1' href='http://somehost/images/' />\n"
78 + "</body></html>";
79
80 loadPageVerifyTitle2(html);
81 }
82 }