提交 4f3f2476 编写于 作者: K kohsuke

Improved the interactive JavaScript debugger support.

Fixed a bug in a form submission when the button is a YUI button.
It used to be that HtmlUnit wasn't passing the initiating button
as a parameter, but that's fixed now.



git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@20660 71c3de6d-444a-0410-be80-ed276b4c234a
上级 9da4ce71
......@@ -140,7 +140,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.jvnet.hudson</groupId>
<artifactId>embedded-rhino-debugger</artifactId>
<version>1.0</version>
<version>1.1</version>
</dependency>
<dependency>
<!-- for testing JNLP launch. -->
......
......@@ -120,7 +120,8 @@ import org.mortbay.jetty.webapp.WebAppContext;
import org.mortbay.jetty.webapp.WebXmlConfiguration;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.tools.shell.JSConsole;
import org.mozilla.javascript.tools.debugger.Dim;
import org.mozilla.javascript.ContextFactory.Listener;
import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.CSSParseException;
import org.w3c.css.sac.ErrorHandler;
......@@ -185,6 +186,21 @@ public abstract class HudsonTestCase extends TestCase {
*/
protected JavaScriptDebugger jsDebugger = new JavaScriptDebugger();
/**
* If no other debugger is installed, install {@link #jsDebugger},
* so as not to interfere with {@link Dim}.
*/
private Listener rhinoContextListener = new Listener() {
public void contextCreated(Context cx) {
if(cx.getDebugger()==null)
cx.setDebugger(jsDebugger,null);
}
public void contextReleased(Context cx) {
}
};
protected HudsonTestCase(String name) {
super(name);
}
......@@ -255,14 +271,12 @@ public abstract class HudsonTestCase extends TestCase {
protected void runTest() throws Throwable {
System.out.println("=== Starting "+ getClass().getSimpleName() + "." + getName());
new JavaScriptEngine(null); // ensure that ContextFactory is initialized
Context cx= ContextFactory.getGlobal().enterContext();
try {
cx.setOptimizationLevel(-1);
cx.setDebugger(jsDebugger,null);
ContextFactory.getGlobal().addListener(rhinoContextListener);
try {
super.runTest();
} finally {
Context.exit();
ContextFactory.getGlobal().removeListener(rhinoContextListener);
}
}
......@@ -491,10 +505,11 @@ public abstract class HudsonTestCase extends TestCase {
* <p>
* Note that installing a debugger appears to make an execution of JavaScript substantially slower.
*/
public void interactiveJavaScriptDebugger() {
org.mozilla.javascript.tools.debugger.Main.mainEmbedded("Rhino debugger: "+getName());
public Dim interactiveJavaScriptDebugger() {
// this can be too late, depending on when this method is invoked.
Functions.DEBUG_YUI = true;
return org.mozilla.javascript.tools.debugger.Main.mainEmbedded("Rhino debugger: "+getName());
}
/**
......@@ -581,8 +596,18 @@ public abstract class HudsonTestCase extends TestCase {
public HtmlPage submit(HtmlForm form, String name) throws Exception {
for( HtmlElement e : form.getHtmlElementsByTagName("button")) {
HtmlElement p = (HtmlElement)e.getParentNode().getParentNode();
if(p.getAttribute("name").equals(name))
if(p.getAttribute("name").equals(name)) {
// To make YUI event handling work, this combo seems to be necessary
// the click will trigger _onClick in buton-*.js, but it doesn't submit the form
// (a comment alluding to this behavior can be seen in submitForm method)
// so to complete it, submit the form later.
//
// Just doing form.submit() doesn't work either, because it doesn't do
// the preparation work needed to pass along the name of the button that
// triggered a submission (more concretely, m_oSubmitTrigger is not set.)
((HtmlButton)e).click();
return (HtmlPage)form.submit((HtmlButton)e);
}
}
throw new AssertionError("No such submit button with the name "+name);
}
......
......@@ -4,6 +4,7 @@ import org.jvnet.hudson.test.HudsonTestCase;
import org.xml.sax.SAXException;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.ElementNotFoundException;
import java.io.IOException;
......@@ -19,13 +20,15 @@ public class HudsonHomeDiskUsageMonitorTest extends HudsonTestCase {
// clikcing yes should take us to somewhere
submit(getForm(mon),"yes");
// TODO: the test doesn't work today because the submit button doesn't send the name in the form.
// this appears to be a bug in HTMLUnit.
// // now dismiss
// submit(getForm(mon),"no");
//
// // and make sure it's gone
// assertNull(getForm(mon));
// now dismiss
submit(getForm(mon),"no");
// and make sure it's gone
try {
fail(getForm(mon)+" shouldn't be there");
} catch (ElementNotFoundException e) {
// as expected
}
}
/**
......
......@@ -23,18 +23,16 @@
*/
package hudson.tasks;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import hudson.model.FreeStyleProject;
import hudson.tasks.Ant.AntInstallation;
import hudson.tasks.Ant.AntInstaller;
import hudson.tasks.Ant.AntInstallation.DescriptorImpl;
import hudson.tasks.Ant.AntInstaller;
import hudson.tools.InstallSourceProperty;
import hudson.tools.ToolProperty;
import hudson.tools.ToolPropertyDescriptor;
import hudson.tools.InstallSourceProperty;
import hudson.util.DescribableList;
import org.jvnet.hudson.test.HudsonTestCase;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册