29 import javafx.application.Platform; 30 import javafx.beans.value.ChangeListener; 31 import javafx.scene.Scene; 32 import javafx.scene.layout.VBox; 33 import javafx.stage.Stage; 34 import javafx.stage.WindowEvent; 35 import org.junit.AfterClass; 36 import org.junit.Assert; 37 import org.junit.BeforeClass; 38 import org.junit.Test; 39 40 import java.util.concurrent.CountDownLatch; 41 import java.util.concurrent.TimeUnit; 42 43 import static org.junit.Assert.fail; 44 import static org.junit.Assume.assumeTrue; 45 46 public class RestoreSceneSizeTest { 47 static CountDownLatch startupLatch; 48 static Stage stage; 49 static double w; 50 static double h; 51 52 public static void main(String[] args) throws Exception { 53 initFX(); 54 try { 55 RestoreSceneSizeTest test = new RestoreSceneSizeTest(); 56 test.testUnfullscreenSize(); 57 } catch (Throwable e) { 58 e.printStackTrace(); 59 } finally { 60 teardown(); 61 } 62 } 63 64 public static class TestApp extends Application { 65 66 @Override 67 public void start(Stage primaryStage) throws Exception { 68 primaryStage.setScene(new Scene(new VBox(), 234, 255)); 69 stage = primaryStage; 70 w = stage.getScene().getWidth(); 71 h = stage.getScene().getHeight(); 72 stage.setFullScreen(true); 73 stage.addEventHandler(WindowEvent.WINDOW_SHOWN, e -> 74 Platform.runLater(startupLatch::countDown)); 75 stage.show(); 76 } 77 } 78 79 @BeforeClass 80 public static void initFX() { 81 startupLatch = new CountDownLatch(1); 82 new Thread(() -> Application.launch(TestApp.class, (String[])null)).start(); 83 try { 84 if (!startupLatch.await(15, TimeUnit.SECONDS)) { 85 fail("Timeout waiting for FX runtime to start"); 86 } 87 } catch (InterruptedException ex) { 88 fail("Unexpected exception: " + ex); 89 } 90 } 91 92 @Test 93 public void testUnfullscreenSize() throws Exception { 94 assumeTrue(Boolean.getBoolean("unstable.test")); // JDK-8193185 95 // Disable on Mac until JDK-8176813 is fixed 96 assumeTrue(!PlatformUtil.isMac()); 97 98 Thread.sleep(200); 99 Assert.assertTrue(stage.isShowing()); 100 Assert.assertTrue(stage.isFullScreen()); 101 102 CountDownLatch latch = new CountDownLatch(2); 103 ChangeListener<Number> listenerW = (observable, oldValue, newValue) -> { 104 if (Math.abs((Double) newValue - w) < 0.1) { 105 latch.countDown(); 106 }; 107 }; 108 ChangeListener<Number> listenerH = (observable, oldValue, newValue) -> { 109 if (Math.abs((Double) newValue - h) < 0.1) { 110 latch.countDown(); 111 }; 112 }; 113 stage.getScene().widthProperty().addListener(listenerW); 114 stage.getScene().heightProperty().addListener(listenerH); 115 Platform.runLater(() -> stage.setFullScreen(false)); 116 latch.await(5, TimeUnit.SECONDS); 117 Thread.sleep(200); 118 Assert.assertFalse(stage.isFullScreen()); | 29 import javafx.application.Platform; 30 import javafx.beans.value.ChangeListener; 31 import javafx.scene.Scene; 32 import javafx.scene.layout.VBox; 33 import javafx.stage.Stage; 34 import javafx.stage.WindowEvent; 35 import org.junit.AfterClass; 36 import org.junit.Assert; 37 import org.junit.BeforeClass; 38 import org.junit.Test; 39 40 import java.util.concurrent.CountDownLatch; 41 import java.util.concurrent.TimeUnit; 42 43 import static org.junit.Assert.fail; 44 import static org.junit.Assume.assumeTrue; 45 46 public class RestoreSceneSizeTest { 47 static CountDownLatch startupLatch; 48 static Stage stage; 49 static double w, h; 50 51 private static final int WIDTH = 234; 52 private static final int HEIGHT = 255; 53 private static double scaleX, scaleY; 54 55 public static void main(String[] args) throws Exception { 56 initFX(); 57 try { 58 RestoreSceneSizeTest test = new RestoreSceneSizeTest(); 59 test.testUnfullscreenSize(); 60 } catch (Throwable e) { 61 e.printStackTrace(); 62 } finally { 63 teardown(); 64 } 65 } 66 67 public static class TestApp extends Application { 68 69 @Override 70 public void start(Stage primaryStage) throws Exception { 71 primaryStage.setScene(new Scene(new VBox(), WIDTH, HEIGHT)); 72 stage = primaryStage; 73 stage.setFullScreen(true); 74 stage.addEventHandler(WindowEvent.WINDOW_SHOWN, e -> { 75 scaleX = stage.getOutputScaleX​(); 76 scaleY = stage.getOutputScaleY(); 77 78 Platform.runLater(startupLatch::countDown); 79 }); 80 stage.show(); 81 } 82 } 83 84 @BeforeClass 85 public static void initFX() { 86 startupLatch = new CountDownLatch(1); 87 new Thread(() -> Application.launch(TestApp.class, (String[])null)).start(); 88 try { 89 if (!startupLatch.await(15, TimeUnit.SECONDS)) { 90 fail("Timeout waiting for FX runtime to start"); 91 } 92 } catch (InterruptedException ex) { 93 fail("Unexpected exception: " + ex); 94 } 95 } 96 97 @Test 98 public void testUnfullscreenSize() throws Exception { 99 // Disable on Mac until JDK-8176813 is fixed 100 assumeTrue(!PlatformUtil.isMac()); 101 102 Thread.sleep(200); 103 w = (Math.ceil(WIDTH * scaleX)) / scaleX; 104 h = (Math.ceil(HEIGHT * scaleY)) / scaleY; 105 Assert.assertTrue(stage.isShowing()); 106 Assert.assertTrue(stage.isFullScreen()); 107 108 CountDownLatch latch = new CountDownLatch(2); 109 ChangeListener<Number> listenerW = (observable, oldValue, newValue) -> { 110 if (Math.abs((Double) newValue - w) < 0.1) { 111 latch.countDown(); 112 }; 113 }; 114 ChangeListener<Number> listenerH = (observable, oldValue, newValue) -> { 115 if (Math.abs((Double) newValue - h) < 0.1) { 116 latch.countDown(); 117 }; 118 }; 119 stage.getScene().widthProperty().addListener(listenerW); 120 stage.getScene().heightProperty().addListener(listenerH); 121 Platform.runLater(() -> stage.setFullScreen(false)); 122 latch.await(5, TimeUnit.SECONDS); 123 Thread.sleep(200); 124 Assert.assertFalse(stage.isFullScreen()); |