From: <rb...@us...> - 2014-01-28 19:50:45
|
Revision: 9082 http://sourceforge.net/p/htmlunit/code/9082 Author: rbri Date: 2014-01-28 19:50:41 +0000 (Tue, 28 Jan 2014) Log Message: ----------- Missing enctype property support added to forms Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml 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/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2014-01-28 19:01:06 UTC (rev 9081) +++ trunk/htmlunit/src/changes/changes.xml 2014-01-28 19:50:41 UTC (rev 9082) @@ -9,6 +9,9 @@ <body> <release version="2.14" date="???" description="FF24, Bugfixes, initial work on IE11"> <action type="fix" dev="rbri"> + JavaScript: Missing enctype property support added to forms. + </action> + <action type="fix" dev="rbri"> JavaScript: Attr firstChild/lastChild fixed when no child at all (FF). </action> <action type="fix" dev="rbri" due-to="Frank Danek"> 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 2014-01-28 19:01:06 UTC (rev 9081) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java 2014-01-28 19:50:41 UTC (rev 9082) @@ -33,6 +33,7 @@ import org.apache.commons.lang3.StringUtils; +import com.gargoylesoftware.htmlunit.FormEncodingType; import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.WebAssert; import com.gargoylesoftware.htmlunit.WebClient; @@ -263,36 +264,55 @@ } /** - * Returns the value of the JavaScript attribute "encoding". + * Returns the value of the JavaScript attribute "enctype". * @return the value of this attribute */ @JsxGetter - public String getEncoding() { + public String getEnctype() { final String encoding = getHtmlForm().getEnctypeAttribute(); - if (!"application/x-www-form-urlencoded".equals(encoding) - && !"multipart/form-data".equals(encoding) + if (!FormEncodingType.URL_ENCODED.getName().equals(encoding) + && !FormEncodingType.MULTIPART.getName().equals(encoding) && !"text/plain".equals(encoding)) { - return "application/x-www-form-urlencoded"; + return FormEncodingType.URL_ENCODED.getName(); } return encoding; } /** - * Sets the value of the JavaScript attribute "encoding". - * @param encoding the new value + * Sets the value of the JavaScript attribute "enctype". + * @param enctype the new value */ @JsxSetter - public void setEncoding(final String encoding) { - WebAssert.notNull("encoding", encoding); + public void setEnctype(final String enctype) { + WebAssert.notNull("encoding", enctype); if (getBrowserVersion().hasFeature(JS_FORM_REJECT_INVALID_ENCODING)) { - if (!"application/x-www-form-urlencoded".equals(encoding) && !"multipart/form-data".equals(encoding)) { + if (!FormEncodingType.URL_ENCODED.getName().equals(enctype) + && !FormEncodingType.MULTIPART.getName().equals(enctype)) { throw Context.reportRuntimeError("Cannot set the encoding property to invalid value: '" - + encoding + "'"); + + enctype + "'"); } } - getHtmlForm().setEnctypeAttribute(encoding); + getHtmlForm().setEnctypeAttribute(enctype); } + /** + * Returns the value of the JavaScript attribute "encoding". + * @return the value of this attribute + */ + @JsxGetter + public String getEncoding() { + return getEnctype(); + } + + /** + * Sets the value of the JavaScript attribute "encoding". + * @param encoding the new value + */ + @JsxSetter + public void setEncoding(final String encoding) { + setEnctype(encoding); + } + private HtmlForm getHtmlForm() { return (HtmlForm) getDomNodeOrDie(); } 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 2014-01-28 19:01:06 UTC (rev 9081) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java 2014-01-28 19:50:41 UTC (rev 9082) @@ -1053,7 +1053,6 @@ */ @Test @Alerts("application/x-www-form-urlencoded") - @NotYetImplemented public void enctype_defaultValue() throws Exception { final String html = "<html><body><script>\n" + "alert(document.createElement('form').enctype)\n" |