|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 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 | + |
| 26 | +package test.robot.javafx.scene; |
| 27 | + |
| 28 | +import javafx.animation.Animation; |
| 29 | +import javafx.animation.KeyFrame; |
| 30 | +import javafx.animation.Timeline; |
| 31 | +import javafx.application.Application; |
| 32 | +import javafx.application.Platform; |
| 33 | +import javafx.scene.Scene; |
| 34 | +import javafx.scene.control.TextField; |
| 35 | +import javafx.scene.layout.Pane; |
| 36 | +import javafx.stage.Stage; |
| 37 | +import javafx.util.Duration; |
| 38 | +import org.junit.jupiter.api.AfterAll; |
| 39 | +import org.junit.jupiter.api.BeforeAll; |
| 40 | +import org.junit.jupiter.api.Test; |
| 41 | +import test.util.Util; |
| 42 | + |
| 43 | +import java.util.concurrent.CountDownLatch; |
| 44 | +import java.util.concurrent.TimeUnit; |
| 45 | + |
| 46 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 47 | + |
| 48 | +public class SceneChangeShouldNotFocusStageTest { |
| 49 | + static Stage stage; |
| 50 | + static CountDownLatch startupLatch = new CountDownLatch(1); |
| 51 | + |
| 52 | + @Test |
| 53 | + void windowShouldRemainIconified() { |
| 54 | + Util.sleep(2000); |
| 55 | + assertTrue(stage.isIconified(), "Stage should be iconified"); |
| 56 | + } |
| 57 | + |
| 58 | + @BeforeAll |
| 59 | + public static void initFX() throws Exception { |
| 60 | + Util.launch(startupLatch, TestApp.class); |
| 61 | + } |
| 62 | + |
| 63 | + @AfterAll |
| 64 | + public static void exit() { |
| 65 | + Util.shutdown(stage); |
| 66 | + } |
| 67 | + |
| 68 | + public static class TestApp extends Application { |
| 69 | + @Override |
| 70 | + public void start(Stage primaryStage) { |
| 71 | + stage = primaryStage; |
| 72 | + Scene scene1 = new Scene(new Pane(new TextField("This is scene1")), 200, 200); |
| 73 | + Scene scene2 = new Scene(new Pane(new TextField("This is scene2")), 200, 200); |
| 74 | + |
| 75 | + Timeline tl = new Timeline(); |
| 76 | + tl.setCycleCount(Animation.INDEFINITE); |
| 77 | + tl.getKeyFrames().addAll(new KeyFrame(Duration.millis(200), e -> stage.setScene(scene1)), |
| 78 | + new KeyFrame(Duration.millis(400), e -> stage.setScene(scene2))); |
| 79 | + |
| 80 | + stage.setOnShown(e -> { |
| 81 | + tl.play(); |
| 82 | + startupLatch.countDown(); |
| 83 | + }); |
| 84 | + |
| 85 | + stage.setIconified(true); |
| 86 | + stage.show(); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + public static void waitForLatch(CountDownLatch latch, int seconds, String msg) throws Exception { |
| 91 | + assertTrue(latch.await(seconds, TimeUnit.SECONDS), "Timeout: " + msg); |
| 92 | + } |
| 93 | +} |
0 commit comments