diff --git a/test/pom.xml b/test/pom.xml index b3319fac844b7f7781396b1de20e5b6ab12556c9..16ef60c68aa8d3b414bfa9f9efff4d2bfad1fcdd 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -140,7 +140,7 @@ THE SOFTWARE. org.jvnet.hudson embedded-rhino-debugger - 1.0 + 1.1 diff --git a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java index 5690253cc278be9a3aaf4307403978b00673c8fb..4c8be52b57134a57e33712dfa88860d20b9de165 100644 --- a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -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 { *

* 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); } diff --git a/test/src/test/java/hudson/diagnosis/HudsonHomeDiskUsageMonitorTest.java b/test/src/test/java/hudson/diagnosis/HudsonHomeDiskUsageMonitorTest.java index f55ba90dd89cc435991cca0b181569927fc821b2..79a3fcd17ea5d4c4490d01501fac4e0564a3a909 100644 --- a/test/src/test/java/hudson/diagnosis/HudsonHomeDiskUsageMonitorTest.java +++ b/test/src/test/java/hudson/diagnosis/HudsonHomeDiskUsageMonitorTest.java @@ -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 + } } /** diff --git a/test/src/test/java/hudson/tasks/AntTest.java b/test/src/test/java/hudson/tasks/AntTest.java index cafc75fec220670928550f1018aa1bc4db658e87..9c29516769f27ce26e619fd4c6bc94a7e182b08c 100644 --- a/test/src/test/java/hudson/tasks/AntTest.java +++ b/test/src/test/java/hudson/tasks/AntTest.java @@ -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;