--- old/tests/system/src/test/java/javafx/stage/ShowAndWaitTest.java 2015-05-15 12:02:33.447134600 -0700 +++ new/tests/system/src/test/java/javafx/stage/ShowAndWaitTest.java 2015-05-15 12:02:32.637133500 -0700 @@ -31,11 +31,17 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import javafx.animation.KeyFrame; +import javafx.animation.Timeline; import javafx.application.Application; import javafx.application.Platform; +import javafx.print.PrinterJob; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; +import javafx.scene.shape.Rectangle; +import javafx.util.Duration; import junit.framework.AssertionFailedError; import org.junit.After; import org.junit.AfterClass; @@ -647,4 +653,90 @@ } } + // Verify that showAndWait throws an exception if called from an + // animation timeline. + @Test + public void testTimeline() throws Throwable { + ensureTest1(); + + final AtomicBoolean animationDone = new AtomicBoolean(false); + final AtomicReference error = new AtomicReference<>(null); + + KeyFrame kf = new KeyFrame(Duration.millis(200), e -> { + try { + tmpStage1 = new TestStage(modality); + stages.add(tmpStage1); + assertFalse(tmpStage1.isPrimary()); + assertFalse(tmpStage1.isShowing()); + try { + tmpStage1.showAndWait(); + fail("Did not get expected exception from showAndWait"); + } catch (IllegalStateException ex) { + // Good + } + assertFalse(tmpStage1.isShowing()); + } catch (Throwable t) { + error.set(t); + } + animationDone.set(true); + }); + Timeline timeline = new Timeline(kf); + timeline.play(); + + Util.sleep(1000); + + if (error.get() != null) { + throw error.get(); + } + assertTrue(animationDone.get()); + assertFalse(tmpStage1.isShowing()); + } + + // Verify that printing throws an exception if called from an + // animation timeline. + @Test + public void testTimelinePrint() throws Throwable { + ensureTest1(); + + final AtomicBoolean animationDone = new AtomicBoolean(false); + final AtomicReference error = new AtomicReference<>(null); + + KeyFrame kf = new KeyFrame(Duration.millis(200), e -> { + try { + PrinterJob job = PrinterJob.createPrinterJob(); + try { + job.showPrintDialog(myApp.primaryStage); + fail("Did not get expected exception from showPrintDialog"); + } catch (IllegalStateException ex) { + // Good + } + try { + job.showPageSetupDialog(myApp.primaryStage); + fail("Did not get expected exception from showPageSetupDialog"); + } catch (IllegalStateException ex) { + // Good + } + try { + Rectangle rect = new Rectangle(200, 100, Color.GREEN); + job.printPage(rect); + fail("Did not get expected exception from printPage"); + } catch (IllegalStateException ex) { + // Good + } + } catch (Throwable t) { + error.set(t); + } + animationDone.set(true); + }); + Timeline timeline = new Timeline(kf); + timeline.play(); + + Util.sleep(1000); + + if (error.get() != null) { + throw error.get(); + } + assertTrue(animationDone.get()); + } + }