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