[Jsimplebrowser-svn] SF.net SVN: jsimplebrowser: [48] trunk
Status: Alpha
Brought to you by:
rdimarco
From: <rdi...@us...> - 2007-08-13 21:08:32
|
Revision: 48 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=48&view=rev Author: rdimarco Date: 2007-08-13 14:08:29 -0700 (Mon, 13 Aug 2007) Log Message: ----------- Refactored to support asynchronous events. Broke XmlHttpRequests but will fix shortly. Modified Paths: -------------- trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java Added Paths: ----------- trunk/core/src/main/java/com/software416/jsimplebrowser/RequestService.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/ trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEvent.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventListener.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventType.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEvent.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventListener.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventType.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEvent.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventListener.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventType.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestFailureEvent.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestServiceImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestSuccessEvent.java trunk/core/src/test/java/com/software416/jsimplebrowser/impl/WindowTest.java trunk/src/site/images/ trunk/src/site/images/Request_Flow_Diagram.png Modified: trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java =================================================================== --- trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java 2007-08-13 21:08:29 UTC (rev 48) @@ -10,6 +10,7 @@ // package com.software416.jsimplebrowser.client; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; @@ -31,11 +32,19 @@ import com.google.inject.Guice; import com.google.inject.Inject; import com.software416.jsimplebrowser.Browser; -import com.software416.jsimplebrowser.BrowserException; +import com.software416.jsimplebrowser.BrowserRuntimeException; import com.software416.jsimplebrowser.Window; +import com.software416.jsimplebrowser.event.BrowserEvent; +import com.software416.jsimplebrowser.event.BrowserEventListener; +import com.software416.jsimplebrowser.event.BrowserEventType; +import com.software416.jsimplebrowser.event.WindowEvent; +import com.software416.jsimplebrowser.event.WindowEventListener; +import com.software416.jsimplebrowser.event.WindowEventType; import com.software416.jsimplebrowser.util.ElementLocator; -public class SimpleClient { +public class SimpleClient implements BrowserEventListener, WindowEventListener{ + public static final int DEFAULT_WAIT_TIME_IN_SECONDS = 15000; + @SuppressWarnings("unused") private static final Log LOG = LogFactory.getLog(SimpleClient.class); @@ -49,6 +58,10 @@ return sc; } + public void setCurrentWindow(String windowName) { + _currentWindowName = windowName; + } + public String getHtmlSource() { return getCurrentWindow().getSource(); } @@ -94,16 +107,16 @@ return windowNames.toArray(new String[windowNames.size()]); } - public void open(String url) throws BrowserException { + public void open(String url) throws URISyntaxException { getCurrentWindow().open(url); } - public void openWindow(String windowName, String url) throws BrowserException { + public void openWindow(String windowName, String url) throws URISyntaxException { _currentWindowName = windowName; getCurrentWindow().open(url); } - public void submitForm(String id) throws BrowserException { + public void submitForm(String id) throws URISyntaxException { getCurrentWindow().submitForm(id, new MultiHashMap()); } @@ -114,7 +127,7 @@ } } - public void click(String id) throws BrowserException { + public void click(String id) throws URISyntaxException { Element e = new ElementLocator(getDocument()).findElement(id); if (e != null) { if (e.getTagName().equalsIgnoreCase("a")) { @@ -146,6 +159,43 @@ } } + public void handleBrowserEvent(BrowserEvent e) { + if (e.getType().equals(BrowserEventType.WINDOW_OPENED)) { + ((Window)e.getTarget()).addWindowEventListener(this); + } + } + + public void handleWindowEvent(WindowEvent e) { + if (e.getType().equals(WindowEventType.LOAD)) { + // Nothing for now. + } else if (e.getType().equals(WindowEventType.REQUEST_FAILED)) { + // Nothing for now. + } + } + + public void waitForWindowToLoad(int timeOut) { + waitForWindowToLoad(getCurrentWindow().getWindowName(), timeOut); + } + + public void waitForWindowToLoad(String windowName) { + waitForWindowToLoad(windowName, DEFAULT_WAIT_TIME_IN_SECONDS); + } + + public void waitForWindowToLoad(String windowName, int timeoutInSeconds) { + Window w = _browser.getWindow(windowName); + long time = System.currentTimeMillis(); + while (w.isWindowLoading()) { + try { + Thread.sleep(50); + if ((System.currentTimeMillis() - time) > (timeoutInSeconds*1000)) { + throw new BrowserRuntimeException("Request has timed out."); + } + } catch (InterruptedException ex) { + return; + } + } + } + // public String[] getAllWindowTitles() { // throw new UnsupportedOperationException(); // } @@ -314,13 +364,6 @@ // // } // -// public void waitForFrameToLoad(String arg0, String arg1) { -// // noop -// } -// -// public void waitForPageToLoad(String arg0) { -// // noop -// } // public void check(String id) { // throw new UnsupportedOperationException(); // } Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java 2007-08-13 21:08:29 UTC (rev 48) @@ -10,21 +10,36 @@ // package com.software416.jsimplebrowser; +import java.net.URISyntaxException; import java.util.List; -import org.apache.commons.httpclient.HttpMethod; - import com.google.inject.ImplementedBy; +import com.software416.jsimplebrowser.event.BrowserEventListener; import com.software416.jsimplebrowser.impl.BrowserImpl; @ImplementedBy(BrowserImpl.class) public interface Browser { public static final String MAIN_BROWSER_WINDOW_NAME = "main"; - public void open(String url) throws BrowserException; - public void open(String url, String window) throws BrowserException; - public HttpResponse makeXmlHttpRequest(String url, String requestBody) throws BrowserException; public Window getWindow(String windowName); public void closeWindow(String windowName); public List<String> getWindowNames(); - HttpResponse makeRequest(HttpMethod hm) throws BrowserException; + + /** + * Open a URL in the current window + * @param url The location to connect to. May be relative URL if a previous request has been + * made in the current window. + * @throws BrowserException - Any problems are sent back to the user + */ + public void open(String url) throws URISyntaxException; + + /** + * Open a URL in the specified window. If the window exists, it will be used. Otherwise, it will be created. + * @param url The location to connect to. May be relative URL if a previous request has been + * made in the current window. + * @throws BrowserException - Any problems are sent back to the user + */ + public void open(String url, String window) throws URISyntaxException; + + public void addBrowserEventListener(BrowserEventListener listener); + public void removeBrowserEventListener(BrowserEventListener listener); } Added: trunk/core/src/main/java/com/software416/jsimplebrowser/RequestService.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/RequestService.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/RequestService.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,43 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser; + +import org.apache.commons.httpclient.HttpMethod; + +import com.google.inject.ImplementedBy; +import com.software416.jsimplebrowser.event.RequestEventListener; +import com.software416.jsimplebrowser.impl.RequestServiceImpl; + +/** + * @author Rob Di Marco + */ +@ImplementedBy(RequestServiceImpl.class) +public interface RequestService { + /** + * Make a Http request with the specified message body. Ofent used to make + * AJAX calls. + * + * @param url The URL to connect to. Must be an absolute URL + * @param requestBody The text that will be passed as the body context to the server + * @return the response ID associated with the request + */ + public String makeXmlHttpRequest(String url, String requestBody); + + /** + * Make a request with a specified request method. Intended for internal use + * @param hm The HttpMethod that will be used to execute the request + * @return the response id. + */ + String makeRequest(HttpMethod hm); + + public void addRequestEventListener(RequestEventListener listener); + public void removeRequestEventListener(RequestEventListener listener); +} Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java 2007-08-13 21:08:29 UTC (rev 48) @@ -10,19 +10,26 @@ // package com.software416.jsimplebrowser; +import java.net.URISyntaxException; + import org.apache.commons.collections.MultiMap; import org.w3c.dom.Document; import com.google.inject.ProvidedBy; +import com.software416.jsimplebrowser.event.WindowEventListener; import com.software416.jsimplebrowser.impl.WindowProvider; @ProvidedBy(WindowProvider.class) public interface Window { - public void open(String url) throws BrowserException; - public void submitForm(String formName, MultiMap parameters) throws BrowserException; + public String getWindowName(); + public String open(String url) throws URISyntaxException; + public String submitForm(String formName, MultiMap parameters) throws URISyntaxException; public HttpResponse getRequestInfo(); public Document getDocument(); public String getSource(); public History getHistory(); public String getLocation(); + public void addWindowEventListener(WindowEventListener listener); + public void removeWindowEventListener(WindowEventListener listener); + public boolean isWindowLoading(); } Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEvent.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEvent.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEvent.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,38 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +import java.util.Map; + +public class BrowserEvent { + private BrowserEventType _type; + private Object _target; + private Map<String, Object> _eventProperties; + public Map<String, Object> getEventProperties() { + return _eventProperties; + } + public void setEventProperties(Map<String, Object> eventProperties) { + _eventProperties = eventProperties; + } + public Object getTarget() { + return _target; + } + public void setTarget(Object target) { + _target = target; + } + public BrowserEventType getType() { + return _type; + } + public void setType(BrowserEventType type) { + _type = type; + } + +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventListener.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventListener.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventListener.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,15 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +public interface BrowserEventListener { + public void handleBrowserEvent(BrowserEvent e); +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventType.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventType.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventType.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,18 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +/** + * @author Rob Di Marco + */ +public enum BrowserEventType { + WINDOW_OPENED, WINDOW_CLOSED; +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEvent.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEvent.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEvent.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,30 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +public abstract class RequestEvent { + public String _requestId; + public RequestEventType _type; + public RequestEventType getType() { + return _type; + } + public void setType(RequestEventType type) { + _type = type; + } + public String getRequestId() { + return _requestId; + } + public void setRequestId(String requestId) { + _requestId = requestId; + } + + public abstract byte[] getResponseBytes(); +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventListener.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventListener.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventListener.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,15 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +public interface RequestEventListener { + public void handleRequestEvent(RequestEvent e); +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventType.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventType.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventType.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,5 @@ +package com.software416.jsimplebrowser.event; + +public enum RequestEventType { + SUCCESS, FAILURE +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEvent.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEvent.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEvent.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,54 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import com.software416.jsimplebrowser.Window; + +public class WindowEvent { + private WindowEventType _type; + private Map<String, Object> _properties = new HashMap<String, Object>(); + private Window _eventWindow; + + public WindowEventType getType() { + return _type; + } + + public void setType(WindowEventType type) { + _type = type; + } + + public void addProperty(String key, Object value) { + _properties.put(key, value); + } + + public Object getProperty(String key) { + return _properties.get(key); + } + + /** + * @return A read only map representing the current properties. + */ + public Map<String, Object> getProperties() { + return Collections.unmodifiableMap(_properties); + } + + public Window getEventWindow() { + return _eventWindow; + } + + public void setEventWindow(Window eventWindow) { + _eventWindow = eventWindow; + } +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventListener.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventListener.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventListener.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,18 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +/** + * @author Rob Di Marco + */ +public interface WindowEventListener { + public void handleWindowEvent(WindowEvent e); +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventType.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventType.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventType.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,5 @@ +package com.software416.jsimplebrowser.event; + +public enum WindowEventType { + LOAD, UNLOAD, REQUEST_FAILED +} Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java 2007-08-13 21:08:29 UTC (rev 48) @@ -10,81 +10,76 @@ // package com.software416.jsimplebrowser.impl; -import java.io.ByteArrayOutputStream; -import java.io.IOException; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.HttpMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.StringRequestEntity; -import org.apache.commons.io.IOUtils; - import com.google.inject.Inject; import com.google.inject.Provider; import com.software416.jsimplebrowser.Browser; -import com.software416.jsimplebrowser.BrowserException; import com.software416.jsimplebrowser.Window; +import com.software416.jsimplebrowser.event.BrowserEvent; +import com.software416.jsimplebrowser.event.BrowserEventListener; +import com.software416.jsimplebrowser.event.BrowserEventType; public class BrowserImpl implements Browser { @Inject private Provider<Window> _windowProvider; - private HttpClient _client = new HttpClient(); private Map<String, Window> _browserWindows = new HashMap<String, Window>(); + private List<BrowserEventListener> _eventListeners = new ArrayList<BrowserEventListener>(); - public synchronized HttpResponseImpl makeRequest(HttpMethod m) throws BrowserException { - HttpResponseImpl ri = new HttpResponseImpl(); - ri.setRequestMethod(m); - - try { - ri.setResponseCode(_client.executeMethod(m)); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - IOUtils.copy(m.getResponseBodyAsStream(), bos); - ri.setResponseBody(bos.toByteArray()); - } catch (HttpException ex) { - throw new BrowserException(ex); - } catch (IOException ex) { - throw new BrowserException(ex); - } - return ri; - } - - public HttpResponseImpl makeXmlHttpRequest(String url, String requestBody) throws BrowserException { - PostMethod m = new PostMethod(url); - try { - m.setRequestEntity(new StringRequestEntity(requestBody, "text/plain",null)); - return makeRequest(m); - } catch (IOException ex) { - throw new BrowserException(ex); - } - } - - public void open(String url) throws BrowserException { + public void open(String url) throws URISyntaxException { open(url, MAIN_BROWSER_WINDOW_NAME); } - public void open(String url, String window) throws BrowserException { + public void open(String url, String window) throws URISyntaxException { getWindow(window).open(url); } public synchronized Window getWindow(String windowName) { if (!_browserWindows.containsKey(windowName)) { - WindowProvider.CURRENT_BROWSER.set(this); + // Create window. + // We use the ThreadLocal current browser variable + // to pass this browser instance to the window that is + // created. + WindowProvider.NEXT_WINDOW_NAME.set(windowName); _browserWindows.put(windowName, _windowProvider.get()); - WindowProvider.CURRENT_BROWSER.remove(); + WindowProvider.NEXT_WINDOW_NAME.remove(); + + // Send the appropriate event + BrowserEvent e = new BrowserEvent(); + e.setType(BrowserEventType.WINDOW_OPENED); + e.setTarget(_browserWindows.get(windowName)); + notifyBrowserEventListeners(e); } return _browserWindows.get(windowName); } public void closeWindow(String windowName) { _browserWindows.remove(windowName); + BrowserEvent e = new BrowserEvent(); + e.setType(BrowserEventType.WINDOW_CLOSED); + e.setTarget(_browserWindows.get(windowName)); + notifyBrowserEventListeners(e); } public List<String> getWindowNames() { return new ArrayList<String>(_browserWindows.keySet()); } + + public void notifyBrowserEventListeners(BrowserEvent e) { + for (BrowserEventListener listener : _eventListeners) { + listener.handleBrowserEvent(e); + } + } + + public void addBrowserEventListener(BrowserEventListener listener) { + _eventListeners.add(listener); + } + + public void removeBrowserEventListener(BrowserEventListener listener) { + _eventListeners.remove(listener); + } } Added: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestFailureEvent.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestFailureEvent.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestFailureEvent.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,48 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.impl; + +import org.apache.commons.httpclient.HttpMethod; + +import com.software416.jsimplebrowser.event.RequestEvent; +import com.software416.jsimplebrowser.event.RequestEventType; + +/** + * @author Rob Di Marco + */ +public class RequestFailureEvent extends RequestEvent{ + private HttpMethod _request; + private Throwable _cause; + + public Throwable getCause() { + return _cause; + } + + public void setCause(Throwable cause) { + _cause = cause; + } + + public RequestFailureEvent() { + setType(RequestEventType.FAILURE); + } + + public HttpMethod getRequest() { + return _request; + } + + public void setRequest(HttpMethod request) { + _request = request; + } + @Override + public byte[] getResponseBytes() { + return null; + } +} \ No newline at end of file Added: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestServiceImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestServiceImpl.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestServiceImpl.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,111 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.impl; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.apache.commons.io.IOUtils; + +import com.google.inject.Singleton; +import com.software416.jsimplebrowser.BrowserRuntimeException; +import com.software416.jsimplebrowser.RequestService; +import com.software416.jsimplebrowser.event.RequestEvent; +import com.software416.jsimplebrowser.event.RequestEventListener; + +/** + * @author Rob Di Marco + */ +@Singleton +public class RequestServiceImpl implements RequestService { + private static final int REQUEST_POOL_THREAD_COUNT = 5; + HttpClient _client = new HttpClient(); + private List<RequestEventListener> _eventListeners = new ArrayList<RequestEventListener>(); + private AtomicInteger _requestIdCounter = new AtomicInteger(1); + private ExecutorService _requestPool = new ThreadPoolExecutor(1, REQUEST_POOL_THREAD_COUNT, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()); + public String makeRequest(final HttpMethod m) { + final String requestId = String.valueOf(_requestIdCounter.addAndGet(1)); + _requestPool.execute(new Runnable() { + + public void run() { + HttpResponseImpl ri = new HttpResponseImpl(); + ri.setRequestMethod(m); + + try { + ri.setResponseCode(_client.executeMethod(m)); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + IOUtils.copy(m.getResponseBodyAsStream(), bos); + ri.setResponseBody(bos.toByteArray()); + notifyOfRequestSuccess(requestId, m, ri); + } catch (HttpException ex) { + notifyOfRequestFailure(requestId, m, ex); + } catch (IOException ex) { + notifyOfRequestFailure(requestId, m, ex); + } + } + }); + return requestId; + } + + protected void notifyOfRequestSuccess(String requestId, HttpMethod request, HttpResponseImpl response) { + RequestSuccessEvent e = new RequestSuccessEvent(); + e.setRequestId(requestId); + e.setRequest(request); + e.setResponse(response); + notifyListenersOfRequestEvent(e); + } + + protected void notifyOfRequestFailure(String requestId, HttpMethod method, Throwable t) { + RequestFailureEvent e = new RequestFailureEvent(); + e.setRequestId(requestId); + e.setRequest(method); + e.setCause(t); + notifyListenersOfRequestEvent(e); + + } + + protected void notifyListenersOfRequestEvent(RequestEvent e) { + for (RequestEventListener listener : _eventListeners) { + listener.handleRequestEvent(e); + } + } + + public String makeXmlHttpRequest(String url, String requestBody) { + PostMethod m = new PostMethod(url); + try { + m.setRequestEntity(new StringRequestEntity(requestBody, "text/plain",null)); + } catch (UnsupportedEncodingException ex) { + throw new BrowserRuntimeException("Really weird encoding issue", ex); + } + return makeRequest(m); + } + + public void addRequestEventListener(RequestEventListener listener) { + _eventListeners.add(listener); + } + public void removeRequestEventListener(RequestEventListener listener) { + _eventListeners.remove(listener); + } + +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestSuccessEvent.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestSuccessEvent.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestSuccessEvent.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,50 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.impl; + +import org.apache.commons.httpclient.HttpMethod; + +import com.software416.jsimplebrowser.event.RequestEvent; +import com.software416.jsimplebrowser.event.RequestEventType; + +/** + * @author Rob Di Marco + */ +public class RequestSuccessEvent extends RequestEvent { + private HttpMethod _request; + private HttpResponseImpl _response; + + public RequestSuccessEvent() { + setType(RequestEventType.SUCCESS); + } + + public HttpMethod getRequest() { + return _request; + } + + public void setRequest(HttpMethod request) { + _request = request; + } + + public HttpResponseImpl getResponse() { + return _response; + } + + public void setResponse(HttpResponseImpl response) { + _response = response; + } + + @Override + public byte[] getResponseBytes() { + return _response.getResponseBody(); + } + +} Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java 2007-08-13 21:08:29 UTC (rev 48) @@ -10,9 +10,13 @@ // package com.software416.jsimplebrowser.impl; -import java.io.IOException; +import java.net.URISyntaxException; +import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -24,73 +28,98 @@ import org.apache.commons.httpclient.URIException; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import com.google.inject.Inject; -import com.software416.jsimplebrowser.Browser; -import com.software416.jsimplebrowser.BrowserException; import com.software416.jsimplebrowser.BrowserRuntimeException; import com.software416.jsimplebrowser.History; import com.software416.jsimplebrowser.HtmlParseException; import com.software416.jsimplebrowser.HttpResponse; +import com.software416.jsimplebrowser.RequestService; import com.software416.jsimplebrowser.Window; +import com.software416.jsimplebrowser.event.RequestEvent; +import com.software416.jsimplebrowser.event.RequestEventListener; +import com.software416.jsimplebrowser.event.RequestEventType; +import com.software416.jsimplebrowser.event.WindowEvent; +import com.software416.jsimplebrowser.event.WindowEventListener; +import com.software416.jsimplebrowser.event.WindowEventType; import com.software416.jsimplebrowser.util.HtmlToDomConverter; -public class WindowImpl implements Window { +public class WindowImpl implements Window, RequestEventListener { + private static final Log LOG = LogFactory.getLog(WindowImpl.class); + @Inject private RequestService _requestService; + private String _windowName; private HttpResponse _requestInfo; private Document _responseDocument; - private Browser _browser; private HtmlToDomConverter _converter = new HtmlToDomConverter(); - private boolean _doFollowRedirects = true; + private boolean _doFollowRedirects = true; + protected List<WindowEventListener> _eventListeners = new ArrayList<WindowEventListener>(); + /** Controls how many threads will be used to emit events to event listeners. */ + private int _eventListenerThreadCount = 1; + private final ExecutorService _eventThreadService = Executors.newFixedThreadPool(_eventListenerThreadCount); + private boolean _isWindowLoading = false; - @Inject - public WindowImpl(Browser b) { - _browser = b; + public WindowImpl(String windowName) { + _windowName = windowName; } - public void open(String url) throws BrowserException { - try { - GetMethod gm; - if (_requestInfo != null) { - gm = new GetMethod(); + protected void setRequestService(RequestService requestService) { + _requestService = requestService; + _requestService.addRequestEventListener(this); + } + + public String open(String url) throws URISyntaxException { + GetMethod gm; + if (_requestInfo != null) { + gm = new GetMethod(); + try { gm.setURI(new URI(new URI(_requestInfo.getLocation(), true), url, true)); - } else { - gm = new GetMethod(url); - } - makeRequest(gm); - } catch (IOException ex) { - throw new BrowserException(ex); - } + } catch (URIException ex) { + LOG.info("Invalid URI Exception", ex); + throw new URISyntaxException(url, ex.getMessage()); + } + } else { + gm = new GetMethod(url); + } + return makeRequest(gm); } - protected void makeRequest(HttpMethod hm) throws BrowserException { - handleResponse(_browser.makeRequest(hm)); + protected String makeRequest(HttpMethod hm) { + _isWindowLoading = true; + return _requestService.makeRequest(hm); } - public void handleResponse(HttpResponse requestInfo) throws BrowserException { + public void handleResponse(HttpResponse requestInfo) { _requestInfo = requestInfo; _responseDocument = null; if (_doFollowRedirects) { String link = findRefreshLink(); if (link != null) { - open(link); + try { + open(link); + } catch (URISyntaxException ex) { + LOG.warn("Weird URI Syntax problem when trying to follow a redirect", ex); + } + } } + _isWindowLoading = false; + WindowEvent e = new WindowEvent(); + e.setType(WindowEventType.LOAD); + notifyOfWindowEvents(e); } - public void submitForm(String formName, MultiMap userSpecifiedParameterMap) throws BrowserException { - try { - HttpMethod m = buildMethodForForm(formName, userSpecifiedParameterMap); - if (m == null) { - throw new BrowserException("Could not submit form '" + formName + "' as it does not exist!!"); - } - makeRequest(m); - } catch (IOException ex) { - throw new BrowserException(ex); + public String submitForm(String formName, MultiMap userSpecifiedParameterMap) throws URISyntaxException { + HttpMethod m = buildMethodForForm(formName, userSpecifiedParameterMap); + if (m == null) { + throw new BrowserRuntimeException("Could not submit form '" + formName + "' as it does not exist!!"); } - } + return makeRequest(m); +} protected String findRefreshLink() { NodeList meta = getDocument().getElementsByTagName("meta"); @@ -110,7 +139,7 @@ } @SuppressWarnings("unchecked") - protected HttpMethod buildMethodForForm(String formName, MultiMap userParamMap) throws URIException { + protected HttpMethod buildMethodForForm(String formName, MultiMap userParamMap) throws URISyntaxException { Element formElement = findFormElementByFormNameOrId(formName); if (formElement == null) { return null; @@ -123,8 +152,12 @@ String formMethod = formElement.getAttribute("method"); boolean usePost = formMethod != null && formMethod.toUpperCase().equals("POST"); HttpMethod rv = usePost ? new PostMethod() : new GetMethod(); - - rv.setURI(new URI(new URI(_requestInfo.getLocation(), true), new URI(formElement.getAttribute("action"), true))); + String action = formElement.getAttribute("action"); + try { + rv.setURI(new URI(new URI(_requestInfo.getLocation(), true), new URI(action, true))); + } catch (URIException ex1) { + throw new URISyntaxException(action, ex1.getMessage()); + } Collection params = formParameters.values(); if (usePost) { @@ -132,8 +165,12 @@ } else { Iterator i = params.iterator(); StringBuilder sb = new StringBuilder(); - if (rv.getURI().getQuery() != null) { - sb.append(rv.getURI().getQuery()); + try { + if (rv.getURI().getQuery() != null) { + sb.append(rv.getURI().getQuery()); + } + } catch (URIException ex1) { + throw new BrowserRuntimeException("Unusual URI problem", ex1); } while (i.hasNext()) { if (sb.length() > 0) { @@ -148,7 +185,10 @@ rv.setURI(newUri); } catch (CloneNotSupportedException ex) { // Should never happen! - throw new RuntimeException(ex); + throw new BrowserRuntimeException(ex); + } catch (URIException ex) { + // Should never happen! + throw new BrowserRuntimeException("Unusual problem with URI", ex); } } @@ -228,7 +268,6 @@ return null; } - public String getSource() { return new String(_requestInfo.getResponseBody()); } @@ -243,10 +282,20 @@ } return _responseDocument; } + + protected void createWindowEvent() { + final WindowEvent e = new WindowEvent(); + _eventThreadService.execute(new Runnable() { + public void run() { + for (WindowEventListener listener : _eventListeners) { + listener.handleWindowEvent(e); + } + } + }); + } public History getHistory() { - // TODO Auto-generated method stub - return null; + throw new UnsupportedOperationException(); } public String getLocation() { @@ -268,7 +317,54 @@ public void setDoFollowRedirects(boolean doFollowRedirects) { _doFollowRedirects = doFollowRedirects; } + + protected void notifyOfWindowEvents(WindowEvent e) { + e.setEventWindow(this); + for (WindowEventListener listener : _eventListeners) { + listener.handleWindowEvent(e); + } + } + + public void addWindowEventListener(WindowEventListener listener) { + _eventListeners.add(listener); + } + public void removeWindowEventListener(WindowEventListener listener) { + _eventListeners.remove(listener); + } + + public void handleRequestEvent(RequestEvent e) { + if (e.getType().equals(RequestEventType.SUCCESS)) { + handleResponse(((RequestSuccessEvent)e).getResponse()); + } else if (e.getType().equals(RequestEventType.FAILURE)) { + WindowEvent we = new WindowEvent(); + we.setType(WindowEventType.REQUEST_FAILED); + we.addProperty("requestId", e.getRequestId()); + notifyOfWindowEvents(we); + } else { + LOG.warn("Unhandled request event: " + e); + } + } + + public boolean isWindowLoading() { + return _isWindowLoading; + } + + public void setWindowLoading(boolean isWindowLoading) { + _isWindowLoading = isWindowLoading; + } + + public String getWindowName() { + return _windowName; + } + + public void setWindowName(String windowName) { + _windowName = windowName; + } + + public RequestService getRequestService() { + return _requestService; + } } Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java 2007-08-13 21:08:29 UTC (rev 48) @@ -10,18 +10,24 @@ // package com.software416.jsimplebrowser.impl; +import com.google.inject.Inject; import com.google.inject.Provider; -import com.software416.jsimplebrowser.Browser; +import com.software416.jsimplebrowser.RequestService; import com.software416.jsimplebrowser.Window; public class WindowProvider implements Provider<Window> { - protected static final ThreadLocal<Browser> CURRENT_BROWSER = new ThreadLocal<Browser>(); + protected static final ThreadLocal<String> NEXT_WINDOW_NAME = new ThreadLocal<String>(); + + @Inject private RequestService _requestService; + public Window get() { - Browser b = CURRENT_BROWSER.get(); - if (b == null) { + String name = NEXT_WINDOW_NAME.get(); + if (name == null) { throw new IllegalStateException("Browser cannot be null"); } - return new WindowImpl(b); + WindowImpl wi = new WindowImpl(name); + wi.setRequestService(_requestService); + return wi; } } Modified: trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java =================================================================== --- trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java 2007-08-13 21:08:29 UTC (rev 48) @@ -13,6 +13,7 @@ import static org.junit.Assert.*; import java.io.IOException; +import java.net.URISyntaxException; import org.apache.commons.collections.MultiHashMap; import org.apache.commons.collections.MultiMap; @@ -35,7 +36,7 @@ System.setProperty("org.apache.commons.logging.simplelog.log.com.software416", "debug"); } - @Test public void testParsingBadPages() throws BrowserException, IOException { + @Test public void testParsingBadPages() throws URISyntaxException, IOException { String baseForm = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("badlyFormattedPage.html")); HttpResponseImpl requestInfo = new HttpResponseImpl(); requestInfo.setRequestMethod(new GetMethod("http://www.foo.com")); @@ -44,7 +45,7 @@ wi.handleResponse(requestInfo); } - @Test public void testGetMetaRefresh() throws BrowserException { + @Test public void testGetMetaRefresh() throws URISyntaxException { WindowImpl w = new WindowImpl(null); w.setDoFollowRedirects(false); HttpResponseImpl ri = new HttpResponseImpl(); @@ -67,7 +68,7 @@ w.handleResponse(ri); assertNull(w.findRefreshLink()); } - @Test public void testDefaultFormValuesMethodGeneration() throws BrowserException, IOException { + @Test public void testDefaultFormValuesMethodGeneration() throws URISyntaxException, IOException, BrowserException { String baseForm = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("formTest1.html")); HttpResponseImpl requestInfo = new HttpResponseImpl(); requestInfo.setRequestMethod(new GetMethod("http://www.foo.com")); @@ -87,7 +88,7 @@ assertTrue(m.getURI().getQuery().contains("selectInput=youGotIt")); assertEquals(6, m.getURI().getQuery().split("&").length); } - @Test public void testFormMethodGeneration() throws BrowserException, URIException { + @Test public void testFormMethodGeneration() throws URISyntaxException, URIException { String baseForm = "<html><body><form name=\"%1$s\" method=\"%2$s\" action=\"%3$s\"></form></body></html>"; HttpResponseImpl requestInfo = new HttpResponseImpl(); requestInfo.setRequestMethod(new GetMethod("http://www.foo.com")); Added: trunk/core/src/test/java/com/software416/jsimplebrowser/impl/WindowTest.java =================================================================== --- trunk/core/src/test/java/com/software416/jsimplebrowser/impl/WindowTest.java (rev 0) +++ trunk/core/src/test/java/com/software416/jsimplebrowser/impl/WindowTest.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,22 @@ +package com.software416.jsimplebrowser.impl; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.google.inject.Guice; +import com.software416.jsimplebrowser.Window; + +public class WindowTest { + @Test public void testInjection() { + String windowName = "testWindow"; + WindowProvider.NEXT_WINDOW_NAME.set(windowName); + Window w = Guice.createInjector().getInstance(Window.class); + assertNotNull(w); + assertEquals(WindowImpl.class, w.getClass()); + assertEquals(windowName, w.getWindowName()); + WindowImpl wi = (WindowImpl)w; + assertNotNull("request service is null", wi.getRequestService()); + WindowProvider.NEXT_WINDOW_NAME.remove(); + } +} Modified: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java 2007-08-13 21:08:29 UTC (rev 48) @@ -10,18 +10,19 @@ // package com.software416.jsimplebrowser.seleniumclient; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import com.software416.jsimplebrowser.BrowserException; import com.software416.jsimplebrowser.client.SimpleClient; import com.software416.jsimplebrowser.util.ElementLocator; import com.thoughtworks.selenium.Selenium; @@ -209,7 +210,7 @@ public void click(String id) { try { _simpleClient.click(id); - } catch (BrowserException ex) { + } catch (URISyntaxException ex) { LOG.warn("Problem clicking id: " + id, ex); } } @@ -284,7 +285,8 @@ try { url = buildUrl(url); _simpleClient.open(url); - } catch (BrowserException ex) { + waitForPageToLoad("15000"); + } catch (URISyntaxException ex) { LOG.warn("Problem loading page", ex); } } @@ -299,7 +301,7 @@ public void openWindow(String windowName, String url) { try { _simpleClient.openWindow(windowName, url); - } catch (BrowserException ex) { + } catch (URISyntaxException ex) { LOG.warn("Problem loading page", ex); } } @@ -323,14 +325,12 @@ } - public void selectFrame(String arg0) { - throw new UnsupportedOperationException(); - + public void selectFrame(String frameName) { + _simpleClient.setCurrentWindow(frameName); } - public void selectWindow(String arg0) { - throw new UnsupportedOperationException(); - + public void selectWindow(String windowName) { + _simpleClient.setCurrentWindow(windowName); } public void setBrowserLogLevel(String arg0) { @@ -353,7 +353,7 @@ public void submit(String id) { try { _simpleClient.submitForm(id); - } catch (BrowserException ex ) { + } catch (URISyntaxException ex ) { LOG.error("Problem submitting form: " + id, ex); } } @@ -366,7 +366,7 @@ throw new UnsupportedOperationException(); } - public void setTimeout(String arg0) { + public void setTimeout(String timeout) { throw new UnsupportedOperationException(); } @@ -375,17 +375,18 @@ } - public void waitForCondition(String arg0, String arg1) { + public void waitForCondition(String condition, String timeOut) { throw new UnsupportedOperationException(); } - public void waitForFrameToLoad(String arg0, String arg1) { - // noop right now until we make requests asynchronous... + public void waitForFrameToLoad(String windowName, String timeOut) { + _simpleClient.waitForWindowToLoad(windowName, Integer.parseInt(timeOut)); } - public void waitForPageToLoad(String arg0) { - // noop right now until we make requests asynchronous... + public void waitForPageToLoad(String timeOutStr) { + int timeOut = StringUtils.isEmpty(timeOutStr) ? SimpleClient.DEFAULT_WAIT_TIME_IN_SECONDS : Integer.parseInt(timeOutStr); + _simpleClient.waitForWindowToLoad(timeOut); } // Added: trunk/src/site/images/Request_Flow_Diagram.png =================================================================== (Binary files differ) Property changes on: trunk/src/site/images/Request_Flow_Diagram.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |