httpunit-commit Mailing List for httpunit (Page 56)
Brought to you by:
russgold
You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(5) |
Sep
(31) |
Oct
(39) |
Nov
(18) |
Dec
(6) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(8) |
Feb
(5) |
Mar
(8) |
Apr
(25) |
May
(20) |
Jun
(23) |
Jul
(28) |
Aug
(10) |
Sep
(3) |
Oct
(32) |
Nov
(61) |
Dec
(24) |
2002 |
Jan
(50) |
Feb
(34) |
Mar
(35) |
Apr
(3) |
May
(25) |
Jun
(25) |
Jul
(30) |
Aug
(146) |
Sep
(49) |
Oct
(156) |
Nov
(121) |
Dec
(54) |
2003 |
Jan
(12) |
Feb
(79) |
Mar
(88) |
Apr
(26) |
May
(67) |
Jun
(29) |
Jul
(8) |
Aug
(16) |
Sep
(20) |
Oct
(17) |
Nov
|
Dec
(5) |
2004 |
Jan
|
Feb
(40) |
Mar
(30) |
Apr
(5) |
May
|
Jun
(83) |
Jul
(34) |
Aug
(20) |
Sep
(44) |
Oct
(46) |
Nov
|
Dec
(14) |
2005 |
Jan
(4) |
Feb
|
Mar
(5) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
(1) |
2006 |
Jan
|
Feb
|
Mar
(26) |
Apr
(8) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(5) |
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
(36) |
May
(38) |
Jun
(1) |
Jul
(1) |
Aug
|
Sep
(4) |
Oct
|
Nov
(18) |
Dec
(4) |
2009 |
Jan
|
Feb
(2) |
Mar
(3) |
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
(35) |
Sep
(1) |
Oct
|
Nov
|
Dec
(1) |
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
(9) |
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(21) |
Oct
(18) |
Nov
(1) |
Dec
|
From: Russell G. <rus...@us...> - 2002-08-20 19:39:23
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv26478/test/com/meterware/httpunit/javascript Modified Files: FormScriptingTest.java Log Message: Added properties for Checkbox Index: FormScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- FormScriptingTest.java 20 Aug 2002 15:09:28 -0000 1.3 +++ FormScriptingTest.java 20 Aug 2002 19:39:20 -0000 1.4 @@ -25,6 +25,8 @@ import com.meterware.httpunit.HttpUnitTest; import com.meterware.httpunit.WebRequest; +import org.xml.sax.SAXException; + import junit.textui.TestRunner; import junit.framework.TestSuite; @@ -175,21 +177,72 @@ } - public void testCheckboxSetChecked() throws Exception { - defineResource( "OnCommand.html", "<html><head></head>" + + public void testCheckboxProperties() throws Exception { + defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" + + "function viewCheckbox( checkbox ) { \n" + + " alert( 'checkbox ' + checkbox.name + ' default = ' + checkbox.defaultChecked )\n;" + + " alert( 'checkbox ' + checkbox.name + ' checked = ' + checkbox.checked )\n;" + + " alert( 'checkbox ' + checkbox.name + ' value = ' + checkbox.value )\n;" + + "}\n" + + "</script></head>" + "<body>" + - "<form name='realform'><input type='checkbox' name='ready'></form>" + + "<form name='realform'><input type='checkbox' name='ready' value='good'></form>" + "<a href='#' name='clear' onMouseOver='document.realform.ready.checked=false;'>clear</a>" + "<a href='#' name='set' onMouseOver='document.realform.ready.checked=true;'>set</a>" + + "<a href='#' name='change' onMouseOver='document.realform.ready.value=\"waiting\";'>change</a>" + + "<a href='#' name='report' onMouseOver='viewCheckbox( document.realform.ready );'>report</a>" + "</body></html>" ); WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); WebForm form = response.getFormWithName( "realform" ); + verifyCheckbox( response, /* default */ false, /* checked */ false, /* value */ "good" ); + assertEquals( "initial parameter value", null, form.getParameterValue( "ready" ) ); response.getLinkWithName( "set" ).mouseOver(); - assertEquals( "changed parameter value", "on", form.getParameterValue( "ready" ) ); + assertEquals( "changed parameter value", "good", form.getParameterValue( "ready" ) ); response.getLinkWithName( "clear" ).mouseOver(); assertEquals( "final parameter value", null, form.getParameterValue( "ready" ) ); + response.getLinkWithName( "change" ).mouseOver(); + assertEquals( "final parameter value", null, form.getParameterValue( "ready" ) ); + verifyCheckbox( response, /* default */ false, /* checked */ false, /* value */ "waiting" ); + form.setParameter( "ready", "waiting" ); + } + + + private void verifyCheckbox( WebResponse response, boolean defaultChecked, boolean checked, String value ) throws SAXException { + response.getLinkWithName( "report" ).mouseOver(); + assertEquals( "Message " + 1 + "-1", "checkbox ready default = " + defaultChecked, response.popNextAlert() ); + assertEquals( "Message " + 1 + "-2", "checkbox ready checked = " + checked, response.popNextAlert() ); + assertEquals( "Message " + 1 + "-3", "checkbox ready value = " + value, response.popNextAlert() ); + } + + + public void testCheckboxOnClickEvent() throws Exception { + defineResource( "OnCommand.html", "<html><head></head>" + + "<body>" + + "<form name='the_form'>" + + " <input type='checkbox' name='color' value='blue' " + + " onClick='alert( \"color-blue is now \" + document.the_form.color.checked );'>" + + "</form>" + + "<a href='#' onClick='document.the_form.color.checked=true;'>blue</a>" + + "</body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + WebForm form = response.getFormWithName( "the_form" ); + assertEquals( "Initial state", null, form.getParameterValue( "color" ) ); + + assertEquals( "Alert message before change", null, response.getNextAlert() ); + form.removeParameter( "color" ); + assertEquals( "Alert message w/o change", null, response.getNextAlert() ); + form.setParameter( "color", "blue" ); + assertEquals( "Alert after change", "color-blue is now true", response.popNextAlert() ); + form.removeParameter( "color" ); + assertEquals( "Alert after change", "color-blue is now false", response.popNextAlert() ); + + assertEquals( "Changed state", null, form.getParameterValue( "color" ) ); + response.getLinks()[ 0 ].click(); + assertEquals( "Final state", "blue", form.getParameterValue( "color" ) ); + assertEquals( "Alert message after JavaScript change", null, response.getNextAlert() ); } |
From: Russell G. <rus...@us...> - 2002-08-20 19:39:22
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv26478 Modified Files: index.html Log Message: Added properties for Checkbox Index: index.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/index.html,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- index.html 20 Aug 2002 15:09:27 -0000 1.21 +++ index.html 20 Aug 2002 19:39:20 -0000 1.22 @@ -42,7 +42,7 @@ <h2>Where do I get releases?</h2> <blockquote>Releases of HttpUnit are available from <a href="http://sourceforge.net/project/showfiles.php?group_id=6550"> the project download page.</a> -<br>Other builds are available from <a href="http://httpunit.sourceforge.net/prerelease">the pre-release directory</a>. +<br>Other builds are available from <a href="http://www.httpunit.org/prerelease">the pre-release directory</a>. </blockquote> <h2>How do I get help, contribute, give feedback, fix bugs and so on?</h2> |
From: Russell G. <rus...@us...> - 2002-08-20 15:09:32
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv32474/test/com/meterware/httpunit/javascript Modified Files: FormScriptingTest.java ScriptingTest.java Log Message: Force graceful degregation when Rhino is missing Index: FormScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- FormScriptingTest.java 19 Aug 2002 18:52:26 -0000 1.2 +++ FormScriptingTest.java 20 Aug 2002 15:09:28 -0000 1.3 @@ -107,11 +107,28 @@ defineResource( "DoIt?color=green", "You made it!" ); defineResource( "OnCommand.html", "<html><head></head>" + "<body>" + - "<form name=spectrum action='DoIt'>" + + "<form name=spectrum action='DoIt' onsubmit='return false;'>" + " <input type=text name=color value=green>" + " <input type=button id=submit value=submit onClick='this.form.submit();'>" + "</form>" + "<a href='#' onClick='document.spectrum.submit(); return false;'>" + + "</body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + + response.getFormWithName( "spectrum" ).getButtons()[0].click(); + assertEquals( "Result of submit", "You made it!", wc.getCurrentPage().getText() ); + } + + + public void testUpdateBeforeSubmit() throws Exception { + defineResource( "DoIt?color=green", "You made it!" ); + defineResource( "OnCommand.html", "<html><head></head>" + + "<body>" + + "<form name=spectrum action='DoIt'>" + + " <input type=text name=color value=red>" + + " <input type=submit onClick='form.color.value=\"green\";'>" + + "</form>" + "</body></html>" ); WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); Index: ScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- ScriptingTest.java 16 Aug 2002 18:52:51 -0000 1.14 +++ ScriptingTest.java 20 Aug 2002 15:09:28 -0000 1.15 @@ -59,9 +59,9 @@ public void testFunctionCallOnLoad() throws Exception { defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" + - // "<!-- " + + "<!-- " + "function sayCheese() { alert( \"Cheese!\" ); }" + - // "// -->" + + "// -->" + "</script></head>" + "<body onLoad='sayCheese()'></body>" ); WebConversation wc = new WebConversation(); |
From: Russell G. <rus...@us...> - 2002-08-20 15:09:32
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting In directory usw-pr-cvs1:/tmp/cvs-serv32474/src/com/meterware/httpunit/scripting Modified Files: ScriptingEngineFactory.java Log Message: Force graceful degregation when Rhino is missing Index: ScriptingEngineFactory.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting/ScriptingEngineFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ScriptingEngineFactory.java 8 Aug 2002 20:47:22 -0000 1.1 +++ ScriptingEngineFactory.java 20 Aug 2002 15:09:28 -0000 1.2 @@ -28,6 +28,10 @@ **/ public interface ScriptingEngineFactory { + /** + * Returns true if this engine is enabled. + */ + public boolean isEnabled(); /** * Associates a scripting engine with the specified HTML web response. |
From: Russell G. <rus...@us...> - 2002-08-20 15:09:31
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv32474/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java JavaScriptEngineFactory.java Log Message: Force graceful degregation when Rhino is missing Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- JavaScript.java 19 Aug 2002 18:52:26 -0000 1.12 +++ JavaScript.java 20 Aug 2002 15:09:28 -0000 1.13 @@ -83,6 +83,8 @@ public void executeScript( String script ) { try { + script = script.trim(); + if (script.startsWith( "<!--" )) script = script.substring( 4 ); Context.getCurrentContext().evaluateString( this, script, "httpunit", 0, null ); } catch (JavaScriptException e) { throw new RuntimeException( "Script '" + script + "' failed: " + e ); Index: JavaScriptEngineFactory.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScriptEngineFactory.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- JavaScriptEngineFactory.java 19 Aug 2002 18:52:26 -0000 1.3 +++ JavaScriptEngineFactory.java 20 Aug 2002 15:09:28 -0000 1.4 @@ -19,24 +19,26 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ -import com.meterware.httpunit.scripting.ScriptingEngineFactory; import com.meterware.httpunit.WebResponse; +import com.meterware.httpunit.scripting.ScriptingEngineFactory; -import java.lang.reflect.InvocationTargetException; -import java.io.FileWriter; -import java.io.PrintWriter; - -import org.mozilla.javascript.ClassDefinitionException; -import org.mozilla.javascript.NotAFunctionException; -import org.mozilla.javascript.PropertyException; -import org.mozilla.javascript.JavaScriptException; -import org.xml.sax.SAXException; /** * * @author <a href="mailto:rus...@ac...">Russell Gold</a> **/ public class JavaScriptEngineFactory implements ScriptingEngineFactory { + + public boolean isEnabled() { + try { + Class.forName( "org.mozilla.javascript.Context" ); + return true; + } catch (Exception e) { + System.err.println( "Rhino classes (js.jar) not found - Javascript disabled" ); + return false; + } + } + public void associate( WebResponse response ) { try { |
From: Russell G. <rus...@us...> - 2002-08-20 15:09:31
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv32474/src/com/meterware/httpunit Modified Files: HttpUnitOptions.java SubmitButton.java WebResponse.java Log Message: Force graceful degregation when Rhino is missing Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- HttpUnitOptions.java 8 Aug 2002 20:47:21 -0000 1.23 +++ HttpUnitOptions.java 20 Aug 2002 15:09:28 -0000 1.24 @@ -376,7 +376,8 @@ if (_scriptingEngine == null) { try { Class factoryClass = Class.forName( _scriptEngineClassName ); - _scriptingEngine = (ScriptingEngineFactory) factoryClass.newInstance(); + final ScriptingEngineFactory factory = (ScriptingEngineFactory) factoryClass.newInstance(); + _scriptingEngine = factory.isEnabled() ? factory : NULL_SCRIPTING_ENGINE_FACTORY; } catch (ClassNotFoundException e) { disableScripting( e, "Unable to find scripting engine factory class " ); } catch (InstantiationException e) { @@ -416,6 +417,7 @@ private static final String DEFAULT_CONTENT_TYPE = "text/plain"; private static final ScriptingEngineFactory NULL_SCRIPTING_ENGINE_FACTORY = new ScriptingEngineFactory() { + public boolean isEnabled() { return false; } public void associate( WebResponse response ) { } }; Index: SubmitButton.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/SubmitButton.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- SubmitButton.java 19 Aug 2002 18:52:26 -0000 1.11 +++ SubmitButton.java 20 Aug 2002 15:09:28 -0000 1.12 @@ -45,7 +45,7 @@ * submits the form. */ public void click() throws IOException, SAXException { - _form.submit( this ); + if (doOnClickEvent()) _form.submit( this ); } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.73 retrieving revision 1.74 diff -u -r1.73 -r1.74 --- WebResponse.java 8 Aug 2002 20:47:21 -0000 1.73 +++ WebResponse.java 20 Aug 2002 15:09:28 -0000 1.74 @@ -481,6 +481,7 @@ * Returns the next javascript alert and removes it from the queue. */ public String popNextAlert() { + if (_alerts.isEmpty()) throw new IllegalStateException( "Tried to pop a non-existent alert" ); return (String) _alerts.removeFirst(); } |
From: Russell G. <rus...@us...> - 2002-08-20 15:09:31
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv32474/doc Modified Files: Javascript-support.html release_notes.txt Log Message: Force graceful degregation when Rhino is missing Index: Javascript-support.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Javascript-support.html,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- Javascript-support.html 19 Aug 2002 18:52:25 -0000 1.8 +++ Javascript-support.html 20 Aug 2002 15:09:27 -0000 1.9 @@ -2,7 +2,9 @@ <head><title>JavaScript Support</title></head> <body> <p> -JavaScript support is very basic at present. Inline deferred scripts (which define functions) are supported, +JavaScript support is very basic at present. The near-term goal is full JavaScript 1.1 support. Currently, we do not plan +to support browser-specific JavaScript. Please let us know via the mailing list your priorities for missing features. +Inline deferred scripts (which define functions) are supported, as are the following DOM elements: <h3>Window</h3> Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.139 retrieving revision 1.140 diff -u -r1.139 -r1.140 --- release_notes.txt 19 Aug 2002 18:52:25 -0000 1.139 +++ release_notes.txt 20 Aug 2002 15:09:27 -0000 1.140 @@ -7,11 +7,16 @@ 3. The regression test "pseudo-server" does not appear to run properly under Unix. Limitations: - 1. JavaScript support is incomplete - 2. JDK 1.2 or higher is required + 1. JDK 1.2 or higher is required Revision History: +20-Aug-2002 + +Problems fixed: + 1. JavaScript - HTML comments were not supported + 2. JavaScript - Errors were reported if Rhino was not present in the classpath + 19-Aug-2002 Additions: |
From: Russell G. <rus...@us...> - 2002-08-20 15:09:30
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv32474 Modified Files: index.html Log Message: Force graceful degregation when Rhino is missing Index: index.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/index.html,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- index.html 14 Jan 2002 18:13:45 -0000 1.20 +++ index.html 20 Aug 2002 15:09:27 -0000 1.21 @@ -12,9 +12,10 @@ HttpUnit makes this easy. Written in Java, HttpUnit emulates the relevant portions of browser behavior, including -form submission, basic <A HREF="ftp://ftp.isi.edu/in-notes/rfc2617.txt">http authentication</A>, +form submission, <a href="doc/JavaScript-support.html">JavaScript</a>, +basic <A HREF="ftp://ftp.isi.edu/in-notes/rfc2617.txt">http authentication</A>, cookies and automatic page redirection, and allows -Java test code to examine returned pages as text, an XML DOM, or containers of forms, tables, and links.</P> +Java test code to examine returned pages either as text, an XML DOM, or containers of forms, tables, and links.</P> <P> A companion framework, <A HREF="doc/servletunit-intro.html">ServletUnit</A> is included in the download. </P> @@ -26,7 +27,7 @@ <strong>HttpUnit</strong> is a free, <A HREF="doc/license.html">open source</A> Java API for accessing web sites without a browser, and is ideally suited for automated unit testing of web sites when combined with a Java unit test framework such as <A HREF="http://www.junit.org">JUnit</a>. -It was designed and implemented by <a href="mailto:rus...@us...">Russell Gold.</a></blockquote> +It was designed and implemented by <a href="mailto:rus...@ht...">Russell Gold.</a></blockquote> <h2>Documentation</h2> <blockquote>A rudimentary <A HREF="doc/Cookbook.html">User's manual</A> is |
From: Russell G. <rus...@us...> - 2002-08-19 18:52:30
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv7684/test/com/meterware/httpunit Modified Files: FormSubmitTest.java Log Message: Added support for form.submit and Button.onClick Index: FormSubmitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormSubmitTest.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- FormSubmitTest.java 16 Aug 2002 17:24:01 -0000 1.20 +++ FormSubmitTest.java 19 Aug 2002 18:52:26 -0000 1.21 @@ -158,6 +158,20 @@ } + public void testNonSubmitButtonDetection() throws Exception { + defineWebPage( "Default", "<form method=GET action = \"/ask\">" + + "<Input type=text name=age value=12>" + + "<Input type=submit name=update>" + + "<Input type=reset>" + + "<Input type=button value=recalculate>" + + "</form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + WebForm form = page.getForms()[0]; + Button[] buttons = form.getButtons(); + assertEquals( "num detected buttons", 3, buttons.length ); + } + + public void testDisabledSubmitButtonDetection() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=age value=12>" + |
From: Russell G. <rus...@us...> - 2002-08-19 18:52:30
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv7684/test/com/meterware/httpunit/javascript Modified Files: FormScriptingTest.java Log Message: Added support for form.submit and Button.onClick Index: FormScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- FormScriptingTest.java 16 Aug 2002 18:52:51 -0000 1.1 +++ FormScriptingTest.java 19 Aug 2002 18:52:26 -0000 1.2 @@ -85,6 +85,42 @@ } + public void testSubmitViaScript() throws Exception { + defineResource( "DoIt?color=green", "You made it!" ); + defineResource( "OnCommand.html", "<html><head></head>" + + "<body>" + + "<form name=spectrum action='DoIt'>" + + " <input type=text name=color value=green>" + + " <input type=submit name=change value=color>" + + "</form>" + + "<a href='#' onClick='document.spectrum.submit(); return false;'>" + + "</body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + + response.getLinks()[ 0 ].click(); + assertEquals( "Result of submit", "You made it!", wc.getCurrentPage().getText() ); + } + + + public void testSubmitViaScriptButton() throws Exception { + defineResource( "DoIt?color=green", "You made it!" ); + defineResource( "OnCommand.html", "<html><head></head>" + + "<body>" + + "<form name=spectrum action='DoIt'>" + + " <input type=text name=color value=green>" + + " <input type=button id=submit value=submit onClick='this.form.submit();'>" + + "</form>" + + "<a href='#' onClick='document.spectrum.submit(); return false;'>" + + "</body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + + response.getFormWithName( "spectrum" ).getButtons()[0].click(); + assertEquals( "Result of submit", "You made it!", wc.getCurrentPage().getText() ); + } + + public void testSetFormTextValue() throws Exception { defineResource( "OnCommand.html", "<html><head></head>" + "<body onLoad=\"document.realform.color.value='green'\">" + |
From: Russell G. <rus...@us...> - 2002-08-19 18:52:30
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv7684/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java JavaScriptEngineFactory.java Log Message: Added support for form.submit and Button.onClick Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- JavaScript.java 16 Aug 2002 18:52:51 -0000 1.11 +++ JavaScript.java 19 Aug 2002 18:52:26 -0000 1.12 @@ -32,6 +32,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.Arrays; +import java.io.IOException; import org.mozilla.javascript.*; import org.xml.sax.SAXException; @@ -93,7 +94,7 @@ try { final Context context = Context.getCurrentContext(); Function f = context.compileFunction( this, "function x() { " + eventScript + "}", "httpunit", 0, null ); - Object result = f.call( context, this, null, NO_ARGS ); + Object result = f.call( context, this, this, NO_ARGS ); return (result instanceof Boolean) ? ((Boolean) result).booleanValue() : true; } catch (Exception e) { e.printStackTrace(); @@ -107,7 +108,7 @@ _scriptable = scriptable; _scriptable.setScriptEngine( this ); if (parent != null) setParentScope( parent ); - } + } public boolean has( String propertyName, Scriptable scriptable ) { @@ -396,6 +397,11 @@ } + public void jsFunction_submit() throws IOException, SAXException { + getDelegate().submit(); + } + + void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { super.initialize( parent, scriptable ); @@ -422,14 +428,26 @@ static public class Control extends JavaScriptEngine { + private Form _form; + public String getClassName() { return "Control"; } + public Form jsGet_form() { + return _form; + } public void jsFunction_focus() {} public void jsFunction_select() {} + + + void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) + throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { + super.initialize( parent, scriptable ); + _form = (Form) parent; + } Scriptable toScriptable( ScriptableDelegate delegate ) Index: JavaScriptEngineFactory.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScriptEngineFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- JavaScriptEngineFactory.java 8 Aug 2002 20:47:22 -0000 1.2 +++ JavaScriptEngineFactory.java 19 Aug 2002 18:52:26 -0000 1.3 @@ -23,6 +23,8 @@ import com.meterware.httpunit.WebResponse; import java.lang.reflect.InvocationTargetException; +import java.io.FileWriter; +import java.io.PrintWriter; import org.mozilla.javascript.ClassDefinitionException; import org.mozilla.javascript.NotAFunctionException; |
From: Russell G. <rus...@us...> - 2002-08-19 18:52:29
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv7684/src/com/meterware/httpunit Modified Files: FormControl.java GetMethodWebRequest.java MessageBodyWebRequest.java PostMethodWebRequest.java SubmitButton.java WebForm.java Added Files: Button.java Log Message: Added support for form.submit and Button.onClick ***** Error reading new file[Errno 2] No such file or directory: 'Button.java' Index: FormControl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- FormControl.java 13 Aug 2002 20:00:39 -0000 1.17 +++ FormControl.java 19 Aug 2002 18:52:25 -0000 1.18 @@ -44,12 +44,15 @@ final static String[] NO_VALUE = new String[0]; private String _name; + private final String _id; private final String _valueAttribute; private final boolean _readOnly; private final boolean _disabled; + private Scriptable _scriptable; FormControl() { + _id = ""; _name = ""; _valueAttribute = ""; _readOnly = false; @@ -58,6 +61,7 @@ FormControl( Node node ) { + _id = NodeUtils.getNodeAttribute( node, "id" ); _name = NodeUtils.getNodeAttribute( node, "name" ); _valueAttribute = NodeUtils.getNodeAttribute( node, "value" ); _readOnly = NodeUtils.isNodeAttributePresent( node, "readonly" ); @@ -74,17 +78,27 @@ /** + * Returns the ID associated with this control, if any. + * @return the control ID, or an empty string if no ID is defined. + **/ + public String getID() { + return _id; + } + + + /** * Returns the current value(s) associated with this control. These values will be transmitted to the server * if the control is 'successful'. **/ - abstract public String[] getValues(); + abstract String[] getValues(); /** * Returns a scriptable object which can act as a proxy for this control. */ public ScriptableDelegate getScriptableObject() { - return new Scriptable(); + if (_scriptable == null) _scriptable = newScriptable(); + return _scriptable; } @@ -191,6 +205,15 @@ /** + * Creates and returns a scriptable object for this control. Subclasses should override this if they use a different + * implementation of Scriptable. + */ + protected Scriptable newScriptable() { + return new Scriptable(); + } + + + /** * Returns the default value of this control in the form. If no value is specified, defaults to the empty string. **/ protected String getValueAttribute() { @@ -219,7 +242,7 @@ if (type.equalsIgnoreCase( "submit" )) { return new SubmitButton( form, node ); } else { - return null; + return new Button( form, node ); } } else if (!node.getNodeName().equals( "input" )) { return null; @@ -235,6 +258,10 @@ return new CheckboxFormControl( node ); } else if (type.equalsIgnoreCase( "submit" ) || type.equalsIgnoreCase( "image" )) { return new SubmitButton( form, node ); + } else if (type.equalsIgnoreCase( "button" )) { + return new Button( form, node ); + } else if (type.equalsIgnoreCase( "reset" )) { + return new Button( form, node ); } else if (type.equalsIgnoreCase( "file" )) { return new FileSubmitFormControl( node ); } else { @@ -453,7 +480,7 @@ } - public ScriptableDelegate getScriptableObject() { + protected FormControl.Scriptable newScriptable() { return new Scriptable(); } Index: GetMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/GetMethodWebRequest.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- GetMethodWebRequest.java 4 Feb 2002 22:33:55 -0000 1.14 +++ GetMethodWebRequest.java 19 Aug 2002 18:52:26 -0000 1.15 @@ -87,6 +87,14 @@ /** + * Constructs a web request for a form submitted from JavaScript. + **/ + GetMethodWebRequest( WebForm sourceForm ) { + super( sourceForm ); + } + + + /** * Constructs a web request for a link. **/ GetMethodWebRequest( WebLink sourceLink ) { Index: MessageBodyWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/MessageBodyWebRequest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- MessageBodyWebRequest.java 25 Jan 2002 19:09:08 -0000 1.8 +++ MessageBodyWebRequest.java 19 Aug 2002 18:52:26 -0000 1.9 @@ -54,10 +54,18 @@ /** - * Constructs a web request for a form. + * Constructs a web request for a form submitted via a button. **/ protected MessageBodyWebRequest( WebForm sourceForm, SubmitButton button, int x, int y ) { super( sourceForm, button, x, y ); + } + + + /** + * Constructs a web request for a form submitted via script. + **/ + protected MessageBodyWebRequest( WebForm sourceForm ) { + super( sourceForm ); } Index: PostMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/PostMethodWebRequest.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- PostMethodWebRequest.java 20 May 2002 16:00:43 -0000 1.24 +++ PostMethodWebRequest.java 19 Aug 2002 18:52:26 -0000 1.25 @@ -117,10 +117,18 @@ /** - * Constructs a web request for a form. + * Constructs a web request for a form submitted by clicking a button. **/ PostMethodWebRequest( WebForm sourceForm, SubmitButton button, int x, int y ) { super( sourceForm, button, x, y ); + } + + + /** + * Constructs a web request for a form submitted via a script. + **/ + PostMethodWebRequest( WebForm sourceForm ) { + super( sourceForm ); } Index: SubmitButton.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/SubmitButton.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- SubmitButton.java 13 Aug 2002 17:57:47 -0000 1.10 +++ SubmitButton.java 19 Aug 2002 18:52:26 -0000 1.11 @@ -27,27 +27,17 @@ /** * This class represents a submit button in an HTML form. **/ -public class SubmitButton extends FormControl { - - -// public static SubmitButton UNNAMED_BUTTON = new SubmitButton(); - +public class SubmitButton extends Button { /** - * Returns the value associated with this submit button. + * Returns true if this submit button is an image map. **/ - public String getValue() { - return getValueAttribute(); + public boolean isImageButton() { + return _isImageButton; } - /** - * Returns the ID associated with the button, if any. - * @return the button ID, or an empty string if no ID is defined. - **/ - public String getID() { - return _id; - } +//--------------------------------- FormButton methods ---------------------------------------------- /** @@ -59,36 +49,6 @@ } - /** - * Returns true if this submit button is an image map. - **/ - public boolean isImageButton() { - return _isImageButton; - } - - - /** - * Returns the current value(s) associated with this control. These values will be transmitted to the server - * if the control is 'successful'. - **/ - public String[] getValues() { - return (isDisabled() || !_pressed) ? NO_VALUE : toArray( getValueAttribute() ); - } - - - void addValues( ParameterProcessor processor, String characterSet ) throws IOException { - if (_pressed && !isDisabled() && getName().length() > 0) { - if (getValueAttribute().length() > 0) { - processor.addParameter( getName(), getValueAttribute(), characterSet ); - } - if (_isImageButton) { - processor.addParameter( getName() + ".x", Integer.toString( _x ), characterSet ); - processor.addParameter( getName() + ".y", Integer.toString( _y ), characterSet ); - } - } - } - - //------------------------------------ Object methods ---------------------------------------- @@ -111,16 +71,13 @@ SubmitButton( WebForm form, Node node ) { - super( node ); - _form = form; + super( form, node ); _isImageButton = NodeUtils.getNodeAttribute( node, "type" ).equalsIgnoreCase( "image" ); - _id = NodeUtils.getNodeAttribute( node, "id" ); } SubmitButton( WebForm form ) { - _form = form; - _id = ""; + super( form ); _isImageButton = false; } @@ -136,15 +93,39 @@ } +//--------------------------------- FormControl methods ---------------------------------------------------------------- + + + /** + * Returns the current value(s) associated with this control. These values will be transmitted to the server + * if the control is 'successful'. + **/ + String[] getValues() { + return (isDisabled() || !_pressed) ? NO_VALUE : toArray( getValueAttribute() ); + } + + + void addValues( ParameterProcessor processor, String characterSet ) throws IOException { + if (_pressed && !isDisabled() && getName().length() > 0) { + if (getValueAttribute().length() > 0) { + processor.addParameter( getName(), getValueAttribute(), characterSet ); + } + if (_isImageButton) { + processor.addParameter( getName() + ".x", Integer.toString( _x ), characterSet ); + processor.addParameter( getName() + ".y", Integer.toString( _y ), characterSet ); + } + } + } + + //------------------------------------------ private members ---------------------------------- - private final WebForm _form; - private final String _id; + + private String[] _value = new String[1]; private final boolean _isImageButton; private boolean _pressed; private int _x; private int _y; - private String[] _value = new String[1]; private String[] toArray( String value ) { Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.57 retrieving revision 1.58 diff -u -r1.57 -r1.58 --- WebForm.java 13 Aug 2002 20:00:39 -0000 1.57 +++ WebForm.java 19 Aug 2002 18:52:26 -0000 1.58 @@ -43,6 +43,7 @@ **/ public class WebForm extends WebRequestSource { private static final FormParameter UNKNOWN_PARAMETER = new FormParameter(); + private Button[] _buttons; /** @@ -100,6 +101,23 @@ /** + * Returns an array containing all of the buttons defined for this form. + **/ + public Button[] getButtons() { + if (_buttons == null) { + FormControl[] controls = getFormControls(); + ArrayList buttonList = new ArrayList(); + for (int i = 0; i < controls.length; i++) { + FormControl control = controls[ i ]; + if (control instanceof Button) buttonList.add( control ); + } + _buttons = (Button[]) buttonList.toArray( new Button[ buttonList.size() ] ); + } + return _buttons; + } + + + /** * Returns an array containing the submit buttons defined for this form. **/ public SubmitButton[] getSubmitButtons() { @@ -220,6 +238,21 @@ } + private WebRequest getScriptedSubmitRequest() { + SubmitButton[] buttons = getSubmitButtons(); + for (int i = 0; i < buttons.length; i++) { + buttons[i].setPressed( false ); + } + + if (getMethod().equalsIgnoreCase( "post" )) { + return new PostMethodWebRequest( this ); + } else { + return new GetMethodWebRequest( this ); + } + + } + + /** * Returns the default value of the named parameter. If the parameter does not exist returns null. **/ @@ -424,6 +457,11 @@ public class Scriptable extends ScriptableDelegate { public String getAction() { return WebForm.this.getAction(); } public void setAction( String newAction ) { setDestination( newAction ); } + + + public void submit() throws IOException, SAXException { + submitRequest( getScriptedSubmitRequest() ); + } public Object get( String propertyName ) { |
From: Russell G. <rus...@us...> - 2002-08-19 18:52:29
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv7684/doc Modified Files: Javascript-support.html release_notes.txt Log Message: Added support for form.submit and Button.onClick Index: Javascript-support.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Javascript-support.html,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- Javascript-support.html 16 Aug 2002 18:52:50 -0000 1.7 +++ Javascript-support.html 19 Aug 2002 18:52:25 -0000 1.8 @@ -43,6 +43,10 @@ <ul> <li>onSubmit - invoked when the form.submit() is invoked</li> </ul> +<h4>methods</h4> +<ul> +<li>submit - submits the form</li> +</ul> <h3>Image</h3> <h4>properties</h4> @@ -62,9 +66,19 @@ </ul> <h3>Input (and subclasses)</h3> +<h4>properties</h4> +<ul> +<li>form - read-only - the form containing the input</li> +</ul> <h4>methods</h4> <ul> <li>focus() - a no-op</li> +</ul> + +<h3>Button</h3> +<h4>events</h4> +<ul> +<li>onClick - invoked when button.click() is called</li> </ul> <h3>Text</h3> Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.138 retrieving revision 1.139 diff -u -r1.138 -r1.139 --- release_notes.txt 16 Aug 2002 18:52:50 -0000 1.138 +++ release_notes.txt 19 Aug 2002 18:52:25 -0000 1.139 @@ -12,6 +12,14 @@ Revision History: +19-Aug-2002 + +Additions: + 1. WebForm.getButtons() now returns all form buttons, including reset buttons and generic buttons. + 2. JavaScript: The "onClick" event is now supported for generic form buttons + 3. JavaScript: Form.submit() is now working + + 16-Aug-2002 Acknowledgements: Thanks to PeterRoyal for fixing the handling of query-only relative URLs and the IllegalStateException when |
From: Russell G. <rus...@us...> - 2002-08-16 18:52:54
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv20283/test/com/meterware/httpunit/javascript Modified Files: ScriptingTest.java Added Files: FormScriptingTest.java JavaScriptTestSuite.java Log Message: Added support for Form.elements ***** Error reading new file[Errno 2] No such file or directory: 'FormScriptingTest.java' ***** Error reading new file[Errno 2] No such file or directory: 'JavaScriptTestSuite.java' Index: ScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ScriptingTest.java 16 Aug 2002 17:24:01 -0000 1.13 +++ ScriptingTest.java 16 Aug 2002 18:52:51 -0000 1.14 @@ -125,61 +125,6 @@ } - public void testSetFormTextValue() throws Exception { - defineResource( "OnCommand.html", "<html><head></head>" + - "<body onLoad=\"document.realform.color.value='green'\">" + - "<form name='realform'><input name='color' value='blue'></form>" + - "</body></html>" ); - WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - WebForm form = response.getFormWithName( "realform" ); - assertEquals( "color parameter value", "green", form.getParameterValue( "color" ) ); - } - - - public void testSetFormTextOnChangeEvent() throws Exception { - defineResource( "OnCommand.html", "<html><head></head>" + - "<body>" + - "<form name='the_form'>" + - " <input name='color' value='blue' " + - " onChange='alert( \"color is now \" + document.the_form.color.value );'>" + - "</form>" + - "<a href='#' onClick='document.the_form.color.value=\"green\";'>green</a>" + - "</body></html>" ); - WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - WebForm form = response.getFormWithName( "the_form" ); - assertEquals( "Initial state", "blue", form.getParameterValue( "color" ) ); - - assertEquals( "Alert message before change", null, response.getNextAlert() ); - form.setParameter( "color", "red" ); - assertEquals( "Alert after change", "color is now red", response.popNextAlert() ); - - assertEquals( "Changed state", "red", form.getParameterValue( "color" ) ); - response.getLinks()[ 0 ].click(); - assertEquals( "Final state", "green", form.getParameterValue( "color" ) ); - assertEquals( "Alert message after JavaScript change", null, response.getNextAlert() ); - } - - - public void testCheckboxSetChecked() throws Exception { - defineResource( "OnCommand.html", "<html><head></head>" + - "<body>" + - "<form name='realform'><input type='checkbox' name='ready'></form>" + - "<a href='#' name='clear' onMouseOver='document.realform.ready.checked=false;'>clear</a>" + - "<a href='#' name='set' onMouseOver='document.realform.ready.checked=true;'>set</a>" + - "</body></html>" ); - WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - WebForm form = response.getFormWithName( "realform" ); - assertEquals( "initial parameter value", null, form.getParameterValue( "ready" ) ); - response.getLinkWithName( "set" ).mouseOver(); - assertEquals( "changed parameter value", "on", form.getParameterValue( "ready" ) ); - response.getLinkWithName( "clear" ).mouseOver(); - assertEquals( "final parameter value", null, form.getParameterValue( "ready" ) ); - } - - public void testLinkMouseOverEvent() throws Exception { defineResource( "OnCommand.html", "<html><head></head>" + "<body>" + @@ -247,54 +192,6 @@ } - public void testFormActionProperty() throws Exception { - WebConversation wc = new WebConversation(); - defineWebPage( "Default", "<form method=GET name='the_form' action = 'ask'>" + - "<Input type=text name=age>" + - "<Input type=submit value=Go>" + - "</form>" + - "<a href='#' name='doTell' onClick='document.the_form.action=\"tell\";'>tell</a>" + - "<a href='#' name='doShow' onClick='alert( document.the_form.action );'>show</a>" ); - WebResponse page = wc.getResponse( getHostPath() + "/Default.html" ); - page.getLinkWithName( "doShow" ).click(); - assertEquals( "Current action", "ask", page.popNextAlert() ); - page.getLinkWithName( "doTell" ).click(); - - WebRequest request = page.getForms()[0].getRequest(); - request.setParameter( "age", "23" ); - assertEquals( getHostPath() + "/tell?age=23", request.getURL().toExternalForm() ); - } - - - public void testFormValidationOnSubmit() throws Exception { - defineResource( "doIt?color=pink", "You got it!", "text/plain" ); - defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" + - "function verifyForm() { " + - " if (document.realform.color.value == 'pink') {" + - " return true;" + - " } else {" + - " alert( 'wrong color' );" + - " return false;" + - " }" + - "}" + - "</script></head>" + - "<body>" + - "<form name='realform' action='doIt' onSubmit='return verifyForm();'>" + - " <input name='color' value='blue'>" + - "</form>" + - "</body></html>" ); - WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - WebForm form = response.getFormWithName( "realform" ); - form.submit(); - assertEquals( "Alert message", "wrong color", response.popNextAlert() ); - assertSame( "Current response", response, wc.getCurrentPage() ); - form.setParameter( "color", "pink" ); - WebResponse newResponse = form.submit(); - assertEquals( "Result of submit", "You got it!", newResponse.getText() ); - } - - public void testLinkIndexes() throws Exception { defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" + "function alertLinks() { " + @@ -361,157 +258,5 @@ assertEquals( "changed image source", "new.jpg", image.getSource() ); } - - public void testFormSelectReadableProperties() throws Exception { - defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" + - "function viewSelect( choices ) { \n" + - " alert( 'select has ' + choices.options.length + ' options' )\n;" + - " alert( 'select still has ' + choices.length + ' options' )\n;" + - " alert( 'select option ' + choices.options[0].index + ' is ' + choices.options[0].text )\n;" + - " alert( 'select 2nd option value is ' + choices.options[1].value )\n;" + - " if (choices.options[0].selected) alert( 'red selected' );\n" + - " if (choices.options[1].selected) alert( 'blue selected' );\n" + - "}\n" + - "</script></head>" + - "<body onLoad='viewSelect( document.the_form.choices )'>" + - "<form name='the_form'>" + - " <select name='choices'>" + - " <option value='1'>red" + - " <option value='3' selected>blue" + - " </select>" + - "</form>" + - "<a href='#' onMouseOver=\"alert( 'selected #' + document.the_form.choices.selectedIndex );\">which</a>" + - "</body></html>" ); - WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - assertEquals( "1st message", "select has 2 options", response.popNextAlert() ); - assertEquals( "2nd message", "select still has 2 options", response.popNextAlert() ); - assertEquals( "3rd message", "select option 0 is red", response.popNextAlert() ); - assertEquals( "4th message", "select 2nd option value is 3", response.popNextAlert() ); - assertEquals( "5th message", "blue selected", response.popNextAlert() ); - - response.getLinks()[0].mouseOver(); - assertEquals( "before change message", "selected #1", response.popNextAlert() ); - response.getFormWithName( "the_form" ).setParameter( "choices", "1" ); - response.getLinks()[0].mouseOver(); - assertEquals( "after change message", "selected #0", response.popNextAlert() ); - } - - - public void testFormSelectOnChangeEvent() throws Exception { - defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" + - "function selectOptionNum( the_select, index ) { \n" + - " for (var i = 0; i < the_select.length; i++) {\n" + - " the_select.options[i].selected = (i == index);\n" + - " }\n" + - "}\n" + - "</script></head>" + - "<body>" + - "<form name='the_form'>" + - " <select name='choices' onChange='alert( \"Selected index is \" + document.the_form.choices.selectedIndex );'>" + - " <option>red" + - " <option selected>blue" + - " </select>" + - "</form>" + - "<a href='#' onClick='selectOptionNum( document.the_form.choices, 0 )'>reset</a>" + - "</body></html>" ); - WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - final WebForm form = response.getFormWithName( "the_form" ); - assertEquals( "Initial state", "blue", form.getParameterValue( "choices" ) ); - - assertEquals( "Alert message before change", null, response.getNextAlert() ); - form.setParameter( "choices", "red" ); - assertEquals( "Alert after change", "Selected index is 0", response.popNextAlert() ); - form.setParameter( "choices", "blue" ); - assertEquals( "Alert after change", "Selected index is 1", response.popNextAlert() ); - - assertEquals( "Initial state", "blue", form.getParameterValue( "choices" ) ); - response.getLinks()[ 0 ].click(); - assertEquals( "Final state", "red", form.getParameterValue( "choices" ) ); - assertEquals( "Alert message after JavaScript change", null, response.getNextAlert() ); - } - - - public void testFormSelectWriteableProperties() throws Exception { - defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" + - "function selectOptionNum( the_select, index ) { \n" + - " for (var i = 0; i < the_select.length; i++) {\n" + - " the_select.options[i].selected = (i == index);\n" + - " }\n" + - "}\n" + - "</script></head>" + - "<body>" + - "<form name='the_form'>" + - " <select name='choices'>" + - " <option value='1'>red" + - " <option value='3' selected>blue" + - " <option value='5'>green" + - " <option value='7'>azure" + - " </select>" + - "</form>" + - "<a href='#' onClick='selectOptionNum( document.the_form.choices, 2 )'>green</a>" + - "<a href='#' onClick='selectOptionNum( document.the_form.choices, 0 )'>red</a>" + - "<a href='#' onClick='document.the_form.choices.options[0].value=\"9\"'>red</a>" + - "<a href='#' onClick='document.the_form.choices.options[0].text=\"orange\"'>orange</a>" + - "</body></html>" ); - WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - WebForm form = response.getFormWithName( "the_form" ); - assertEquals( "initial selection", "3", form.getParameterValue( "choices" ) ); - - response.getLinks()[0].click(); - assertEquals( "2nd selection", "5", form.getParameterValue( "choices" ) ); - response.getLinks()[1].click(); - assertEquals( "3rd selection", "1", form.getParameterValue( "choices" ) ); - response.getLinks()[2].click(); - assertEquals( "4th selection", "9", form.getParameterValue( "choices" ) ); - - assertMatchingSet( "Displayed options", new String[] { "red", "blue", "green", "azure" }, form.getOptions( "choices" ) ); - response.getLinks()[3].click(); - assertMatchingSet( "Modified options", new String[] { "orange", "blue", "green", "azure" }, form.getOptions( "choices" ) ); - } - - - public void testFormSelectOverwriteOptions() throws Exception { - defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" + - "function rewriteSelect( the_select ) { \n" + - " the_select.options[0] = new Option( 'apache', 'a' );\n" + - " the_select.options[1] = new Option( 'comanche', 'c' );\n" + - " the_select.options[2] = new Option( 'sioux', 'x' );\n" + - " the_select.options[3] = new Option( 'iriquois', 'q' );\n" + - "}\n" + - "</script></head>" + - "<body>" + - "<form name='the_form'>" + - " <select name='choices'>" + - " <option value='1'>red" + - " <option value='2'>yellow" + - " <option value='3' selected>blue" + - " <option value='5'>green" + - " </select>" + - "</form>" + - "<a href='#' onMouseOver='document.the_form.choices.options.length=3;'>shorter</a>" + - "<a href='#' onMouseOver='document.the_form.choices.options[1]=null;'>weed</a>" + - "<a href='#' onMouseOver='rewriteSelect( document.the_form.choices );'>replace</a>" + - "</body></html>" ); - WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - WebForm form = response.getFormWithName( "the_form" ); - assertMatchingSet( "initial values", new String[] { "1", "2", "3", "5" }, form.getOptionValues( "choices" ) ); - assertMatchingSet( "initial text", new String[] { "red", "yellow", "blue", "green" }, form.getOptions( "choices" ) ); - - response.getLinks()[0].mouseOver(); - assertMatchingSet( "modified values", new String[] { "1", "2", "3" }, form.getOptionValues( "choices" ) ); - assertMatchingSet( "modified text", new String[] { "red", "yellow", "blue" }, form.getOptions( "choices" ) ); - - response.getLinks()[1].mouseOver(); - assertMatchingSet( "weeded values", new String[] { "1", "3" }, form.getOptionValues( "choices" ) ); - assertMatchingSet( "weeded text", new String[] { "red", "blue" }, form.getOptions( "choices" ) ); - - response.getLinks()[2].mouseOver(); - assertMatchingSet( "replaced values", new String[] { "a", "c", "x", "q" }, form.getOptionValues( "choices" ) ); - assertMatchingSet( "replaced text", new String[] { "apache", "comanche", "sioux", "iriquois" }, form.getOptions( "choices" ) ); - } } |
From: Russell G. <rus...@us...> - 2002-08-16 18:52:54
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv20283/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java Log Message: Added support for Form.elements Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- JavaScript.java 14 Aug 2002 22:33:00 -0000 1.10 +++ JavaScript.java 16 Aug 2002 18:52:51 -0000 1.11 @@ -391,6 +391,11 @@ } + public Scriptable jsGet_elements() { + return _controls; + } + + void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { super.initialize( parent, scriptable ); @@ -423,6 +428,8 @@ public void jsFunction_focus() {} + + public void jsFunction_select() {} Scriptable toScriptable( ScriptableDelegate delegate ) |
From: Russell G. <rus...@us...> - 2002-08-16 18:52:54
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv20283/test/com/meterware/httpunit Modified Files: HttpUnitSuite.java Log Message: Added support for Form.elements Index: HttpUnitSuite.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- HttpUnitSuite.java 1 Aug 2002 20:23:16 -0000 1.20 +++ HttpUnitSuite.java 16 Aug 2002 18:52:51 -0000 1.21 @@ -61,7 +61,7 @@ result.addTest( JTidyPrintWriterTest.suite() ); addOptionalTestCase( result, "com.meterware.httpunit.XMLPageTest" ); addOptionalTestCase( result, "com.meterware.httpunit.FileUploadTest" ); - addOptionalTestCase( result, "com.meterware.httpunit.javascript.ScriptingTest" ); + addOptionalTestCase( result, "com.meterware.httpunit.javascript.JavaScriptTestSuite" ); addOptionalTestCase( result, "com.meterware.servletunit.ServletUnitSuite" ); return result; } |
From: Russell G. <rus...@us...> - 2002-08-16 18:52:53
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv20283/doc Modified Files: Javascript-support.html release_notes.txt Log Message: Added support for Form.elements Index: Javascript-support.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Javascript-support.html,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- Javascript-support.html 15 Aug 2002 00:06:31 -0000 1.6 +++ Javascript-support.html 16 Aug 2002 18:52:50 -0000 1.7 @@ -35,7 +35,8 @@ <h4>properties</h4> <ul> <li>action - r/w the action associated with the form</li> -<li>document - the enclosing document</li> +<li>document - r/o the enclosing document</li> +<li>elements - r/o an array of controls in the form</li> <li><name> - the name of a control in the form</li> </ul> <h4>events</h4> Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.137 retrieving revision 1.138 diff -u -r1.137 -r1.138 --- release_notes.txt 16 Aug 2002 17:23:59 -0000 1.137 +++ release_notes.txt 16 Aug 2002 18:52:50 -0000 1.138 @@ -7,7 +7,7 @@ 3. The regression test "pseudo-server" does not appear to run properly under Unix. Limitations: - 1. JavaScript support is minimal + 1. JavaScript support is incomplete 2. JDK 1.2 or higher is required @@ -20,6 +20,10 @@ Problems fixes: 1. Relative URLs beginning with "?" were not being handled properly. 2. Disabling scripting result in IllegalStateException being thrown. + +Additions: + 1. JavaScript: The select() method is now defined as a no-op for controls + 2. JavaScript: Form.elements is now defined 14-Aug-2002 Additions: |
From: Russell G. <rus...@us...> - 2002-08-16 17:24:42
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv22152/doc Modified Files: release_notes.txt Log Message: Peter Royal: fixed scripting disabled, query-only URL parsing bugs Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.136 retrieving revision 1.137 diff -u -r1.136 -r1.137 --- release_notes.txt 15 Aug 2002 00:06:31 -0000 1.136 +++ release_notes.txt 16 Aug 2002 17:23:59 -0000 1.137 @@ -12,6 +12,15 @@ Revision History: +16-Aug-2002 +Acknowledgements: + Thanks to PeterRoyal for fixing the handling of query-only relative URLs and the IllegalStateException when + scripting is disable. + +Problems fixes: + 1. Relative URLs beginning with "?" were not being handled properly. + 2. Disabling scripting result in IllegalStateException being thrown. + 14-Aug-2002 Additions: 1. The focus() method is now defined as a no-op for all controls |
From: Russell G. <rus...@us...> - 2002-08-16 17:24:04
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv22152/test/com/meterware/httpunit/javascript Modified Files: ScriptingTest.java Log Message: Peter Royal: fixed scripting disabled, query-only URL parsing bugs Index: ScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- ScriptingTest.java 13 Aug 2002 20:00:39 -0000 1.12 +++ ScriptingTest.java 16 Aug 2002 17:24:01 -0000 1.13 @@ -19,13 +19,7 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ -import com.meterware.httpunit.HttpUnitTest; -import com.meterware.httpunit.WebConversation; -import com.meterware.httpunit.WebResponse; -import com.meterware.httpunit.WebForm; -import com.meterware.httpunit.WebLink; -import com.meterware.httpunit.WebImage; -import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.*; import junit.framework.TestSuite; import junit.textui.TestRunner; @@ -215,6 +209,25 @@ assertEquals( "initial parameter value", "blue", form.getParameterValue( "color" ) ); link.click(); assertEquals( "changed parameter value", "green", form.getParameterValue( "color" ) ); + } + + + public void testScriptDisabled() throws Exception { + HttpUnitOptions.setScriptingEnabled( false ); + defineResource( "nothing.html", "Should get here" ); + defineResource( "OnCommand.html", "<html><head></head>" + + "<body>" + + "<form name='realform'><input name='color' value='blue'></form>" + + "<a href='nothing.html' onClick=\"document.realform.color.value='green';return false;\">green</a>" + + "</body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + WebForm form = response.getFormWithName( "realform" ); + WebLink link = response.getLinks()[0]; + assertEquals( "initial parameter value", "blue", form.getParameterValue( "color" ) ); + link.click(); + assertEquals( "unchanged parameter value", "blue", form.getParameterValue( "color" ) ); + assertEquals( "Expected result", "Should get here", wc.getCurrentPage().getText() ); } |
From: Russell G. <rus...@us...> - 2002-08-16 17:24:04
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv22152/test/com/meterware/httpunit Modified Files: FormSubmitTest.java Log Message: Peter Royal: fixed scripting disabled, query-only URL parsing bugs Index: FormSubmitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormSubmitTest.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- FormSubmitTest.java 5 Aug 2002 15:20:51 -0000 1.19 +++ FormSubmitTest.java 16 Aug 2002 17:24:01 -0000 1.20 @@ -110,6 +110,16 @@ } + public void testSubmitStringWithQueryOnlyRelativeURL() throws Exception { + defineWebPage( "/blah/blah/blah", "<form method=GET action = '?recall=true'>" + + "<Input type=submit value=Go>" + + "</form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/blah/blah/blah.html" ); + WebRequest request = page.getForms()[0].getRequest(); + assertEquals( getHostPath() + "/blah/blah/blah.html?recall=true", request.getURL().toExternalForm() ); + } + + public void testSubmitStringAfterSetAction() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=age>" + |
From: Russell G. <rus...@us...> - 2002-08-16 17:24:03
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting In directory usw-pr-cvs1:/tmp/cvs-serv22152/src/com/meterware/httpunit/scripting Modified Files: ScriptableDelegate.java Log Message: Peter Royal: fixed scripting disabled, query-only URL parsing bugs Index: ScriptableDelegate.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting/ScriptableDelegate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ScriptableDelegate.java 8 Aug 2002 20:47:22 -0000 1.1 +++ ScriptableDelegate.java 16 Aug 2002 17:24:00 -0000 1.2 @@ -30,14 +30,21 @@ private ScriptingEngine _scriptEngine; + private static final ScriptingEngine NULL_SCRIPT_ENGINE = new ScriptingEngine() { + public void executeScript( String script ) { + } + public boolean performEvent( String eventScript ) { + return true; + } + }; + /** * Executes the specified scripted event. **/ public boolean doEvent( String eventScript ) { - if (_scriptEngine == null) throw new IllegalStateException( "Script engine must be defined before running an event" ); if (eventScript.length() == 0) return true; - return _scriptEngine.performEvent( eventScript ); + return getScriptEngine().performEvent( eventScript ); } @@ -45,8 +52,7 @@ * Executes the specified script. **/ public void runScript( String script ) { - if (_scriptEngine == null) throw new IllegalStateException( "Script engine must be defined before running an event" ); - _scriptEngine.executeScript( script ); + if (script.length() != 0) getScriptEngine().executeScript( script ); } @@ -80,6 +86,11 @@ */ public void setScriptEngine( ScriptingEngine scriptEngine ) { _scriptEngine = scriptEngine; + } + + + private ScriptingEngine getScriptEngine() { + return _scriptEngine != null ? _scriptEngine : NULL_SCRIPT_ENGINE; } } |
From: Russell G. <rus...@us...> - 2002-08-16 17:24:03
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv22152/src/com/meterware/httpunit Modified Files: WebRequest.java Log Message: Peter Royal: fixed scripting disabled, query-only URL parsing bugs Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.43 retrieving revision 1.44 diff -u -r1.43 -r1.44 --- WebRequest.java 15 Aug 2002 00:06:31 -0000 1.43 +++ WebRequest.java 16 Aug 2002 17:24:00 -0000 1.44 @@ -70,12 +70,20 @@ public URL getURL() throws MalformedURLException { if (getURLBase() == null || getURLString().indexOf( ':' ) > 0) validateProtocol( getURLString() ); if (getURLBase() == null || getURLBase().toString().indexOf( "?" ) < 0) { - return new URL( getURLBase(), getURLString() ); + return newURL( getURLBase(), getURLString() ); } else { final String urlBaseString = getURLBase().toString(); URL newurlbase = new URL( urlBaseString.substring( 0, urlBaseString.indexOf( "?" ) ) ); - return new URL( newurlbase, getURLString() ); + return newURL( newurlbase, getURLString() ); } + } + + + /** + * Creates a new URL, handling the case where the relative URL begins with a '?' + */ + private URL newURL( final URL base, final String spec ) throws MalformedURLException { + return spec.startsWith( "?" ) ? new URL( base + spec ) : new URL( base, spec ); } |
From: Russell G. <rus...@us...> - 2002-08-15 18:29:11
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv30221 Modified Files: WebLinkTest.java Log Message: Refactored to remove references to deprecated method Index: WebLinkTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- WebLinkTest.java 1 Aug 2002 14:58:59 -0000 1.22 +++ WebLinkTest.java 15 Aug 2002 18:29:08 -0000 1.23 @@ -263,68 +263,39 @@ // first link should not have any param request = links[0].getRequest(); assertNotNull( request); - Enumeration e = request.getParameterNames(); - assertNotNull( e); - assertTrue( "Should not have any params", !e.hasMoreElements() ); + String[] names = request.getRequestParameterNames(); + assertNotNull( names ); + assertEquals( "Num parameters found", 0, names.length ); assertEquals("Non Existent parameter should be empty","",request.getParameter("nonexistent")); // second link should have one parameter - request = links[1].getRequest(); - assertNotNull( request ); - e = request.getParameterNames(); - assertTrue( "No parameter found", e.hasMoreElements() ); - String paramName = (String)e.nextElement(); - assertNotNull(paramName); - assertTrue( "More than one parameter found", !e.hasMoreElements()); - assertEquals("param1",paramName); - assertEquals("value1",request.getParameter(paramName)); + checkLinkParameters( links[1], new String[] { "param1" }, + new String[][] { { "value1" } }); // third link should have 2 parameters. !! Order of parameters cannot be guaranted. - request = links[2].getRequest(); - assertNotNull( request ); - e = request.getParameterNames(); - assertTrue( "No parameters found", e.hasMoreElements() ); - paramName = (String)e.nextElement(); - assertNotNull(paramName); - assertTrue( "Only one parameter found", e.hasMoreElements()); - String paramName2 = (String)e.nextElement(); - assertNotNull(paramName2); - assertTrue("different names",!paramName.equals(paramName2)); - assertTrue("test names for param1",paramName.equals("param1") || paramName2.equals("param1")); - assertTrue("test names for param2",paramName.equals("param2") || paramName2.equals("param2")); - assertEquals("value1",request.getParameter("param1")); - assertEquals("value2",request.getParameter("param2")); + checkLinkParameters( links[2], new String[] { "param1", "param2" }, + new String[][] { { "value1" }, { "value2" } }); // fourth link should have 1 parameter with 2 values. - request = links[3].getRequest(); - assertNotNull( request ); - e = request.getParameterNames(); - assertTrue( "No parameters found", e.hasMoreElements() ); - paramName = (String)e.nextElement(); - assertNotNull(paramName); - String[] values = request.getParameterValues("param1"); - assertEquals("Length of ",2,values.length); - assertMatchingSet("Values",new String[] {"value1", "value3"}, values); + checkLinkParameters( links[3], new String[] { "param1" }, + new String[][] { { "value1", "value3" } }); // fifth link should have 2 parameters with one with 2 values. - request = links[4].getRequest(); - assertNotNull( request ); - e = request.getParameterNames(); - assertTrue( "No parameters found", e.hasMoreElements() ); - paramName = (String)e.nextElement(); - assertNotNull(paramName); - assertTrue( "Only one parameter found", e.hasMoreElements() ); - paramName2 = (String)e.nextElement(); - assertNotNull(paramName2); - assertTrue("different names",!paramName.equals(paramName2)); - values = request.getParameterValues("param1"); - assertEquals("Length of ",2,values.length); - assertMatchingSet("Values for param1",new String[] {"value1", "value3"}, values); - assertMatchingSet("Values form param2",new String[] {"value2"}, request.getParameterValues("param2")); - assertEquals("value2",request.getParameter("param2")); + checkLinkParameters( links[4], new String[] { "param1", "param2" }, + new String[][] { { "value1", "value3" }, { "value2" } }); } + private void checkLinkParameters( WebLink link, String[] expectedNames, String[][] expectedValues ) { + WebRequest request = link.getRequest(); + assertNotNull( request ); + assertMatchingSet( "Parameter names", expectedNames, request.getRequestParameterNames() ); + for (int i = 0; i < expectedValues.length; i++) { + assertMatchingSet( expectedNames[i] + " values", expectedValues[i], request.getParameterValues( expectedNames[i] )); + } + } + + public void testEncodedLinkParameters() throws Exception { WebConversation wc = new WebConversation(); defineWebPage( "encodedLinks", "<html><head><title>Encode Test</title></head>" + @@ -334,7 +305,7 @@ WebResponse mapPage = wc.getResponse( getHostPath() + "/encodedLinks.html" ); WebLink link = mapPage.getLinks()[0]; WebRequest wr = link.getRequest(); - assertMatchingSet( "Request parameter names", new String[] { "$dollar", "#hash" }, toStringArray( wr.getParameterNames() ) ); + assertMatchingSet( "Request parameter names", new String[] { "$dollar", "#hash" }, wr.getRequestParameterNames() ); assertEquals( "Value of $dollar", "%percent", wr.getParameter( "$dollar" ) ); assertEquals( "Value of #hash", "&ersand", wr.getParameter( "#hash" ) ); } @@ -349,7 +320,7 @@ WebResponse mapPage = wc.getResponse( getHostPath() + "/encodedLinks.html" ); WebLink link = mapPage.getLinks()[0]; WebRequest wr = link.getRequest(); - assertMatchingSet( "Request parameter names", new String[] { "arg1", "valueless" }, toStringArray( wr.getParameterNames() ) ); + assertMatchingSet( "Request parameter names", new String[] { "arg1", "valueless" }, wr.getRequestParameterNames() ); assertEquals( "Value of arg1", null, wr.getParameter( "arg1" ) ); } @@ -363,7 +334,7 @@ WebResponse mapPage = wc.getResponse( getHostPath() + "/encodedLinks.html" ); WebLink link = mapPage.getLinks()[0]; WebRequest wr = link.getRequest(); - assertMatchingSet( "Request parameter names", new String[] { "arg0", "arg1", "valueless" }, toStringArray( wr.getParameterNames() ) ); + assertMatchingSet( "Request parameter names", new String[] { "arg0", "arg1", "valueless" }, wr.getRequestParameterNames() ); assertMatchingSet( "Value of arg0", new String[] { "0", "2" }, wr.getParameterValues( "arg0" ) ); assertEquals( "Actual query", "arg0=0&arg1&arg0=2&valueless=", wr.getQueryString() ); } @@ -383,15 +354,6 @@ wr.setParameter( "arg0", "3" ); fail( "Did not prevent change to link parameters" ); } catch (IllegalRequestParameterException e) {} - } - - - private String[] toStringArray( Enumeration e ) { - Vector v = new Vector(); - while (e.hasMoreElements()) v.addElement( e.nextElement() ); - String[] result = new String[ v.size() ]; - v.copyInto( result ); - return result; } |
From: Russell G. <rus...@us...> - 2002-08-15 00:06:35
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv13563/test/com/meterware/httpunit Modified Files: WebFormTest.java Log Message: Handle embedded spaces in URL Index: WebFormTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- WebFormTest.java 13 Aug 2002 17:57:47 -0000 1.24 +++ WebFormTest.java 15 Aug 2002 00:06:32 -0000 1.25 @@ -23,6 +23,7 @@ import com.meterware.pseudoserver.WebResource; import java.net.URL; +import java.net.HttpURLConnection; import junit.framework.Test; import junit.framework.TestCase; @@ -447,6 +448,36 @@ WebRequest request = form.getRequest(); request.setParameter( "name", "Charlie" ); assertEquals( "Request URL", getHostPath() + "/SayHello?speed=fast", request.getURL().toExternalForm() ); + + WebResponse answer = wc.getResponse( request ); + String[][] cells = answer.getTables()[0].asText(); + + assertEquals( "Message", "Hello, there", cells[0][0] ); + } + + + public void testPostWithEmbeddedSpace() throws Exception { + String sessionID = "/ID=03.019c010101010001.00000001.a202000000000019. 0d09"; + defineResource( "login", "redirectoring", HttpURLConnection.HTTP_MOVED_PERM ); + super.addResourceHeader( "login", "Location: " + getHostPath() + sessionID + "/login" ); + defineResource( sessionID + "/login", + "<html><head></head>" + + "<form method=POST action='SayHello'>" + + "<input type=text name=name><input type=submit></form></body></html>" ); + defineResource( sessionID + "/SayHello", new PseudoServlet() { + public WebResource getPostResponse() { + String name = getParameter( "name" )[0]; + WebResource result = new WebResource( "<html><body><table><tr><td>Hello, there" + + "</td></tr></table></body></html>" ); + return result; + } + } ); + + WebConversation wc = new WebConversation(); + WebResponse formPage = wc.getResponse( getHostPath() + "/login" ); + WebForm form = formPage.getForms()[0]; + WebRequest request = form.getRequest(); + request.setParameter( "name", "Charlie" ); WebResponse answer = wc.getResponse( request ); String[][] cells = answer.getTables()[0].asText(); |
From: Russell G. <rus...@us...> - 2002-08-15 00:06:35
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv13563/src/com/meterware/httpunit Modified Files: WebRequest.java Log Message: Handle embedded spaces in URL Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- WebRequest.java 25 Jul 2002 11:19:18 -0000 1.42 +++ WebRequest.java 15 Aug 2002 00:06:31 -0000 1.43 @@ -298,9 +298,28 @@ **/ private WebRequest( URL urlBase, String urlString, String target, ParameterHolder parameterHolder ) { _urlBase = urlBase; - _urlString = urlString; + _urlString = escape( urlString ); _target = target; _parameterHolder = parameterHolder; + } + + + private static String escape( String urlString ) { + if (urlString.indexOf( ' ' ) < 0) return urlString; + StringBuffer sb = new StringBuffer(); + + int start = 0; + do { + int index = urlString.indexOf( ' ', start ); + if (index < 0) { + sb.append( urlString.substring( start ) ); + break; + } else { + sb.append( urlString.substring( start, index ) ).append( "%20" ); + start = index+1; + } + } while (true); + return sb.toString(); } |