httpunit-commit Mailing List for httpunit (Page 57)
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-15 00:06:35
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/pseudoserver In directory usw-pr-cvs1:/tmp/cvs-serv13563/test/com/meterware/pseudoserver Modified Files: PseudoServerTest.java Log Message: Handle embedded spaces in URL Index: PseudoServerTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/pseudoserver/PseudoServerTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PseudoServerTest.java 24 Jul 2002 17:28:57 -0000 1.1 +++ PseudoServerTest.java 15 Aug 2002 00:06:32 -0000 1.2 @@ -124,6 +124,20 @@ } + public void testFunkyGet() throws Exception { + String resourceName = "ID=03.019c010101010001.00000001.a202000000000019. 0d09/login/"; + String resourceValue = "the desired content"; + + defineResource( resourceName, resourceValue ); + + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( getHostPath() + '/' + resourceName ); + WebResponse response = wc.getResponse( request ); + assertEquals( "requested resource", resourceValue, response.getText().trim() ); + assertEquals( "content type", "text/html", response.getContentType() ); + } + + private String asBytes( String s ) { StringBuffer sb = new StringBuffer(); char[] chars = s.toCharArray(); |
From: Russell G. <rus...@us...> - 2002-08-15 00:06:35
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver In directory usw-pr-cvs1:/tmp/cvs-serv13563/src/com/meterware/pseudoserver Modified Files: PseudoServer.java Log Message: Handle embedded spaces in URL Index: PseudoServer.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/PseudoServer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PseudoServer.java 24 Jul 2002 17:28:56 -0000 1.1 +++ PseudoServer.java 15 Aug 2002 00:06:32 -0000 1.2 @@ -166,10 +166,29 @@ private String asResourceName( String rawName ) { if (rawName.startsWith( "/" )) { - return rawName; + return escape( rawName ); } else { - return "/" + rawName; + return escape( "/" + rawName ); } + } + + + 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(); } |
From: Russell G. <rus...@us...> - 2002-08-15 00:06:35
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv13563/doc Modified Files: Javascript-support.html faq.html release_notes.txt Log Message: Handle embedded spaces in URL Index: Javascript-support.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Javascript-support.html,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Javascript-support.html 13 Aug 2002 20:00:38 -0000 1.5 +++ Javascript-support.html 15 Aug 2002 00:06:31 -0000 1.6 @@ -60,6 +60,12 @@ <li>onMouseOver - invoked when link.mouseOver() is invoked<li> </ul> +<h3>Input (and subclasses)</h3> +<h4>methods</h4> +<ul> +<li>focus() - a no-op</li> +</ul> + <h3>Text</h3> <h4>properties</h4> <ul> Index: faq.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/faq.html,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- faq.html 30 Jul 2002 14:11:14 -0000 1.14 +++ faq.html 15 Aug 2002 00:06:31 -0000 1.15 @@ -8,6 +8,7 @@ <LI><A HREF="#Cannot unzip">Why can't I unzip the download library?</A></LI> <LI><A HREF="#org.xml.sax">What is the org.xml.sax package?</A></LI> <LI><A HREF="#javascript">How do I use HttpUnit to test my pages that use JavaScript?</A></LI> +<LI><A HREF="#norhino">JavaScript is not being executed at all. Why not?</A></LI> <LI><A HREF="sslfaq.html">Does HttpUnit support https?</A></LI> <LI><A HREF="#proxy">Can I use HttpUnit through a proxy server?</A></LI> <LI><A HREF="#charset">Why isn't HttpUnit handling my non-English pages?</A></LI> @@ -30,8 +31,11 @@ and install Tidy.jar in your classpath. <A NAME="javascript"><H2>How do I use HttpUnit to test my pages that use JavaScript?</H2></A> -Unfortunately, you can't - yet. I have started to add JavaScript support, but it is very basic as yet. -If you would like to help out, please examine the code in cvs. +You should not have to do anything special; however, not all JavaScript constructs are supported as yet. See +<a href="javascript-support.html">the list of supported JavaScript features</a> for more information. + +<A NAME="#norhino"><H2>JavaScript is not being executed at all. Why not?</H2></A> +If you do not have the Rhino JAR (js.jar) in your classpath, JavaScript features do not work. <A NAME="proxy"><H2>Can I use HttpUnit through a proxy server?</H2></A> Yes. HttpUnit uses java.net.HttpURLConnection, so the Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.135 retrieving revision 1.136 diff -u -r1.135 -r1.136 --- release_notes.txt 13 Aug 2002 20:00:38 -0000 1.135 +++ release_notes.txt 15 Aug 2002 00:06:31 -0000 1.136 @@ -12,6 +12,13 @@ Revision History: +14-Aug-2002 +Additions: + 1. The focus() method is now defined as a no-op for all controls + +Problems fixed: + 1. Embedded spaces in URLs are now encoded when a request is made + 13-Aug-2002 Additions: 1. The onChange event now works for Select controls, Text controls, and TextArea controls. |
From: Russell G. <rus...@us...> - 2002-08-14 22:33:03
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv32605/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java Log Message: Added no-op Input.focus() Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- JavaScript.java 13 Aug 2002 20:00:39 -0000 1.9 +++ JavaScript.java 14 Aug 2002 22:33:00 -0000 1.10 @@ -422,6 +422,9 @@ } + public void jsFunction_focus() {} + + Scriptable toScriptable( ScriptableDelegate delegate ) throws PropertyException, JavaScriptException, NotAFunctionException, SAXException { JavaScriptEngine element = (JavaScriptEngine) Context.getCurrentContext().newObject( this, getScriptableClassName( delegate ) ); |
From: Russell G. <rus...@us...> - 2002-08-13 20:00:42
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv31453/test/com/meterware/httpunit/javascript Modified Files: ScriptingTest.java Log Message: Added onChange method for text and select controls Index: ScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ScriptingTest.java 8 Aug 2002 20:47:22 -0000 1.11 +++ ScriptingTest.java 13 Aug 2002 20:00:39 -0000 1.12 @@ -131,7 +131,7 @@ } - public void testSetFormFieldValue() throws Exception { + 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>" + @@ -143,6 +143,31 @@ } + 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>" + @@ -357,6 +382,41 @@ 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() ); } |
From: Russell G. <rus...@us...> - 2002-08-13 20:00:42
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv31453/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java Log Message: Added onChange method for text and select controls Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- JavaScript.java 8 Aug 2002 20:47:22 -0000 1.8 +++ JavaScript.java 13 Aug 2002 20:00:39 -0000 1.9 @@ -366,6 +366,8 @@ static public class Form extends HTMLElement { + private Scriptable _controls; + public String getClassName() { return "Form"; } @@ -388,6 +390,22 @@ getDelegate().setAction( action ); } + + void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) + throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { + super.initialize( parent, scriptable ); + initializeControls(); + } + + + private void initializeControls() throws PropertyException, NotAFunctionException, JavaScriptException, SAXException { + ScriptableDelegate scriptables[] = getDelegate().getControls(); + Control[] controls = new Control[ scriptables.length ]; + for (int i = 0; i < controls.length; i++) { + controls[ i ] = (Control) toScriptable( scriptables[ i ] ); + } + _controls = Context.getCurrentContext().newArray( this, controls ); + } private WebForm.Scriptable getDelegate() { |
From: Russell G. <rus...@us...> - 2002-08-13 20:00:41
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv31453/src/com/meterware/httpunit Modified Files: FormControl.java WebForm.java Log Message: Added onChange method for text and select controls Index: FormControl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- FormControl.java 8 Aug 2002 20:47:21 -0000 1.16 +++ FormControl.java 13 Aug 2002 20:00:39 -0000 1.17 @@ -508,10 +508,29 @@ } -class TextFormControl extends FormControl { +abstract class ScalarFormControl extends FormControl { - private String[] _value = new String[1]; - private String[] _defaultValue; + private final String _onChangeEvent; + + + public ScalarFormControl( Node node ) { + super( node ); + _onChangeEvent = NodeUtils.getNodeAttribute( node, "onchange" ); + } + + + protected void sendOnChangeEvent() { + if (_onChangeEvent.length() > 0) getScriptableObject().doEvent( _onChangeEvent ); + } + +} + + +class TextFormControl extends ScalarFormControl { + + private String[] _value = new String[1]; + private String[] _defaultValue; + private Scriptable _scriptable; public TextFormControl( Node node, String defaultValue ) { @@ -538,7 +557,8 @@ public ScriptableDelegate getScriptableObject() { - return new Scriptable(); + if (_scriptable == null) _scriptable = new Scriptable(); + return _scriptable; } @@ -549,12 +569,15 @@ void claimValue( List values ) { if (isReadOnly()) return; + + String oldValue = getValues()[0]; if (values.isEmpty()) { _value[0] = ""; } else { _value[0] = (String) values.get(0); values.remove(0); } + if (!(oldValue.equals( _value[0] ))) sendOnChangeEvent(); } @@ -637,7 +660,7 @@ } -class FileSubmitFormControl extends FormControl { +class FileSubmitFormControl extends ScalarFormControl { private UploadFileSpec _fileToUpload; @@ -684,7 +707,7 @@ } -class SelectionFormControl extends FormControl { +class SelectionFormControl extends ScalarFormControl { private final boolean _multiSelect; private final boolean _listBox; @@ -770,7 +793,8 @@ void claimUniqueValue( List values ) { - _selectionOptions.claimUniqueValues( values ); + boolean changed = _selectionOptions.claimUniqueValues( values ); + if (changed) sendOnChangeEvent(); } @@ -884,21 +908,23 @@ } - void claimUniqueValues( List values ) { - for (int i = 0; i < _options.length; i++) _options[i].setSelected( false ); - + boolean claimUniqueValues( List values ) { + boolean changed = false; int numMatches = 0; for (int i = 0; i < _options.length; i++) { - if (values.contains( _options[i].getValue() )) { - _options[i].setSelected( true ); + final boolean newValue = values.contains( _options[i].getValue() ); + if (newValue != _options[i].isSelected()) changed = true; + _options[i].setSelected( newValue ); + if (newValue) { values.remove( _options[i].getValue() ); numMatches++; - if (!_multiSelect) break; + if (!_multiSelect) for (++i; i < _options.length; i++) _options[i].setSelected( false ); } } if (!_listBox && numMatches == 0) { throw new IllegalParameterValueException( getName(), (String) values.get(0), getOptionValues() ); } + return changed; } Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.56 retrieving revision 1.57 diff -u -r1.56 -r1.57 --- WebForm.java 13 Aug 2002 17:57:47 -0000 1.56 +++ WebForm.java 13 Aug 2002 20:00:39 -0000 1.57 @@ -435,6 +435,16 @@ public void setParameterValue( String name, String value ) { getParameter( name ).getScriptableObject().set( "value", value ); } + + + public ScriptableDelegate[] getControls() { + FormControl[] controls = getFormControls(); + ScriptableDelegate[] result = new ScriptableDelegate[ controls.length ]; + for (int i = 0; i < result.length; i++) { + result[i] = controls[i].getScriptableObject(); + } + return result; + } } |
From: Russell G. <rus...@us...> - 2002-08-13 20:00:41
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv31453/doc Modified Files: Javascript-support.html release_notes.txt Log Message: Added onChange method for text and select controls Index: Javascript-support.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Javascript-support.html,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Javascript-support.html 8 Aug 2002 20:47:21 -0000 1.4 +++ Javascript-support.html 13 Aug 2002 20:00:38 -0000 1.5 @@ -63,13 +63,21 @@ <h3>Text</h3> <h4>properties</h4> <ul> -<li>value - read/write - the current text value</li> +<li>value - read/write - the current text value</li> +</ul> +<h4>events</h4> +<ul> +<li>onChange - invoked when the value of the control is changed via form.setParameter</li> </ul> <h3>TextArea</h3> <h4>properties</h4> <ul> -<li>value - read/write - the current text value</li> +<li>value - read/write - the current text value</li> +</ul> +<h4>events</h4> +<ul> +<li>onChange - invoked when the value of the control is changed via form.setParameter</li> </ul> <h3>Hidden</h3> @@ -81,7 +89,11 @@ <h3>Password</h3> <h4>properties</h4> <ul> -<li>value - read/write - the current text value</li> +<li>value - read/write - the current text value</li> +</ul> +<h4>events</h4> +<ul> +<li>onChange - invoked when the value of the control is changed via form.setParameter</li> </ul> <h3>Checkbox</h3> @@ -97,6 +109,10 @@ <li>selectedIndex - read-only - the index of the selected option</li> <li>options - read-write - an array of the options associated with the control</li> <li>options.length - read-write - the number of options associated with the control</li> +</ul> +<h4>events</h4> +<ul> +<li>onChange - invoked when the value of the control is changed via form.setParameter</li> </ul> <h3>Option</h3> Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.134 retrieving revision 1.135 diff -u -r1.134 -r1.135 --- release_notes.txt 13 Aug 2002 17:57:47 -0000 1.134 +++ release_notes.txt 13 Aug 2002 20:00:38 -0000 1.135 @@ -12,6 +12,10 @@ Revision History: +13-Aug-2002 +Additions: + 1. The onChange event now works for Select controls, Text controls, and TextArea controls. + 9-Aug-2002 Additions: 1. The SubmitButton class now supports a click() method to submit the form using that button. |
From: Russell G. <rus...@us...> - 2002-08-13 17:57:50
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv25269/src/com/meterware/httpunit Modified Files: SubmitButton.java WebForm.java WebRequestSource.java Log Message: Added Button.submit to submit a form from a button Index: SubmitButton.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/SubmitButton.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- SubmitButton.java 25 Mar 2002 05:07:29 -0000 1.9 +++ SubmitButton.java 13 Aug 2002 17:57:47 -0000 1.10 @@ -22,6 +22,7 @@ import java.io.IOException; import org.w3c.dom.Node; +import org.xml.sax.SAXException; /** * This class represents a submit button in an HTML form. @@ -29,7 +30,7 @@ public class SubmitButton extends FormControl { - public static SubmitButton UNNAMED_BUTTON = new SubmitButton(); +// public static SubmitButton UNNAMED_BUTTON = new SubmitButton(); /** @@ -50,6 +51,15 @@ /** + * Performs the action associated with clicking this button. For a submit button this typically + * submits the form. + */ + public void click() throws IOException, SAXException { + _form.submit( this ); + } + + + /** * Returns true if this submit button is an image map. **/ public boolean isImageButton() { @@ -102,17 +112,25 @@ SubmitButton( WebForm form, Node node ) { super( node ); + _form = form; _isImageButton = NodeUtils.getNodeAttribute( node, "type" ).equalsIgnoreCase( "image" ); _id = NodeUtils.getNodeAttribute( node, "id" ); } - public void setPressed( boolean pressed ) { + SubmitButton( WebForm form ) { + _form = form; + _id = ""; + _isImageButton = false; + } + + + void setPressed( boolean pressed ) { _pressed = pressed; } - public void setLocation( int x, int y ) { + void setLocation( int x, int y ) { _x = x; _y = y; } @@ -120,19 +138,13 @@ //------------------------------------------ private members ---------------------------------- - + private final WebForm _form; private final String _id; private final boolean _isImageButton; private boolean _pressed; private int _x; private int _y; private String[] _value = new String[1]; - - - private SubmitButton() { - _id = ""; - _isImageButton = false; - } private String[] toArray( String value ) { Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.55 retrieving revision 1.56 diff -u -r1.55 -r1.56 --- WebForm.java 8 Aug 2002 20:47:21 -0000 1.55 +++ WebForm.java 13 Aug 2002 17:57:47 -0000 1.56 @@ -49,8 +49,16 @@ * Submits this form using the web client from which it was originally obtained. **/ public WebResponse submit() throws IOException, SAXException { + return submit( getDefaultButton() ); + } + + + /** + * Submits this form using the web client from which it was originally obtained. + **/ + WebResponse submit( SubmitButton button ) throws IOException, SAXException { String event = NodeUtils.getNodeAttribute( getNode(), "onsubmit" ); - if (event.length() == 0 || getScriptableObject().doEvent( event )) return submitRequest(); + if (event.length() == 0 || getScriptableObject().doEvent( event )) return submitRequest( getRequest( button ) ); return getBaseResponse(); } @@ -475,10 +483,8 @@ private SubmitButton getDefaultButton() { if (getSubmitButtons().length == 1) { return getSubmitButtons()[0]; - } else if (getSubmitButtonVector().contains( SubmitButton.UNNAMED_BUTTON )) { - return getSubmitButton( "" ); } else { - return null; + return getSubmitButton( "" ); } } @@ -492,7 +498,7 @@ if (control instanceof SubmitButton) _buttonVector.add( control ); } - if (_buttonVector.isEmpty()) _buttonVector.addElement( SubmitButton.UNNAMED_BUTTON ); + if (_buttonVector.isEmpty()) _buttonVector.addElement( new SubmitButton( this ) ); } return _buttonVector; } Index: WebRequestSource.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequestSource.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- WebRequestSource.java 6 Aug 2002 19:14:56 -0000 1.11 +++ WebRequestSource.java 13 Aug 2002 17:57:47 -0000 1.12 @@ -174,9 +174,18 @@ **/ final protected WebResponse submitRequest() throws IOException, SAXException { + return submitRequest( getRequest() ); + } + + + /** + * Submits a request to the web client from which this request source was originally obtained. + **/ + final + protected WebResponse submitRequest( WebRequest request ) throws IOException, SAXException { return getDestination().equals( "#" ) ? _baseResponse - : _baseResponse.getClient().sendRequest( getRequest() ); + : _baseResponse.getClient().sendRequest( request ); } |
From: Russell G. <rus...@us...> - 2002-08-13 17:57:50
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv25269/test/com/meterware/httpunit Modified Files: WebFormTest.java Log Message: Added Button.submit to submit a form from a button Index: WebFormTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- WebFormTest.java 1 Aug 2002 14:58:59 -0000 1.23 +++ WebFormTest.java 13 Aug 2002 17:57:47 -0000 1.24 @@ -79,6 +79,23 @@ } + public void testSubmitFromButton() throws Exception { + defineWebPage( "Form", "<form method=GET id=main action = 'tryMe'>" + + "<Input type=text Name=name>" + + "<input type=\"checkbox\" name=second checked>Enabled" + + "<input type=submit name=save value=none>" + + "<input type=submit name=save value=all>" + + "</form>" ); + defineResource( "/tryMe?name=master&second=on&save=all", "You made it!" ); + WebResponse wr = _wc.getResponse( getHostPath() + "/Form.html" ); + WebForm form = wr.getFormWithID( "main" ); + form.setParameter( "name", "master" ); + SubmitButton button = form.getSubmitButton( "save", "all" ); + button.click(); + assertEquals( "Expected response", "You made it!", _wc.getCurrentPage().getText() ); + } + + public void testFindNoForm() throws Exception { defineWebPage( "NoForms", "This has no forms but it does" + "have <a href=\"/other.html\">an active link</A>" + |
From: Russell G. <rus...@us...> - 2002-08-13 17:57:50
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv25269 Modified Files: .cvsignore Log Message: Added Button.submit to submit a form from a button Index: .cvsignore =================================================================== RCS file: /cvsroot/httpunit/httpunit/.cvsignore,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- .cvsignore 28 Feb 2002 14:30:32 -0000 1.3 +++ .cvsignore 13 Aug 2002 17:57:47 -0000 1.4 @@ -1,5 +1,9 @@ build *.ipr +*.iws savejars dist -lib \ No newline at end of file +lib +bin +.project +.classpath \ No newline at end of file |
From: Russell G. <rus...@us...> - 2002-08-13 17:57:50
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv25269/doc Modified Files: release_notes.txt Log Message: Added Button.submit to submit a form from a button Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.133 retrieving revision 1.134 diff -u -r1.133 -r1.134 --- release_notes.txt 8 Aug 2002 20:47:21 -0000 1.133 +++ release_notes.txt 13 Aug 2002 17:57:47 -0000 1.134 @@ -12,6 +12,10 @@ Revision History: + 9-Aug-2002 +Additions: + 1. The SubmitButton class now supports a click() method to submit the form using that button. + 8-Aug-2002 Changes: 1. The class com.meterware.httpunit.ScriptableObject has been renamed as com.meterware.httpunit.scripting.ScriptableDelegate |
From: Russell G. <rus...@us...> - 2002-08-13 16:19:26
|
Update of /cvsroot/httpunit/httpunit/jars In directory usw-pr-cvs1:/tmp/cvs-serv22734 Added Files: js.jar Log Message: Re-added with binary option |
From: Russell G. <rus...@us...> - 2002-08-13 16:18:35
|
Update of /cvsroot/httpunit/httpunit/jars In directory usw-pr-cvs1:/tmp/cvs-serv22388 Removed Files: js.jar Log Message: remove js.jar (forgot binary option) |
From: Russell G. <rus...@us...> - 2002-08-08 20:47:26
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv16831/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java JavaScriptEngineFactory.java Log Message: Class renaming, added support for Option constructor and options property writing Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- JavaScript.java 7 Aug 2002 20:36:24 -0000 1.7 +++ JavaScript.java 8 Aug 2002 20:47:22 -0000 1.8 @@ -20,13 +20,15 @@ * *******************************************************************************************************************/ import com.meterware.httpunit.HTMLPage; -import com.meterware.httpunit.ScriptEngine; import com.meterware.httpunit.WebForm; import com.meterware.httpunit.WebResponse; import com.meterware.httpunit.WebLink; import com.meterware.httpunit.WebImage; -import com.meterware.httpunit.scripting.SelectionOptions; + +import com.meterware.httpunit.scripting.ScriptingEngine; +import com.meterware.httpunit.scripting.ScriptableDelegate; import com.meterware.httpunit.scripting.SelectionOption; +import com.meterware.httpunit.scripting.SelectionOptions; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; @@ -73,9 +75,9 @@ } - abstract static class JavaScriptEngine extends ScriptableObject implements ScriptEngine { + abstract static class JavaScriptEngine extends ScriptableObject implements ScriptingEngine { - protected com.meterware.httpunit.ScriptableObject _scriptable; + protected ScriptableDelegate _scriptable; public void executeScript( String script ) { @@ -100,7 +102,7 @@ } - void initialize( JavaScriptEngine parent, com.meterware.httpunit.ScriptableObject scriptable ) + void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { _scriptable = scriptable; _scriptable.setScriptEngine( this ); @@ -135,10 +137,10 @@ private Object convertIfNeeded( final Object property ) { if (property == null) return NOT_FOUND; - if (!(property instanceof com.meterware.httpunit.ScriptableObject)) return property; + if (!(property instanceof ScriptableDelegate)) return property; try { - return toScriptable( (com.meterware.httpunit.ScriptableObject) property ); + return toScriptable( (ScriptableDelegate) property ); } catch (PropertyException e) { throw new RuntimeException( e.toString() ); } catch (NotAFunctionException e) { @@ -164,7 +166,7 @@ * Converts a scriptable delegate obtained from a subobject into the appropriate Rhino-compatible Scriptable. * This default implementation throws an exception. **/ - Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) + Scriptable toScriptable( ScriptableDelegate delegate ) throws PropertyException, NotAFunctionException, JavaScriptException, SAXException { throw new UnsupportedOperationException(); } @@ -197,7 +199,7 @@ } - void initialize( JavaScriptEngine parent, com.meterware.httpunit.ScriptableObject scriptable ) + void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { super.initialize( parent, scriptable ); _document = (Document) Context.getCurrentContext().newObject( this, "Document" ); @@ -212,7 +214,7 @@ } - Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) { + Scriptable toScriptable( ScriptableDelegate delegate ) { return null; } @@ -235,7 +237,7 @@ } - void initialize( JavaScriptEngine parent, com.meterware.httpunit.ScriptableObject scriptable ) + void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { super.initialize( parent, scriptable ); initializeLinks(); @@ -294,7 +296,7 @@ } - Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) + Scriptable toScriptable( com.meterware.httpunit.scripting.ScriptableDelegate delegate ) throws PropertyException, JavaScriptException, NotAFunctionException, SAXException { JavaScriptEngine element = (JavaScriptEngine) Context.getCurrentContext().newObject( this, getScriptableClassName( delegate ) ); element.initialize( this, delegate ); @@ -302,7 +304,7 @@ } - private String getScriptableClassName( com.meterware.httpunit.ScriptableObject delegate ) { + private String getScriptableClassName( ScriptableDelegate delegate ) { if (delegate instanceof WebForm.Scriptable) { return "Form"; } else if (delegate instanceof WebLink.Scriptable) { @@ -310,7 +312,7 @@ } else if (delegate instanceof WebImage.Scriptable) { return "Image"; } else { - throw new IllegalArgumentException( "Unknown ScriptableObject class: " + delegate.getClass() ); + throw new IllegalArgumentException( "Unknown ScriptableDelegate class: " + delegate.getClass() ); } } @@ -332,7 +334,7 @@ } - void initialize( JavaScriptEngine parent, com.meterware.httpunit.ScriptableObject scriptable ) + void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { super.initialize( parent, scriptable ); _document = (Document) parent; @@ -369,7 +371,7 @@ } - Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) + Scriptable toScriptable( ScriptableDelegate delegate ) throws PropertyException, NotAFunctionException, JavaScriptException, SAXException { final Control control = (Control) Context.getCurrentContext().newObject( this, "Control" ); control.initialize( this, delegate ); @@ -402,7 +404,7 @@ } - Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) + Scriptable toScriptable( ScriptableDelegate delegate ) throws PropertyException, JavaScriptException, NotAFunctionException, SAXException { JavaScriptEngine element = (JavaScriptEngine) Context.getCurrentContext().newObject( this, getScriptableClassName( delegate ) ); element.initialize( this, delegate ); @@ -410,11 +412,11 @@ } - private String getScriptableClassName( com.meterware.httpunit.ScriptableObject delegate ) { + private String getScriptableClassName( ScriptableDelegate delegate ) { if (delegate instanceof SelectionOptions) { return "Options"; } else { - throw new IllegalArgumentException( "Unknown ScriptableObject class: " + delegate.getClass() ); + throw new IllegalArgumentException( "Unknown ScriptableDelegate class: " + delegate.getClass() ); } } @@ -433,18 +435,33 @@ } + public void jsSet_length( int length ) { + getDelegate().setLength( length ); + } + + + public void put( int i, Scriptable scriptable, Object object ) { + if (object == null) { + getDelegate().put( i, null ); + } else { + if (!(object instanceof Option)) throw new IllegalArgumentException( "May only add an Option to this array" ); + Option option = (Option) object; + getDelegate().put( i, option.getDelegate() ); + } + } + + private SelectionOptions getDelegate() { return (SelectionOptions) _scriptable; } - Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) + Scriptable toScriptable( ScriptableDelegate delegate ) throws PropertyException, JavaScriptException, NotAFunctionException, SAXException { JavaScriptEngine element = (JavaScriptEngine) Context.getCurrentContext().newObject( this, "Option" ); element.initialize( this, delegate ); return element; } - } @@ -455,6 +472,12 @@ } + public void jsConstructor( String text, String value, boolean defaultSelected, boolean selected ) { + _scriptable = WebResponse.newDelegate( "Option" ); + getDelegate().initialize( text, value, defaultSelected, selected ); + } + + public int jsGet_index() { return getDelegate().getIndex(); } @@ -465,6 +488,11 @@ } + public void jsSet_text( String text ) { + getDelegate().setText( text ); + } + + public String jsGet_value() { return getDelegate().getValue(); } @@ -490,8 +518,9 @@ } - private SelectionOption getDelegate() { + SelectionOption getDelegate() { return (SelectionOption) _scriptable; } } + } Index: JavaScriptEngineFactory.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScriptEngineFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JavaScriptEngineFactory.java 5 Aug 2002 18:58:43 -0000 1.1 +++ JavaScriptEngineFactory.java 8 Aug 2002 20:47:22 -0000 1.2 @@ -19,7 +19,7 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ -import com.meterware.httpunit.ScriptingEngineFactory; +import com.meterware.httpunit.scripting.ScriptingEngineFactory; import com.meterware.httpunit.WebResponse; import java.lang.reflect.InvocationTargetException; |
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting In directory usw-pr-cvs1:/tmp/cvs-serv16831/src/com/meterware/httpunit/scripting Modified Files: SelectionOption.java SelectionOptions.java Added Files: ScriptableDelegate.java ScriptingEngine.java ScriptingEngineFactory.java Log Message: Class renaming, added support for Option constructor and options property writing ***** Error reading new file[Errno 2] No such file or directory: 'ScriptableDelegate.java' ***** Error reading new file[Errno 2] No such file or directory: 'ScriptingEngine.java' ***** Error reading new file[Errno 2] No such file or directory: 'ScriptingEngineFactory.java' Index: SelectionOption.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting/SelectionOption.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SelectionOption.java 7 Aug 2002 20:36:24 -0000 1.1 +++ SelectionOption.java 8 Aug 2002 20:47:22 -0000 1.2 @@ -30,7 +30,7 @@ String getText(); -// void setText( String text ); + void setText( String text ); String getValue(); @@ -49,5 +49,8 @@ int getIndex(); + + + void initialize( String text, String value, boolean defaultSelected, boolean selected ); } Index: SelectionOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting/SelectionOptions.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SelectionOptions.java 7 Aug 2002 20:36:24 -0000 1.1 +++ SelectionOptions.java 8 Aug 2002 20:47:22 -0000 1.2 @@ -23,11 +23,27 @@ /** + * Represents an array of Options * * @author <a href="mailto:rus...@ac...">Russell Gold</a> **/ public interface SelectionOptions { + /** + * Returns the length of this array + */ int getLength(); + + + /** + * Sets a new length to this array + */ + void setLength( int length ); + + + /** + * Specify the specified option + */ + void put( int i, SelectionOption option ); } |
From: Russell G. <rus...@us...> - 2002-08-08 20:47:26
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv16831/src/com/meterware/httpunit Modified Files: FormControl.java HTMLPage.java HttpUnitOptions.java WebForm.java WebImage.java WebLink.java WebResponse.java Removed Files: ScriptEngine.java ScriptableObject.java ScriptingEngineFactory.java Log Message: Class renaming, added support for Option constructor and options property writing Index: FormControl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- FormControl.java 7 Aug 2002 20:36:23 -0000 1.15 +++ FormControl.java 8 Aug 2002 20:47:21 -0000 1.16 @@ -21,6 +21,7 @@ *******************************************************************************************************************/ import com.meterware.httpunit.scripting.SelectionOptions; import com.meterware.httpunit.scripting.SelectionOption; +import com.meterware.httpunit.scripting.ScriptableDelegate; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; @@ -82,7 +83,7 @@ /** * Returns a scriptable object which can act as a proxy for this control. */ - public ScriptableObject getScriptableObject() { + public ScriptableDelegate getScriptableObject() { return new Scriptable(); } @@ -243,7 +244,7 @@ } - class Scriptable extends ScriptableObject { + class Scriptable extends ScriptableDelegate { } } @@ -452,7 +453,7 @@ } - public ScriptableObject getScriptableObject() { + public ScriptableDelegate getScriptableObject() { return new Scriptable(); } @@ -536,7 +537,7 @@ } - public ScriptableObject getScriptableObject() { + public ScriptableDelegate getScriptableObject() { return new Scriptable(); } @@ -750,7 +751,7 @@ } - public ScriptableObject getScriptableObject() { + public ScriptableDelegate getScriptableObject() { if (_scriptable == null) _scriptable = new Scriptable(); return _scriptable; } @@ -778,7 +779,7 @@ } - class Option extends ScriptableObject implements SelectionOption { + static class Option extends ScriptableDelegate implements SelectionOption { private String _text; private String _value; @@ -787,6 +788,10 @@ private int _index; + Option() { + } + + Option( String text, String value, boolean selected ) { _text = text; _value = value; @@ -812,6 +817,14 @@ //------------------------- SelectionOption methods ------------------------------ + public void initialize( String text, String value, boolean defaultSelected, boolean selected ) { + _text = text; + _value = value; + _defaultSelected = defaultSelected; + _selected = selected; + } + + public int getIndex() { return _index; } @@ -822,6 +835,11 @@ } + public void setText( String text ) { + _text = text; + } + + public String getValue() { return _value; } @@ -848,13 +866,10 @@ } - class Options extends ScriptableObject implements SelectionOptions { + class Options extends ScriptableDelegate implements SelectionOptions { private Option[] _options; - private String[] _text; - private String[] _value; - Options( Node selectionNode ) { NodeList nl = ((Element) selectionNode).getElementsByTagName( "option" ); @@ -905,20 +920,16 @@ String[] getDisplayedText() { - if (_text == null) { - _text = new String[ _options.length ]; - for (int i = 0; i < _text.length; i++) _text[i] = _options[i].getText(); - } - return _text; + String[] displayedText = new String[ _options.length ]; + for (int i = 0; i < displayedText.length; i++) displayedText[i] = _options[i].getText(); + return displayedText; } String[] getValues() { - if (_value == null) { - _value = new String[ _options.length ]; - for (int i = 0; i < _value.length; i++) _value[i] = _options[i].getValue(); - } - return _value; + String[] values = new String[ _options.length ]; + for (int i = 0; i < values.length; i++) values[i] = _options[i].getValue(); + return values; } @@ -935,6 +946,46 @@ public int getLength() { return _options.length; + } + + + public void setLength( int length ) { + if (length < 0 || length >= _options.length) return; + Option[] newArray = new Option[ length ]; + System.arraycopy( _options, 0, newArray, 0, length ); + _options = newArray; + } + + + public void put( int i, SelectionOption option ) { + if (i < 0) return; + + if (option == null) { + if (i >= _options.length) return; + deleteOptionsEntry( i ); + } else { + if (i >= _options.length) { + i = _options.length; + expandOptionsArray(); + } + _options[i] = (Option) option; + _options[i].setIndex(i); + } + } + + + private void deleteOptionsEntry( int i ) { + Option[] newArray = new Option[ _options.length-1 ]; + System.arraycopy( _options, 0, newArray, 0, i ); + System.arraycopy( _options, i+1, newArray, i, newArray.length - i ); + _options = newArray; + } + + + private void expandOptionsArray() { + Option[] newArray = new Option[ _options.length+1 ]; + System.arraycopy( _options, 0, newArray, 0, _options.length ); + _options = newArray; } Index: HTMLPage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLPage.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- HTMLPage.java 6 Aug 2002 21:42:08 -0000 1.5 +++ HTMLPage.java 8 Aug 2002 20:47:21 -0000 1.6 @@ -19,6 +19,8 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ +import com.meterware.httpunit.scripting.ScriptableDelegate; + import java.io.ByteArrayInputStream; import java.io.UnsupportedEncodingException; @@ -127,7 +129,7 @@ } - public class Scriptable extends ScriptableObject { + public class Scriptable extends ScriptableDelegate { public Object get( String propertyName ) { WebForm wf = getFormWithName( propertyName ); Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- HttpUnitOptions.java 5 Aug 2002 18:58:43 -0000 1.22 +++ HttpUnitOptions.java 8 Aug 2002 20:47:21 -0000 1.23 @@ -20,6 +20,8 @@ * *******************************************************************************************************************/ +import com.meterware.httpunit.scripting.ScriptingEngineFactory; + import java.util.Vector; /** Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.54 retrieving revision 1.55 diff -u -r1.54 -r1.55 --- WebForm.java 6 Aug 2002 19:14:55 -0000 1.54 +++ WebForm.java 8 Aug 2002 20:47:21 -0000 1.55 @@ -19,6 +19,8 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ +import com.meterware.httpunit.scripting.ScriptableDelegate; + import java.io.IOException; import java.net.URL; @@ -411,7 +413,7 @@ } - public class Scriptable extends ScriptableObject { + public class Scriptable extends ScriptableDelegate { public String getAction() { return WebForm.this.getAction(); } public void setAction( String newAction ) { setDestination( newAction ); } @@ -593,7 +595,7 @@ } - ScriptableObject getScriptableObject() { + ScriptableDelegate getScriptableObject() { return getControls()[0].getScriptableObject(); } Index: WebImage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebImage.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- WebImage.java 5 Aug 2002 17:34:25 -0000 1.2 +++ WebImage.java 8 Aug 2002 20:47:21 -0000 1.3 @@ -19,6 +19,8 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ +import com.meterware.httpunit.scripting.ScriptableDelegate; + import java.net.URL; import org.w3c.dom.Node; @@ -77,7 +79,7 @@ } - public class Scriptable extends ScriptableObject { + public class Scriptable extends ScriptableDelegate { public Object get( String propertyName ) { if (propertyName.equalsIgnoreCase( "src" )) { Index: WebLink.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- WebLink.java 6 Aug 2002 19:14:56 -0000 1.23 +++ WebLink.java 8 Aug 2002 20:47:21 -0000 1.24 @@ -19,6 +19,8 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ +import com.meterware.httpunit.scripting.ScriptableDelegate; + import java.net.URL; import java.net.MalformedURLException; @@ -230,7 +232,7 @@ } - public class Scriptable extends ScriptableObject { + public class Scriptable extends ScriptableDelegate { public Object get( String propertyName ) { if (propertyName.equalsIgnoreCase( "href" )) { Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.72 retrieving revision 1.73 diff -u -r1.72 -r1.73 --- WebResponse.java 6 Aug 2002 19:14:57 -0000 1.72 +++ WebResponse.java 8 Aug 2002 20:47:21 -0000 1.73 @@ -20,6 +20,8 @@ * *******************************************************************************************************************/ +import com.meterware.httpunit.scripting.ScriptableDelegate; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -488,7 +490,16 @@ } - public class Scriptable extends ScriptableObject { + public static ScriptableDelegate newDelegate( String delegateClassName ) { + if (delegateClassName.equalsIgnoreCase( "Option" )) { + return new SelectionFormControl.Option(); + } else { + throw new IllegalArgumentException( "No such scripting class supported: " + delegateClassName ); + } + } + + + public class Scriptable extends ScriptableDelegate { public void alert( String message ) { _alerts.addLast( message ); |
From: Russell G. <rus...@us...> - 2002-08-08 20:47:26
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv16831/doc Modified Files: Javascript-support.html release_notes.txt Log Message: Class renaming, added support for Option constructor and options property writing Index: Javascript-support.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Javascript-support.html,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Javascript-support.html 7 Aug 2002 20:36:23 -0000 1.3 +++ Javascript-support.html 8 Aug 2002 20:47:21 -0000 1.4 @@ -93,19 +93,22 @@ <h3>Select</h3> <h4>properties</h4> <ul> -<li>length - read-only - the number of options associated with the control</li> -<li>selectedIndex - read-only - the index of the selected option</li> -<li>options.length - read-only - the number of options associated with the control</li> +<li>length - read-only - the number of options associated with the control</li> +<li>selectedIndex - read-only - the index of the selected option</li> +<li>options - read-write - an array of the options associated with the control</li> +<li>options.length - read-write - the number of options associated with the control</li> </ul> <h3>Option</h3> +<h4>constructor</h4> +You may construct an Option object and assign it to an element in the Select.options array <h4>properties</h4> <ul> -<li>text - read-only - the display text associated with the option (listed after the <'option> tag)</li> -<li>value - read-write - the value associated with the option (from the 'value' attribute)</li> +<li>text - read-write - the display text associated with the option (listed after the <'option> tag)</li> +<li>value - read-write - the value associated with the option (from the 'value' attribute)</li> <li>selected - read-write - true if this option is currently selected</li> <li>defaultSelected - read-only - true if this option is selected by default</li> -<li>index - read-only - the index of this option in its select</li> +<li>index - read-only - the index of this option in its select</li> </ul> </body> Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.132 retrieving revision 1.133 diff -u -r1.132 -r1.133 --- release_notes.txt 7 Aug 2002 20:36:23 -0000 1.132 +++ release_notes.txt 8 Aug 2002 20:47:21 -0000 1.133 @@ -12,10 +12,17 @@ Revision History: + 8-Aug-2002 +Changes: + 1. The class com.meterware.httpunit.ScriptableObject has been renamed as com.meterware.httpunit.scripting.ScriptableDelegate + +Additions: + 1. The Option object now supports a constructor and writing to the text property + 7-Aug-2002 Additions: 1. JavaScript: the Select control now supports the length, options, and selectedIndex properties - 2. JavaScript: the Options object now supports the index, defaultSelected, selected (r/w), value (r/w) and + 2. JavaScript: the Option object now supports the index, defaultSelected, selected (r/w), value (r/w) and text (read-only) properties 6-Aug-2002 |
From: Russell G. <rus...@us...> - 2002-08-08 20:47:26
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv16831/test/com/meterware/httpunit/javascript Modified Files: ScriptingTest.java Log Message: Class renaming, added support for Option constructor and options property writing Index: ScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ScriptingTest.java 7 Aug 2002 20:36:24 -0000 1.10 +++ ScriptingTest.java 8 Aug 2002 20:47:22 -0000 1.11 @@ -380,6 +380,7 @@ "<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" ); @@ -392,6 +393,52 @@ 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-07 20:36:27
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv31870/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java Log Message: Added JavaScript support for Select and Option Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- JavaScript.java 6 Aug 2002 19:14:59 -0000 1.6 +++ JavaScript.java 7 Aug 2002 20:36:24 -0000 1.7 @@ -25,6 +25,8 @@ import com.meterware.httpunit.WebResponse; import com.meterware.httpunit.WebLink; import com.meterware.httpunit.WebImage; +import com.meterware.httpunit.scripting.SelectionOptions; +import com.meterware.httpunit.scripting.SelectionOption; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; @@ -66,6 +68,8 @@ ScriptableObject.defineClass( scope, Control.class ); ScriptableObject.defineClass( scope, Link.class ); ScriptableObject.defineClass( scope, Image.class ); + ScriptableObject.defineClass( scope, Options.class ); + ScriptableObject.defineClass( scope, Option.class ); } @@ -115,7 +119,21 @@ if (result != NOT_FOUND) return result; if (_scriptable == null) return NOT_FOUND; - final Object property = _scriptable.get( propertyName ); + return convertIfNeeded( _scriptable.get( propertyName ) ); + + } + + + public Object get( int i, Scriptable scriptable ) { + Object result = super.get( i, scriptable ); + if (result != NOT_FOUND) return result; + if (_scriptable == null) return NOT_FOUND; + + return convertIfNeeded( _scriptable.get( i ) ); + } + + + private Object convertIfNeeded( final Object property ) { if (property == null) return NOT_FOUND; if (!(property instanceof com.meterware.httpunit.ScriptableObject)) return property; @@ -358,6 +376,22 @@ return control; } + + public String jsGet_action() { + return getDelegate().getAction(); + } + + + public void jsSet_action( String action ) { + getDelegate().setAction( action ); + } + + + + private WebForm.Scriptable getDelegate() { + return (WebForm.Scriptable) _scriptable; + } + } @@ -366,6 +400,98 @@ public String getClassName() { return "Control"; } + + + Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) + throws PropertyException, JavaScriptException, NotAFunctionException, SAXException { + JavaScriptEngine element = (JavaScriptEngine) Context.getCurrentContext().newObject( this, getScriptableClassName( delegate ) ); + element.initialize( this, delegate ); + return element; + } + + + private String getScriptableClassName( com.meterware.httpunit.ScriptableObject delegate ) { + if (delegate instanceof SelectionOptions) { + return "Options"; + } else { + throw new IllegalArgumentException( "Unknown ScriptableObject class: " + delegate.getClass() ); + } + } + } + + static public class Options extends JavaScriptEngine { + + public String getClassName() { + return "Options"; + } + + + public int jsGet_length() { + return getDelegate().getLength(); + } + + + private SelectionOptions getDelegate() { + return (SelectionOptions) _scriptable; + } + + + Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) + throws PropertyException, JavaScriptException, NotAFunctionException, SAXException { + JavaScriptEngine element = (JavaScriptEngine) Context.getCurrentContext().newObject( this, "Option" ); + element.initialize( this, delegate ); + return element; + } + + } + + + static public class Option extends JavaScriptEngine { + + public String getClassName() { + return "Option"; + } + + + public int jsGet_index() { + return getDelegate().getIndex(); + } + + + public String jsGet_text() { + return getDelegate().getText(); + } + + + public String jsGet_value() { + return getDelegate().getValue(); + } + + + public void jsSet_value( String value ) { + getDelegate().setValue( value ); + } + + + public boolean jsGet_selected() { + return getDelegate().isSelected(); + } + + + public void jsSet_selected( boolean selected ) { + getDelegate().setSelected( selected ); + } + + + public boolean jsGet_defaultSelected() { + return getDelegate().isDefaultSelected(); + } + + + private SelectionOption getDelegate() { + return (SelectionOption) _scriptable; + } + } } |
From: Russell G. <rus...@us...> - 2002-08-07 20:36:27
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting In directory usw-pr-cvs1:/tmp/cvs-serv31870/src/com/meterware/httpunit/scripting Added Files: SelectionOption.java SelectionOptions.java Log Message: Added JavaScript support for Select and Option ***** Error reading new file[Errno 2] No such file or directory: 'SelectionOption.java' ***** Error reading new file[Errno 2] No such file or directory: 'SelectionOptions.java' |
From: Russell G. <rus...@us...> - 2002-08-07 20:36:27
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv31870/test/com/meterware/httpunit/javascript Modified Files: ScriptingTest.java Log Message: Added JavaScript support for Select and Option Index: ScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- ScriptingTest.java 6 Aug 2002 21:42:08 -0000 1.9 +++ ScriptingTest.java 7 Aug 2002 20:36:24 -0000 1.10 @@ -25,6 +25,7 @@ import com.meterware.httpunit.WebForm; import com.meterware.httpunit.WebLink; import com.meterware.httpunit.WebImage; +import com.meterware.httpunit.WebRequest; import junit.framework.TestSuite; import junit.textui.TestRunner; @@ -208,6 +209,25 @@ } + 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'>" + @@ -303,5 +323,75 @@ 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 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>" + + "</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" ) ); + } } |
From: Russell G. <rus...@us...> - 2002-08-07 20:36:27
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv31870/src/com/meterware/httpunit Modified Files: FormControl.java ScriptableObject.java Log Message: Added JavaScript support for Select and Option Index: FormControl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- FormControl.java 5 Aug 2002 19:42:52 -0000 1.14 +++ FormControl.java 7 Aug 2002 20:36:23 -0000 1.15 @@ -19,6 +19,9 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ +import com.meterware.httpunit.scripting.SelectionOptions; +import com.meterware.httpunit.scripting.SelectionOption; + import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.Element; @@ -681,14 +684,12 @@ class SelectionFormControl extends FormControl { + private final boolean _multiSelect; private final boolean _listBox; - private final String[] _optionValues; - private final String[] _displayedOptions; - private String[] _values; - private boolean[] _selectionIndexes; - private boolean[] _initialIndexes; + private Options _selectionOptions; + private Scriptable _scriptable; SelectionFormControl( Node node ) { @@ -697,27 +698,23 @@ _multiSelect = NodeUtils.isNodeAttributePresent( node, "multiple" ); _listBox = _multiSelect || NodeUtils.isNodeAttributePresent( node, "size" ); - _optionValues = getInitialOptionValues( node ); - _displayedOptions = getInitialDisplayedOptions( node ); - _initialIndexes = getInitialSelectionIndexes( node ); - _selectionIndexes = (boolean[]) _initialIndexes.clone(); - _values = getSelectedValues( _selectionIndexes, _optionValues ); + _selectionOptions = new Options( node ); } public String[] getValues() { - return _values; + return _selectionOptions.getSelectedValues(); } public String[] getOptionValues() { - return _optionValues; + return _selectionOptions.getValues(); } public String[] getDisplayedOptions() { - return _displayedOptions; + return _selectionOptions.getDisplayedText(); } @@ -729,6 +726,36 @@ } + class Scriptable extends FormControl.Scriptable { + + public Object get( String propertyName ) { + if (propertyName.equalsIgnoreCase( "options" )) { + return _selectionOptions; + } else if (propertyName.equalsIgnoreCase( "length" )) { + return new Integer( getOptionValues().length ); + } else if (propertyName.equalsIgnoreCase( "selectedIndex" )) { + return new Integer( _selectionOptions.getFirstSelectedIndex() ); + } else { + return super.get( propertyName ); + } + } + + + public void set( String propertyName, Object value ) { + if (propertyName.equalsIgnoreCase( "value" )) { + } else { + super.set( propertyName, value ); + } + } + } + + + public ScriptableObject getScriptableObject() { + if (_scriptable == null) _scriptable = new Scriptable(); + return _scriptable; + } + + void updateRequiredParameters( Hashtable required ) { if (isReadOnly()) required.put( getName(), getValues() ); } @@ -742,103 +769,200 @@ void claimUniqueValue( List values ) { - boolean[] matches = new boolean[ _optionValues.length ]; - int numMatches = 0; - for (int i = 0; i < matches.length; i++) { - matches[i] = values.contains( _optionValues[i] ); - if (matches[i]) { - numMatches++; - if (!_multiSelect) break; - } + _selectionOptions.claimUniqueValues( values ); + } + + + final void reset() { + _selectionOptions.reset(); + } + + + class Option extends ScriptableObject implements SelectionOption { + + private String _text; + private String _value; + private boolean _defaultSelected; + private boolean _selected; + private int _index; + + + Option( String text, String value, boolean selected ) { + _text = text; + _value = value; + _defaultSelected = _selected = selected; } - if (!_listBox) { - if (numMatches == 0) throw new IllegalParameterValueException( getName(), (String) values.get(0), getOptionValues() ); + + void reset() { + _selected = _defaultSelected; } - for (int i = 0; i < matches.length; i++) { - if (matches[i]) values.remove( _optionValues[i] ); + + void addValueIfSelected( List list ) { + if (_selected) list.add( _value ); } - _selectionIndexes = matches; - _values = getSelectedValues( matches, _optionValues ); - } + void setIndex( int index ) { + _index = index; + } - void reset() { - _selectionIndexes = (boolean[]) _initialIndexes.clone(); - _values = getSelectedValues( _selectionIndexes, _optionValues ); + + //------------------------- SelectionOption methods ------------------------------ + + + public int getIndex() { + return _index; + } + + + public String getText() { + return _text; + } + + + public String getValue() { + return _value; + } + + + public void setValue( String value ) { + _value = value; + } + + + public boolean isDefaultSelected() { + return _defaultSelected; + } + + + public void setSelected( boolean selected ) { + _selected = selected; + } + + + public boolean isSelected() { + return _selected; + } } - private String[] getSelectedValues( boolean[] selected, String[] optionValues ) { - ArrayList values = new ArrayList(); - for (int i = 0; i < selected.length; i++) { - if (selected[i]) { - values.add( optionValues[i] ); + class Options extends ScriptableObject implements SelectionOptions { + + private Option[] _options; + + private String[] _text; + private String[] _value; + + + Options( Node selectionNode ) { + NodeList nl = ((Element) selectionNode).getElementsByTagName( "option" ); + + _options = new Option[ nl.getLength() ]; + for (int i = 0; i < _options.length; i++) { + _options[i] = new Option( getValue( nl.item(i).getFirstChild() ), + getOptionValue( nl.item(i) ), + nl.item(i).getAttributes().getNamedItem( "selected" ) != null ); + _options[i].setIndex(i); } } - return (String[]) values.toArray( new String[ values.size() ] ); - } - private boolean[] getInitialSelectionIndexes( Node selectionNode ) { - boolean noneSelected = true; - NodeList nl = ((Element) selectionNode).getElementsByTagName( "option" ); - boolean isSelected[] = new boolean[ nl.getLength() ]; - for (int i = 0; i < nl.getLength(); i++) { - if (nl.item(i).getAttributes().getNamedItem( "selected" ) != null) { - isSelected[i] = true; - noneSelected = false; + void claimUniqueValues( List values ) { + for (int i = 0; i < _options.length; i++) _options[i].setSelected( false ); + + int numMatches = 0; + for (int i = 0; i < _options.length; i++) { + if (values.contains( _options[i].getValue() )) { + _options[i].setSelected( true ); + values.remove( _options[i].getValue() ); + numMatches++; + if (!_multiSelect) break; + } + } + if (!_listBox && numMatches == 0) { + throw new IllegalParameterValueException( getName(), (String) values.get(0), getOptionValues() ); } } - if (!_listBox && noneSelected && isSelected.length > 0) { - isSelected[0] = true; + + String[] getSelectedValues() { + ArrayList list = new ArrayList(); + for (int i = 0; i < _options.length; i++) { + _options[i].addValueIfSelected( list ); + } + if (!_listBox && list.isEmpty() && _options.length > 0) list.add( _options[0].getValue() ); + return (String[]) list.toArray( new String[ list.size() ] ); } - return isSelected; - } - private String[] getInitialDisplayedOptions( Node node ) { - Vector options = new Vector(); - NodeList nl = ((Element) node).getElementsByTagName( "option" ); - for (int i = 0; i < nl.getLength(); i++) { - options.addElement( getValue( nl.item(i).getFirstChild() ) ); + void reset() { + for (int i = 0; i < _options.length; i++) { + _options[i].reset(); + } } - String[] result = new String[ options.size() ]; - options.copyInto( result ); - return result; - } - private String[] getInitialOptionValues( Node selectNode ) { - NodeList nl = ((Element) selectNode).getElementsByTagName( "option" ); - ArrayList options = new ArrayList( nl.getLength() ); - for (int i = 0; i < nl.getLength(); i++) { - options.add( getOptionValue( nl.item(i) ) ); + String[] getDisplayedText() { + if (_text == null) { + _text = new String[ _options.length ]; + for (int i = 0; i < _text.length; i++) _text[i] = _options[i].getText(); + } + return _text; } - return (String[]) options.toArray( new String[ options.size() ] ); - } - private String getOptionValue( Node optionNode ) { - NamedNodeMap nnm = optionNode.getAttributes(); - if (nnm.getNamedItem( "value" ) != null) { - return getValue( nnm.getNamedItem( "value" ) ); - } else { - return getValue( optionNode.getFirstChild() ); + String[] getValues() { + if (_value == null) { + _value = new String[ _options.length ]; + for (int i = 0; i < _value.length; i++) _value[i] = _options[i].getValue(); + } + return _value; } - } - private static String getValue( Node node ) { - return (node == null) ? "" : emptyIfNull( node.getNodeValue() ); - } + + /** + * Returns the index of the first item selected, or -1 if none is selected. + */ + int getFirstSelectedIndex() { + for (int i = 0; i < _options.length; i++) { + if (_options[i].isSelected()) return i; + } + return -1; + } + + + public int getLength() { + return _options.length; + } - private static String emptyIfNull( String value ) { - return (value == null) ? "" : value; + public Object get( int index ) { + return _options[ index ]; + } + + + private String getOptionValue( Node optionNode ) { + NamedNodeMap nnm = optionNode.getAttributes(); + if (nnm.getNamedItem( "value" ) != null) { + return getValue( nnm.getNamedItem( "value" ) ); + } else { + return getValue( optionNode.getFirstChild() ); + } + } + + private String getValue( Node node ) { + return (node == null) ? "" : emptyIfNull( node.getNodeValue() ); + } + + + private String emptyIfNull( String value ) { + return (value == null) ? "" : value; + } + } + } //============================= exception class IllegalParameterValueException ====================================== Index: ScriptableObject.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ScriptableObject.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ScriptableObject.java 6 Aug 2002 19:14:55 -0000 1.3 +++ ScriptableObject.java 7 Aug 2002 20:36:24 -0000 1.4 @@ -58,6 +58,14 @@ /** + * Returns the value of the index property. Will return null if the property does not exist. + **/ + public Object get( int index ) { + return null; + } + + + /** * Sets the value of the named property. Will throw a runtime exception if the property does not exist or * cannot accept the specified value. **/ |
From: Russell G. <rus...@us...> - 2002-08-07 20:36:26
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv31870/doc Modified Files: Javascript-support.html release_notes.txt Log Message: Added JavaScript support for Select and Option Index: Javascript-support.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Javascript-support.html,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Javascript-support.html 6 Aug 2002 21:42:08 -0000 1.2 +++ Javascript-support.html 7 Aug 2002 20:36:23 -0000 1.3 @@ -34,6 +34,7 @@ <h3>Form</h3> <h4>properties</h4> <ul> +<li>action - r/w the action associated with the form</li> <li>document - the enclosing document</li> <li><name> - the name of a control in the form</li> </ul> @@ -87,6 +88,24 @@ <h4>properties</h4> <ul> <li>checked - read/write - the state of the checkbox</li> +</ul> + +<h3>Select</h3> +<h4>properties</h4> +<ul> +<li>length - read-only - the number of options associated with the control</li> +<li>selectedIndex - read-only - the index of the selected option</li> +<li>options.length - read-only - the number of options associated with the control</li> +</ul> + +<h3>Option</h3> +<h4>properties</h4> +<ul> +<li>text - read-only - the display text associated with the option (listed after the <'option> tag)</li> +<li>value - read-write - the value associated with the option (from the 'value' attribute)</li> +<li>selected - read-write - true if this option is currently selected</li> +<li>defaultSelected - read-only - true if this option is selected by default</li> +<li>index - read-only - the index of this option in its select</li> </ul> </body> Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.131 retrieving revision 1.132 diff -u -r1.131 -r1.132 --- release_notes.txt 6 Aug 2002 21:42:08 -0000 1.131 +++ release_notes.txt 7 Aug 2002 20:36:23 -0000 1.132 @@ -4,7 +4,7 @@ 1. The "_new" and "_empty" frame targets are not handled correctly 2. The "accept-charset" attribute for forms is ignored; the page content character set is used to encode any response. This behavior matches that currently used by IE and Navigator. - 3. The regression test "pseudo-server" does not appear to run properly under JDK 1.4 + 3. The regression test "pseudo-server" does not appear to run properly under Unix. Limitations: 1. JavaScript support is minimal @@ -12,6 +12,12 @@ Revision History: + 7-Aug-2002 +Additions: + 1. JavaScript: the Select control now supports the length, options, and selectedIndex properties + 2. JavaScript: the Options object now supports the index, defaultSelected, selected (r/w), value (r/w) and + text (read-only) properties + 6-Aug-2002 Acknowledgements: Thanks to Hans-Joerg Hessmann for a faster algorithm for the table lookups @@ -22,6 +28,7 @@ Additions: 1. JavaScript: the link.onClick event is now supported 2. JavaScript: the form.onSubmit event is now supported + 3. JavaScript: the form.action property is read-write 5-Aug-2002 Additions: |
From: Russell G. <rus...@us...> - 2002-08-07 20:35:23
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting In directory usw-pr-cvs1:/tmp/cvs-serv31041/src/com/meterware/httpunit/scripting Log Message: Directory /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting added to the repository |