< prev index next >

tests/system/src/test/java/sandbox/app/JFXPanelApp.java

Print this page
rev 9292 : 8139326: [TEST] Unit tests for JFXPanel with security manager don't detect errors

*** 26,35 **** --- 26,36 ---- package sandbox.app; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FlowLayout; + import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.scene.Scene; import javax.swing.JButton;
*** 45,54 **** --- 46,58 ---- * The main program in this class will run the test such that the application * will be shutdown by an explicit call to System.exit(). */ public class JFXPanelApp { + private final AtomicBoolean createSceneDone = new AtomicBoolean(false); + private final AtomicReference<Throwable> err = new AtomicReference<>(null); + private void initApp(final boolean implicitExit) throws Exception { final JFrame frame = new JFrame("JFXPanel Test"); frame.setLayout(new BorderLayout()); JPanel swingPanel = new JPanel();
*** 74,83 **** --- 78,104 ---- frame.pack(); frame.setVisible(true); // Hide the frame after the specified amount of time Timer timer = new Timer(SHOWTIME, e -> { + // Verify that the FX scene was created successfully + if (!createSceneDone.get()) { + System.exit(ERROR_TIMEOUT); + } + Throwable t = err.get(); + if (t != null) { + if (t instanceof SecurityException) { + System.exit(ERROR_SECURITY_EXCEPTION); + } else if (t instanceof ExceptionInInitializerError) { + Throwable cause = t.getCause(); + if (cause instanceof SecurityException) { + System.exit(ERROR_SECURITY_EXCEPTION); + } + } + System.exit(ERROR_UNEXPECTED_EXCEPTION); + } + if (implicitExit) { frame.setVisible(false); frame.dispose(); } else { System.exit(ERROR_NONE);
*** 86,110 **** timer.setRepeats(false); timer.start(); } private void createScene(final JFXPanel jfxPanel) throws Exception { - final AtomicReference<Throwable> err = new AtomicReference<>(null); Platform.runLater(() -> { try { final Scene scene = Util.createScene(); jfxPanel.setScene(scene); } catch (Error | Exception t) { err.set(t); } }); - Throwable t = err.get(); - if (t instanceof Error) { - throw (Error)t; - } else if (t instanceof Exception) { - throw (Exception)t; - } } public JFXPanelApp(boolean implicitExit) { try { try { --- 107,127 ---- timer.setRepeats(false); timer.start(); } private void createScene(final JFXPanel jfxPanel) throws Exception { Platform.runLater(() -> { try { final Scene scene = Util.createScene(); jfxPanel.setScene(scene); } catch (Error | Exception t) { + t.printStackTrace(); err.set(t); + } finally { + createSceneDone.set(true); } }); } public JFXPanelApp(boolean implicitExit) { try { try {
< prev index next >