1 /*
   2  * Copyright (c) 2014, 2016, 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.com.sun.glass.ui.monocle;
  27 
  28 import com.sun.glass.ui.monocle.TestLogShim;
  29 import test.robot.com.sun.glass.ui.monocle.TestApplication;
  30 import javafx.application.Platform;
  31 import javafx.scene.Group;
  32 import javafx.scene.Scene;
  33 import javafx.scene.input.MouseButton;
  34 import javafx.scene.robot.Robot;
  35 import javafx.stage.Modality;
  36 import javafx.stage.Stage;
  37 import junit.framework.AssertionFailedError;
  38 import org.junit.*;
  39 import org.junit.rules.TestName;
  40 
  41 
  42 public class ModalDialogTest {
  43 
  44     @Rule
  45     public TestName name = new TestName();
  46 
  47     @Before
  48     public void setUpScreen() throws Exception {
  49         TestLogShim.reset();
  50         TestLogShim.log(name.getMethodName());
  51         TestApplication.showFullScreenScene();
  52     }
  53 
  54     @Test
  55     public void test1() throws Exception {
  56         Stage rootStage = TestApplication.getStage();
  57         rootStage.getScene().setOnMouseClicked(
  58                 (e) -> TestLogShim.format("Clicked at %.0f, %.0f",
  59                         e.getScreenX(), e.getScreenY()));
  60         Platform.runLater(() -> {
  61             final Stage p = new Stage();
  62             p.initOwner(rootStage);
  63             p.initModality(Modality.APPLICATION_MODAL);
  64             p.setX(0);
  65             p.setY(0);
  66             p.setWidth(200);
  67             p.setHeight(200);
  68             p.setScene(new Scene(new Group()));
  69             p.getScene().setOnMouseClicked(
  70                     (e) -> TestLogShim.format("Clicked at %.0f, %.0f",
  71                             e.getScreenX(), e.getScreenY()));
  72             p.show();
  73         });
  74         TestLogShim.clear();
  75         Platform.runLater(() -> {
  76             Robot robot = new Robot();
  77             robot.mouseMove(300, 400);
  78             robot.mousePress(MouseButton.PRIMARY);
  79             robot.mouseRelease(MouseButton.PRIMARY);
  80             robot.mouseMove(100, 100);
  81             robot.mousePress(MouseButton.PRIMARY);
  82             robot.mouseRelease(MouseButton.PRIMARY);
  83         });
  84         TestLogShim.waitForLog("Clicked at 100, 100");
  85         if (TestLogShim.countLog("Clicked at 300, 400") != 0) {
  86             throw new AssertionFailedError("Disabled window should not receive mouse events!");
  87         }
  88     }
  89 }
  90