diff -r 000000000000 -r 621825e167d7 ko/kosample/js/src/test/java/org/apidesign/bck2brwsr/kosample/js/JsInteractionTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ko/kosample/js/src/test/java/org/apidesign/bck2brwsr/kosample/js/JsInteractionTest.java Tue Apr 26 08:04:12 2016 +0200 @@ -0,0 +1,57 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012-2015 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.kosample.js; + +import java.io.Closeable; +import net.java.html.boot.script.Scripts; +import org.netbeans.html.boot.spi.Fn; +import static org.testng.Assert.assertEquals; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** Tests for behavior of @JavaScriptBody methods. Set your JavaScript + * environment up (for example define alert or use some + * emulation library like env.js), register script presenter + * and then you can call methods that deal with JavaScript in your tests. + */ +public class JsInteractionTest { + private Closeable jsEngine; + @BeforeMethod public void initializeJSEngine() throws Exception { + jsEngine = Fn.activate(Scripts.createPresenter()); + } + + @AfterMethod public void shutdownJSEngine() throws Exception { + jsEngine.close(); + } + @Test public void testCallbackFromJavaScript() throws Exception { + class R implements Runnable { + int called; + + @Override + public void run() { + called++; + } + } + R callback = new R(); + + Dialogs.confirmByUser("Hello", callback); + + assertEquals(callback.called, 1, "One immediate callback"); + } +}