Using HTTP protocol rather than reflection tricks as HTTP will work on all known implementations
1.1 --- a/ko-bck2brwsr/src/test/java/org/apidesign/html/ko2brwsr/Bck2BrwsrKnockoutTest.java Wed May 29 19:36:31 2013 +0200
1.2 +++ b/ko-bck2brwsr/src/test/java/org/apidesign/html/ko2brwsr/Bck2BrwsrKnockoutTest.java Mon Jun 24 14:19:09 2013 +0200
1.3 @@ -20,6 +20,13 @@
1.4 */
1.5 package org.apidesign.html.ko2brwsr;
1.6
1.7 +import java.io.BufferedReader;
1.8 +import java.io.IOException;
1.9 +import java.io.InputStreamReader;
1.10 +import java.net.URI;
1.11 +import java.net.URISyntaxException;
1.12 +import java.net.URL;
1.13 +import java.net.URLConnection;
1.14 import java.util.Map;
1.15 import net.java.html.BrwsrCtx;
1.16 import org.apidesign.bck2brwsr.core.JavaScriptBody;
1.17 @@ -27,6 +34,7 @@
1.18 import org.apidesign.html.context.spi.Contexts;
1.19 import org.apidesign.html.json.spi.Technology;
1.20 import org.apidesign.html.json.spi.Transfer;
1.21 +import org.apidesign.html.json.tck.KOTest;
1.22 import org.apidesign.html.json.tck.KnockoutTCK;
1.23 import org.openide.util.lookup.ServiceProvider;
1.24 import org.testng.annotations.Factory;
1.25 @@ -41,6 +49,7 @@
1.26 return VMTest.newTests().
1.27 withClasses(testClasses()).
1.28 withLaunchers("bck2brwsr").
1.29 + withTestAnnotation(KOTest.class).
1.30 build();
1.31 }
1.32
1.33 @@ -78,4 +87,38 @@
1.34 "var f = new Function(s); return f.apply(null, args);"
1.35 )
1.36 private static native Object execScript(String s, Object[] arguments);
1.37 +
1.38 + @JavaScriptBody(args = { }, body =
1.39 + "var h;"
1.40 + + "if (!!window && !!window.location && !!window.location.href)\n"
1.41 + + " h = window.location.href;\n"
1.42 + + "else "
1.43 + + " h = null;"
1.44 + + "return h;\n"
1.45 + )
1.46 + private static native String findBaseURL();
1.47 +
1.48 + @Override
1.49 + public URI prepareURL(String content, String mimeType, String[] parameters) {
1.50 + try {
1.51 + final URL baseURL = new URL(findBaseURL());
1.52 + StringBuilder sb = new StringBuilder();
1.53 + sb.append("/dynamic?mimeType=").append(mimeType);
1.54 + for (int i = 0; i < parameters.length; i++) {
1.55 + sb.append("¶m" + i).append("=").append(parameters[i]);
1.56 + }
1.57 + String mangle = content.replace("\n", "%0a")
1.58 + .replace("\"", "\\\"").replace(" ", "%20");
1.59 + sb.append("&content=").append(mangle);
1.60 +
1.61 + URL query = new URL(baseURL, sb.toString());
1.62 + String uri = (String) query.getContent(new Class[] { String.class });
1.63 + URI connectTo = new URI(uri.trim());
1.64 + return connectTo;
1.65 + } catch (IOException ex) {
1.66 + throw new IllegalStateException(ex);
1.67 + } catch (URISyntaxException ex) {
1.68 + throw new IllegalStateException(ex);
1.69 + }
1.70 + }
1.71 }