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