[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HTMLPage.java,1.6,1.7 HttpUnitOptions.jav
Brought to you by:
russgold
From: Russell G. <rus...@us...> - 2002-08-30 15:20:12
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv9438/src/com/meterware/httpunit Modified Files: HTMLPage.java HttpUnitOptions.java ParsedHTML.java WebClient.java Log Message: Added support for JavaScript includes Index: HTMLPage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLPage.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- HTMLPage.java 8 Aug 2002 20:47:21 -0000 1.6 +++ HTMLPage.java 30 Aug 2002 15:20:08 -0000 1.7 @@ -23,6 +23,7 @@ import java.io.ByteArrayInputStream; import java.io.UnsupportedEncodingException; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -77,7 +78,22 @@ */ public String getScripts() throws SAXException { NodeList nl = ((Document) getOriginalDOM()).getElementsByTagName( "script" ); - return NodeUtils.asText( nl ); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < nl.getLength(); i++) { + Node scriptNode = nl.item(i); + String src = NodeUtils.getNodeAttribute( scriptNode, "src", null ); + if (src == null) { + sb.append( NodeUtils.asText( scriptNode.getChildNodes() ) ); + } else { + try { + WebRequest req = new GetMethodWebRequest( getBaseURL(), src ); + sb.append( getResponse().getClient().getResource( req ).getText() ); + } catch (IOException e) { + throw new RuntimeException( "Error loading included script: " + e ); + } + } + } + return sb.toString(); } Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- HttpUnitOptions.java 29 Aug 2002 15:32:44 -0000 1.25 +++ HttpUnitOptions.java 30 Aug 2002 15:20:09 -0000 1.26 @@ -222,8 +222,8 @@ /** * If true, tells HttpUnit to throw an exception on any attempt to set a form parameter to a value - * which could not be set via the browser. The default is true (parameters are validated). - * Note: this only applies to a WebRequest created after this setting is changed. A request created + * which could not be set via the browser. The default is true (parameters are validated).<br> + * <b>Note:</b> this only applies to a WebRequest created after this setting is changed. A request created * with this option disabled will not only not be checked for correctness, its parameter submission * order will not be guaranteed, and changing parameters will not trigger Javascript onChange / onClick events. **/ Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- ParsedHTML.java 29 Aug 2002 15:32:44 -0000 1.26 +++ ParsedHTML.java 30 Aug 2002 15:20:09 -0000 1.27 @@ -347,6 +347,11 @@ } + WebResponse getResponse() { + return _response; + } + + interface TablePredicate { public boolean isTrue( WebTable table ); } Index: WebClient.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- WebClient.java 23 Aug 2002 19:33:12 -0000 1.28 +++ WebClient.java 30 Aug 2002 15:20:09 -0000 1.29 @@ -79,7 +79,7 @@ public WebResponse getResponse( WebRequest request ) throws MalformedURLException, IOException, SAXException { tellListeners( request ); - WebResponse response = getNextPage( request ); + WebResponse response = getResource( request ); if (response != null) { tellListeners( response ); updateClient( response ); @@ -90,9 +90,10 @@ /** - * Evaluates the request and returns the desired page. Will return null if the current target is to be unaffected. + * Returns the resource specified by the request. Does not update the client or load included framesets. + * May return null if the resource is a JavaScript URL which would normally leave the client unchanged. */ - private WebResponse getNextPage( WebRequest request ) throws IOException { + public WebResponse getResource( WebRequest request ) throws IOException { String urlString = request.getURLString().trim(); if (urlString.startsWith( "about:" )) { return WebResponse.BLANK_RESPONSE; |