[Httpunit-commit] CVS: httpunit/test/com/meterware/httpunit/javascript FormScriptingTest.java,NONE,1
Brought to you by:
russgold
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" ) ); - } } |