[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HTMLPage.java,NONE,1.1 ScriptEngine.java,
Brought to you by:
russgold
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv10054/src/com/meterware/httpunit
Modified Files:
FormControl.java ScriptableObject.java WebForm.java
WebResponse.java
Added Files:
HTMLPage.java ScriptEngine.java
Removed Files:
ReceivedPage.java
Log Message:
Initialize JavaScript implementation
***** Error reading new file[Errno 2] No such file or directory: 'HTMLPage.java'
***** Error reading new file[Errno 2] No such file or directory: 'ScriptEngine.java'
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- FormControl.java 14 May 2002 18:38:54 -0000 1.11
+++ FormControl.java 24 Jul 2002 20:54:31 -0000 1.12
@@ -240,16 +240,7 @@
}
- class Scriptable implements ScriptableObject {
-
- public Object get( String propertyName ) {
- throw new RuntimeException( "Unknown property: " + propertyName );
- }
-
-
- public void set( String propertyName, Object value ) {
- throw new RuntimeException( "Unknown property: " + propertyName );
- }
+ class Scriptable extends ScriptableObject {
}
}
Index: ScriptableObject.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ScriptableObject.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ScriptableObject.java 8 Apr 2002 18:40:23 -0000 1.1
+++ ScriptableObject.java 24 Jul 2002 20:54:31 -0000 1.2
@@ -25,17 +25,42 @@
*
* @author <a href="mailto:rus...@ac...">Russell Gold</a>
**/
-public interface ScriptableObject {
+abstract public class ScriptableObject {
+
+ private ScriptEngine _scriptEngine;
+
+
+ /**
+ * Executes the specified scripted event.
+ **/
+ public void doEvent( String eventScript ) {
+ if (_scriptEngine == null) throw new IllegalStateException( "Script engine must be defined before running an event" );
+ _scriptEngine.executeScript( eventScript );
+ }
+
/**
- * Returns the value of the named property. Will throw a runtime exception if the property does not exist.
+ * Returns the value of the named property. Will return null if the property does not exist.
**/
- public Object get( String propertyName );
+ public Object get( String propertyName ) {
+ return null;
+ }
/**
* Sets the value of the named property. Will throw a runtime exception if the property does not exist or
* cannot accept the specified value.
**/
- public void set( String propertyName, Object value );
+ public void set( String propertyName, Object value ) {
+ throw new RuntimeException( "No such property: " + propertyName );
+ }
+
+
+ /**
+ * Specifies the scripting engine to be used.
+ */
+ public void setScriptEngine( ScriptEngine scriptEngine ) {
+ _scriptEngine = scriptEngine;
+ }
+
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- WebForm.java 8 Apr 2002 18:40:23 -0000 1.49
+++ WebForm.java 24 Jul 2002 20:54:31 -0000 1.50
@@ -400,17 +400,13 @@
}
- public class Scriptable implements ScriptableObject {
+ public class Scriptable extends ScriptableObject {
public String getAction() { return WebForm.this.getAction(); }
public void setAction( String newAction ) { _action = newAction; }
public void setParameterValue( String name, String value ) {
getParameter( name ).getScriptableObject().set( "value", value );
}
-
-
- public void set( String propertyName, Object value ) {}
- public Object get( String propertyName ) { return null; }
}
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- WebResponse.java 15 Jul 2002 14:30:32 -0000 1.67
+++ WebResponse.java 24 Jul 2002 20:54:31 -0000 1.68
@@ -33,6 +33,7 @@
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
+import java.util.LinkedList;
import java.util.zip.GZIPInputStream;
import org.w3c.dom.Document;
@@ -453,6 +454,50 @@
}
+//---------------------------------------- JavaScript methods ----------------------------------------
+
+ private LinkedList _alerts = new LinkedList();
+
+ /**
+ * Returns the next javascript alert without removing it from the queue.
+ */
+ public String getNextAlert() {
+ return _alerts.isEmpty() ? null : (String) _alerts.getFirst();
+ }
+
+
+ /**
+ * Returns the next javascript alert and removes it from the queue.
+ */
+ public String popNextAlert() {
+ return (String) _alerts.removeFirst();
+ }
+
+
+ public Scriptable getScriptableObject() {
+ return new Scriptable();
+ }
+
+
+ public class Scriptable extends ScriptableObject {
+
+ public void alert( String message ) {
+ _alerts.addLast( message );
+ }
+
+
+ public HTMLPage.Scriptable getDocument() throws SAXException {
+ return getReceivedPage().getScriptableObject();
+ }
+
+
+ public void load() throws SAXException {
+ doEvent( getReceivedPage().getScripts() );
+ doEvent( getReceivedPage().getOnLoadEvent() );
+ }
+ }
+
+
//---------------------------------------- Object methods --------------------------------------------
abstract
@@ -586,7 +631,7 @@
private WebFrame[] _frames;
- private ReceivedPage _page;
+ private HTMLPage _page;
private String _contentHeader;
@@ -863,11 +908,11 @@
}
- private ReceivedPage getReceivedPage() throws SAXException {
+ private HTMLPage getReceivedPage() throws SAXException {
if (_page == null) {
try {
if (!isHTML()) throw new NotHTMLException( getContentType() );
- _page = new ReceivedPage( _url, _frameName, getText(), getCharacterSet() );
+ _page = new HTMLPage( _url, _frameName, getText(), getCharacterSet() );
} catch (IOException e) {
throw new SAXException( e );
}
|