From: <mgu...@us...> - 2013-05-23 13:58:38
|
Revision: 8288 http://sourceforge.net/p/htmlunit/code/8288 Author: mguillem Date: 2013-05-23 13:58:35 +0000 (Thu, 23 May 2013) Log Message: ----------- dispatchEvent of type submit on a form has to submit the form Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 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-05-23 13:54:10 UTC (rev 8287) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java 2013-05-23 13:58:35 UTC (rev 8288) @@ -54,6 +54,7 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; +import com.gargoylesoftware.htmlunit.javascript.host.Event; import com.gargoylesoftware.htmlunit.protocol.javascript.JavaScriptURLConnection; /** @@ -471,4 +472,12 @@ return null; } + @Override + public boolean dispatchEvent(final Event event) { + if (event.getType().equals(Event.TYPE_SUBMIT)) { + submit(); + return true; + } + return super.dispatchEvent(event); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2013-05-23 13:54:10 UTC (rev 8287) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2013-05-23 13:58:35 UTC (rev 8288) @@ -18,6 +18,8 @@ import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF17; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; +import java.net.URL; + import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.WebDriver; @@ -2033,6 +2035,48 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = "page2 loaded", IE = "exception") + public void dispatchEvent_submitOnForm() throws Exception { + final String html = "<html><head><title>page 1</title></head><body>\n" + + "<form action='page2' id='theForm'><span id='foo'/></form>\n" + + "<script>\n" + + "try {\n" + + " var e = document.createEvent('HTMLEvents');\n" + + " e.initEvent('submit', true, false);\n" + + " document.getElementById('theForm').dispatchEvent(e);\n" + + "} catch(e) { alert('exception'); }\n" + + "</script></body></html>"; + + final String page2 = "<html><body><script>alert('page2 loaded');</script></body></html>"; + + getMockWebConnection().setResponse(new URL(getDefaultUrl() + "page2"), page2); + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(IE = "exception") + public void dispatchEvent_submitOnFormChild() throws Exception { + final String html = "<html><head><title>page 1</title></head><body>\n" + + "<form action='page2'><span id='foo'/></form>\n" + + "<script>\n" + + "try {\n" + + " var e = document.createEvent('HTMLEvents');\n" + + " e.initEvent('submit', true, false);\n" + + " document.getElementById('foo').dispatchEvent(e);\n" + + "} catch(e) { alert('exception'); }\n" + + "</script></body></html>"; + + final WebDriver webDriver = loadPageWithAlerts2(html); + assertEquals("page 1", webDriver.getTitle()); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts(DEFAULT = { "true", "true", "false" }, IE = "exception") public void hasAttribute() throws Exception { final String html = |