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 import org.openqa.selenium.By;
23 import org.openqa.selenium.WebDriver;
24
25
26
27
28
29
30
31
32
33
34 @RunWith(BrowserRunner.class)
35 public class HTMLSpanElementTest extends WebDriverTestCase {
36
37
38
39
40 @Test
41 @Alerts("no")
42 public void doScroll() throws Exception {
43 final String html = DOCTYPE_HTML
44 + "<html>\n"
45 + " <head>\n"
46 + " <script>\n"
47 + LOG_TITLE_FUNCTION
48 + " function test() {\n"
49 + " var span = document.getElementById('s');\n"
50 + " if(span.doScroll) {\n"
51 + " log('yes');\n"
52 + " span.doScroll();\n"
53 + " span.doScroll('down');\n"
54 + " } else {\n"
55 + " log('no');\n"
56 + " }\n"
57 + " }\n"
58 + " </script>\n"
59 + " </head>\n"
60 + " <body onload='test()'><span id='s'>abc</span></body>\n"
61 + "</html>";
62
63 loadPageVerifyTitle2(html);
64 }
65
66
67
68
69 @Test
70 @Alerts("[object HTMLSpanElement] undefined")
71 public void cite() throws Exception {
72 final String html = DOCTYPE_HTML
73 + "<html>\n"
74 + " <head>\n"
75 + " <script>\n"
76 + LOG_TITLE_FUNCTION
77 + " function test() {\n"
78 + " debug(document.createElement('span'));\n"
79 + " }\n"
80 + " function debug(e) {\n"
81 + " log(e + ' ' + e.cite);\n"
82 + " }\n"
83 + " </script>\n"
84 + " </head>\n"
85 + " <body onload='test()'></body>\n"
86 + "</html>";
87
88 loadPageVerifyTitle2(html);
89 }
90
91
92
93
94 @Test
95 @Alerts("beforeSpace afterSpace")
96 public void getText() throws Exception {
97 final String html = DOCTYPE_HTML
98 + "<html><head></head><body>\n"
99 + "<div id='foo'><span>beforeSpace</span><span> </span><span>afterSpace</span></div>\n"
100 + "</body></html>";
101
102 final WebDriver driver = loadPage2(html);
103 assertEquals(getExpectedAlerts()[0], driver.findElement(By.id("foo")).getText());
104 }
105 }