From: <rb...@us...> - 2013-11-26 18:40:50
|
Revision: 8807 http://sourceforge.net/p/htmlunit/code/8807 Author: rbri Date: 2013-11-26 18:40:44 +0000 (Tue, 26 Nov 2013) Log Message: ----------- form.enctype property default value Issue 1560 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-11-24 19:35:40 UTC (rev 8806) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-11-26 18:40:44 UTC (rev 8807) @@ -900,12 +900,8 @@ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME), @WebBrowser(value = IE, minVersion = 10) }) JS_FORM_ACTION_EXPANDURL, - /** Indicates if form.encoding returns a recognized value when attribute is incorrect. */ - @BrowserFeature({ @WebBrowser(value = FF, minVersion = 17), @WebBrowser(value = IE, minVersion = 10) }) - JS_FORM_ENCODING_NORMALIZED, - /** Setting form.encoding only allowed for valid encodings. */ - @BrowserFeature({ @WebBrowser(value = IE, minVersion = 10) }) + @BrowserFeature(@WebBrowser(IE)) JS_FORM_REJECT_INVALID_ENCODING, /** Indicated that the body of a not yet loaded frame/iframe is null. */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java 2013-11-24 19:35:40 UTC (rev 8806) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java 2013-11-26 18:40:44 UTC (rev 8807) @@ -18,7 +18,6 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_80; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_81; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FORM_ACTION_EXPANDURL; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FORM_ENCODING_NORMALIZED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FORM_REJECT_INVALID_ENCODING; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; @@ -270,10 +269,10 @@ @JsxGetter public String getEncoding() { final String encoding = getHtmlForm().getEnctypeAttribute(); - if (getBrowserVersion().hasFeature(JS_FORM_ENCODING_NORMALIZED)) { - if (!"application/x-www-form-urlencoded".equals(encoding) && !"multipart/form-data".equals(encoding)) { - return "application/x-www-form-urlencoded"; - } + if (!"application/x-www-form-urlencoded".equals(encoding) + && !"multipart/form-data".equals(encoding) + && !"text/plain".equals(encoding)) { + return "application/x-www-form-urlencoded"; } return encoding; } @@ -316,8 +315,7 @@ final WebRequest request = getHtmlForm().getWebRequest(null); final String target = page.getResolvedTarget(getTarget()); final boolean isHashJump = HttpMethod.GET == request.getHttpMethod() && action.endsWith("#"); - webClient.download(page.getEnclosingWindow(), target, request, - isHashJump, "JS form.submit()"); + webClient.download(page.getEnclosingWindow(), target, request, isHashJump, "JS form.submit()"); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java 2013-11-24 19:35:40 UTC (rev 8806) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java 2013-11-26 18:40:44 UTC (rev 8807) @@ -197,6 +197,88 @@ * @throws Exception if the test fails */ @Test + @Alerts("application/x-www-form-urlencoded") + public void defaultEnctype() throws Exception { + enctype(null); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("application/x-www-form-urlencoded") + public void emptyEnctype() throws Exception { + enctype(""); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("application/x-www-form-urlencoded") + public void blankEnctype() throws Exception { + enctype(" "); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("application/x-www-form-urlencoded") + public void unknownEnctype() throws Exception { + enctype("unknown"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("application/x-www-form-urlencoded") + public void urlencodedEnctype() throws Exception { + enctype("application/x-www-form-urlencoded"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("multipart/form-data") + public void multipartEnctype() throws Exception { + enctype("multipart/form-data"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("text/plain") + public void plainEnctype() throws Exception { + enctype("text/plain"); + } + + private void enctype(final String encoding) throws Exception { + String html + = "<html><head><title>foo</title><script>\n" + + "function doTest(){\n" + + " alert(document.forms[0].encoding);\n" + + "}\n" + + "</script></head><body onload='doTest()'>\n" + + "<form name='testForm'"; + if (null != encoding) { + html = html + " enctype='" + encoding + "'"; + } + html = html + ">\n" + + " <input type='submit' name='submit1'/>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts({ "multipart/form-data", "application/x-www-form-urlencoded", "application/x-www-form-urlencoded" }) public void encodingProperty() throws Exception { doTestProperty("encoding", "enctype", "multipart/form-data", "application/x-www-form-urlencoded"); @@ -206,9 +288,18 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "myEncoding", "newEncoding", "newEncoding" }, - FF = { "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "newEncoding" }, - IE10 = { "application/x-www-form-urlencoded", "exception" }) + @Alerts(DEFAULT = { "text/plain", "application/x-www-form-urlencoded", "newEncoding" }, + IE = { "text/plain", "exception" }) + public void encodingProperty_textPlain() throws Exception { + doTestProperty("encoding", "enctype", "text/plain", "newEncoding"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "newEncoding" }, + IE = { "application/x-www-form-urlencoded", "exception" }) public void encodingProperty_dummyValues() throws Exception { doTestProperty("encoding", "enctype", "myEncoding", "newEncoding"); } @@ -870,9 +961,6 @@ @Alerts(DEFAULT = "2", IE10 = "3") public void submit_twice() throws Exception { - final String count = getExpectedAlerts()[0]; - setExpectedAlerts(); - final String html = "<html><head><script>\n" + "function test() {\n" + " var f = document.forms[0];\n" @@ -885,8 +973,9 @@ + "</form></body></html>"; getMockWebConnection().setDefaultResponse(""); - loadPageWithAlerts2(html); - assertEquals(Integer.parseInt(count), getMockWebConnection().getRequestCount()); + loadPage2(html); + + assertEquals(Integer.parseInt(getExpectedAlerts()[0]), getMockWebConnection().getRequestCount()); } /** |