boot-fx/src/test/java/net/java/html/boot/fx/FXBrowsersTest.java
changeset 1037 e390a06dbfac
parent 1016 665b10c62f3d
     1.1 --- a/boot-fx/src/test/java/net/java/html/boot/fx/FXBrowsersTest.java	Sun Nov 01 16:59:42 2015 +0100
     1.2 +++ b/boot-fx/src/test/java/net/java/html/boot/fx/FXBrowsersTest.java	Thu Dec 17 22:23:41 2015 +0100
     1.3 @@ -50,6 +50,7 @@
     1.4  import javafx.scene.layout.BorderPane;
     1.5  import javafx.scene.web.WebView;
     1.6  import javafx.stage.Stage;
     1.7 +import net.java.html.BrwsrCtx;
     1.8  import net.java.html.js.JavaScriptBody;
     1.9  import static org.testng.Assert.*;
    1.10  import org.testng.annotations.BeforeClass;
    1.11 @@ -82,6 +83,43 @@
    1.12          }.start();
    1.13          App.CDL.await();
    1.14      }
    1.15 +    
    1.16 +    @JavaScriptBody(args = {  }, body = "return true;")
    1.17 +    static boolean inJS() {
    1.18 +        return false;
    1.19 +    }
    1.20 +
    1.21 +    @Test
    1.22 +    public void brwsrCtxExecute() throws Throwable {
    1.23 +        assertFalse(inJS(), "We aren't in JS now");
    1.24 +        final CountDownLatch init = new CountDownLatch(1);
    1.25 +        final BrwsrCtx[] ctx = { null };
    1.26 +        FXBrowsers.runInBrowser(App.getV1(), new Runnable() {
    1.27 +            @Override
    1.28 +            public void run() {
    1.29 +                assertTrue(inJS(), "We are in JS context now");
    1.30 +                ctx[0] = BrwsrCtx.findDefault(FXBrowsersTest.class);
    1.31 +                init.countDown();
    1.32 +            }
    1.33 +        });
    1.34 +        init.await();
    1.35 +
    1.36 +        final CountDownLatch cdl = new CountDownLatch(1);
    1.37 +        class R implements Runnable {
    1.38 +            @Override
    1.39 +            public void run() {
    1.40 +                if (Platform.isFxApplicationThread()) {
    1.41 +                    assertTrue(inJS());
    1.42 +                    cdl.countDown();
    1.43 +                } else {
    1.44 +                    ctx[0].execute(this);
    1.45 +                }
    1.46 +            }
    1.47 +        }
    1.48 +        new Thread(new R(), "Background thread").start();
    1.49 +
    1.50 +        cdl.await();
    1.51 +    }
    1.52  
    1.53      @Test
    1.54      public void behaviorOfTwoWebViewsAtOnce() throws Throwable {