Using asynchronous XMLHttpRequest to let chrome browser repain when executing tests
1.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java Tue Jan 22 11:59:25 2013 +0100
1.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java Tue Jan 22 13:34:57 2013 +0100
1.3 @@ -65,18 +65,49 @@
1.4 Object res = invokeMethod(clazz, method);
1.5 setAttr("result", "value", res);
1.6 }
1.7 +
1.8 + @JavaScriptBody(args = { "url", "callback", "arr" }, body = ""
1.9 + + "var request = new XMLHttpRequest();\n"
1.10 + + "request.open('GET', url, true);\n"
1.11 + + "request.onreadystatechange = function() {\n"
1.12 + + " if (this.readyState!==4) return;\n"
1.13 + + " arr[0] = this.responseText;\n"
1.14 + + " callback.run__V();\n"
1.15 + + "};"
1.16 + + "request.send();"
1.17 + )
1.18 + private static native void loadText(String url, Runnable callback, String[] arr) throws IOException;
1.19
1.20 - public static void harness(String url) {
1.21 + public static void harness(String url) throws IOException {
1.22 log("Connecting to " + url);
1.23 - try {
1.24 - URL u = new URL(url);
1.25 - for (;;) {
1.26 - String data = (String) u.getContent(new Class[] { String.class });
1.27 + Request r = new Request(url);
1.28 + }
1.29 +
1.30 + private static class Request implements Runnable {
1.31 + private final String[] arr = { null };
1.32 + private final String url;
1.33 +
1.34 + private Request(String url) throws IOException {
1.35 + this.url = url;
1.36 + loadText(url, this, arr);
1.37 + }
1.38 +
1.39 + @Override
1.40 + public void run() {
1.41 + try {
1.42 + String data = arr[0];
1.43 log("\nGot \"" + data + "\"");
1.44 +
1.45 + if (data == null) {
1.46 + log("Some error exiting");
1.47 + closeWindow();
1.48 + return;
1.49 + }
1.50 +
1.51 if (data.isEmpty()) {
1.52 log("No data, exiting");
1.53 closeWindow();
1.54 - break;
1.55 + return;
1.56 }
1.57
1.58 Case c = Case.parseData(data);
1.59 @@ -89,12 +120,13 @@
1.60 result = encodeURL("" + result);
1.61
1.62 log("Sending back: " + url + "?request=" + c.getRequestId() + "&result=" + result);
1.63 - u = new URL(url + "?request=" + c.getRequestId() + "&result=" + result);
1.64 + String u = url + "?request=" + c.getRequestId() + "&result=" + result;
1.65 +
1.66 + loadText(u, this, arr);
1.67 +
1.68 + } catch (Exception ex) {
1.69 + log(ex.getMessage());
1.70 }
1.71 -
1.72 -
1.73 - } catch (Exception ex) {
1.74 - log(ex.getMessage());
1.75 }
1.76 }
1.77