From: <rb...@us...> - 2017-06-14 17:35:52
|
Revision: 14606 http://sourceforge.net/p/htmlunit/code/14606 Author: rbri Date: 2017-06-14 17:35:49 +0000 (Wed, 14 Jun 2017) Log Message: ----------- more applet support Modified Paths: -------------- trunk/htmlunit/src/main/java/netscape/javascript/JSObject.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAppletTest.java trunk/htmlunit/src/test/resources/applets/simpleAppletDoIt.html trunk/htmlunit/src/test/resources/applets/simpleAppletDoIt.jar trunk/htmlunit/src/test/resources/objects/simpleAppletDoIt.jar Modified: trunk/htmlunit/src/main/java/netscape/javascript/JSObject.java =================================================================== --- trunk/htmlunit/src/main/java/netscape/javascript/JSObject.java 2017-06-13 12:11:06 UTC (rev 14605) +++ trunk/htmlunit/src/main/java/netscape/javascript/JSObject.java 2017-06-14 17:35:49 UTC (rev 14606) @@ -64,7 +64,14 @@ LOG.info("JSObject call '" + methodName + "(" + args + ")'"); } - throw new RuntimeException("Not yet implemented (netscape.javascript.JSObject.call(String, Object[]))."); + final Object jsResult = ScriptableObject.callMethod(scriptableObject_, methodName, args); + if (jsResult instanceof ScriptableObject) { + return new JSObject((ScriptableObject) jsResult); + } + if (jsResult instanceof ConsString) { + return ((ConsString) jsResult).toString(); + } + return jsResult; } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAppletTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAppletTest.java 2017-06-13 12:11:06 UTC (rev 14605) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAppletTest.java 2017-06-14 17:35:49 UTC (rev 14606) @@ -308,6 +308,48 @@ * @throws Exception if the test fails */ @Test + public void checkAppletCall() throws Exception { + if (getBrowserVersion().isChrome()) { + return; + } + + final URL url = getClass().getResource("/applets/simpleAppletDoIt.html"); + + final WebClient webClient = getWebClient(); + final List<String> collectedStatus = new ArrayList<>(); + final StatusHandler statusHandler = new StatusHandler() { + @Override + public void statusMessageChanged(final Page page, final String message) { + collectedStatus.add(message); + } + }; + webClient.setStatusHandler(statusHandler); + webClient.getOptions().setAppletEnabled(true); + + final HtmlPage page = webClient.getPage(url); + + final HtmlTextInput input = page.getHtmlElementById("myInput"); + + HtmlButton button = page.getHtmlElementById("callWithoutParams"); + button.click(); + + assertEquals(2, collectedStatus.size()); + assertEquals("call: 'callSample'", collectedStatus.get(0)); + assertEquals(" 'done'", collectedStatus.get(1)); + assertEquals("undefined", input.asText()); + + button = page.getHtmlElementById("callWithStringParam"); + button.click(); + + assertEquals(4, collectedStatus.size()); + assertEquals("call: 'callSample'", collectedStatus.get(2)); + assertEquals("HtmlUnit", input.asText()); + } + + /** + * @throws Exception if the test fails + */ + @Test public void checkAppletExecJs() throws Exception { if (getBrowserVersion().isChrome()) { return; Modified: trunk/htmlunit/src/test/resources/applets/simpleAppletDoIt.html =================================================================== --- trunk/htmlunit/src/test/resources/applets/simpleAppletDoIt.html 2017-06-13 12:11:06 UTC (rev 14605) +++ trunk/htmlunit/src/test/resources/applets/simpleAppletDoIt.html 2017-06-14 17:35:49 UTC (rev 14606) @@ -7,6 +7,12 @@ var script = "document.getElementById('myInput').outerHTML"; applet.execJS(script); } + + function callSample(param) { + var input = document.getElementById('myInput'); + input.value = param; + return 'done'; + } </script> </head> <body> @@ -37,4 +43,7 @@ <button onclick="execJsOuterHtml()" id="execJsOuterHtml">execJsOuterHtml</button> <button onclick="document.applets[0].setValueAttribute('myInput', 'HtmlUnit')" id="setValueAttribute">setValueAttribute</button> +<button onclick="document.applets[0].callWithoutParams('callSample')" id="callWithoutParams">callWithoutParams</button> +<button onclick="document.applets[0].callWithStringParam('callSample')" id="callWithStringParam">callWithStringParam</button> + </body></html> Modified: trunk/htmlunit/src/test/resources/applets/simpleAppletDoIt.jar =================================================================== (Binary files differ) Modified: trunk/htmlunit/src/test/resources/objects/simpleAppletDoIt.jar =================================================================== (Binary files differ) |