1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit;
16
17 import java.util.ArrayList;
18 import java.util.Arrays;
19 import java.util.List;
20
21 import org.htmlunit.junit.BrowserRunner;
22 import org.htmlunit.util.MimeType;
23 import org.htmlunit.util.NameValuePair;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.openqa.selenium.WebDriver;
27
28
29
30
31
32
33
34
35
36 @RunWith(BrowserRunner.class)
37 public class HttpWebConnection2Test extends WebDriverTestCase {
38
39
40
41
42
43 @Test
44 public void brokenGzip() throws Exception {
45 final byte[] content = new byte[] {-1};
46 final List<NameValuePair> headers = new ArrayList<>();
47 headers.add(new NameValuePair("Content-Encoding", "gzip"));
48 headers.add(new NameValuePair(HttpHeader.CONTENT_LENGTH, String.valueOf(content.length)));
49
50 final MockWebConnection conn = getMockWebConnection();
51 conn.setResponse(URL_FIRST, content, 404, "OK", MimeType.TEXT_HTML, headers);
52
53
54 final WebDriver driver = loadPageWithAlerts2(URL_FIRST);
55 assertTrue(driver.getPageSource().length() > 100);
56 }
57
58
59
60
61 @Test
62 public void redirectBrokenGzip() throws Exception {
63 final String html = DOCTYPE_HTML + "<html></html>";
64
65 final List<NameValuePair> headers = Arrays.asList(new NameValuePair("Location", URL_SECOND.toString()),
66 new NameValuePair("Content-Encoding", "gzip"));
67 final MockWebConnection conn = getMockWebConnection();
68 conn.setResponse(URL_FIRST, "12", 302, "Some error", MimeType.TEXT_HTML, headers);
69 conn.setResponse(URL_SECOND, html);
70
71 final WebDriver driver = loadPageWithAlerts2(URL_FIRST);
72 assertEquals(URL_SECOND.toString(), driver.getCurrentUrl());
73 }
74
75 }