From: <rb...@us...> - 2013-11-09 12:03:46
|
Revision: 8755 http://sourceforge.net/p/htmlunit/code/8755 Author: rbri Date: 2013-11-09 12:03:43 +0000 (Sat, 09 Nov 2013) Log Message: ----------- missing test case for parameter checking and fix added Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMParser.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMParserTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMParser.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMParser.java 2013-11-08 20:05:10 UTC (rev 8754) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMParser.java 2013-11-09 12:03:43 UTC (rev 8755) @@ -16,6 +16,8 @@ import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; +import net.sourceforge.htmlunit.corejs.javascript.Context; +import net.sourceforge.htmlunit.corejs.javascript.Undefined; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; @@ -52,7 +54,10 @@ * @return the generated document */ @JsxFunction - public XMLDocument parseFromString(final String str, final String contentType) { + public XMLDocument parseFromString(final String str, final Object contentType) { + if (Undefined.instance == contentType) { + throw Context.reportRuntimeError("Missing 'contentType' parameter"); + } final XMLDocument document = new XMLDocument(); document.setParentScope(getParentScope()); document.setPrototype(getPrototype(XMLDocument.class)); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMParserTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMParserTest.java 2013-11-08 20:05:10 UTC (rev 8754) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMParserTest.java 2013-11-09 12:03:43 UTC (rev 8755) @@ -91,7 +91,6 @@ loadPageWithAlerts2(content); } - /** * @throws Exception if the test fails */ @@ -116,6 +115,28 @@ } /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "ex: parseFromString", + IE8 = "ex: new DOMParser") + public void parseFromString_missingMimeType() throws Exception { + final String content = "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " try {\n" + + " var parser=new DOMParser();\n" + + " try {\n" + + " parser.parseFromString('');\n" + + " } catch(e) { alert('ex: parseFromString'); }\n" + + " } catch(e) { alert('ex: new DOMParser'); }\n" + + " }\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "</body></html>"; + loadPageWithAlerts2(content); + } + + /** * Regression test for bug 2899485. * @throws Exception if an error occurs */ |