ko/kosample/js/src/test/java/org/apidesign/bck2brwsr/kosample/js/JsInteractionTest.java
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.kosample.js;
20 import java.io.Closeable;
21 import net.java.html.boot.script.Scripts;
22 import org.netbeans.html.boot.spi.Fn;
23 import static org.testng.Assert.assertEquals;
24 import org.testng.annotations.AfterMethod;
25 import org.testng.annotations.BeforeMethod;
26 import org.testng.annotations.Test;
28 /** Tests for behavior of @JavaScriptBody methods. Set your JavaScript
29 * environment up (for example define <code>alert</code> or use some
30 * emulation library like <em>env.js</em>), register script presenter
31 * and then you can call methods that deal with JavaScript in your tests.
33 public class JsInteractionTest {
34 private Closeable jsEngine;
35 @BeforeMethod public void initializeJSEngine() throws Exception {
36 jsEngine = Fn.activate(Scripts.createPresenter());
39 @AfterMethod public void shutdownJSEngine() throws Exception {
42 @Test public void testCallbackFromJavaScript() throws Exception {
43 class R implements Runnable {
53 Dialogs.confirmByUser("Hello", callback);
55 assertEquals(callback.called, 1, "One immediate callback");