1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.html;
16
17 import org.htmlunit.MockWebConnection;
18 import org.htmlunit.SimpleWebTestCase;
19 import org.htmlunit.WebClient;
20 import org.htmlunit.junit.annotation.Alerts;
21 import org.junit.jupiter.api.Test;
22
23
24
25
26
27
28
29
30 public class HtmlNoScript2Test extends SimpleWebTestCase {
31
32
33
34
35 @Test
36 @Alerts("<body>\r\n"
37 + " <noscript><div>hello</noscript>\r\n"
38 + "</body>")
39 public void asXml_jsEnabled() throws Exception {
40 final String html = DOCTYPE_HTML
41 + "<html><body>\n"
42 + "<noscript><div>hello</noscript>"
43 + "</body></html>";
44
45 final HtmlPage page = loadPage(html);
46 assertEquals(getExpectedAlerts()[0], page.getBody().asXml());
47 }
48
49
50
51
52 @Test
53 public void asXml_jsDisabled() throws Exception {
54 final String html = DOCTYPE_HTML
55 + "<html><body>\n"
56 + "<noscript><div>hello</noscript>"
57 + "</body></html>";
58
59 final String expected = "<body>\r\n"
60 + " <noscript>\r\n"
61 + " <div>hello</div>\r\n"
62 + " </noscript>\r\n"
63 + "</body>";
64
65 final WebClient client = getWebClient();
66 client.getOptions().setJavaScriptEnabled(false);
67
68 final MockWebConnection webConnection = new MockWebConnection();
69 webConnection.setDefaultResponse(html);
70 client.setWebConnection(webConnection);
71
72 final HtmlPage page = client.getPage(URL_FIRST);
73 assertEquals(expected, page.getBody().asXml());
74 }
75
76
77
78
79 @Test
80 public void asNormalizedTextjsEnabled() throws Exception {
81 final String htmlContent = DOCTYPE_HTML
82 + "<html><body>\n"
83 + "<noscript>hello</noscript>"
84 + "</body></html>";
85
86 final HtmlPage page = loadPage(htmlContent);
87 assertEquals("", page.getBody().asNormalizedText());
88 }
89
90
91
92
93 @Test
94 public void asNormalizedText_jsDisabled() throws Exception {
95 final String html = DOCTYPE_HTML
96 + "<html><body>\n"
97 + "<noscript>hello</noscript>"
98 + "</body></html>";
99
100 final String expected = "hello";
101
102 final WebClient client = getWebClient();
103 client.getOptions().setJavaScriptEnabled(false);
104
105 final MockWebConnection webConnection = new MockWebConnection();
106 webConnection.setDefaultResponse(html);
107 client.setWebConnection(webConnection);
108
109 final HtmlPage page = client.getPage(URL_FIRST);
110 assertEquals(expected, page.getBody().asNormalizedText());
111 }
112
113
114
115
116 @Test
117 public void isEmptyXmlTagExpanded() throws Exception {
118 final String html = DOCTYPE_HTML
119 + "<html><body>\n"
120 + "<noscript></noscript>"
121 + "</body></html>";
122
123 final HtmlPage page = loadPage(html);
124 assertTrue(page.asXml().contains("</noscript>"));
125 }
126 }