[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit FrameHolder.java,1.7,1.8 WebClient.java,1
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-02-27 23:36:43
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv23354/src/com/meterware/httpunit
Modified Files:
FrameHolder.java WebClient.java WebForm.java WebFrame.java
WebLink.java WebRequest.java WebRequestSource.java
WebWindow.java
Log Message:
Frame support now includes searching the current window
Index: FrameHolder.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FrameHolder.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- FrameHolder.java 17 Nov 2002 00:17:06 -0000 1.7
+++ FrameHolder.java 27 Feb 2003 23:35:58 -0000 1.8
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2002, Russell Gold
+ * Copyright (c) 2002-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -21,17 +21,14 @@
*******************************************************************************************************************/
import java.io.IOException;
import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.List;
+import java.util.*;
import org.xml.sax.SAXException;
/**
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
class FrameHolder {
@@ -49,7 +46,13 @@
WebResponse get( String target ) {
- return (WebResponse) _contents.get( getFrameName( target ) );
+ final WebResponse response = (WebResponse) _contents.get( getFrameName( target ) );
+ if (response != null) return response;
+ for (Iterator iterator = _contents.keySet().iterator(); iterator.hasNext();) {
+ String name = (String) iterator.next();
+ if (name.endsWith( ':' + target )) return (WebResponse) _contents.get( name );
+ }
+ return null;
}
@@ -63,6 +66,23 @@
}
+ String getTargetFrame( WebRequest request ) {
+ if (WebRequest.NEW_WINDOW.equalsIgnoreCase( request.getTarget() )) {
+ return WebRequest.TOP_FRAME;
+ } else if (WebRequest.TOP_FRAME.equalsIgnoreCase( request.getTarget() )) {
+ return WebRequest.TOP_FRAME;
+ } else {
+ final String computedTarget = getTargetFrameName( request.getSourceFrame(), request.getTarget() );
+ if (_contents.get( computedTarget ) != null) return computedTarget;
+ for (Iterator iterator = _contents.keySet().iterator(); iterator.hasNext();) {
+ String name = (String) iterator.next();
+ if (name.endsWith( ':' + request.getTarget() )) return name;
+ }
+ return request.getTarget();
+ }
+ }
+
+
String getFrameName( String target ) {
if (WebRequest.TOP_FRAME.equalsIgnoreCase( target )) {
return _frameName;
@@ -107,6 +127,15 @@
for (int i = 0; i < frameNames.length; i++) {
_contents.put( frameNames[ i ], WebResponse.BLANK_RESPONSE );
}
+ }
+
+ /**
+ * Returns the qualified name of a target frame.
+ */
+ private static String getTargetFrameName( String sourceFrameName, final String relativeName ) {
+ if (relativeName.equalsIgnoreCase( WebRequest.TOP_FRAME )) return WebRequest.TOP_FRAME;
+ if (sourceFrameName.indexOf( ':' ) < 0) return relativeName;
+ return WebFrame.getParentFrameName( sourceFrameName ) + ':' + relativeName;
}
}
Index: WebClient.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- WebClient.java 13 Dec 2002 12:57:11 -0000 1.48
+++ WebClient.java 27 Feb 2003 23:35:58 -0000 1.49
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2002, Russell Gold
+* Copyright (c) 2000-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -396,6 +396,12 @@
final
protected void updateMainWindow( String target, WebResponse response ) throws MalformedURLException, IOException, SAXException {
getMainWindow().updateWindow( target, response, new RequestContext() );
+ }
+
+
+ final
+ protected String getTargetFrame( WebRequest request ) {
+ return getMainWindow().getTargetFrame( request );
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -r1.78 -r1.79
--- WebForm.java 17 Feb 2003 23:54:41 -0000 1.78
+++ WebForm.java 27 Feb 2003 23:35:59 -0000 1.79
@@ -63,7 +63,7 @@
public WebResponse submit( SubmitButton button ) throws IOException, SAXException {
String event = getAttribute( "onsubmit" );
if (event.length() == 0 || getScriptableObject().doEvent( event )) return submitRequest( getRequest( button ) );
- return getBaseResponse().getWindow().getFrameContents( getTarget() );
+ return getBaseResponse().getWindow().getFrameContents( getPageFrame() );
}
Index: WebFrame.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebFrame.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- WebFrame.java 4 Feb 2003 05:32:03 -0000 1.11
+++ WebFrame.java 27 Feb 2003 23:36:00 -0000 1.12
@@ -73,17 +73,6 @@
}
- /**
- * Returns the qualified name of a target frame.
- *
- */
- static String getTargetFrameName( String sourceFrameName, final String relativeName ) {
- if (relativeName.equalsIgnoreCase( WebRequest.PARENT_FRAME )) return getParentFrameName( sourceFrameName );
- if (sourceFrameName.indexOf( ':' ) < 0) return relativeName;
- return getParentFrameName( sourceFrameName ) + ':' + relativeName;
- }
-
-
static String getParentFrameName( String parentFrameName ) {
if (parentFrameName.indexOf( ':' ) < 0) return WebRequest.TOP_FRAME;
return parentFrameName.substring( 0, parentFrameName.lastIndexOf( ':' ) );
Index: WebLink.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- WebLink.java 30 Dec 2002 21:46:55 -0000 1.38
+++ WebLink.java 27 Feb 2003 23:36:01 -0000 1.39
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2002, Russell Gold
+* Copyright (c) 2000-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -87,7 +87,7 @@
WebResponse response = null;
String event = getAttribute( "onclick" );
if (event.length() == 0 || getScriptableObject().doEvent( event )) response = submitRequest();
- if (response == null) response = getBaseResponse().getWindow().getFrameContents( getTarget() );
+ if (response == null) response = getBaseResponse().getWindow().getFrameContents( getPageFrame() );
return response;
}
Index: WebRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- WebRequest.java 14 Feb 2003 19:04:24 -0000 1.54
+++ WebRequest.java 27 Feb 2003 23:36:01 -0000 1.55
@@ -94,9 +94,17 @@
/**
* Returns the target for this web request.
- **/
+ */
public String getTarget() {
- return _target;
+ return _requestTarget;
+ }
+
+
+ /**
+ * Returns the frame from which this request originates.
+ */
+ String getSourceFrame() {
+ return _sourceFrame;
}
@@ -281,7 +289,7 @@
* Constructs a web request using a base URL, a relative URL string, and a target.
**/
protected WebRequest( URL urlBase, String urlString, String target ) {
- this( urlBase, urlString, target, new UncheckedParameterHolder() );
+ this( urlBase, urlString, TOP_FRAME, target, new UncheckedParameterHolder() );
}
@@ -298,7 +306,7 @@
protected WebRequest( WebRequestSource requestSource ) {
- this( requestSource.getBaseURL(), requestSource.getRelativePage(), requestSource.getTarget(), newParameterHolder( requestSource ) );
+ this( requestSource.getBaseURL(), requestSource.getRelativePage(), requestSource.getPageFrame(), requestSource.getTarget(), newParameterHolder( requestSource ) );
_webRequestSource = requestSource;
setHeaderField( "Referer", requestSource.getBaseURL().toExternalForm() );
}
@@ -316,10 +324,11 @@
/**
* Constructs a web request using a base URL, a relative URL string, and a target.
**/
- private WebRequest( URL urlBase, String urlString, String target, ParameterHolder parameterHolder ) {
+ private WebRequest( URL urlBase, String urlString, String sourceFrame, String requestTarget, ParameterHolder parameterHolder ) {
_urlBase = urlBase;
+ _sourceFrame = sourceFrame;
+ _requestTarget = requestTarget;
_urlString = urlString.toLowerCase().startsWith( "http" ) ? escape( urlString ) : urlString;
- _target = target;
_parameterHolder = parameterHolder;
}
@@ -430,16 +439,18 @@
//---------------------------------- package members --------------------------------
/** The target indicating the topmost frame of a window. **/
- final static String TOP_FRAME = "_top";
+ static final String TOP_FRAME = "_top";
/** The target indicating the parent of a frame. **/
- final static String PARENT_FRAME = "_parent";
+ static final String PARENT_FRAME = "_parent";
/** The target indicating a new, empty window. **/
- final static String NEW_WINDOW = "_blank";
+ static final String NEW_WINDOW = "_blank";
+ /** The target indicating the same frame. **/
+ static final String SAME_FRAME = "_self";
- WebRequestSource getWebRequestSource() {
+ WebRequestSource getWebRequestSource() {
return _webRequestSource;
}
@@ -459,8 +470,9 @@
private final ParameterHolder _parameterHolder;
private URL _urlBase;
+ private String _sourceFrame;
+ private String _requestTarget;
private String _urlString;
- private String _target = TOP_FRAME;
private Hashtable _headers;
private WebRequestSource _webRequestSource;
Index: WebRequestSource.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequestSource.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- WebRequestSource.java 27 Dec 2002 13:43:11 -0000 1.23
+++ WebRequestSource.java 27 Feb 2003 23:36:01 -0000 1.24
@@ -1,7 +1,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2001-2002, Russell Gold
+ * Copyright (c) 2001-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -58,15 +58,23 @@
/**
* Returns the target for this request source.
- **/
+ */
public String getTarget() {
- if (getSpecifiedTarget().length() == 0 || getSpecifiedTarget().equalsIgnoreCase( "_self" )) {
+ if (getSpecifiedTarget().length() == 0 || getSpecifiedTarget().equalsIgnoreCase( WebRequest.SAME_FRAME )) {
return _pageFrame;
- } else if (getSpecifiedTarget().equalsIgnoreCase( "_top" )) {
- return "_top";
+ } else if (getSpecifiedTarget().equalsIgnoreCase( WebRequest.PARENT_FRAME )) {
+ return WebFrame.getParentFrameName( _pageFrame );
} else {
- return WebFrame.getTargetFrameName( _pageFrame, getSpecifiedTarget() );
+ return getSpecifiedTarget();
}
+ }
+
+
+ /**
+ * Returns the name of the frame containing this request source.
+ */
+ public String getPageFrame() {
+ return _pageFrame;
}
Index: WebWindow.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebWindow.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- WebWindow.java 17 Nov 2002 00:17:07 -0000 1.8
+++ WebWindow.java 27 Feb 2003 23:36:02 -0000 1.9
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2002, Russell Gold
+ * Copyright (c) 2002-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -146,7 +146,7 @@
_client.tellListeners( request );
WebResponse response = null;
- final String frameName = getTargetFrame( request.getTarget() );
+ final String frameName = getTargetFrame( request );
String urlString = request.getURLString().trim();
if (urlString.startsWith( "about:" )) {
response = WebResponse.BLANK_RESPONSE;
@@ -164,13 +164,10 @@
}
- private String getTargetFrame( String target ) {
- if (WebRequest.NEW_WINDOW.equalsIgnoreCase( target )) {
- return WebRequest.TOP_FRAME;
- } else {
- return target;
- }
+ String getTargetFrame( WebRequest request ) {
+ return _frameContents.getTargetFrame( request );
}
+
/**
* Returns the name of the currently active frames.
|