rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotationsTest.java
1.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotationsTest.java Thu Sep 12 14:15:47 2013 +0200
1.2 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotationsTest.java Sun Nov 09 10:36:08 2014 +0100
1.3 @@ -17,6 +17,7 @@
1.4 */
1.5 package org.apidesign.bck2brwsr.vmtest.impl;
1.6
1.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
1.8 import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
1.9 import org.apidesign.bck2brwsr.vmtest.VMTest;
1.10 import org.testng.annotations.Factory;
1.11 @@ -26,29 +27,44 @@
1.12 * @author Jaroslav Tulach <jtulach@netbeans.org>
1.13 */
1.14 public class HtmlAnnotationsTest {
1.15 + static int firstCheck;
1.16 +
1.17 + private void assertMulNotDefinedForTheFirstTime() {
1.18 + if (firstCheck++ == 0) {
1.19 + Object mul = windowMul();
1.20 + assert mul == null : "htmlannotations.js should not be processed before first call to HtmlAnnotations class";
1.21 + }
1.22 + }
1.23 +
1.24 @BrwsrTest public void fourtyTwo() throws Exception {
1.25 + assertMulNotDefinedForTheFirstTime();
1.26 assertEquals(HtmlAnnotations.fourtyTwo(), 42);
1.27 }
1.28
1.29 @BrwsrTest public void externalMul() throws Exception {
1.30 + assertMulNotDefinedForTheFirstTime();
1.31 assertEquals(HtmlAnnotations.useExternalMul(7, 6), 42);
1.32 }
1.33
1.34 @BrwsrTest public void callRunnableFromJS() throws Exception {
1.35 + assertMulNotDefinedForTheFirstTime();
1.36 assertEquals(HtmlAnnotations.callback(), 1);
1.37 }
1.38
1.39 @BrwsrTest public void callStaticMethodFromJS() throws Exception {
1.40 + assertMulNotDefinedForTheFirstTime();
1.41 assertEquals(HtmlAnnotations.staticCallback(), 1);
1.42 }
1.43
1.44 @BrwsrTest public void callbackWithFourParamsAndReturnType() throws Exception {
1.45 + assertMulNotDefinedForTheFirstTime();
1.46 Object instance = HtmlAnnotations.create();
1.47 assertNotNull(instance, "Instance created");
1.48 assertEquals(HtmlAnnotations.first(instance, 42, 31), 42);
1.49 }
1.50
1.51 @BrwsrTest public void callbackWithObjectParamsAndReturnType() throws Exception {
1.52 + assertMulNotDefinedForTheFirstTime();
1.53 Object instance = HtmlAnnotations.create();
1.54 assertNotNull(instance, "Instance created");
1.55 assertEquals(HtmlAnnotations.onError(instance, 42.0), 42.0);
1.56 @@ -65,6 +81,9 @@
1.57 assert obj != null : msg;
1.58 }
1.59
1.60 + @JavaScriptBody(args = {}, body = "return window.mul ? window.mul : null;")
1.61 + private static native Object windowMul();
1.62 +
1.63 @Factory public static Object[] create() {
1.64 return VMTest.create(HtmlAnnotationsTest.class);
1.65 }