[Httpunit-commit] SF.net SVN: httpunit:[995] trunk/httpunit
Brought to you by:
russgold
From: <wol...@us...> - 2008-11-05 23:35:03
|
Revision: 995 http://httpunit.svn.sourceforge.net/httpunit/?rev=995&view=rev Author: wolfgang_fahl Date: 2008-11-05 23:34:58 +0000 (Wed, 05 Nov 2008) Log Message: ----------- FR [ 2163079 ] make form.name property mutable by Peter De Bruycker Modified Paths: -------------- trunk/httpunit/src/com/meterware/httpunit/WebForm.java trunk/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java trunk/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java Modified: trunk/httpunit/src/com/meterware/httpunit/WebForm.java =================================================================== --- trunk/httpunit/src/com/meterware/httpunit/WebForm.java 2008-11-05 22:27:09 UTC (rev 994) +++ trunk/httpunit/src/com/meterware/httpunit/WebForm.java 2008-11-05 23:34:58 UTC (rev 995) @@ -19,6 +19,7 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ +import com.meterware.httpunit.scripting.IdentifiedDelegate; import com.meterware.httpunit.scripting.NamedDelegate; import com.meterware.httpunit.scripting.ScriptableDelegate; import com.meterware.httpunit.scripting.FormScriptable; @@ -719,7 +720,12 @@ } - public class Scriptable extends HTMLElementScriptable implements NamedDelegate, FormScriptable { + /** + * + * Scriptable implementation for the WebForm + * + */ + public class Scriptable extends HTMLElementScriptable implements NamedDelegate, IdentifiedDelegate, FormScriptable { public String getAction() { return WebForm.this.getAction(); } public void setAction( String newAction ) { setDestination( newAction ); _presetParameters = null; } @@ -734,9 +740,21 @@ } + /** + * return the name of the WebForm + * @return the name + */ public String getName() { - return WebForm.this.getID().length() != 0 ? WebForm.this.getID() : WebForm.this.getName(); + return WebForm.this.getName().length() != 0 ? WebForm.this.getName() : WebForm.this.getID(); } + + /** + * return the id of the WebForm + * @return the id + */ + public String getID() { + return WebForm.this.getID(); + } /** @@ -771,6 +789,8 @@ setTargetAttribute( value.toString() ); } else if (propertyName.equals( "action" )) { setAction( value.toString() ); + } else if (propertyName.equals( "name" )) { + getElement().setAttribute( "name", value.toString() ); } else if (value instanceof String) { setParameterValue( propertyName, (String) value ); } else if (value instanceof Number) { Modified: trunk/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java =================================================================== --- trunk/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java 2008-11-05 22:27:09 UTC (rev 994) +++ trunk/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java 2008-11-05 23:34:58 UTC (rev 995) @@ -897,6 +897,10 @@ } + /** + * Form functions + * + */ static public class Form extends HTMLElement { private ElementArray _controls; @@ -908,6 +912,15 @@ public String jsGet_name() { return getDelegate().getName(); } + + /** + * @since FR [ 2163079 ] make form.name property mutable + * by Peter De Bruycker + * @param name + */ + public void jsSet_name( String name ) { + getDelegate().set( "name", name ); + } public String jsGet_action() { return getDelegate().getAction(); Modified: trunk/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java =================================================================== --- trunk/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java 2008-11-05 22:27:09 UTC (rev 994) +++ trunk/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java 2008-11-05 23:34:58 UTC (rev 995) @@ -67,14 +67,39 @@ "<form id='the_form_with_id'/>" + "<script type='JavaScript'>" + " alert( document.forms[1].name );" + + "</script>" + + "<form id='the_form_with_id2' name='the_form_with_name2'/>" + + "<script type='JavaScript'>" + + " alert( document.forms[2].name );" + "</script>" ); WebConversation wc = new WebConversation(); wc.getResponse( getHostPath() + "/OnCommand.html" ); assertEquals( "Message 1", "the_form_with_name", wc.popNextAlert() ); assertEquals( "Message 2", "the_form_with_id", wc.popNextAlert() ); + assertEquals( "Message 3", "the_form_with_name2", wc.popNextAlert() ); } /** + * FR [ 2163079 ] make form.name property mutable by Peter De Bruycker + * + * @throws Exception + */ + public void testModifyingFormNameProperty() throws Exception { + WebConversation wc = new WebConversation(); + defineWebPage( + "Default", + "<form id = 'the_form' name = 'form_name'/>" + + "<a href='#' name='doTell' onClick='document.forms[0].name=\"new_form_name\";'>tell</a>" + + "<a href='#' name='doShow' onClick='alert( document.forms[0].name );'>show</a>"); + WebResponse page = wc.getResponse(getHostPath() + "/Default.html"); + page.getLinkWithName("doShow").click(); + assertEquals("Initial name", "form_name", wc.popNextAlert()); + page.getLinkWithName("doTell").click(); + page.getLinkWithName("doShow").click(); + assertEquals("Current name", "new_form_name", wc.popNextAlert()); + } + + /** * test to access attributes from java script * @throws Exception */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |