[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit WebResponse.java,1.82,1.83 WebWindow.java
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-10-09 01:58:26
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv8505/src/com/meterware/httpunit
Modified Files:
WebResponse.java WebWindow.java
Log Message:
Added JavaScript support for Window.open
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -r1.82 -r1.83
--- WebResponse.java 4 Oct 2002 02:16:00 -0000 1.82
+++ WebResponse.java 9 Oct 2002 01:58:23 -0000 1.83
@@ -546,7 +546,7 @@
public ClientProperties getClientProperties() {
- return _client.getClientProperties();
+ return _client == null ? ClientProperties.getDefaultProperties() : _client.getClientProperties();
}
@@ -561,6 +561,32 @@
}
+ public Scriptable open( String name, String urlString, String features, boolean replace )
+ throws IOException, SAXException {
+ WebWindow[] windows = _client.getOpenWindows();
+ for (int i = 0; i < windows.length; i++) {
+ WebWindow window = windows[i];
+ if (window.getName().equals( name )) return openInWindow( window, name, urlString, "_top" );
+ }
+
+ return openInWindow( _window, name, urlString, "_blank" );
+ }
+
+
+ private Scriptable openInWindow( WebWindow window, String name, String urlString, String target ) throws IOException, SAXException {
+ try {
+ if (urlString == null || urlString.trim().length() == 0) urlString = "about:";
+ WebRequest request = new GetMethodWebRequest( getURL(), urlString, target );
+ WebResponse response = window.getResponse( request );
+ response._window.setName( name );
+ return response.getScriptableObject();
+ } catch (RuntimeException e) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+
/**
* Returns the value of the named property. Will return null if the property does not exist.
**/
@@ -668,7 +694,7 @@
//------------------------------------------ package members ------------------------------------------------
- final static String BLANK_HTML = "<html><head><title>Blank</title></head><body></body></html>";
+ final static String BLANK_HTML = "";
final static WebResponse BLANK_RESPONSE = new DefaultWebResponse( BLANK_HTML );
Index: WebWindow.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebWindow.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WebWindow.java 4 Oct 2002 15:19:25 -0000 1.3
+++ WebWindow.java 9 Oct 2002 01:58:23 -0000 1.4
@@ -38,6 +38,23 @@
/** A map of frame names to current contents. **/
private FrameHolder _frameContents;
+ /** The name of the window, set via JavaScript. **/
+ private String _name = "";
+
+
+ public WebClient getClient() {
+ return _client;
+ }
+
+
+ /**
+ * Returns the name of this window. Windows created through normal HTML or browser commands have empty names,
+ * but JavaScript can set the name. A name may be used as a target for a request.
+ */
+ public String getName() {
+ return _name;
+ }
+
/**
* Submits a GET method request and returns a response.
@@ -64,9 +81,7 @@
public WebResponse getResponse( WebRequest request ) throws MalformedURLException, IOException, SAXException {
WebResponse response = _client.getResourceForWindow( request, this );
- if (response != null) updateWindow( request.getTarget(), response );
-
- return getFrameContents( request.getTarget() );
+ return response == null ? null : updateWindow( request.getTarget(), response );
}
@@ -108,15 +123,16 @@
* Updates this web client based on a received response. This includes updating
* cookies and frames.
**/
- void updateWindow( String requestTarget, WebResponse response ) throws MalformedURLException, IOException, SAXException {
- _client.updateClient( response );
+ WebResponse updateWindow( String requestTarget, WebResponse response ) throws MalformedURLException, IOException, SAXException {
+ _client.updateClient( response );
if (HttpUnitOptions.getAutoRefresh() && response.getRefreshRequest() != null) {
- getResponse( response.getRefreshRequest() );
+ return getResponse( response.getRefreshRequest() );
} else if (shouldFollowRedirect( response )) {
delay( HttpUnitOptions.getRedirectDelay() );
- getResponse( new RedirectWebRequest( response ) );
+ return getResponse( new RedirectWebRequest( response ) );
} else {
_client.updateFrameContents( this, requestTarget, response );
+ return response;
}
}
@@ -136,8 +152,8 @@
}
- public WebClient getClient() {
- return _client;
+ void setName( String name ) {
+ _name = name;
}
|