Author: [email protected]
Date: Sun Jul 12 13:10:02 2009
New Revision: 5718
Removed:
branches/htmlunit/user/src/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.xml
Modified:
branches/htmlunit/user/src/com/google/gwt/junit/HostedModePluginObject.java
branches/htmlunit/user/src/com/google/gwt/junit/RunStyleHtmlUnit.java
branches/htmlunit/user/src/com/google/gwt/junit/RunStyleHtmlUnitHosted.java
branches/htmlunit/user/test/com/google/gwt/user/client/rpc/TestSetValidator.java
Log:
Get HTMLUnit hosted-mode hooks in place (with the patch to HTMLUnit posted
on the HTMLUnit thread).
Modified:
branches/htmlunit/user/src/com/google/gwt/junit/HostedModePluginObject.java
==============================================================================
---
branches/htmlunit/user/src/com/google/gwt/junit/HostedModePluginObject.java
(original)
+++
branches/htmlunit/user/src/com/google/gwt/junit/HostedModePluginObject.java
Sun Jul 12 13:10:02 2009
@@ -15,25 +15,132 @@
*/
package com.google.gwt.junit;
-import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable;
+import com.gargoylesoftware.htmlunit.javascript.host.Window;
-public class HostedModePluginObject extends SimpleScriptable {
+import net.sourceforge.htmlunit.corejs.javascript.Context;
+import net.sourceforge.htmlunit.corejs.javascript.Function;
+import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
+import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;
- private static boolean injectHostedMode = false;
+/**
+ * HTMLUnit object that represents the hosted-mode plugin.
+ */
+public class HostedModePluginObject extends ScriptableObject {
- public static void setInjectHostedMode(boolean injectHostedMode) {
- HostedModePluginObject.injectHostedMode = injectHostedMode;
+ /**
+ * Function object which implements the connect method on the hosted-mode
+ * plugin.
+ */
+ private class ConnectMethod extends ScriptableObject implements Function
{
+
+ private static final long serialVersionUID = -8799481412144205779L;
+
+ public Object call(Context context, Scriptable scope, Scriptable
thisObj,
+ Object[] args) {
+ // Allow extra arguments for forward compatibility
+ if (args.length < 3) {
+ throw Context.reportRuntimeError("Bad number of parameters for
function"
+ + " connect: expected 3, got " + args.length);
+ }
+ try {
+ return connect((String) args[0], (String) args[1], (Window)
args[2]);
+ } catch (ClassCastException e) {
+ throw Context.reportRuntimeError("Incorrect parameter types for "
+ + " connect: expected String/String/Window");
+ }
+ }
+
+ public Scriptable construct(Context context, Scriptable scope,
Object[] args) {
+ throw Context.reportRuntimeError("Function connect can't be used as
a "
+ + "constructor");
+ }
+
+ @Override
+ public String getClassName() {
+ return "function HostedModePluginObject.connect";
+ }
+ }
+
+ /**
+ * Function object which implements the init method on the hosted-mode
+ * plugin.
+ */
+ private class InitMethod extends ScriptableObject implements Function {
+
+ private static final long serialVersionUID = -8799481412144205779L;
+
+ public Object call(Context context, Scriptable scope, Scriptable
thisObj,
+ Object[] args) {
+ // Allow extra arguments for forward compatibility
+ if (args.length < 1) {
+ throw Context.reportRuntimeError("Bad number of parameters for
function"
+ + " init: expected 1, got " + args.length);
+ }
+ try {
+ return init((String) args[0]);
+ } catch (ClassCastException e) {
+ throw Context.reportRuntimeError("Incorrect parameter types for "
+ + " initt: expected String");
+ }
+ }
+
+ public Scriptable construct(Context context, Scriptable scope,
Object[] args) {
+ throw Context.reportRuntimeError("Function init can't be used as a "
+ + "constructor");
+ }
+
+ @Override
+ public String getClassName() {
+ return "function HostedModePluginObject.init";
+ }
}
- public void jsConstructor() {
- boolean stopHere = true;
+ private static final long serialVersionUID = -1815031145376726799L;
+
+ private Scriptable connectMethod = new ConnectMethod();
+ private Scriptable initMethod = new InitMethod();
+ private Window window;
+
+ /**
+ * Initiate a hosted mode connection to the requested port and load the
+ * requested module.
+ *
+ * @param port "host:port" or "address:port" to use for the OOPHM server
+ * @param module module name to load
+ * @param window $wnd for this module
+ * @return true if the connection succeeds
+ */
+ public boolean connect(String port, String module, Window window) {
+ this.window = window;
+ System.err.println("connect(port=" + port + ", module=" + module
+ + ", window=" + System.identityHashCode(window) + ")");
+ // TODO: actually connect to the OOPHM server at port, send LoadModule
msg
+ return true;
}
- public boolean jsxFunction_connect(String port, String module,
- Object window) {
- if (!injectHostedMode) {
- return false;
+ @Override
+ public Object get(String name, Scriptable start) {
+ if ("connect".equals(name)) {
+ return connectMethod;
+ } else if ("init".equals(name)) {
+ return initMethod;
}
- return false;
+ return NOT_FOUND;
+ }
+
+ @Override
+ public String getClassName() {
+ return "HostedModePluginObject";
+ }
+
+ /**
+ * Verify that the plugin can be initialized properly and supports the
+ * requested version.
+ *
+ * @param version hosted mode protocol version
+ * @return true if initialization succeeds, otherwise false
+ */
+ public boolean init(String version) {
+ return true;
}
}
Modified:
branches/htmlunit/user/src/com/google/gwt/junit/RunStyleHtmlUnit.java
==============================================================================
--- branches/htmlunit/user/src/com/google/gwt/junit/RunStyleHtmlUnit.java
(original)
+++ branches/htmlunit/user/src/com/google/gwt/junit/RunStyleHtmlUnit.java
Sun Jul 12 13:10:02 2009
@@ -38,6 +38,9 @@
*/
public class RunStyleHtmlUnit extends RunStyleRemote {
+ /**
+ * Runs HTMLUnit in a separate thread.
+ */
protected class HtmlUnitThread extends Thread implements AlertHandler,
IncorrectnessListener, OnbeforeunloadHandler {
@@ -126,7 +129,19 @@
for (int i = 0; i < targetsIn.length; ++i) {
String browserName = targetsIn[i];
BrowserVersion browser = BrowserVersion.FIREFOX_2;
- // TODO(jat): find the browser name in BrowserVersion
+ // TODO(jat): better way to do this
+ if ("ff2".equalsIgnoreCase(browserName)) {
+ browser = BrowserVersion.FIREFOX_2;
+ } else if ("ff3".equalsIgnoreCase(browserName)) {
+ browser = BrowserVersion.FIREFOX_3;
+ } else if ("ie6".equalsIgnoreCase(browserName)) {
+ browser = BrowserVersion.INTERNET_EXPLORER_6;
+ } else if ("ie7".equalsIgnoreCase(browserName)) {
+ browser = BrowserVersion.INTERNET_EXPLORER_7;
+ } else {
+ shell.getTopLogger().log(TreeLogger.WARN, "Unrecognized browser "
+ + browserName + " -- using ff2");
+ }
browsers[i] = browser;
}
RunStyleHtmlUnit runStyle = new RunStyleHtmlUnitHosted(shell,
browsers);
@@ -151,14 +166,14 @@
}
}
- protected HtmlUnitThread createHtmlUnitThread(BrowserVersion browser,
String url) {
- return new HtmlUnitThread(browser, url);
- }
-
@Override
public void maybeCompileModule(String moduleName)
throws UnableToCompleteException {
- // TODO(jat): substitute appropriate user agent
+ // TODO(jat): substitute appropriate user agent, support multiple
agents
shell.compileForWebMode(moduleName, "gecko1_8");
+ }
+
+ protected HtmlUnitThread createHtmlUnitThread(BrowserVersion browser,
String url) {
+ return new HtmlUnitThread(browser, url);
}
}
Modified:
branches/htmlunit/user/src/com/google/gwt/junit/RunStyleHtmlUnitHosted.java
==============================================================================
---
branches/htmlunit/user/src/com/google/gwt/junit/RunStyleHtmlUnitHosted.java
(original)
+++
branches/htmlunit/user/src/com/google/gwt/junit/RunStyleHtmlUnitHosted.java
Sun Jul 12 13:10:02 2009
@@ -19,6 +19,12 @@
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.WebWindow;
+import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
+import com.gargoylesoftware.htmlunit.javascript.host.Window;
+
+import net.sourceforge.htmlunit.corejs.javascript.Context;
+import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;
/**
@@ -26,6 +32,30 @@
*/
public class RunStyleHtmlUnitHosted extends RunStyleHtmlUnit {
+ /**
+ * JavaScriptEngine subclass that provides a hook of initializing the
+ * __gwt_HostedModePlugin property on any new window, so it acts just
like
+ * Firefox with the XPCOM plugin installed.
+ */
+ private static class HostedJavaScriptEngine extends JavaScriptEngine {
+
+ private static final long serialVersionUID = 3594816610842448691L;
+
+ public HostedJavaScriptEngine(WebClient webClient) {
+ super(webClient);
+ }
+
+ @Override
+ protected void initHook(WebWindow webWindow, Context context, Window
window) {
+ window.defineProperty("__gwt_HostedModePlugin",
+ new HostedModePluginObject(), ScriptableObject.READONLY);
+ }
+ }
+
+ /**
+ * Run HMTLUnit in a separate thread, replacing the default
JavaScriptEngine
+ * with one that has the necessary hosted mode hooks.
+ */
protected class HtmlUnitHostedThread extends HtmlUnitThread {
public HtmlUnitHostedThread(BrowserVersion browser, String url) {
@@ -34,7 +64,8 @@
@Override
protected void setupWebClient(WebClient webClient) {
- HostedModePluginObject.setInjectHostedMode(true);
+ JavaScriptEngine hostedEngine = new
HostedJavaScriptEngine(webClient);
+ webClient.setJavaScriptEngine(hostedEngine);
}
}
@@ -57,6 +88,7 @@
@Override
protected String getMyUrl(String moduleName) {
+ // TODO(jat): get the correct address/port
return super.getMyUrl(moduleName) + "?gwt.hosted=localhost:9997";
}
}
Modified:
branches/htmlunit/user/test/com/google/gwt/user/client/rpc/TestSetValidator.java
==============================================================================
---
branches/htmlunit/user/test/com/google/gwt/user/client/rpc/TestSetValidator.java
(original)
+++
branches/htmlunit/user/test/com/google/gwt/user/client/rpc/TestSetValidator.java
Sun Jul 12 13:10:02 2009
@@ -15,16 +15,16 @@
*/
package com.google.gwt.user.client.rpc;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertSame;
-
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeTreeMap;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeTreeSet;
import
com.google.gwt.user.client.rpc.TestSetFactory.SerializableDoublyLinkedNode;
import
com.google.gwt.user.client.rpc.TestSetFactory.SerializablePrivateNoArg;
import
com.google.gwt.user.client.rpc.TestSetFactory.SerializableWithTwoArrays;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertSame;
import java.util.ArrayList;
import java.util.HashMap;
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---