- do Alpha 8 release

- Copy artifacts to local www for dist via CVS.

A dist/webclient-pom.xml

- Create Maven POM for error free artifact resolution

M dist/mcp-test/src/test/java/cardemo/CarDemoTest.java

- Update clientIds

- Use new package for WebclientTestCase

M dist/mcp-test/src/test/java/jsf_jmaki/JsfjMakiTest.java

- Use new timeout mechanism.

- Use new package for WebclientTestCase

M dist/netbeans/build.xml
M dist/netbeans/nbproject/project.properties

- alpha 8

M webclient/build-tests.xml

- remove cardemo from automated test run

M webclient/classes_spec/org/mozilla/mcp/MCP.java
A webclient/classes_spec/org/mozilla/mcp/TimeoutHandler.java

- Generalized timeout mechanism

A webclient/classes_spec/org/mozilla/mcp/CompareFiles.java
A webclient/classes_spec/org/mozilla/mcp/THTTPD.java
A webclient/classes_spec/org/mozilla/mcp/junit/TestLogStrings.properties
A webclient/classes_spec/org/mozilla/mcp/junit/WebclientTestCase.java
A webclient/classes_spec/org/mozilla/mcp/junit/package.html
R webclient/test/automated/src/classes/org/mozilla/util/THTTPD.java
R webclient/test/automated/src/classes/org/mozilla/webclient/CompareFiles.java
R webclient/test/automated/src/classes/org/mozilla/webclient/TestLogStrings.properties
R webclient/test/automated/src/classes/org/mozilla/webclient/WebclientTestCase.java
M webclient/test/automated/src/classes/org/mozilla/webclient/BookmarksTest.java
M webclient/test/automated/src/classes/org/mozilla/webclient/BrowserControlFactoryTest.java
M webclient/test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java
M webclient/test/automated/src/classes/org/mozilla/webclient/DOMTest.java
M webclient/test/automated/src/classes/org/mozilla/webclient/DocumentLoadListenerTest.java
M webclient/test/automated/src/classes/org/mozilla/webclient/HistoryTest.java
M webclient/test/automated/src/classes/org/mozilla/webclient/KeyListenerTest.java
M webclient/test/automated/src/classes/org/mozilla/webclient/MouseListenerTest.java
M webclient/test/automated/src/classes/org/mozilla/webclient/NavigationTest.java
M webclient/test/automated/src/classes/org/mozilla/webclient/PreferencesTest.java
M webclient/test/automated/src/classes/org/mozilla/webclient/ProfileManagerTest.java
M webclient/test/automated/src/classes/org/mozilla/webclient/WindowCreatorTest.java
M webclient/test/automated/src/classes/org/mozilla/webclient/impl/WebclientFactoryImplTest.java
M webclient/test/automated/src/classes/org/mozilla/webclient/impl/wrapper_native/TestGtkBrowserControlCanvas.java
M webclient/test/automated/src/classes/org/mozilla/webclient/impl/wrapper_native/WrapperFactoryImplTest.java

- New package for mcp JUnit support
This commit is contained in:
edburns%acm.org 2007-05-04 17:10:35 +00:00
Родитель 16b8570020
Коммит dc2221972c
30 изменённых файлов: 542 добавлений и 82 удалений

54
java/dist/build.xml поставляемый
Просмотреть файл

@ -32,11 +32,12 @@
<property name="name" value="webclient"/>
<property name="major.version" value="2" />
<property name="minor.version" value="0" />
<property name="release.version" value="a6" />
<property name="release.version.full" value="alpha_6" />
<property name="release.version" value="a8" />
<property name="release.version.full" value="alpha_8" />
<property name="version"
value="${major.version}_${minor.version}_${release.version}"/>
<property name="full.version" value="${major.version}_${minor.version}_${release.version.full}"/>
<property name="snapshot" value="-SNAPSHOT" />
<!-- ************ Per user local properties ******************************* -->
@ -54,7 +55,8 @@
<property name="javadoc.protected" value="true"/>
<property name="dist.jar" value="${dist.home}/lib/${name}-${version}.jar"/>
<target name="release">
<target name="release"
description="Build a Webclient Release">
<antcall target="prepare" />
<antcall target="uptodate" />
@ -64,6 +66,7 @@
<antcall target="copy.test.src" />
<antcall target="copy.core.src" />
<antcall target="copy.build.support" />
<antcall target="copy.release.notes" />
<antcall target="build.javadocs" />
<antcall target="build.zip" />
</target>
@ -134,6 +137,10 @@
</and>
</condition>
<condition property="has.mozdocdir">
<available file="${mozdocdir}" />
</condition>
</target>
@ -148,9 +155,13 @@
targetfile="${dist.javadocs}/index.html" >
<srcfiles dir= "${source.home}">
<include name="**/webclient/classes_spec/**/*.java" />
<include name="**/webclient/webclient/test/automated/src/classes/org/mozilla/webclient/WebclientTestCase.java" />
<include name="**/webclient/webclient/test/automated/src/classes/org/mozilla/webclient/CompareFiles.java" />
<include name="**/webclient/webclient/test/automated/src/classes/org/mozilla/webclient/TestLogStrings.properties" />
<include name="**/util/classes/**/*.java" />
<include name="**/dom/classes/**/*.java" />
</srcfiles>
</uptodate>
<echo message="javadoc up to date: ${javadocs.uptodate}" />
@ -160,7 +171,7 @@
<jar jarfile="${dist.jar}" >
<manifest>
<attribute name="Specification-Title" value="${Name}"/>
<attribute name="Specification-Version" value="2.0"/>
<attribute name="Specification-Version" value="${major.version}.${minor.version}"/>
<attribute name="Implementation-Title" value="'${name}': ${Name}"/>
<attribute name="Implementation-Version" value="${version}"/>
<attribute name="Implementation-Vendor" value="mozilla.org"/>
@ -169,13 +180,21 @@
</manifest>
<fileset dir="${dist.classes}"
excludes="**/test/**" />
excludes="**/test/**">
</fileset>
</jar>
</target>
<target name="edburns.compile">
<ant inheritAll="false" dir="${source.home}/webclient"
target="compile.classes_spec" />
</target>
<target name="compile.all" unless="core.java.classes.uptodate"
depends="uptodate">
<ant inheritAll="false" dir="${source.home}" />
<ant inheritAll="false" dir="${source.home}/webclient"
target="compile.test" />
</target>
<target name="copy.binaries" depends="prepare">
@ -239,6 +258,11 @@
<fileset dir="${source.home}/dom/classes">
<exclude name="**/*.html" />
</fileset>
<fileset dir="${source.home}/webclient/test/automated/src/classes">
<include name="**/CompareFiles.java" />
<include name="**/WebclientTestCase.java" />
<include name="**/TestLogStrings.properties" />
</fileset>
</copy>
@ -252,13 +276,25 @@
<copy todir="${dist.home}/non-ide">
<fileset dir="${basedir}/non-ide" />
</copy>
</target>
<target name="copy.release.notes" depends="prepare" if="has.mozdocdir">
<copy file="${mozdocdir}/webclient/release-notes/${full.version}.html" todir="${dist.home}" />
<copy file="${mozdocdir}/webclient/release-notes/${full.version}-detail.html" todir="${dist.home}" />
</target>
<target name="deploy.to.local.www" depends="prepare" if="has.mozdocdir"
description="After building the release, it can be deployed to the local mozilla-org CVS workarea">
<copy file="${dist.jar}"
tofile="${mozdocdir}/webclient/bin/maven2/org/mozilla/webclient/${major.version}.${minor.version}${snapshot}/${name}-${major.version}.${minor.version}${snapshot}.jar" />
<copy file="${name}-pom.xml"
tofile="${mozdocdir}/webclient/bin/maven2/org/mozilla/webclient/${major.version}.${minor.version}${snapshot}/${name}-${major.version}.${minor.version}${snapshot}.pom" />
<copy file="${objdir}/${name}_${version}_${platform}.zip"
todir="${mozdocdir}/webclient/bin/${platform}" />
</target>
<target name="build.javadocs" depends="prepare,uptodate"
unless="javadocs.uptodate"
description="Create the JavaDoc API documentation">
unless="javadocs.uptodate">
<copy todir="${dist.javadocs}">
<fileset dir="${source.home}/webclient/classes_spec">
<include name="**/*.jpg" />
@ -278,9 +314,11 @@
bottom="Copyright &#169; 2002-2007 Mozilla.org All Rights Reserved.">
<fileset dir="${source.home}">
<include name="**/*.java"/>
<include name="**/WebclientTestCase.java"/>
<exclude name="**/impl/**/*.java" />
<exclude name="**/*ICE*.java" />
<exclude name="**/cardemo/**/*.java" />
<exclude name="**/jsf_jmaki/**/*.java" />
<exclude name="**/wrapper_nonnative/**/*.java" />
<exclude name="**/*Impl.java" />
<exclude name="**/test*/**/*.java" />
@ -288,6 +326,8 @@
<exclude name="xpcom/**/*.*" />
<exclude name="dom/blackconnect/**/*.*" />
<exclude name="pluggable-jvm/**/*.*" />
<exclude name="**/*THTTPD*.java" />
<exclude name="**/*CompareFiles*.java" />
<exclude name="**/*Bookmark*.java" />
<exclude name="**/*Preferences*.java" />
<exclude name="**/PrefChangedCallback.java" />

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: CarDemoTest.java,v 1.7 2007-03-15 00:33:10 edburns%acm.org Exp $
* $Id: CarDemoTest.java,v 1.8 2007-05-04 17:10:16 edburns%acm.org Exp $
*/
/*
@ -30,7 +30,7 @@ import java.util.Map;
import junit.framework.TestFailure;
import org.mozilla.mcp.AjaxListener;
import org.mozilla.mcp.MCP;
import org.mozilla.webclient.WebclientTestCase;
import org.mozilla.mcp.junit.WebclientTestCase;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Document;
@ -121,13 +121,13 @@ public class CarDemoTest extends WebclientTestCase {
mcp.addAjaxListener(listener);
// Load the main page of the app
mcp.blockingLoad("http://javaserver.org/jsf-ajax-cardemo/faces/chooseLocale.jsp");
mcp.blockingLoad("http://webdev1.sun.com/jsf-ajax-cardemo/faces/chooseLocale.jsp");
// Choose the "German" language button
mcp.blockingClickElement("j_id_id73:Germany");
// Choose the roadster
mcp.blockingClickElement("j_id_id18:j_id_id43");
// Sample the Basis-Preis and Ihr Preis before the ajax transaction
Element pricePanel = mcp.findElement("j_id_id10:zone1");
Element pricePanel = mcp.findElement("j_id_id21:zone1");
assertNotNull(pricePanel);
String pricePanelText = pricePanel.getTextContent();
@ -137,7 +137,7 @@ public class CarDemoTest extends WebclientTestCase {
// Choose the "Tempomat" checkbox
bitSet.clear();
mcp.clickElement("j_id_id10:j_id_id63j_id_1");
mcp.clickElement("j_id_id21:j_id_id67j_id_1");
while (!bitSet.get(TestFeature.STOP_WAITING.ordinal())) {
Thread.currentThread().sleep(5000);
@ -152,7 +152,7 @@ public class CarDemoTest extends WebclientTestCase {
bitSet.clear();
// Sample the Basis-Preis and Ihr-Preis after the ajax transaction
pricePanel = mcp.findElement("j_id_id10:zone1");
pricePanel = mcp.findElement("j_id_id21:zone1");
assertNotNull(pricePanel);
pricePanelText = pricePanel.getTextContent();

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: JsfjMakiTest.java,v 1.1 2007-04-21 03:25:36 edburns%acm.org Exp $
* $Id: JsfjMakiTest.java,v 1.2 2007-05-04 17:10:16 edburns%acm.org Exp $
*/
/*
@ -31,7 +31,8 @@ import java.util.Map;
import junit.framework.TestFailure;
import org.mozilla.mcp.AjaxListener;
import org.mozilla.mcp.MCP;
import org.mozilla.webclient.WebclientTestCase;
import org.mozilla.mcp.TimeoutHandler;
import org.mozilla.mcp.junit.WebclientTestCase;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Document;
@ -48,9 +49,7 @@ public class JsfjMakiTest extends WebclientTestCase {
super(testName);
}
private int ajaxTimeOut = 60000;
private int ajaxWaitInterval = 5000;
private TimeoutHandler timeoutHandler = null;
public void setUp() {
super.setUp();
@ -76,8 +75,25 @@ public class JsfjMakiTest extends WebclientTestCase {
public void testInplace() throws Exception {
mcp.getRealizedVisibleBrowserWindow();
final Thread testThread = Thread.currentThread();
timeoutHandler = new TimeoutHandler() {
public void timeout() {
super.timeout();
testThread.interrupt();
fail("Action timed out");
}
};
mcp.setTimeoutHandler(timeoutHandler);
final BitSet bitSet = new BitSet();
AjaxListener listener = new AjaxListener() {
public void timedOut() {
fail("Timed out waiting for ajax transaction to complete.");
}
public void errorAjax(Map eventMap) {
fail("Received error on Ajax transaction");
}
public void endAjax(Map eventMap) {
bitSet.flip(TestFeature.RECEIVED_END_AJAX_EVENT.ordinal());
if (null != eventMap) {
@ -126,7 +142,11 @@ public class JsfjMakiTest extends WebclientTestCase {
mcp.addAjaxListener(listener);
// Load the main page of the app
mcp.blockingLoad("http://localhost:8080/jsf-jmaki/index-demo.jsf");
mcp.blockingLoad("http://webdev2.sun.com/jsf-jmaki/index-demo.jsf");
if (timeoutHandler.isDidTimeout()) {
fail("timed out waiting for load");
}
// Choose the inplace test
mcp.blockingClickElement("inplace-test");
@ -174,18 +194,19 @@ public class JsfjMakiTest extends WebclientTestCase {
Thread.currentThread().sleep(10000);
mcp.deleteBrowserControl();
}
private void makeAjaxAssertions(BitSet bitSet) throws Exception {
// Artifically wait for the ajax transaction to complete, or the timeout to be reached.
int i = 0;
while (!bitSet.get(TestFeature.STOP_WAITING.ordinal()) ||
((i * getAjaxWaitInterval()) > getAjaxTimeOut())) {
while (true) {
if (bitSet.get(TestFeature.STOP_WAITING.ordinal())) {
break;
}
i++;
Thread.currentThread().sleep(getAjaxWaitInterval());
Thread.currentThread().sleep(mcp.getTimeoutWaitInterval());
}
// Ensure the timeout was not reached
assertFalse(((i * getAjaxWaitInterval()) > getAjaxTimeOut()));
// assert that the ajax transaction succeeded
assertTrue(bitSet.get(TestFeature.RECEIVED_END_AJAX_EVENT.ordinal()));
@ -255,22 +276,5 @@ public class JsfjMakiTest extends WebclientTestCase {
makeAjaxAssertions(bitSet);
}
public int getAjaxTimeOut() {
return ajaxTimeOut;
}
public void setAjaxTimeOut(int ajaxTimeOut) {
this.ajaxTimeOut = ajaxTimeOut;
}
public int getAjaxWaitInterval() {
return ajaxWaitInterval;
}
public void setAjaxWaitInterval(int ajaxWaitInterval) {
this.ajaxWaitInterval = ajaxWaitInterval;
}
}

4
java/dist/netbeans/build.xml поставляемый
Просмотреть файл

@ -210,7 +210,7 @@ ${so.prefix}xul.${so.extension}.
<property name="debug.jvm.args" value="" />
<property name="test.browser.url"
value="${basedir}/../2_0_alpha_6.html" />
value="${basedir}/../2_0_alpha_8.html" />
<java classname="org.mozilla.webclient.test.TestBrowser" fork="true">
<jvmarg value="-DNSPR_LOG_MODULES=webclient:4,webclientstub:4,pluglets:4"/>
@ -340,7 +340,7 @@ ${so.prefix}xul.${so.extension}.
<echo file="${build.classes.dir}/META-INF/services/org.mozilla.webclient.WebclientFactory">org.mozilla.webclient.impl.WebclientFactoryImpl</echo>
<echo file="${build.classes.dir}/META-INF/services/org.mozilla.webclient.impl.WrapperFactory">org.mozilla.webclient.impl.wrapper_native.WrapperFactoryImpl</echo>
<move failonerror="false" file="${file.reference.webclient-2_0_a6.jar}"
<move failonerror="false" file="${file.reference.webclient-2_0_a8.jar}"
tofile="${basedir}/../lib/outofdate-webclient_jar" />
</target>

Просмотреть файл

@ -19,15 +19,15 @@ dist.javadoc.dir=${dist.dir}/javadoc
file.reference.main-java=../test/manual/src/main/java
file.reference.main-java-1=../test/automated/src/main/java
file.reference.main-java-2=../src/main/java
file.reference.webclient-2_0_a6.jar=../lib/webclient-2_0_a6.jar
file.reference.webclient-2_0_a8.jar=../lib/webclient-2_0_a8.jar
jar.compress=false
javac.classpath=\
${file.reference.webclient-2_0_a6.jar}
${file.reference.webclient-2_0_a8.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.source=1.6
javac.target=1.6
javac.source=1.5
javac.target=1.5
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}:\

60
java/dist/webclient-pom.xml поставляемый Executable file
Просмотреть файл

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.mozilla.webclient</groupId>
<artifactId>webclient</artifactId>
<packaging>pom</packaging>
<name>Mozilla Webclient</name>
<version>2.0-SNAPSHOT</version>
<description>Artifacts for non-native portion of Mozilla Webclient
spec and implementation.</description>
<url>http://www.mozilla.org/projects/blackwood/webclient/</url>
<issueManagement>
<system>bugzilla</system>
<url>https://bugzilla.mozilla.org/</url>
</issueManagement>
<mailingLists>
<mailingList>
<name>Mozilla Java Webclient Newsgroup</name>
<post>http://groups.google.com/group/mozilla.dev.embedding/post</post>
<archive>http://groups.google.com/group/mozilla.dev.embedding/</archive>
</mailingList>
</mailingLists>
<developers>
<developer>
<id>edburns</id>
<name>Ed Burns</name>
<email>edburns@acm.org</email>
<organization>Sun Microsystems, Inc.</organization>
<roles>
<role>project-owner</role>
</roles>
<timezone>-6</timezone>
</developer>
</developers>
<contributors>
</contributors>
<licenses>
<license>
<name>Mozilla Public License 1.1</name>
<url>http://www.mozilla.org/MPL/MPL-1.1.html</url>
<distribution>manual</distribution>
<comments>Due to Webclient's current dependency on native code, it
is not possible to distribute Webclient entirely via Maven. The
Jar portion of Webclient can be distributed via Maven,
however.</comments>
</license>
</licenses>
<scm>
<connection>scm:cvs:pserver:anonymous:@cvs-mirror.mozilla.org:/cvsroot:Blackwood</connection>
<developerConnection>scm:cvs:ext:username:@cvs.mozilla.org:/cvsroot:Blackwood</developerConnection>
<url>http://bonsai.mozilla.org/rview.cgi?dir=mozilla/java&amp;cvsroot=/cvsroot&amp;module=default</url>
</scm>
<organization>
<name>Mozilla Organization</name>
<url>http://www.mozilla.org/</url>
</organization>
</project>

Просмотреть файл

@ -191,7 +191,6 @@ PENDING(edburns): 20070130 XULRunner has no bookmarks
<test name="org.mozilla.webclient.WindowCreatorTest"/>
<test name="org.mozilla.webclient.DOMTest"/>
<test name="org.mozilla.webclient.CurrentPageTest"/>
<test name="cardemo.CarDemoTest"/>
<!-- non running
<test name="org.mozilla.webclient.wrapper_native.gtk.TestGtkBrowserControlCanvas"/>
-->

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: CompareFiles.java,v 1.4 2004-04-23 14:52:20 edburns%acm.org Exp $
* $Id: CompareFiles.java,v 1.1 2007-05-04 17:10:17 edburns%acm.org Exp $
*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
@ -24,7 +24,7 @@
* Contributor(s): Ed Burns &lt;edburns@acm.org&gt;
*/
package org.mozilla.webclient;
package org.mozilla.mcp;
import java.io.*;

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: MCP.java,v 1.9 2007-04-21 03:25:37 edburns%acm.org Exp $
* $Id: MCP.java,v 1.10 2007-05-04 17:10:17 edburns%acm.org Exp $
*/
/*
@ -91,6 +91,8 @@ public class MCP {
private Robot robot;
private DOMTreeDumper treeDumper = null;
private CountDownLatch latch = null;
private TimeoutHandler timeoutHandler = null;
private long Timeout = 30000L;
private void createLatch() {
if (null != latch) {
@ -528,6 +530,7 @@ public class MCP {
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
startTimeoutCheckIfNecessary();
} catch (NumberFormatException ex) {
LOGGER.throwing(this.getClass().getName(), "clickElementGivenId",
@ -612,6 +615,7 @@ public class MCP {
Navigation2 nav = getNavigation();
synchronized (this) {
nav.loadURL(url);
startTimeoutCheckIfNecessary();
createLatch();
try {
lockLatch();
@ -652,6 +656,10 @@ public class MCP {
case ((int) DocumentLoadEvent.END_AJAX_EVENT_MASK):
case ((int) DocumentLoadEvent.END_DOCUMENT_LOAD_EVENT_MASK):
openLatch();
if (null != MCP.this.timeoutThread) {
MCP.this.abortTimeoutCheck();
}
break;
case ((int) DocumentLoadEvent.START_URL_LOAD_EVENT_MASK):
String method = (String) eventData.get("method");
@ -683,4 +691,165 @@ public class MCP {
}
private void startTimeoutCheckIfNecessary() {
// If we are already tracking a timeout...
if (null != timeoutThread) {
abortTimeoutCheck();
}
if (null != getTimeoutHandler()) {
timeoutRunnable = new TimeoutRunnable();
timeoutThread = new Thread(timeoutRunnable,
"TimeoutThread-" + getTimeoutHandler().toString());
timeoutThread.start();
}
}
private void abortTimeoutCheck() {
assert(null != timeoutThread);
assert(null != timeoutRunnable);
timeoutRunnable.setRunning(false);
timeoutThread.interrupt();
timeoutRunnable = null;
timeoutThread = null;
}
private Thread timeoutThread = null;
private TimeoutRunnable timeoutRunnable = null;
/**
* <p>Return the currently installed {@link TimeoutHandler}, if
* any.</p>
*/
public TimeoutHandler getTimeoutHandler() {
return timeoutHandler;
}
/**
* <p>Install an instance of {@link TimeoutHandler} that will be
* used for all subsequent browser interactions (clicks, loads, Ajax
* transactions, etc). To remove the <code>TimeoutHandler</code>,
* pass <code>null</code> to this method. If a handler is
* installed, the timer is automatically started when a browser
* interaction commences. If the browser interaction does not
* complete within {@link #getTimeout} milliseconds, the {@link
* TimeoutHandler#timeout} method is called on the argument
* <code>TimeoutHandler</code> instance.</p>
*/
public void setTimeoutHandler(TimeoutHandler timeoutHandler) {
if (null != timeoutThread) {
abortTimeoutCheck();
}
this.timeoutHandler = timeoutHandler;
}
/**
* <p>Return the number of milliseconds that must elapse before the
* {@link TimeoutHandler} is called. Note that a
* <code>TimeoutHandler</code> is only called if the user has
* installed one by calling {@link #setTimeoutHandler}.</p>
*/
public long getTimeout() {
return Timeout;
}
/**
* <p>Set the number of milliseconds that must elapse before the
* {@link TimeoutHandler} is called, if such an instance has been
* installed via a previous call to {@link @setTimeoutHandler}.</p>
*/
public void setTimeout(long Timeout) {
this.Timeout = Timeout;
}
private long waitInterval = 5000L;
/**
* <p>Return the number of milliseconds to wait between timeout
* checks.</p>
*/
public long getTimeoutWaitInterval() {
return waitInterval;
}
/**
* <p>Set the number of milliseconds to wait between timeout
* checks.</p>
*/
public void setTimeoutWaitInterval(long waitInterval) {
this.waitInterval = waitInterval;
}
private class TimeoutRunnable implements Runnable {
public void run() {
setRunning(true);
while (isRunning()) {
try {
Thread.currentThread().sleep(MCP.this.getTimeoutWaitInterval());
} catch (InterruptedException ex) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.log(Level.WARNING, "Thread " +
Thread.currentThread().getName() +
" interrupted while sleeping.", ex);
}
setRunning(false);
return;
}
if (isTimedout()) {
setRunning(false);
if (null != MCP.this.getTimeoutHandler()) {
MCP.this.getTimeoutHandler().timeout();
}
}
}
}
private long startTime = -1L;
private boolean running = false;
public boolean isRunning() {
return running;
}
public void setRunning(boolean newValue) {
if (newValue) {
startTime = System.currentTimeMillis();
}
else {
startTime = -1L;
}
this.running = newValue;
}
/**
* <p>Returns <code>true</code> if {@link isTiming} returns <code>true</code>
* and the elapsed time between when timing commenced and
* the current time is greater than the value returned by {@link getTimeout}.
* Otherwise, returns <code>false</code>. This method need not be called
* by the user.
*/
public boolean isTimedout() {
boolean result = false;
if (isRunning()) {
result = (MCP.this.getTimeout() < (System.currentTimeMillis() - startTime));
}
return result;
}
}
}

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: THTTPD.java,v 1.6 2005-03-13 17:56:16 edburns%acm.org Exp $
* $Id: THTTPD.java,v 1.1 2007-05-04 17:10:17 edburns%acm.org Exp $
*/
/*
@ -24,7 +24,7 @@
* Contributor(s): Ed Burns &lt;edburns@acm.org&gt;
*/
package org.mozilla.util;
package org.mozilla.mcp;
import java.io.File;
import java.net.ServerSocket;

Просмотреть файл

@ -0,0 +1,125 @@
/*
* $Id: TimeoutHandler.java,v 1.1 2007-05-04 17:10:17 edburns%acm.org Exp $
*/
/*
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun
* Microsystems, Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s): Ed Burns &lt;edburns@acm.org&gt;
*/
package org.mozilla.mcp;
/**
* <p>This class provides a simple facility for placing a time bound on
* browser interactions (clicks, Ajax transactions, etc).</p>
*
* <p>Usage</p>
*
* <p>A useful pattern is to use this as an inner class within a JUnit
* testscase:</p>
<pre><code>
final Thread testThread = Thread.currentThread();
timeoutHandler = new TimeoutHandler() {
public void timeout() {
super.timeout();
testThread.interrupt();
fail("Action timed out");
}
};
mcp.setTimeoutHandler(timeoutHandler);
</code></pre>
*
* <p><code>TimeoutHandler</code> has a boolean JavaBeans property
* called <code>didTimeout</code> that can be used after blocking
* operations to test if a timeout happened.</p>
<pre><code>
if (timeoutHandler.isDidTimeout()) {
fail("timed out waiting for load");
}
</code></pre>
*
* <p>Another useful pattern is to combine the previous inner class
* approach with having the browser perform a non-blocking operation,
* and then causing the main thread to enter a loop until either a
* condition is met, or the timeout occurs:</p>
*
<pre><code>
bitSet.clear();
mcp.clickElement(inplaceFields.get(1));
makeAjaxAssertions(bitSet);
//...
private void makeAjaxAssertions(BitSet bitSet) throws Exception {
// Artifically wait for the ajax transaction to complete, or the timeout to be reached.
int i = 0;
while (true) {
if (bitSet.get(TestFeature.STOP_WAITING.ordinal())) {
break;
}
i++;
Thread.currentThread().sleep(mcp.getTimeoutWaitInterval());
}
// assert that the ajax transaction succeeded
assertTrue(bitSet.get(TestFeature.RECEIVED_END_AJAX_EVENT.ordinal()));
}
</code></pre>
*
* <p>The above code will either exit normally, by virtuo of the
* AjaxListener being called and it setting the STOP_WAITING bit in the
* bitset, or it will terminate due to timeout, in which case the inner
* class timeout method will be called.</p>
*
* @author edburns
*/
public class TimeoutHandler {
/**
* <p>The default implementation sets the value of the
* <code>didTimeout</code> JavaBeans property to
* <code>true</code>.</p>
*/
public void timeout() {
setDidTimeout(true);
}
private boolean didTimeout = false;
/**
* <p>Getter for boolean JavaBeans property
* <code>didTimeout</code>.</p>
*/
public boolean isDidTimeout() {
return didTimeout;
}
/**
* <p>Setter for boolean JavaBeans property
* <code>didTimeout</code>.</p>
*/
public void setDidTimeout(boolean didTimeout) {
this.didTimeout = didTimeout;
}
}

Просмотреть файл

@ -0,0 +1 @@
# Sample ResourceBundle properties file

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: WebclientTestCase.java,v 1.15 2007-03-03 20:35:14 edburns%acm.org Exp $
* $Id: WebclientTestCase.java,v 1.1 2007-05-04 17:10:17 edburns%acm.org Exp $
*/
/*
@ -24,7 +24,7 @@
* Contributor(s): Ed Burns &lt;edburns@acm.org&gt;
*/
package org.mozilla.webclient;
package org.mozilla.mcp.junit;
// WebclientTestCase.java
@ -38,19 +38,26 @@ import java.util.logging.Logger;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.framework.TestResult;
import org.mozilla.mcp.CompareFiles;
import org.mozilla.util.THTTPD;
import org.mozilla.mcp.THTTPD;
import org.mozilla.webclient.BrowserControlFactory;
/**
*
* <B>WebclientTestCase</B> is a class ...
* <p>WebclientTestCase extends <code>junit.framework.TestCase</code>
* and allows using MCP from a JUnit test. It makes assertions that
* verify preconditions for running MCP.</p>
*
* <B>Lifetime And Scope</B> <P>
* <p>This class currently has a number of undocumented and unsupported
* features that can be useful if you take the time to look at the
* source. Specifically, it has the ability to capture output from
* running the testcase, compare that output with a golden file, and it
* has a trivial HTTP server built in so webclient automated tests can
* run without any extra server baggage.</p>
*
* @version $Id: WebclientTestCase.java,v 1.15 2007-03-03 20:35:14 edburns%acm.org Exp $
* @version $Id: WebclientTestCase.java,v 1.1 2007-05-04 17:10:17 edburns%acm.org Exp $
*
* @see Blah
* @see Bloo
*
*/
@ -63,8 +70,8 @@ public abstract class WebclientTestCase extends TestCase
public static final String WEBCLIENTSTUB_LOG_MODULE = "webclientstub";
public static final String WEBCLIENT_LOG_MODULE = "webclient";
public static String OUTPUT_FILE_ROOT = null;
public static final String TEST_LOG = "org.mozilla.webclient.test";
public static final String TEST_LOG_STRINGS = "org.mozilla.webclient.TestLogStrings";
public static final String TEST_LOG = "org.mozilla.mcp.junit";
public static final String TEST_LOG_STRINGS = "org.mozilla.mcp.junit.TestLogStrings";
public static final Logger LOGGER = getLogger(TEST_LOG);

Просмотреть файл

@ -0,0 +1,43 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!--
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Ed Burns &gt;edburns@acm.org&lt;
-->
<html>
<head>
<title>org.mozilla.mcp.junit</title>
</head>
<body>
<p>JUnit Support for Mozilla Control Program</p>
<img width="120" height="86" src="../mcp.jpg" style="float:left; padding:1%;" alt="Master Control Program, from TRON" />
<p>This class extends JUnit TestCase for use with MCP.</p>
</body>
</html>

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: BookmarksTest.java,v 1.1 2003-09-28 06:29:18 edburns%acm.org Exp $
* $Id: BookmarksTest.java,v 1.2 2007-05-04 17:10:18 edburns%acm.org Exp $
*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
@ -32,6 +32,7 @@ import junit.framework.Test;
import java.util.Enumeration;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import org.mozilla.mcp.junit.WebclientTestCase;
// BookmarksTest.java

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: BrowserControlFactoryTest.java,v 1.4 2006-03-05 03:53:26 edburns%acm.org Exp $
* $Id: BrowserControlFactoryTest.java,v 1.5 2007-05-04 17:10:18 edburns%acm.org Exp $
*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
@ -28,6 +28,7 @@ package org.mozilla.webclient;
import junit.framework.TestSuite;
import junit.framework.Test;
import org.mozilla.mcp.junit.WebclientTestCase;
// BrowserControlFactoryTest.java

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: CurrentPageTest.java,v 1.16 2007-02-26 21:32:35 edburns%acm.org Exp $
* $Id: CurrentPageTest.java,v 1.17 2007-05-04 17:10:35 edburns%acm.org Exp $
*/
/*
@ -43,6 +43,7 @@ import java.awt.datatransfer.DataFlavor;
import java.io.File;
import java.io.FileInputStream;
import java.io.BufferedReader;
import org.mozilla.mcp.junit.WebclientTestCase;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: DOMTest.java,v 1.3 2007-03-06 03:28:47 edburns%acm.org Exp $
* $Id: DOMTest.java,v 1.4 2007-05-04 17:10:35 edburns%acm.org Exp $
*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
@ -37,6 +37,7 @@ import java.awt.Robot;
import java.io.File;
import java.io.FileInputStream;
import org.mozilla.mcp.junit.WebclientTestCase;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: DocumentLoadListenerTest.java,v 1.5 2006-03-17 00:26:02 edburns%acm.org Exp $
* $Id: DocumentLoadListenerTest.java,v 1.6 2007-05-04 17:10:35 edburns%acm.org Exp $
*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
@ -42,6 +42,7 @@ import java.io.InputStream;
import java.awt.Robot;
import java.awt.event.InputEvent;
import org.mozilla.mcp.junit.WebclientTestCase;
// DocumentLoadListenerTest.java

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: HistoryTest.java,v 1.3 2004-10-26 19:33:15 edburns%acm.org Exp $
* $Id: HistoryTest.java,v 1.4 2007-05-04 17:10:35 edburns%acm.org Exp $
*/
/*
@ -37,6 +37,7 @@ import java.awt.BorderLayout;
import java.io.File;
import java.io.FileInputStream;
import org.mozilla.mcp.junit.WebclientTestCase;
// HistoryTest.java

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: KeyListenerTest.java,v 1.4 2007-02-15 04:59:50 edburns%acm.org Exp $
* $Id: KeyListenerTest.java,v 1.5 2007-05-04 17:10:35 edburns%acm.org Exp $
*/
/*
@ -36,6 +36,7 @@ import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.awt.event.InputEvent;
import java.awt.BorderLayout;
import org.mozilla.mcp.junit.WebclientTestCase;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: MouseListenerTest.java,v 1.3 2005-08-20 19:25:52 edburns%acm.org Exp $
* $Id: MouseListenerTest.java,v 1.4 2007-05-04 17:10:35 edburns%acm.org Exp $
*/
/*
@ -37,6 +37,7 @@ import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.InputEvent;
import java.awt.BorderLayout;
import org.mozilla.mcp.junit.WebclientTestCase;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: NavigationTest.java,v 1.21 2007-02-23 19:03:12 edburns%acm.org Exp $
* $Id: NavigationTest.java,v 1.22 2007-05-04 17:10:35 edburns%acm.org Exp $
*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
@ -36,6 +36,7 @@ import java.awt.BorderLayout;
import java.io.File;
import java.io.FileInputStream;
import org.mozilla.mcp.junit.WebclientTestCase;
// NavigationTest.java

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: PreferencesTest.java,v 1.2 2004-04-01 14:54:57 edburns%acm.org Exp $
* $Id: PreferencesTest.java,v 1.3 2007-05-04 17:10:35 edburns%acm.org Exp $
*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
@ -31,6 +31,7 @@ import junit.framework.Test;
import java.util.Properties;
import java.util.Iterator;
import org.mozilla.mcp.junit.WebclientTestCase;
// PreferencesTest.java

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: ProfileManagerTest.java,v 1.3 2004-11-05 06:40:27 edburns%acm.org Exp $
* $Id: ProfileManagerTest.java,v 1.4 2007-05-04 17:10:35 edburns%acm.org Exp $
*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
@ -28,6 +28,7 @@ package org.mozilla.webclient;
import junit.framework.TestSuite;
import junit.framework.Test;
import org.mozilla.mcp.junit.WebclientTestCase;
// ProfileManagerTest.java

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: WindowCreatorTest.java,v 1.4 2007-01-22 12:35:14 edburns%acm.org Exp $
* $Id: WindowCreatorTest.java,v 1.5 2007-05-04 17:10:35 edburns%acm.org Exp $
*/
/*
@ -43,6 +43,7 @@ import java.awt.BorderLayout;
import java.io.File;
import java.io.FileInputStream;
import org.mozilla.mcp.junit.WebclientTestCase;
// WindowCreatorTest.java

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: WebclientFactoryImplTest.java,v 1.1 2003-09-28 06:29:19 edburns%acm.org Exp $
* $Id: WebclientFactoryImplTest.java,v 1.2 2007-05-04 17:10:35 edburns%acm.org Exp $
*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
@ -29,7 +29,7 @@ package org.mozilla.webclient.impl;
import junit.framework.TestSuite;
import junit.framework.Test;
import org.mozilla.webclient.WebclientTestCase;
import org.mozilla.mcp.junit.WebclientTestCase;
// WebclientFactoryImplTest.java

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: TestGtkBrowserControlCanvas.java,v 1.1 2004-04-23 14:52:21 edburns%acm.org Exp $
* $Id: TestGtkBrowserControlCanvas.java,v 1.2 2007-05-04 17:10:35 edburns%acm.org Exp $
*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
@ -31,7 +31,7 @@ package org.mozilla.webclient.impl.wrapper_native;
import org.mozilla.util.Assert;
import org.mozilla.util.ParameterCheck;
import org.mozilla.webclient.WebclientTestCase;
import org.mozilla.mcp.junit.WebclientTestCase;
/**
*
@ -39,7 +39,7 @@ import org.mozilla.webclient.WebclientTestCase;
*
* <B>Lifetime And Scope</B> <P>
*
* @version $Id: TestGtkBrowserControlCanvas.java,v 1.1 2004-04-23 14:52:21 edburns%acm.org Exp $
* @version $Id: TestGtkBrowserControlCanvas.java,v 1.2 2007-05-04 17:10:35 edburns%acm.org Exp $
*
* @see Blah
* @see Bloo

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: WrapperFactoryImplTest.java,v 1.4 2004-04-20 16:17:43 edburns%acm.org Exp $
* $Id: WrapperFactoryImplTest.java,v 1.5 2007-05-04 17:10:35 edburns%acm.org Exp $
*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
@ -31,7 +31,7 @@ import junit.framework.Test;
import org.mozilla.webclient.BrowserControl;
import org.mozilla.webclient.BrowserControlFactory;
import org.mozilla.webclient.WebclientTestCase;
import org.mozilla.mcp.junit.WebclientTestCase;
import org.mozilla.webclient.impl.BrowserControlImpl;
// WrapperFactoryImplTest.java