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