1.1 --- a/htmlpage/src/test/java/org/apidesign/bck2brwsr/htmlpage/ProcessPageTest.java Tue Oct 16 12:42:00 2012 +0200
1.2 +++ b/htmlpage/src/test/java/org/apidesign/bck2brwsr/htmlpage/ProcessPageTest.java Fri Nov 09 09:00:46 2012 +0100
1.3 @@ -81,6 +81,45 @@
1.4 }
1.5 assertEquals(ret, "You want this window to be named something", "We expect that the JavaCode performs all the wiring");
1.6 }
1.7 +
1.8 + @Test public void clickWithArgumentCalled() throws Exception {
1.9 + StringBuilder sb = new StringBuilder();
1.10 + sb.append(
1.11 + "var window = new Object();\n"
1.12 + + "var doc = new Object();\n"
1.13 + + "doc.button = new Object();\n"
1.14 + + "doc.title = new Object();\n"
1.15 + + "doc.title.innerHTML = 'nothing';\n"
1.16 + + "doc.text = new Object();\n"
1.17 + + "doc.text.value = 'something';\n"
1.18 + + "doc.getElementById = function(id) {\n"
1.19 + + " switch(id) {\n"
1.20 + + " case 'pg.button': return doc.button;\n"
1.21 + + " case 'pg.title': return doc.title;\n"
1.22 + + " case 'pg.text': return doc.text;\n"
1.23 + + " }\n"
1.24 + + " throw id;\n"
1.25 + + " }\n"
1.26 + + "\n"
1.27 + + "function clickAndCheck() {\n"
1.28 + + " doc.title.onclick();\n"
1.29 + + " return doc.title.innerHTML.toString();\n"
1.30 + + "};\n"
1.31 + + "\n"
1.32 + + "window.document = doc;\n"
1.33 + );
1.34 + Invocable i = compileClass(sb, "org/apidesign/bck2brwsr/htmlpage/PageController");
1.35 +
1.36 + Object ret = null;
1.37 + try {
1.38 + ret = i.invokeFunction("clickAndCheck");
1.39 + } catch (ScriptException ex) {
1.40 + fail("Execution failed in " + sb, ex);
1.41 + } catch (NoSuchMethodException ex) {
1.42 + fail("Cannot find method in " + sb, ex);
1.43 + }
1.44 + assertEquals(ret, "pg.title", "Title has been passed to the method argument");
1.45 + }
1.46
1.47 static Invocable compileClass(StringBuilder sb, String... names) throws ScriptException, IOException {
1.48 if (sb == null) {