[Httpunit-commit] CVS: httpunit/test/com/meterware/httpunit RequestTargetTest.java,NONE,1.1 WebFrame
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2000-10-02 16:32:15
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv1035/test/com/meterware/httpunit Modified Files: HttpUnitSuite.java WebLinkTest.java Added Files: RequestTargetTest.java WebFrameTest.java Log Message: Begin frame support --- NEW FILE --- package com.meterware.httpunit; import java.net.URL; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import java.util.Vector; /** * Tests to ensure the proper handling of the target attribute. **/ public class RequestTargetTest extends HttpUnitTest { public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); } public static Test suite() { return new TestSuite( RequestTargetTest.class ); } public RequestTargetTest( String name ) { super( name ); } public void setUp() throws Exception { super.setUp(); _wc = new WebConversation(); } public void testDefaultLinkTarget() throws Exception { defineWebPage( "Initial", "Here is a <a href=\"SimpleLink.html\">simple link</a>." ); WebRequest request = new GetMethodWebRequest( getHostPath() + "/Initial.html" ); assertEquals( "new link target", WebRequest.TOP_FRAME, request.getTarget() ); WebResponse response = _wc.getResponse( request ); assertEquals( "default response target", WebRequest.TOP_FRAME, response.getTarget() ); WebLink link = response.getLinks()[0]; assertEquals( "default link target", WebRequest.TOP_FRAME, link.getTarget() ); assertEquals( "default request target", WebRequest.TOP_FRAME, link.getRequest().getTarget() ); } public void testExplicitLinkTarget() throws Exception { defineWebPage( "Initial", "Here is a <a href=\"SimpleLink.html\" target=\"subframe\">simple link</a>." ); WebLink link = _wc.getResponse( getHostPath() + "/Initial.html" ).getLinks()[0]; assertEquals( "explicit link target", "subframe", link.getTarget() ); assertEquals( "request target", "subframe", link.getRequest().getTarget() ); } public void testInheritedLinkTarget() throws Exception { defineWebPage( "Initial", "Here is a <a href=\"SimpleLink.html\" target=\"subframe\">simple link</a>." ); defineWebPage( "SimpleLink", "Here is <a href=\"Initial.html\">another simple link</a>." ); WebLink link = _wc.getResponse( getHostPath() + "/Initial.html" ).getLinks()[0]; assertEquals( "explicit link target", "subframe", link.getTarget() ); assertEquals( "request target", "subframe", link.getRequest().getTarget() ); WebResponse response = _wc.getResponse( link.getRequest() ); assertEquals( "response target", "subframe", response.getTarget() ); link = response.getLinks()[0]; assertEquals( "inherited link target", "subframe", link.getTarget() ); } public void testInheritedLinkTargetInTable() throws Exception { defineWebPage( "Initial", "Here is a <a href=\"SimpleLink.html\" target=\"subframe\">simple link</a>." ); defineWebPage( "SimpleLink", "Here is <table><tr><td><a href=\"Initial.html\">another simple link</a>.</td></tr></table>" ); WebLink link = _wc.getResponse( getHostPath() + "/Initial.html" ).getLinks()[0]; assertEquals( "explicit link target", "subframe", link.getTarget() ); assertEquals( "request target", "subframe", link.getRequest().getTarget() ); WebResponse response = _wc.getResponse( link.getRequest() ); assertEquals( "response target", "subframe", response.getTarget() ); WebTable table = response.getTables()[0]; TableCell cell = table.getTableCell(0,0); link = cell.getLinks()[0]; assertEquals( "inherited link target", "subframe", link.getTarget() ); } public void testDefaultFormTarget() throws Exception { defineWebPage( "Initial", "Here is a simple form: " + "<form method=POST action = \"/servlet/Login\"><B>" + "<input type=\"checkbox\" name=first>Disabled" + "<br><Input type=submit value = \"Log in\">" + "</form>" ); WebResponse response = _wc.getResponse( getHostPath() + "/Initial.html" ); assertEquals( "Num forms in page", 1, response.getForms().length ); WebForm form = response.getForms()[0]; assertEquals( "default form target", WebRequest.TOP_FRAME, form.getTarget() ); assertEquals( "default request target", WebRequest.TOP_FRAME, form.getRequest().getTarget() ); } public void testExplicitPostFormTarget() throws Exception { defineWebPage( "Initial", "Here is a simple form: " + "<form method=POST action = \"/servlet/Login\" target=\"subframe\"><B>" + "<input type=\"checkbox\" name=first>Disabled" + "<br><Input type=submit value = \"Log in\">" + "</form>" ); WebForm form = _wc.getResponse( getHostPath() + "/Initial.html" ).getForms()[0]; assertEquals( "explicit form target", "subframe", form.getTarget() ); assertEquals( "request target", "subframe", form.getRequest().getTarget() ); } public void testExplicitGetFormTarget() throws Exception { defineWebPage( "Initial", "Here is a simple form: " + "<form method=GET action = \"/servlet/Login\" target=\"subframe\"><B>" + "<input type=\"checkbox\" name=first>Disabled" + "<br><Input type=submit value = \"Log in\">" + "</form>" ); WebForm form = _wc.getResponse( getHostPath() + "/Initial.html" ).getForms()[0]; assertEquals( "explicit form target", "subframe", form.getTarget() ); assertEquals( "request target", "subframe", form.getRequest().getTarget() ); } public void testInheritedFormTarget() throws Exception { defineWebPage( "Initial", "Here is a <a href=\"SimpleLink.html\" target=\"subframe\">simple link</a>." ); defineWebPage( "SimpleLink", "Here is a simple form: " + "<form method=GET action = \"/servlet/Login\" target=\"subframe\"><B>" + "<input type=\"checkbox\" name=first>Disabled" + "<br><Input type=submit value = \"Log in\">" + "</form>" ); WebLink link = _wc.getResponse( getHostPath() + "/Initial.html" ).getLinks()[0]; assertEquals( "explicit link target", "subframe", link.getTarget() ); assertEquals( "request target", "subframe", link.getRequest().getTarget() ); WebResponse response = _wc.getResponse( link.getRequest() ); assertEquals( "response target", "subframe", response.getTarget() ); WebForm form = response.getForms()[0]; assertEquals( "inherited form target", "subframe", form.getTarget() ); } private WebConversation _wc; } --- NEW FILE --- package com.meterware.httpunit; import java.net.URL; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import java.util.Vector; /** * A test of the web frame functionality. **/ public class WebFrameTest extends HttpUnitTest { public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); } public static Test suite() { return new TestSuite( WebFrameTest.class ); } public WebFrameTest( String name ) { super( name ); } public void setUp() throws Exception { super.setUp(); _wc = new WebConversation(); } public void testFrameNames() 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" ); assertMatchingSet( "frame set names", new String[] { "packageListFrame", "packageFrame", "classFrame" }, 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 ); } private WebConversation _wc; } Index: HttpUnitSuite.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- HttpUnitSuite.java 2000/09/15 16:38:44 1.6 +++ HttpUnitSuite.java 2000/10/02 16:32:10 1.7 @@ -40,6 +40,8 @@ suite.addTest( WebLinkTest.suite() ); suite.addTest( HtmlTablesTest.suite() ); suite.addTest( WebFormTest.suite() ); + suite.addTest( WebFrameTest.suite() ); + suite.addTest( RequestTargetTest.suite() ); suite.addTest( FormParametersTest.suite() ); suite.addTest( Base64Test.suite() ); return suite; Index: WebLinkTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- WebLinkTest.java 2000/09/27 18:04:04 1.5 +++ WebLinkTest.java 2000/10/02 16:32:10 1.6 @@ -105,12 +105,40 @@ link = _simplePage.getLinkWithImageText( "Next -->" ); assertNotNull( "the image link was not found", link ); assertEquals( "image link URL", getHostPath() + "/basic.html", link.getRequest().getURL().toExternalForm() ); + + HttpUnitOptions.setImagesTreatedAsAltText( true ); + link = _simplePage.getLinkWith( "Next -->" ); + assertNotNull( "the image link was not found", link ); + assertEquals( "image link URL", getHostPath() + "/basic.html", link.getRequest().getURL().toExternalForm() ); + + HttpUnitOptions.setImagesTreatedAsAltText( false ); + link = _simplePage.getLinkWith( "Next -->" ); + assertNull( "the image link was found based on its hidden alt attribute", link ); } public void testLinkText() throws Exception { WebLink link = _simplePage.getLinks()[0]; assertEquals( "Link text", "an active link", link.asText() ); + } + + + public void testLinkFollowing() throws Exception { + WebConversation wc = new WebConversation(); + defineWebPage( "Initial", "Go to <a href=\"Next.html\">the next page.</a> <a name=\"bottom\">Bottom</a>" ); + defineWebPage( "Next", "And go back to <a href=\"Initial.html#Bottom\">the first page.</a>" ); + + WebResponse initialPage = wc.getResponse( getHostPath() + "/Initial.html" ); + assertEquals( "Num links in initial page", 1, initialPage.getLinks().length ); + WebLink link = initialPage.getLinks()[0]; + + WebResponse nextPage = wc.getResponse( link.getRequest() ); + assertEquals( "Title of next page", "Next", nextPage.getTitle() ); + assertEquals( "Num links in next page", 1, nextPage.getLinks().length ); + link = nextPage.getLinks()[0]; + + WebResponse thirdPage = wc.getResponse( link.getRequest() ); + assertEquals( "Title of next page", "Initial", thirdPage.getTitle() ); } |