< prev index next >

tests/system/src/test/java/test/javafx/stage/RestoreStagePositionTest.java

Print this page
rev 10376 : 8176818: Disable failing full-screen and maximize tests on Mac
Reviewed-by:


   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package test.javafx.stage;
  26 

  27 import javafx.application.Application;
  28 import javafx.application.Platform;
  29 import javafx.beans.value.ChangeListener;
  30 import javafx.scene.Scene;
  31 import javafx.scene.layout.VBox;
  32 import javafx.stage.Stage;
  33 import javafx.stage.WindowEvent;
  34 import org.junit.AfterClass;
  35 import org.junit.Assert;
  36 import org.junit.BeforeClass;
  37 import org.junit.Test;
  38 
  39 import java.util.concurrent.CountDownLatch;
  40 import java.util.concurrent.TimeUnit;
  41 
  42 import static org.junit.Assert.fail;

  43 
  44 public class RestoreStagePositionTest {
  45     static CountDownLatch startupLatch;
  46     static Stage stage;
  47 
  48     public static void main(String[] args) throws Exception {
  49         initFX();
  50         try {
  51             RestoreStagePositionTest test = new RestoreStagePositionTest();
  52             test.testUfullscreenPosition();
  53             test.testDemaximizedPosition();
  54         } catch (Throwable e) {
  55             e.printStackTrace();
  56         } finally {
  57             teardown();
  58         }
  59     }
  60 
  61     public static class TestApp extends Application {
  62 


  71             stage.show();
  72         }
  73     }
  74 
  75     @BeforeClass
  76     public static void initFX() {
  77         startupLatch = new CountDownLatch(1);
  78         new Thread(() -> Application.launch(TestApp.class, (String[])null)).start();
  79         try {
  80             if (!startupLatch.await(15, TimeUnit.SECONDS)) {
  81                 fail("Timeout waiting for FX runtime to start");
  82             }
  83         } catch (InterruptedException ex) {
  84             fail("Unexpected exception: " + ex);
  85         }
  86     }
  87 
  88 
  89     @Test
  90     public void testUfullscreenPosition() throws Exception {



  91         Thread.sleep(200);
  92         Assert.assertTrue(stage.isShowing());
  93         Assert.assertFalse(stage.isFullScreen());
  94 
  95         double x = stage.getX();
  96         double y = stage.getY();
  97 
  98         Platform.runLater(() -> stage.setFullScreen(true));
  99         Thread.sleep(400);
 100         Assert.assertTrue(stage.isFullScreen());
 101         CountDownLatch latch = new CountDownLatch(2);
 102 
 103         ChangeListener<Number> listenerX = (observable, oldValue, newValue) -> {
 104             if (Math.abs((Double) newValue - x) < 0.1) {
 105                 latch.countDown();
 106             };
 107         };
 108         ChangeListener<Number> listenerY = (observable, oldValue, newValue) -> {
 109             if (Math.abs((Double) newValue - y) < 0.1) {
 110                 latch.countDown();
 111             };
 112         };
 113         stage.xProperty().addListener(listenerX);
 114         stage.yProperty().addListener(listenerY);
 115         Platform.runLater(() -> stage.setFullScreen(false));
 116         latch.await(5, TimeUnit.SECONDS);
 117         stage.xProperty().removeListener(listenerX);
 118         stage.xProperty().removeListener(listenerY);
 119 
 120         Assert.assertEquals("Window was moved", x, stage.getX(), 0.1);
 121         Assert.assertEquals("Window was moved", y, stage.getY(), 0.1);
 122     }
 123 
 124     @Test
 125     public void testDemaximizedPosition() throws Exception {



 126         Thread.sleep(200);
 127         Assert.assertTrue(stage.isShowing());
 128         Assert.assertFalse(stage.isMaximized());
 129 
 130         double x = stage.getX();
 131         double y = stage.getY();
 132 
 133         Platform.runLater(() -> stage.setMaximized(true));
 134         Thread.sleep(200);
 135         Assert.assertTrue(stage.isMaximized());
 136         CountDownLatch latch = new CountDownLatch(2);
 137 
 138         ChangeListener<Number> listenerX = (observable, oldValue, newValue) -> {
 139             if (Math.abs((Double) newValue - x) < 0.1) {
 140                 latch.countDown();
 141             };
 142         };
 143         ChangeListener<Number> listenerY = (observable, oldValue, newValue) -> {
 144             if (Math.abs((Double) newValue - y) < 0.1) {
 145                 latch.countDown();


   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package test.javafx.stage;
  26 
  27 import com.sun.javafx.PlatformUtil;
  28 import javafx.application.Application;
  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 RestoreStagePositionTest {
  47     static CountDownLatch startupLatch;
  48     static Stage stage;
  49 
  50     public static void main(String[] args) throws Exception {
  51         initFX();
  52         try {
  53             RestoreStagePositionTest test = new RestoreStagePositionTest();
  54             test.testUfullscreenPosition();
  55             test.testDemaximizedPosition();
  56         } catch (Throwable e) {
  57             e.printStackTrace();
  58         } finally {
  59             teardown();
  60         }
  61     }
  62 
  63     public static class TestApp extends Application {
  64 


  73             stage.show();
  74         }
  75     }
  76 
  77     @BeforeClass
  78     public static void initFX() {
  79         startupLatch = new CountDownLatch(1);
  80         new Thread(() -> Application.launch(TestApp.class, (String[])null)).start();
  81         try {
  82             if (!startupLatch.await(15, TimeUnit.SECONDS)) {
  83                 fail("Timeout waiting for FX runtime to start");
  84             }
  85         } catch (InterruptedException ex) {
  86             fail("Unexpected exception: " + ex);
  87         }
  88     }
  89 
  90 
  91     @Test
  92     public void testUfullscreenPosition() throws Exception {
  93         // Disable on Mac until JDK-8176813 is fixed
  94         assumeTrue(!PlatformUtil.isMac());
  95 
  96         Thread.sleep(200);
  97         Assert.assertTrue(stage.isShowing());
  98         Assert.assertFalse(stage.isFullScreen());
  99 
 100         double x = stage.getX();
 101         double y = stage.getY();
 102 
 103         Platform.runLater(() -> stage.setFullScreen(true));
 104         Thread.sleep(400);
 105         Assert.assertTrue(stage.isFullScreen());
 106         CountDownLatch latch = new CountDownLatch(2);
 107 
 108         ChangeListener<Number> listenerX = (observable, oldValue, newValue) -> {
 109             if (Math.abs((Double) newValue - x) < 0.1) {
 110                 latch.countDown();
 111             };
 112         };
 113         ChangeListener<Number> listenerY = (observable, oldValue, newValue) -> {
 114             if (Math.abs((Double) newValue - y) < 0.1) {
 115                 latch.countDown();
 116             };
 117         };
 118         stage.xProperty().addListener(listenerX);
 119         stage.yProperty().addListener(listenerY);
 120         Platform.runLater(() -> stage.setFullScreen(false));
 121         latch.await(5, TimeUnit.SECONDS);
 122         stage.xProperty().removeListener(listenerX);
 123         stage.xProperty().removeListener(listenerY);
 124 
 125         Assert.assertEquals("Window was moved", x, stage.getX(), 0.1);
 126         Assert.assertEquals("Window was moved", y, stage.getY(), 0.1);
 127     }
 128 
 129     @Test
 130     public void testDemaximizedPosition() throws Exception {
 131         // Disable on Mac until JDK-8089230 is fixed
 132         assumeTrue(!PlatformUtil.isMac());
 133 
 134         Thread.sleep(200);
 135         Assert.assertTrue(stage.isShowing());
 136         Assert.assertFalse(stage.isMaximized());
 137 
 138         double x = stage.getX();
 139         double y = stage.getY();
 140 
 141         Platform.runLater(() -> stage.setMaximized(true));
 142         Thread.sleep(200);
 143         Assert.assertTrue(stage.isMaximized());
 144         CountDownLatch latch = new CountDownLatch(2);
 145 
 146         ChangeListener<Number> listenerX = (observable, oldValue, newValue) -> {
 147             if (Math.abs((Double) newValue - x) < 0.1) {
 148                 latch.countDown();
 149             };
 150         };
 151         ChangeListener<Number> listenerY = (observable, oldValue, newValue) -> {
 152             if (Math.abs((Double) newValue - y) < 0.1) {
 153                 latch.countDown();
< prev index next >