jaroslav@1018
|
1 |
/**
|
jaroslav@1018
|
2 |
* Back 2 Browser Bytecode Translator
|
jaroslav@1018
|
3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@1018
|
4 |
*
|
jaroslav@1018
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@1018
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@1018
|
7 |
* the Free Software Foundation, version 2 of the License.
|
jaroslav@1018
|
8 |
*
|
jaroslav@1018
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@1018
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@1018
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@1018
|
12 |
* GNU General Public License for more details.
|
jaroslav@1018
|
13 |
*
|
jaroslav@1018
|
14 |
* You should have received a copy of the GNU General Public License
|
jaroslav@1018
|
15 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@1018
|
16 |
* If not, see http://opensource.org/licenses/GPL-2.0.
|
jaroslav@1018
|
17 |
*/
|
jaroslav@1018
|
18 |
package org.apidesign.bck2brwsr.htmlpage;
|
jaroslav@1018
|
19 |
|
jaroslav@1018
|
20 |
import java.util.Map;
|
jaroslav@1018
|
21 |
import net.java.html.json.Context;
|
jaroslav@1018
|
22 |
import org.apidesign.bck2brwsr.core.JavaScriptBody;
|
jaroslav@1018
|
23 |
import org.apidesign.bck2brwsr.vmtest.VMTest;
|
jaroslav@1018
|
24 |
import org.apidesign.html.json.tck.KnockoutTCK;
|
jaroslav@1018
|
25 |
import org.openide.util.lookup.ServiceProvider;
|
jaroslav@1018
|
26 |
import org.testng.annotations.Factory;
|
jaroslav@1018
|
27 |
|
jaroslav@1018
|
28 |
/**
|
jaroslav@1018
|
29 |
*
|
jaroslav@1018
|
30 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@1018
|
31 |
*/
|
jaroslav@1018
|
32 |
@ServiceProvider(service = KnockoutTCK.class)
|
jaroslav@1018
|
33 |
public final class Bck2BrwsrKnockoutTest extends KnockoutTCK {
|
jaroslav@1018
|
34 |
@Factory public static Object[] create() {
|
jaroslav@1054
|
35 |
return VMTest.newTests().
|
jaroslav@1054
|
36 |
withClasses(testClasses()).
|
jaroslav@1054
|
37 |
withLaunchers("bck2brwsr").
|
jaroslav@1054
|
38 |
build();
|
jaroslav@1018
|
39 |
}
|
jaroslav@1018
|
40 |
|
jaroslav@1018
|
41 |
@Override
|
jaroslav@1018
|
42 |
public Context createContext() {
|
jaroslav@1018
|
43 |
return BrwsrCntxt.DEFAULT;
|
jaroslav@1018
|
44 |
}
|
jaroslav@1018
|
45 |
|
jaroslav@1018
|
46 |
|
jaroslav@1018
|
47 |
|
jaroslav@1018
|
48 |
@Override
|
jaroslav@1018
|
49 |
public Object createJSON(Map<String, Object> values) {
|
jaroslav@1018
|
50 |
Object json = createJSON();
|
jaroslav@1018
|
51 |
|
jaroslav@1018
|
52 |
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
jaroslav@1018
|
53 |
putValue(json, entry.getKey(), entry.getValue());
|
jaroslav@1018
|
54 |
}
|
jaroslav@1018
|
55 |
return json;
|
jaroslav@1018
|
56 |
}
|
jaroslav@1018
|
57 |
|
jaroslav@1018
|
58 |
@JavaScriptBody(args = {}, body = "return new Object();")
|
jaroslav@1018
|
59 |
private static native Object createJSON();
|
jaroslav@1018
|
60 |
|
jaroslav@1018
|
61 |
@JavaScriptBody(args = { "json", "key", "value" }, body = "json[key] = value;")
|
jaroslav@1018
|
62 |
private static native void putValue(Object json, String key, Object value);
|
jaroslav@1019
|
63 |
|
jaroslav@1019
|
64 |
@Override
|
jaroslav@1019
|
65 |
public Object executeScript(String script, Object[] arguments) {
|
jaroslav@1019
|
66 |
return execScript(script, arguments);
|
jaroslav@1019
|
67 |
}
|
jaroslav@1019
|
68 |
|
jaroslav@1019
|
69 |
@JavaScriptBody(args = { "s", "args" }, body =
|
jaroslav@1019
|
70 |
"var f = new Function(s); return f.apply(null, args);"
|
jaroslav@1019
|
71 |
)
|
jaroslav@1019
|
72 |
private static native Object execScript(String s, Object[] arguments);
|
jaroslav@1018
|
73 |
}
|