diff -r 8d29792a09c6 -r fd3a354d6e8f rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotationsTest.java --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotationsTest.java Thu Sep 12 14:15:47 2013 +0200 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotationsTest.java Sun Nov 09 10:36:08 2014 +0100 @@ -17,6 +17,7 @@ */ package org.apidesign.bck2brwsr.vmtest.impl; +import org.apidesign.bck2brwsr.core.JavaScriptBody; import org.apidesign.bck2brwsr.vmtest.BrwsrTest; import org.apidesign.bck2brwsr.vmtest.VMTest; import org.testng.annotations.Factory; @@ -26,29 +27,44 @@ * @author Jaroslav Tulach */ public class HtmlAnnotationsTest { + static int firstCheck; + + private void assertMulNotDefinedForTheFirstTime() { + if (firstCheck++ == 0) { + Object mul = windowMul(); + assert mul == null : "htmlannotations.js should not be processed before first call to HtmlAnnotations class"; + } + } + @BrwsrTest public void fourtyTwo() throws Exception { + assertMulNotDefinedForTheFirstTime(); assertEquals(HtmlAnnotations.fourtyTwo(), 42); } @BrwsrTest public void externalMul() throws Exception { + assertMulNotDefinedForTheFirstTime(); assertEquals(HtmlAnnotations.useExternalMul(7, 6), 42); } @BrwsrTest public void callRunnableFromJS() throws Exception { + assertMulNotDefinedForTheFirstTime(); assertEquals(HtmlAnnotations.callback(), 1); } @BrwsrTest public void callStaticMethodFromJS() throws Exception { + assertMulNotDefinedForTheFirstTime(); assertEquals(HtmlAnnotations.staticCallback(), 1); } @BrwsrTest public void callbackWithFourParamsAndReturnType() throws Exception { + assertMulNotDefinedForTheFirstTime(); Object instance = HtmlAnnotations.create(); assertNotNull(instance, "Instance created"); assertEquals(HtmlAnnotations.first(instance, 42, 31), 42); } @BrwsrTest public void callbackWithObjectParamsAndReturnType() throws Exception { + assertMulNotDefinedForTheFirstTime(); Object instance = HtmlAnnotations.create(); assertNotNull(instance, "Instance created"); assertEquals(HtmlAnnotations.onError(instance, 42.0), 42.0); @@ -65,6 +81,9 @@ assert obj != null : msg; } + @JavaScriptBody(args = {}, body = "return window.mul ? window.mul : null;") + private static native Object windowMul(); + @Factory public static Object[] create() { return VMTest.create(HtmlAnnotationsTest.class); }