[Httpunit-commit] CVS: httpunit/test/com/meterware/httpunit/javascript ScriptingTest.java,1.4,1.5
Brought to you by:
russgold
From: Russell G. <rus...@us...> - 2002-08-05 17:34:28
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv19892/test/com/meterware/httpunit/javascript Modified Files: ScriptingTest.java Log Message: Added support for Javascript image object Index: ScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ScriptingTest.java 5 Aug 2002 15:21:19 -0000 1.4 +++ ScriptingTest.java 5 Aug 2002 17:34:25 -0000 1.5 @@ -24,6 +24,7 @@ import com.meterware.httpunit.WebResponse; import com.meterware.httpunit.WebForm; import com.meterware.httpunit.WebLink; +import com.meterware.httpunit.WebImage; import junit.framework.TestSuite; import junit.textui.TestRunner; @@ -151,7 +152,7 @@ defineResource( "OnCommand.html", "<html><head></head>" + "<body>" + "<form name='realform'><input name='color' value='blue'></form>" + - "<a href='#' onMouseOver=\"document.realform.color.value='green'\">green</a>" + + "<a href='#' onMouseOver=\"document.realform.color.value='green';\">green</a>" + "</body></html>" ); WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); @@ -189,6 +190,50 @@ assertEquals( "Alert message", getHostPath() + "/sample.html", response.popNextAlert() ); assertNull( "Alert should have been removed", response.getNextAlert() ); } + + + public void testDocumentFindImages() throws Exception { + defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" + + "function getFound( object ) {\n" + + " return (object == null) ? \"did not find \" : \"found \";\n" + + " }\n" + + "function viewImages() { \n" + + " alert( \"found \" + document.images.length + \" images(s)\" );\n" + + " alert( getFound( document.realimage ) + \"image 'realimage'\" )\n;" + + " alert( getFound( document.noimage ) + \"image 'noimage'\" );\n" + + " alert( '2nd image is ' + document.images[1].src ); }\n" + + "</script></head>\n" + + "<body onLoad='viewImages()'>\n" + + "<img name='realimage' src='pict1.gif'>\n" + + "<img name='2ndimage' src='pict2.gif'>\n" + + "</body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + JavaScript.run( response ); + assertEquals( "Alert message", "found 2 images(s)", response.popNextAlert() ); + assertEquals( "Alert message", "found image 'realimage'", response.popNextAlert() ); + assertEquals( "Alert message", "did not find image 'noimage'", response.popNextAlert() ); + assertEquals( "Alert message", "2nd image is pict2.gif", response.popNextAlert() ); + assertNull( "Alert should have been removed", response.getNextAlert() ); + } + + public void testImageSwap() throws Exception { + defineResource( "OnCommand.html", "<html><head></head>" + + "<body>" + + "<img name='theImage' src='initial.gif'>" + + "<a href='#' onMouseOver=\"document.theImage.src='new.jpg';\">green</a>" + + "</body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + JavaScript.run( response ); + WebImage image = response.getImageWithName( "theImage" ); + WebLink link = response.getLinks()[0]; + assertEquals( "initial image source", "initial.gif", image.getSource() ); + link.mouseOver(); + assertEquals( "changed image source", "new.jpg", image.getSource() ); + } + + } |