This repository has been archived by the owner on Jun 24, 2021. It is now read-only.
JDK-8193502: Dialog height switches between correct and too small when showing and hiding one dialog repeatedly on Linux #456
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5f04502
Fix JDK-8193502 - Dialog height switches between correct and too smal…
e2f41e2
Add space after if
3614c6f
Add test
tsayao 176a0f0
Review adjustments
tsayao 2c3162c
Cleaning
tsayao 4848a27
Rename test case
ecaee4c
Fix whitespace issue
tsayao 32a6ba6
Fix JDK-8197536: TableView, ListView: unexpected scrolling behaviour …
tsayao 8a01f74
Revert "Fix JDK-8197536: TableView, ListView: unexpected scrolling be…
tsayao 5511915
Remove package prefix from assert call
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
tests/system/src/test/java/test/robot/javafx/scene/dialog/JDK8193502Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/* | ||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package test.robot.javafx.scene.dialog; | ||
tsayao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import javafx.application.Application; | ||
import javafx.application.Platform; | ||
import javafx.scene.Scene; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.control.ButtonType; | ||
import javafx.scene.control.Dialog; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.robot.Robot; | ||
import javafx.stage.Stage; | ||
import javafx.stage.StageStyle; | ||
import javafx.stage.WindowEvent; | ||
import javafx.scene.input.MouseButton; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import test.util.Util; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class JDK8193502Test { | ||
tsayao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
static final double DIALOG_WIDTH = 300.0d; | ||
static final double DIALOG_HEIGHT = DIALOG_WIDTH; | ||
static Robot robot; | ||
static Button button; | ||
static Stage stage; | ||
static Scene scene; | ||
static Dialog<Void> dialog; | ||
static CountDownLatch startupLatch = new CountDownLatch(1); | ||
static CountDownLatch dialogShownLatch; | ||
static CountDownLatch dialogHideLatch; | ||
|
||
@Test(timeout = 15000) | ||
public void dialogSizeOnReShownTest() throws Exception { | ||
Thread.sleep(400); | ||
clickButton(); | ||
hide(); | ||
clickButton(); | ||
Assert.assertEquals("Dialog width should remain the same", DIALOG_WIDTH, dialog.getDialogPane().getWidth(), | ||
0.0); | ||
Assert.assertEquals("Dialog height should remain the same", DIALOG_HEIGHT, dialog.getDialogPane().getHeight(), | ||
0.0); | ||
hide(); | ||
} | ||
|
||
private void clickButton() throws Exception { | ||
dialogShownLatch = new CountDownLatch(1); | ||
mouseClick(button.getLayoutX() + button.getWidth() / 2, button.getLayoutY() + button.getHeight() / 2); | ||
|
||
Thread.sleep(400); | ||
waitForLatch(dialogShownLatch, 10, "Failed to show Dialog"); | ||
} | ||
|
||
private void hide() throws Exception { | ||
dialogHideLatch = new CountDownLatch(1); | ||
Platform.runLater(() -> dialog.close()); | ||
Thread.sleep(600); | ||
waitForLatch(dialogHideLatch, 10, "Failed to hide Dialog"); | ||
} | ||
|
||
@BeforeClass | ||
public static void initFX() throws Exception { | ||
new Thread(() -> Application.launch(TestApp.class, (String[]) null)).start(); | ||
waitForLatch(startupLatch, 10, "FX runtime failed to start."); | ||
} | ||
|
||
@AfterClass | ||
public static void exit() { | ||
Platform.runLater(() -> stage.hide()); | ||
Platform.exit(); | ||
} | ||
|
||
private void mouseClick(double x, double y) { | ||
Util.runAndWait(() -> { | ||
robot.mouseMove((int) (scene.getWindow().getX() + scene.getX() + x), | ||
(int) (scene.getWindow().getY() + scene.getY() + y)); | ||
robot.mousePress(MouseButton.PRIMARY); | ||
robot.mouseRelease(MouseButton.PRIMARY); | ||
}); | ||
} | ||
|
||
public static class TestApp extends Application { | ||
@Override | ||
public void start(Stage primaryStage) { | ||
robot = new Robot(); | ||
stage = primaryStage; | ||
|
||
dialog = getTestDialog(); | ||
button = new Button("Open Dialog"); | ||
button.setOnAction(evt -> dialog.show()); | ||
|
||
scene = new Scene(button, 200, 200); | ||
stage.setScene(scene); | ||
|
||
stage.initStyle(StageStyle.UNDECORATED); | ||
stage.addEventHandler(WindowEvent.WINDOW_SHOWN, e -> Platform.runLater(startupLatch::countDown)); | ||
|
||
stage.show(); | ||
} | ||
|
||
private static Dialog<Void> getTestDialog() { | ||
final Label dialogContent = new Label(); | ||
dialogContent.setText("Dialog content"); | ||
|
||
final Dialog<Void> testDialog = new Dialog<>(); | ||
|
||
testDialog.getDialogPane().setContent(dialogContent); | ||
testDialog.getDialogPane().getButtonTypes().add(ButtonType.CLOSE); | ||
testDialog.getDialogPane().setPrefSize(DIALOG_WIDTH, DIALOG_HEIGHT); | ||
|
||
testDialog.getDialogPane().getScene().getWindow().addEventHandler(WindowEvent.WINDOW_SHOWN, | ||
e -> Platform.runLater(dialogShownLatch::countDown)); | ||
|
||
testDialog.getDialogPane().getScene().getWindow().addEventHandler(WindowEvent.WINDOW_HIDDEN, | ||
e -> Platform.runLater(dialogHideLatch::countDown)); | ||
|
||
return testDialog; | ||
} | ||
} | ||
|
||
public static void waitForLatch(CountDownLatch latch, int seconds, String msg) throws Exception { | ||
org.junit.Assert.assertTrue("Timeout: " + msg, latch.await(seconds, TimeUnit.SECONDS)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to ensure that there are no cases where
set_view
can be called without a subsequent call towindow_configure
.