[Httpunit-commit] CVS: httpunit/test/com/meterware/httpunit WebFrameTest.java,1.1,1.2
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2000-10-04 15:45:51
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv23587/test/com/meterware/httpunit Modified Files: WebFrameTest.java Log Message: Added frame support Index: WebFrameTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFrameTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- WebFrameTest.java 2000/10/02 16:32:10 1.1 +++ WebFrameTest.java 2000/10/04 15:45:47 1.2 @@ -32,44 +32,93 @@ public void setUp() throws Exception { super.setUp(); _wc = new WebConversation(); - } - - public void testFrameNames() throws Exception { - defineResource( "Initial.html", + defineWebPage( "Linker", "This is a trivial page with <a href=Target.html>one link</a>" ); + defineWebPage( "Target", "This is another page with <a href=Form.html target=\"_top\">one link</a>" ); + defineWebPage( "Form", "This is a page with a simple form: " + + "<form action=submit><input name=name><input type=submit></form>" + + "<a href=Linker.html target=red>a link</a>"); + defineResource( "Frames.html", "<HTML><HEAD><TITLE>Initial</TITLE></HEAD>" + "<FRAMESET cols=\"20%,80%\">" + - " <FRAMESET rows=\"30%,70%\">" + - " <FRAME src=\"overview-frame.html\" name=\"packageListFrame\">" + - " <FRAME src=allclasses-frame.html name=packageFrame>" + - " </FRAMESET>" + - " <FRAME src=\"overview-summary.html\" name=\"classFrame\">" + + " <FRAME src=\"Linker.html\" name=\"red\">" + + " <FRAME src=Form.html name=blue>" + "</FRAMESET></HTML>" ); + } + + + public void testDefaultFrameNames() throws Exception { + defineWebPage( "Initial", "This is a trivial page" ); WebResponse response = _wc.getResponse( getHostPath() + "/Initial.html" ); + assertMatchingSet( "Frames defined for the conversation", new String[] { "_top" }, _wc.getFrameNames() ); + } + + + public void testDefaultFrameContents() throws Exception { + WebResponse response = _wc.getResponse( getHostPath() + "/Linker.html" ); + assert( "Default response not the same as default frame contents", response == _wc.getFrameContents( "_top" ) ); + response = _wc.getResponse( response.getLinks()[0].getRequest() ); + assert( "Second response not the same as default frame contents", response == _wc.getFrameContents( "_top" ) ); + } + + public void testFrameNames() throws Exception { + WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); assertMatchingSet( "frame set names", - new String[] { "packageListFrame", "packageFrame", "classFrame" }, + new String[] { "red", "blue" }, response.getFrameNames() ); } - - - - public void testFrameRetrieval() throws Exception { - defineResource( "Initial.html", - "<HTML><HEAD><TITLE>Initial</TITLE></HEAD>" + - "<FRAMESET cols=\"20%,80%\">" + - " <FRAMESET rows=\"30%,70%\">" + - " <FRAME src=\"overview-frame.html\" name=\"packageListFrame\">" + - " <FRAME src=allclasses-frame.html name=packageFrame>" + - " </FRAMESET>" + - " <FRAME src=\"overview-summary.html\" name=\"classFrame\">" + - "</FRAMESET></HTML>" ); - WebResponse response = _wc.getResponse( getHostPath() + "/Initial.html" ); - assertEquals( "number of frames found", 3, response.getFrames().length ); + + public void testFrameRequests() throws Exception { + WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); + WebRequest[] requests = response.getFrameRequests(); + assertEquals( "Number of frame requests", 2, requests.length ); + assertEquals( "Target for first request", "red", requests[0].getTarget() ); + assertEquals( "URL for second request", getHostPath() + "/Form.html", requests[1].getURL().toExternalForm() ); } - - - + + + public void testFrameLoading() throws Exception { + WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); + + assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); + assertEquals( "Number of links in first frame", 1, _wc.getFrameContents( "red" ).getLinks().length ); + assertEquals( "Number of forms in second frame", 1, _wc.getFrameContents( "blue" ).getForms().length ); + } + + + public void testInFrameLinks() throws Exception { + WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); + + response = _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); + assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); + assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); + assertEquals( "URL for second request", getHostPath() + "/Target.html", response.getURL().toExternalForm() ); + } + + + public void testCrossFrameLinks() throws Exception { + WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); + + _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); + response = _wc.getResponse( _wc.getFrameContents( "blue" ).getLinks()[0].getRequest() ); + assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); + assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); + assertEquals( "URL for second request", getHostPath() + "/Linker.html", response.getURL().toExternalForm() ); + } + + + public void testLinkToTopFrame() throws Exception { + WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); + + response = _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); + response = _wc.getResponse( response.getLinks()[0].getRequest() ); + assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "_top" ) ); + assertEquals( "URL for second request", getHostPath() + "/Form.html", response.getURL().toExternalForm() ); + assertMatchingSet( "Frames defined for the conversation", new String[] { "_top" }, _wc.getFrameNames() ); + } + + private WebConversation _wc; } |