< prev index next >

tests/system/src/test/java/test/javafx/scene/NewSceneSizeTest.java

Print this page

        

@@ -39,15 +39,16 @@
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
 
 public class NewSceneSizeTest {
     static CountDownLatch startupLatch;
-    static volatile Stage stage;
+    static volatile Stage primaryStage;
+
+    private static double scaleX, scaleY;
 
     public static void main(String[] args) throws Exception {
         initFX();
         try {
             NewSceneSizeTest test = new NewSceneSizeTest();

@@ -60,16 +61,20 @@
     }
 
     public static class TestApp extends Application {
 
         @Override
-        public void start(Stage primaryStage) throws Exception {
-            primaryStage.setScene(new Scene(new VBox()));
-            stage = primaryStage;
-            stage.addEventHandler(WindowEvent.WINDOW_SHOWN, e ->
-                    Platform.runLater(startupLatch::countDown));
-            stage.show();
+        public void start(Stage stage) throws Exception {
+            stage.setScene(new Scene(new VBox()));
+            primaryStage = stage;
+            primaryStage.addEventHandler(WindowEvent.WINDOW_SHOWN, e -> {
+                scaleX = primaryStage.getOutputScaleX​();
+                scaleY = primaryStage.getOutputScaleY();
+
+                Platform.runLater(startupLatch::countDown);
+            });
+            primaryStage.show();
         }
     }
 
     @BeforeClass
     public static void initFX() {

@@ -84,11 +89,10 @@
         }
     }
 
     @Test
     public void testNewSceneSize() throws Exception {
-        assumeTrue(Boolean.getBoolean("unstable.test")); // JDK-8193185
         Thread.sleep(200);
         final int nTries = 100;
         Stage childStage[] = new Stage[nTries];
         double w[] = new double[nTries];
         double h[] = new double[nTries];

@@ -104,12 +108,14 @@
                     Stage stage = new Stage();
                     childStage[fI] = stage;
                     stage.setResizable(fI % 2 == 0);
                     Scene scene = new Scene(new VBox(), 300 - fI, 200 - fI);
                     stage.setScene(scene);
-                    w[fI] = stage.getScene().getWidth();
-                    h[fI] = stage.getScene().getHeight();
+                    w[fI] = (Math.ceil((300 - fI) * scaleX))
+                            / scaleX;
+                    h[fI] = (Math.ceil((200 - fI) * scaleY))
+                            / scaleY;
                     Assert.assertTrue(w[fI] > 1);
                     Assert.assertTrue(h[fI] > 1);
                     stage.widthProperty().addListener(listenerW = (v, o, n) -> {
                         if (Math.abs((Double) n - w[fI]) < 0.1) {
                             stage.widthProperty().removeListener(listenerW);

@@ -128,17 +134,17 @@
         }
         latch.await(5, TimeUnit.SECONDS);
         Thread.sleep(200);
         for (int i = 0; i < nTries; i++) {
             Assert.assertEquals("Wrong scene " + i + " width", w[i],
-                                           childStage[i].getScene().getWidth());
+                                    childStage[i].getScene().getWidth(), 0.1);
             Assert.assertEquals("Wrong scene " + i + " height", h[i],
-                                          childStage[i].getScene().getHeight());
+                                    childStage[i].getScene().getHeight(), 0.1);
         }
     }
 
     @AfterClass
     public static void teardown() {
-        Platform.runLater(stage::hide);
+        Platform.runLater(primaryStage::hide);
         Platform.exit();
     }
 }
< prev index next >