jaroslav@1189: /** jaroslav@1189: * HTML via Java(tm) Language Bindings jaroslav@1189: * Copyright (C) 2013 Jaroslav Tulach jaroslav@1189: * jaroslav@1189: * This program is free software: you can redistribute it and/or modify jaroslav@1189: * it under the terms of the GNU General Public License as published by jaroslav@1189: * the Free Software Foundation, version 2 of the License. jaroslav@1189: * jaroslav@1189: * This program is distributed in the hope that it will be useful, jaroslav@1189: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@1189: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@1189: * GNU General Public License for more details. apidesign.org jaroslav@1189: * designates this particular file as subject to the jaroslav@1189: * "Classpath" exception as provided by apidesign.org jaroslav@1189: * in the License file that accompanied this code. jaroslav@1189: * jaroslav@1189: * You should have received a copy of the GNU General Public License jaroslav@1189: * along with this program. Look for COPYING file in the top folder. jaroslav@1189: * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException jaroslav@1189: */ jaroslav@1189: package org.apidesign.html.ko2brwsr; jaroslav@1189: jaroslav@1189: import java.util.Map; jaroslav@1220: import net.java.html.BrwsrCtx; jaroslav@1189: import org.apidesign.bck2brwsr.core.JavaScriptBody; jaroslav@1189: import org.apidesign.bck2brwsr.vmtest.VMTest; jaroslav@1220: import org.apidesign.html.context.spi.Contexts; jaroslav@1220: import org.apidesign.html.json.spi.Technology; jaroslav@1220: import org.apidesign.html.json.spi.Transfer; jaroslav@1189: import org.apidesign.html.json.tck.KnockoutTCK; jaroslav@1189: import org.openide.util.lookup.ServiceProvider; jaroslav@1189: import org.testng.annotations.Factory; jaroslav@1189: jaroslav@1189: /** jaroslav@1189: * jaroslav@1189: * @author Jaroslav Tulach jaroslav@1189: */ jaroslav@1189: @ServiceProvider(service = KnockoutTCK.class) jaroslav@1189: public final class Bck2BrwsrKnockoutTest extends KnockoutTCK { jaroslav@1189: @Factory public static Object[] create() { jaroslav@1189: return VMTest.newTests(). jaroslav@1189: withClasses(testClasses()). jaroslav@1189: withLaunchers("bck2brwsr"). jaroslav@1189: build(); jaroslav@1189: } jaroslav@1189: jaroslav@1189: @Override jaroslav@1220: public BrwsrCtx createContext() { jaroslav@1220: return Contexts.newBuilder(). jaroslav@1220: register(Transfer.class, BrwsrCtxImpl.DEFAULT, 9). jaroslav@1220: register(Technology.class, BrwsrCtxImpl.DEFAULT, 9).build(); jaroslav@1189: } jaroslav@1189: jaroslav@1189: jaroslav@1189: jaroslav@1189: @Override jaroslav@1189: public Object createJSON(Map values) { jaroslav@1189: Object json = createJSON(); jaroslav@1189: jaroslav@1189: for (Map.Entry entry : values.entrySet()) { jaroslav@1189: putValue(json, entry.getKey(), entry.getValue()); jaroslav@1189: } jaroslav@1189: return json; jaroslav@1189: } jaroslav@1189: jaroslav@1189: @JavaScriptBody(args = {}, body = "return new Object();") jaroslav@1189: private static native Object createJSON(); jaroslav@1189: jaroslav@1189: @JavaScriptBody(args = { "json", "key", "value" }, body = "json[key] = value;") jaroslav@1189: private static native void putValue(Object json, String key, Object value); jaroslav@1189: jaroslav@1189: @Override jaroslav@1189: public Object executeScript(String script, Object[] arguments) { jaroslav@1189: return execScript(script, arguments); jaroslav@1189: } jaroslav@1189: jaroslav@1189: @JavaScriptBody(args = { "s", "args" }, body = jaroslav@1189: "var f = new Function(s); return f.apply(null, args);" jaroslav@1189: ) jaroslav@1189: private static native Object execScript(String s, Object[] arguments); jaroslav@1189: }