1.1 --- a/rt/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/impl/Console.java Tue Apr 02 12:46:03 2013 +0200
1.2 +++ b/rt/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/impl/Console.java Tue Apr 02 15:52:25 2013 +0200
1.3 @@ -41,21 +41,73 @@
1.4 @JavaScriptBody(args = {"id", "attr"}, body =
1.5 "return window.document.getElementById(id)[attr].toString();")
1.6 private static native Object getAttr(String id, String attr);
1.7 + @JavaScriptBody(args = {"elem", "attr"}, body =
1.8 + "return elem[attr].toString();")
1.9 + private static native Object getAttr(Object elem, String attr);
1.10
1.11 @JavaScriptBody(args = {"id", "attr", "value"}, body =
1.12 "window.document.getElementById(id)[attr] = value;")
1.13 private static native void setAttr(String id, String attr, Object value);
1.14 + @JavaScriptBody(args = {"elem", "attr", "value"}, body =
1.15 + "elem[attr] = value;")
1.16 + private static native void setAttr(Object id, String attr, Object value);
1.17
1.18 @JavaScriptBody(args = {}, body = "return; window.close();")
1.19 private static native void closeWindow();
1.20
1.21 + private static Object textArea;
1.22 + private static Object statusArea;
1.23 +
1.24 private static void log(String newText) {
1.25 - String id = "bck2brwsr.result";
1.26 + if (textArea == null) {
1.27 + return;
1.28 + }
1.29 String attr = "value";
1.30 - setAttr(id, attr, getAttr(id, attr) + "\n" + newText);
1.31 - setAttr(id, "scrollTop", getAttr(id, "scrollHeight"));
1.32 + setAttr(textArea, attr, getAttr(textArea, attr) + "\n" + newText);
1.33 + setAttr(textArea, "scrollTop", getAttr(textArea, "scrollHeight"));
1.34 }
1.35
1.36 + private static void beginTest(Case c) {
1.37 + Object[] arr = new Object[2];
1.38 + beginTest(c.getClassName() + "." + c.getMethodName(), c, arr);
1.39 + textArea = arr[0];
1.40 + statusArea = arr[1];
1.41 + }
1.42 +
1.43 + private static void finishTest(Case c, Object res) {
1.44 + if ("null".equals(res)) {
1.45 + setAttr(statusArea, "innerHTML", "OK");
1.46 + setAttr(statusArea, "href", null);
1.47 + } else {
1.48 + setAttr(statusArea, "innerHTML", "run again");
1.49 + }
1.50 + statusArea = null;
1.51 + textArea = null;
1.52 + }
1.53 +
1.54 + @JavaScriptBody(args = { "test", "c", "arr" }, body =
1.55 + "var ul = window.document.getElementById('bck2brwsr.result');\n"
1.56 + + "var li = window.document.createElement('li');\n"
1.57 + + "var span = window.document.createElement('span');\n"
1.58 + + "span.innerHTML = test + ' - ';\n"
1.59 + + "var p = window.document.createElement('p');\n"
1.60 + + "var status = window.document.createElement('a');\n"
1.61 + + "status.innerHTML = 'running';"
1.62 + + "status.href = '#';\n"
1.63 + + "status.onclick = function() { c.again__V_3Ljava_lang_Object_2(arr); }\n"
1.64 + + "var pre = window.document.createElement('textarea');\n"
1.65 + + "pre.width = '90%';"
1.66 + + "pre.height = 100;"
1.67 + + "li.appendChild(span);\n"
1.68 + + "li.appendChild(status);\n"
1.69 + + "li.appendChild(p);\n"
1.70 + + "p.appendChild(pre);\n"
1.71 + + "ul.appendChild(li);\n"
1.72 + + "arr[0] = pre;\n"
1.73 + + "arr[1] = status;\n"
1.74 + )
1.75 + private static native void beginTest(String test, Case c, Object[] arr);
1.76 +
1.77 public static void execute() throws Exception {
1.78 String clazz = (String) getAttr("clazz", "value");
1.79 String method = (String) getAttr("method", "value");
1.80 @@ -109,19 +161,9 @@
1.81 }
1.82
1.83 Case c = Case.parseData(data);
1.84 - if (c.getHtmlFragment() != null) {
1.85 - setAttr("bck2brwsr.fragment", "innerHTML", c.getHtmlFragment());
1.86 - }
1.87 - log("Invoking " + c.getClassName() + '.' + c.getMethodName() + " as request: " + c.getRequestId());
1.88 -
1.89 - Object result = invokeMethod(c.getClassName(), c.getMethodName());
1.90 -
1.91 - setAttr("bck2brwsr.fragment", "innerHTML", "");
1.92 - log("Result: " + result);
1.93 -
1.94 - result = encodeURL("" + result);
1.95 -
1.96 - log("Sending back: " + url + "?request=" + c.getRequestId() + "&result=" + result);
1.97 + beginTest(c);
1.98 + Object result = c.runTest();
1.99 + finishTest(c, result);
1.100 String u = url + "?request=" + c.getRequestId() + "&result=" + result;
1.101
1.102 loadText(u, this, arr);
1.103 @@ -247,6 +289,30 @@
1.104 return value("html", data);
1.105 }
1.106
1.107 + void again(Object[] arr) {
1.108 + try {
1.109 + textArea = arr[0];
1.110 + statusArea = arr[1];
1.111 + setAttr(textArea, "value", "");
1.112 + runTest();
1.113 + } catch (Exception ex) {
1.114 + log(ex.getClass().getName() + ":" + ex.getMessage());
1.115 + }
1.116 + }
1.117 +
1.118 + private Object runTest() throws IllegalAccessException, IllegalArgumentException, ClassNotFoundException, UnsupportedEncodingException, InvocationTargetException, InstantiationException, SecurityException {
1.119 + if (this.getHtmlFragment() != null) {
1.120 + setAttr("bck2brwsr.fragment", "innerHTML", this.getHtmlFragment());
1.121 + }
1.122 + log("Invoking " + this.getClassName() + '.' + this.getMethodName() + " as request: " + this.getRequestId());
1.123 + Object result = invokeMethod(this.getClassName(), this.getMethodName());
1.124 + setAttr("bck2brwsr.fragment", "innerHTML", "");
1.125 + log("Result: " + result);
1.126 + result = encodeURL("" + result);
1.127 + log("Sending back: ...?request=" + this.getRequestId() + "&result=" + result);
1.128 + return result;
1.129 + }
1.130 +
1.131 @JavaScriptBody(args = "s", body = "return eval('(' + s + ')');")
1.132 private static native Object toJSON(String s);
1.133
2.1 --- a/rt/launcher/src/main/resources/org/apidesign/bck2brwsr/launcher/harness.xhtml Tue Apr 02 12:46:03 2013 +0200
2.2 +++ b/rt/launcher/src/main/resources/org/apidesign/bck2brwsr/launcher/harness.xhtml Tue Apr 02 15:52:25 2013 +0200
2.3 @@ -31,8 +31,8 @@
2.4
2.5 <h1>Bck2Brwsr Execution Harness</h1>
2.6
2.7 - <textarea id="bck2brwsr.result" rows="25" style="width: 100%;" disabled="">
2.8 - </textarea>
2.9 + <ul id="bck2brwsr.result" style="width: 100%;" >
2.10 + </ul>
2.11
2.12 <div id="bck2brwsr.fragment"/>
2.13