[HtmlUnit] SVN: [15465] trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit

rbri--- via HtmlUnit-develop <[email protected]> Sun, 15 Jul 2018 17:38:16 +0000
Newsgroups gmane.comp.java.htmlunit.devel
Message-ID <[email protected]>
Revision: 15465
          http://sourceforge.net/p/htmlunit/code/15465
Author:   rbri
Date:     2018-07-15 17:38:14 +0000 (Sun, 15 Jul 2018)
Log Message:
-----------
next step in our endless encoding fight

Modified Paths:
--------------
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java	2018-07-15 15:06:46 UTC (rev 15464)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java	2018-07-15 17:38:14 UTC (rev 15465)
@@ -38,7 +38,7 @@
     private final String firstResponse_;
     private final String otherResponse_;
     private ServerSocket server_;
-    private Charset charset_ = StandardCharsets.UTF_8;
+    private Charset charset_ = StandardCharsets.ISO_8859_1;
     private List<String> requests_ = new ArrayList<>();
 
     /**
@@ -87,17 +87,27 @@
                                 break;
                             }
                         }
-                        requests_.add(writer.toString());
-                        try (OutputStream out = socket.getOutputStream()) {
-                            final String response;
-                            if (first || otherResponse_ == null) {
-                                response = firstResponse_;
+                        final String requestString = writer.toString();
+
+                        final String response;
+                        if (requestString.contains("/favicon.ico")) {
+                            response = "HTTP/1.1 404 Not Found\r\n"
+                                    + "Content-Length: 0\r\n"
+                                    + "Content-Type: text/html; charset=iso-8859-1\r\n"
+                                    + "Connection: Closed\r\n\r\n";
+                        }
+                        else {
+                            requests_.add(writer.toString());
+                            try (OutputStream out = socket.getOutputStream()) {
+                                if (first || otherResponse_ == null) {
+                                    response = firstResponse_;
+                                }
+                                else {
+                                    response = otherResponse_;
+                                }
+                                first = false;
+                                out.write(response.getBytes(charset_));
                             }
-                            else {
-                                response = otherResponse_;
-                            }
-                            first = false;
-                            out.write(response.getBytes(charset_));
                         }
                     }
                 }

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java	2018-07-15 15:06:46 UTC (rev 15464)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java	2018-07-15 17:38:14 UTC (rev 15465)
@@ -158,8 +158,8 @@
      * @throws Exception if the test fails
      */
     @Test
-    @Alerts(DEFAULT = "/bug.html?k%C3%B6nig",
-            IE = "/bug.html?k\u00c3\u00b6nig")
+    @Alerts(DEFAULT = "/bug.html?k%EF%BF%BDnig",
+            IE = "/bug.html?k\u00ef\u00bf\u00bdnig")
     @NotYetImplemented(IE)
     public void linkUrlEncodingUTF8() throws Exception {
         final String html = "<html>\n"
@@ -176,14 +176,17 @@
                 + "\r\n"
                 + html;
 
-        final String response = "HTTP/1.1 200 OK\r\n"
-                + "Content-Length: 2\r\n"
+        final String html2 = "<html><head><title>foo</title></head><body>"
+                + "</body></html>";
+
+        final String secondResponse = "HTTP/1.1 200 OK\r\n"
+                + "Content-Length: " + html2.length() + "\r\n"
                 + "Content-Type: text/html\r\n"
                 + "\r\n"
-                + "<html><head><title>foo</title></head><body>"
-                + "</body></html>";
+                + html2;
 
-        primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, response);
+        primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse);
+        primitiveWebServer_.setCharset(StandardCharsets.ISO_8859_1);
         primitiveWebServer_.start();
 
         final WebDriver driver = getWebDriver();
@@ -192,9 +195,6 @@
         driver.findElement(By.id("myLink")).click();
 
         String reqUrl = primitiveWebServer_.getRequests().get(1);
-        if (reqUrl.contains("/favicon.ico")) {
-            reqUrl = primitiveWebServer_.getRequests().get(2);
-        }
         reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1);
 
         assertEquals(getExpectedAlerts()[0], reqUrl);

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java	2018-07-15 15:06:46 UTC (rev 15464)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java	2018-07-15 17:38:14 UTC (rev 15465)
@@ -1641,7 +1641,7 @@
         final URL url = new URL("http://host/x+y\u00E9/a\u00E9 b?c \u00E9 d");
         final HtmlPage page = loadPage(BrowserVersion.FIREFOX_60, "<html></html>", new ArrayList<String>(), url);
         final WebRequest wrs = page.getWebResponse().getWebRequest();
-        assertEquals("http://host/x+y%C3%A9/a%C3%A9%20b?c%20%E9%20d", wrs.getUrl());
+        assertEquals("http://host/x+y%C3%A9/a%C3%A9%20b?c%20%C3%A9%20d", wrs.getUrl());
     }
 
     /**

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java	2018-07-15 15:06:46 UTC (rev 15464)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java	2018-07-15 17:38:14 UTC (rev 15465)
@@ -46,6 +46,7 @@
  *
  * @author Marc Guillemot
  * @author Ahmed Ashour
+ * @author Ronald Brill
  */
 @RunWith(BrowserRunner.class)
 public class WebResponseTest extends WebServerTestCase {
@@ -54,7 +55,7 @@
      * @throws Exception if the test fails
      */
     @Test
-    public void encoding() throws Exception {
+    public void encodingCharsetUtf8() throws Exception {
         final String title = "\u6211\u662F\u6211\u7684FOCUS";
         final String content =
             "<html><head>\n"
@@ -66,7 +67,7 @@
         final WebClient client = getWebClient();
 
         final MockWebConnection webConnection = new MockWebConnection();
-        webConnection.setResponse(URL_FIRST, content.getBytes(UTF_8), 200, "OK", "text/html", null);
+        webConnection.setResponse(URL_FIRST, content.getBytes(UTF_8), 200, "OK", "text/html; charset=UTF-8", null);
         client.setWebConnection(webConnection);
         final WebRequest request = new WebRequest(URL_FIRST);
         request.setCharset(UTF_8);


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot