M dist/mcp-test/src/test/java/cardemo/CarDemoTest.java
- this automated test is now a complete example for how to test an ajax web application in an automated fashion. M dom/classes/org/mozilla/dom/NodeImpl.java M dom/jni/org_mozilla_dom_NodeImpl.cpp - implement getTextContent() from DOM level 3. M webclient/build-tests.xml - add cardemoTest to unit test list as a place-holder until I can write a testcase that doesn't require the public Internet. A webclient/classes_spec/org/mozilla/mcp/AjaxListener.java - New class. Docs forthcoming. M webclient/classes_spec/org/mozilla/mcp/MCP.java - new methods to support complete ajax automated testing. M webclient/src_moz/AjaxListener.cpp M webclient/src_moz/AjaxListener.h - add mIsObserving flag. From our dtor, make sure to remove ourselves from the EmbedProgress. M webclient/src_moz/EmbedProgress.cpp M webclient/src_moz/EmbedProgress.h - We need to add ourselves as an observer both from SetCapturePageInfo and SetEventRegistration. M webclient/src_moz/NativeBrowserControl.cpp - Unit testing found a bug! We can't call mWindow->ReleaseChildren() until after we remove ourself as a listener. git-svn-id: svn://10.0.0.236/trunk@221594 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -1,12 +1,34 @@
|
||||
/*
|
||||
* CarDemoTest.java
|
||||
* JUnit based test
|
||||
*
|
||||
* Created on March 3, 2007, 2:31 PM
|
||||
* $Id: CarDemoTest.java,v 1.6 2007-03-09 04:34:23 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 <edburns@acm.org>
|
||||
*/
|
||||
package cardemo;
|
||||
|
||||
import java.util.BitSet;
|
||||
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.w3c.dom.Element;
|
||||
@@ -36,19 +58,79 @@ public class CarDemoTest extends WebclientTestCase {
|
||||
|
||||
}
|
||||
|
||||
enum TestFeature {
|
||||
RECEIVED_END_AJAX_EVENT,
|
||||
HAS_MAP,
|
||||
HAS_VALID_PARTIAL_RESPONSE,
|
||||
HAS_VALID_READYSTATE,
|
||||
STOP_WAITING
|
||||
}
|
||||
|
||||
public void testCardemo() throws Exception {
|
||||
mcp.getRealizedVisibleBrowserWindow();
|
||||
final BitSet bitSet = new BitSet();
|
||||
AjaxListener listener = new AjaxListener() {
|
||||
public void endAjax(Map eventMap) {
|
||||
bitSet.flip(TestFeature.RECEIVED_END_AJAX_EVENT.ordinal());
|
||||
if (null != eventMap) {
|
||||
bitSet.flip(TestFeature.HAS_MAP.ordinal());
|
||||
}
|
||||
String responseText = (String) eventMap.get("responseText");
|
||||
if (null != responseText) {
|
||||
if (-1 != responseText.indexOf("<partial-response>") &&
|
||||
-1 != responseText.indexOf("</partial-response>")) {
|
||||
bitSet.flip(TestFeature.HAS_VALID_PARTIAL_RESPONSE.ordinal());
|
||||
}
|
||||
}
|
||||
String readyState = (String) eventMap.get("readyState");
|
||||
bitSet.set(TestFeature.HAS_VALID_READYSTATE.ordinal(),
|
||||
null != readyState && readyState.equals("4"));
|
||||
bitSet.flip(TestFeature.STOP_WAITING.ordinal());
|
||||
|
||||
}
|
||||
};
|
||||
mcp.addAjaxListener(listener);
|
||||
|
||||
// Load the main page of the app
|
||||
mcp.blockingLoad("http://webdev1.sun.com/jsf-ajax-cardemo/faces/chooseLocale.jsp");
|
||||
mcp.blockingLoad("http://javaserver.org/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");
|
||||
assertNotNull(pricePanel);
|
||||
String pricePanelText = pricePanel.getTextContent();
|
||||
|
||||
assertNotNull(pricePanelText);
|
||||
assertTrue(pricePanelText.matches("(?s).*Basis-Preis\\s*15700.*"));
|
||||
assertTrue(pricePanelText.matches("(?s).*Ihr Preis\\s*15700.*"));
|
||||
|
||||
// Choose the "Tempomat" checkbox
|
||||
mcp.clickElement("j_id_id21:j_id_id67j_id_1");
|
||||
bitSet.clear();
|
||||
mcp.clickElement("j_id_id10:j_id_id63j_id_1");
|
||||
|
||||
while (!bitSet.get(TestFeature.STOP_WAITING.ordinal())) {
|
||||
Thread.currentThread().sleep(5000);
|
||||
}
|
||||
|
||||
// assert that the ajax transaction succeeded
|
||||
assertTrue(bitSet.get(TestFeature.RECEIVED_END_AJAX_EVENT.ordinal()));
|
||||
assertTrue(bitSet.get(TestFeature.HAS_MAP.ordinal()));
|
||||
assertTrue(bitSet.get(TestFeature.HAS_VALID_PARTIAL_RESPONSE.ordinal()));
|
||||
assertTrue(bitSet.get(TestFeature.HAS_VALID_READYSTATE.ordinal()));
|
||||
bitSet.clear();
|
||||
|
||||
// Sample the Basis-Preis and Ihr-Preis after the ajax transaction
|
||||
pricePanel = mcp.findElement("j_id_id10:zone1");
|
||||
assertNotNull(pricePanel);
|
||||
pricePanelText = pricePanel.getTextContent();
|
||||
|
||||
Thread.currentThread().sleep(10000);
|
||||
assertNotNull(pricePanelText);
|
||||
assertTrue(pricePanelText.matches("(?s).*Basis-Preis\\s*15700.*"));
|
||||
assertTrue(pricePanelText.matches("(?s).*Ihr Preis\\s*16600.*"));
|
||||
|
||||
mcp.deleteBrowserControl();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user