« HTTPS testing with jWebUnit | Main | Boston User Groups »

HttpUnit and document.referrer

Another small patch to HttpUnit 1.6.1 to go along with my other one. The following JavaScript blows up in HttpUnit, but runs fine in a normal browser:

var temp = document.referrer;
if (temp.length <= 1) {
temp = "no referrer"
}

The resulting stack trace is below. The fix is to add the following method to the Document nested class in HttpUnit's JavaScript class.

public String jsGet_referrer() throws SAXException {
return "";
}

You could stub that method out with something more interesting, but that's good enough for me at this time.


org.mozilla.javascript.EcmaError: TypeError: Cannot read property "length" from undefined (httpunit#59)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3226)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3216)
at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3232)
at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3251)
at org.mozilla.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3264)
at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1321)
at org.mozilla.javascript.gen.c1._c0(httpunit:59)
at org.mozilla.javascript.gen.c1.call(httpunit)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:337)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2755)
at org.mozilla.javascript.gen.c1.call(httpunit)
at org.mozilla.javascript.gen.c1.exec(httpunit)
at org.mozilla.javascript.Context.evaluateString(Context.java:1132)
at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.executeScript(JavaScript.java:150)
at com.meterware.httpunit.scripting.ScriptableDelegate.runScript(ScriptableDelegate.java:65)
at com.meterware.httpunit.ParsedHTML.interpretScriptElement(ParsedHTML.java:325)
at com.meterware.httpunit.ParsedHTML.access$700(ParsedHTML.java:37)
at com.meterware.httpunit.ParsedHTML$ScriptFactory.recordElement(ParsedHTML.java:489)
at com.meterware.httpunit.ParsedHTML$2.processElement(ParsedHTML.java:706)
at com.meterware.httpunit.NodeUtils$PreOrderTraversal.perform(NodeUtils.java:195)
at com.meterware.httpunit.ParsedHTML.loadElements(ParsedHTML.java:722)
at com.meterware.httpunit.ParsedHTML.getFrames(ParsedHTML.java:1034)
at com.meterware.httpunit.WebResponse.getFrames(WebResponse.java:1098)
at com.meterware.httpunit.WebResponse.getFrameRequests(WebResponse.java:875)
at com.meterware.httpunit.FrameHolder.updateFrames(FrameHolder.java:179)
at com.meterware.httpunit.WebWindow.updateFrameContents(WebWindow.java:252)
at com.meterware.httpunit.WebClient.updateFrameContents(WebClient.java:485)
at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:146)
at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:130)
at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:121)
at com.meterware.httpunit.WebClient.getResponse(WebClient.java:113)
at net.sourceforge.jwebunit.HttpUnitDialog.(HttpUnitDialog.java:48)
at net.sourceforge.jwebunit.WebTester.beginAt(WebTester.java:55)
at net.sourceforge.jwebunit.WebTestCase.beginAt(WebTestCase.java:46)
(... additional lines deleted ...)