1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.html;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.annotation.Alerts;
19 import org.junit.jupiter.api.Test;
20 import org.openqa.selenium.By;
21 import org.openqa.selenium.WebDriver;
22 import org.openqa.selenium.htmlunit.HtmlUnitDriver;
23
24
25
26
27
28
29
30
31
32 public class HtmlHeadTest extends WebDriverTestCase {
33
34
35
36
37
38 @Test
39 @Alerts("HEAD")
40 public void addedWhenMissing() throws Exception {
41 final String htmlContent =
42 "<html><body>\n"
43 + "<script>\n"
44 + LOG_TITLE_FUNCTION
45 + " log(document.firstChild.firstChild.tagName);\n"
46 + "</script>\n"
47 + "</body></html>";
48
49 loadPageVerifyTitle2(htmlContent);
50 }
51
52
53
54
55 @Test
56 @Alerts("[object HTMLHeadElement]")
57 public void simpleScriptable() throws Exception {
58 final String html = DOCTYPE_HTML
59 + "<html><head id='myId'><script>\n"
60 + LOG_TITLE_FUNCTION
61 + " function test() {\n"
62 + " log(document.getElementById('myId'));\n"
63 + " }\n"
64 + "</script>\n"
65 + "</head><body onload='test()'>\n"
66 + "</body></html>";
67
68 final WebDriver driver = loadPageVerifyTitle2(html);
69 if (driver instanceof HtmlUnitDriver) {
70 final HtmlElement element = toHtmlElement(driver.findElement(By.id("myId")));
71 assertTrue(element instanceof HtmlHead);
72 }
73 }
74 }