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.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 @RunWith(BrowserRunner.class)
30 public class HTMLBaseElementTest extends WebDriverTestCase {
31
32
33
34
35 @Test
36 @Alerts({"http://www.foo.com/images/", "§§URL§§", "", "_blank"})
37 public void hrefAndTarget() throws Exception {
38 final String html = DOCTYPE_HTML
39 + "<html>\n"
40 + " <head>\n"
41 + " <base id='b1' href='http://www.foo.com/images/' />\n"
42 + " <base id='b2' target='_blank' />\n"
43 + " <script>\n"
44 + LOG_TITLE_FUNCTION
45 + " function test() {\n"
46 + " log(document.getElementById('b1').href);\n"
47 + " log(document.getElementById('b2').href);\n"
48 + " log(document.getElementById('b1').target);\n"
49 + " log(document.getElementById('b2').target);\n"
50 + " }\n"
51 + " </script>\n"
52 + " </head>\n"
53 + " <body onload='test()'>foo</body>\n"
54 + "</html>";
55
56 expandExpectedAlertsVariables(URL_FIRST);
57 loadPageVerifyTitle2(html);
58 }
59
60
61
62
63 @Test
64 @Alerts({"[object HTMLBaseElement]", "function HTMLBaseElement() { [native code] }"})
65 public void type() throws Exception {
66 final String html = DOCTYPE_HTML
67 + "<html><head>\n"
68 + "<script>\n"
69 + LOG_TITLE_FUNCTION
70 + " function test() {\n"
71 + " var elem = document.getElementById('b1');\n"
72 + " try {\n"
73 + " log(elem);\n"
74 + " log(HTMLBaseElement);\n"
75 + " } catch(e) { logEx(e); }\n"
76 + " }\n"
77 + "</script>\n"
78 + "</head>\n"
79 + "<body onload='test()'>\n"
80 + " <base id='b1' href='http://somehost/images/' />\n"
81 + "</body></html>";
82
83 loadPageVerifyTitle2(html);
84 }
85 }