com.google.gwt.junit.remote
Class BrowserManagerServer

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by com.google.gwt.junit.remote.BrowserManagerServer
All Implemented Interfaces:
BrowserManager, java.io.Serializable, java.rmi.Remote

public class BrowserManagerServer
extends java.rmi.server.UnicastRemoteObject
implements BrowserManager

Manages instances of a web browser as child processes. This class is experimental and unsupported. An instance of this class can create browser windows using one specific shell-level command. It performs process management (baby sitting) on behalf of a remote client. This can be useful for running a GWTTestCase on a browser that cannot be run on the native platform. For example, a GWTTestCase test running on Linux could use a remote call to a Windows machine to test with Internet Explorer.

Calling main(String[]) can instantiate and register multiple instances of this class at given RMI namespace locations.

This system has been tested on Internet Explorer 6 & 7. Firefox does not work in the general case; if an existing Firefox process is already running, new processes simply delegate to the existing process and terminate, which breaks the model. A shell script that sets MOZNOREMOTE=1 and cleans up locks/sessions is needed. Safari on MacOS requires very special treatment given Safari's poor command line support, but that is beyond the scope of this documentation.

TODO(scottb): We technically need a watchdog thread to slurp up stdout and stderr from the child processes, or they might block. However, most browsers never write to stdout and stderr, so this is low priority. (There is now a thread that is spawned for each task to wait for an exit value - this might be adapted for that purpose one day.)

This class is not actually serializable as-is, because timer is not serializable.

see http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4062587

See Also:
Serialized Form

Method Summary
 void keepAlive(int token, long keepAliveMs)
          Keeps the browser process represented by token alive for keepAliveMs, starting now.
 void killBrowser(int token)
          Forceably kills the browser process represented by token, disregarding any previous calls to BrowserManager.keepAlive(int, long).
 int launchNewBrowser(java.lang.String url, long keepAliveMs)
          Launches a new browser window for the specified URL.
static void main(java.lang.String[] args)
          Starts up and registers one or more browser servers.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Starts up and registers one or more browser servers. Command-line entry point.

Throws:
java.lang.Exception

keepAlive

public void keepAlive(int token,
                      long keepAliveMs)
Description copied from interface: BrowserManager
Keeps the browser process represented by token alive for keepAliveMs, starting now.

Specified by:
keepAlive in interface BrowserManager
Parameters:
token - an opaque token representing the browser window
keepAliveMs - the number of milliseconds to let the browser process live; if roughly keepAliveMs milliseconds elapse without a subsequent call to this method, the browser process associated with token will be forceably terminated
See Also:
BrowserManager.keepAlive(int, long)

killBrowser

public void killBrowser(int token)
Description copied from interface: BrowserManager
Forceably kills the browser process represented by token, disregarding any previous calls to BrowserManager.keepAlive(int, long). If the process has already terminated, this method completes normally.

Specified by:
killBrowser in interface BrowserManager
Parameters:
token - an opaque token representing the browser window process
See Also:
BrowserManager.killBrowser(int)

launchNewBrowser

public int launchNewBrowser(java.lang.String url,
                            long keepAliveMs)
Description copied from interface: BrowserManager
Launches a new browser window for the specified URL.

Specified by:
launchNewBrowser in interface BrowserManager
Parameters:
url - the URL to browse to
keepAliveMs - the initial number of milliseconds to let the browser process live; if roughly keepAliveMs milliseconds expire without a subsequent call to BrowserManager.keepAlive(int, long), the browser process will be forceably terminated
Returns:
a positive integer that serves an an opaque token representing the new browser window.
See Also:
BrowserManager.launchNewBrowser(java.lang.String, long)