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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

rbri
Revision: 14463
          http://sourceforge.net/p/htmlunit/code/14463
Author:   rbri
Date:     2017-05-19 14:10:08 +0000 (Fri, 19 May 2017)
Log Message:
-----------
test added
Issue 1885

Modified Paths:
--------------
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2017-05-18 18:04:02 UTC (rev 14462)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2017-05-19 14:10:08 UTC (rev 14463)
@@ -705,6 +705,12 @@
                 webRequest.setRequestParameters(requestParameters);
             }
 
+            // check content type if it is multipart enctype
+            if (request.getContentType() != null
+                        && request.getContentType().startsWith(FormEncodingType.MULTIPART.getName())) {
+                webRequest.setEncodingType(FormEncodingType.MULTIPART);
+            }
+
             final RawResponseData resp = MockConnection_.getRawResponse(webRequest);
 
             // write WebResponse to HttpServletResponse

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java 2017-05-18 18:04:02 UTC (rev 14462)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java 2017-05-19 14:10:08 UTC (rev 14463)
@@ -31,6 +31,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.http.entity.ContentType;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.openqa.selenium.By;
@@ -41,6 +42,8 @@
 import com.gargoylesoftware.htmlunit.BrowserRunner;
 import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts;
 import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented;
+import com.gargoylesoftware.htmlunit.FormEncodingType;
+import com.gargoylesoftware.htmlunit.HttpMethod;
 import com.gargoylesoftware.htmlunit.MockWebConnection;
 import com.gargoylesoftware.htmlunit.WebDriverTestCase;
 import com.gargoylesoftware.htmlunit.util.NameValuePair;
@@ -405,6 +408,67 @@
     }
 
     /**
+     * @throws Exception if an error occurs
+     */
+    @Test
+    public void formMultipartEncodingTypeTest() throws Exception {
+        final String html = "<!DOCTYPE html>\n"
+            + "<html><head><title>first</title></head><body>\n"
+            + "  <p>hello world</p>\n"
+            + "  <form id='myForm' action='" + URL_SECOND
+                    + "' method='" + HttpMethod.POST
+                    + "' enctype='" + FormEncodingType.MULTIPART.getName()
+                    + "'>\n"
+            + "    <input type='file' value='file1'>\n"
+            + "    <button id='myButton' type='submit'>Submit</button>\n"
+            + "  </form>\n"
+            + "</body></html>";
+        final String secondContent
+            = "<html><head><title>second</title></head><body>\n"
+            + "  <p>hello world</p>\n"
+            + "</body></html>";
+
+        getMockWebConnection().setResponse(URL_SECOND, secondContent, ContentType.MULTIPART_FORM_DATA.getMimeType());
+
+        final WebDriver driver = loadPage2(html, URL_FIRST);
+        driver.findElement(By.id("myButton")).click();
+
+        assertEquals(2, getMockWebConnection().getRequestCount());
+        assertEquals(URL_SECOND.toString(), getMockWebConnection().getLastWebRequest().getUrl());
+        assertEquals(FormEncodingType.MULTIPART, getMockWebConnection().getLastWebRequest().getEncodingType());
+    }
+
+    /**
+     * @throws Exception if an error occurs
+     */
+    @Test
+    public void formUrlEncodedEncodingTypeTest() throws Exception {
+        final String html = "<!DOCTYPE html>\n"
+            + "<html><head><title>first</title></head><body>\n"
+            + "  <p>hello world</p>\n"
+            + "  <form id='myForm' action='" + URL_SECOND
+                        + "' method='" + HttpMethod.POST
+                        + "' enctype='" + FormEncodingType.URL_ENCODED.getName()
+                        + "'>\n"
+            + "    <button id='myButton' type='submit'>Submit</button>\n"
+            + "  </form>\n"
+            + "</body></html>";
+        final String secondContent
+            = "<html><head><title>second</title></head><body>\n"
+            + "  <p>hello world</p>\n"
+            + "</body></html>";
+
+        getMockWebConnection().setResponse(URL_SECOND, secondContent);
+
+        final WebDriver driver = loadPage2(html, URL_FIRST);
+        driver.findElement(By.id("myButton")).click();
+
+        assertEquals(2, getMockWebConnection().getRequestCount());
+        assertEquals(URL_SECOND.toString(), getMockWebConnection().getLastWebRequest().getUrl());
+        assertEquals(FormEncodingType.URL_ENCODED, getMockWebConnection().getLastWebRequest().getEncodingType());
+    }
+
+    /**
      * Servlet for {@link #acceptEncodingHeader()}.
      */
     public static class AcceptEncodingHeaderServlet extends HttpServlet {


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
HtmlUnit-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop
Loading...