mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
JBR-7988 Wayland: WLPopupLocation test: incorrect size detected
This commit is contained in:
@@ -105,6 +105,7 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
double effectiveScale; // protected by dataLock
|
||||
private final WLSize wlSize = new WLSize();
|
||||
boolean repositionPopup = false; // protected by dataLock
|
||||
boolean resizePending = false; // protected by dataLock
|
||||
|
||||
static {
|
||||
initIDs();
|
||||
@@ -495,6 +496,7 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
return repositionPopup;
|
||||
}
|
||||
}
|
||||
|
||||
private void markPopupNeedsReposition() {
|
||||
synchronized (dataLock) {
|
||||
repositionPopup = true;
|
||||
@@ -507,6 +509,24 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean resizePending() {
|
||||
synchronized (dataLock) {
|
||||
return resizePending;
|
||||
}
|
||||
}
|
||||
|
||||
private void markResizePending() {
|
||||
synchronized (dataLock) {
|
||||
resizePending = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void resizeCompleted() {
|
||||
synchronized (dataLock) {
|
||||
resizePending = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setBounds(int newX, int newY, int newWidth, int newHeight, int op) {
|
||||
Dimension newSize = constrainSize(newWidth, newHeight);
|
||||
boolean positionChanged = (op == SET_BOUNDS || op == SET_LOCATION);
|
||||
@@ -532,7 +552,10 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
}
|
||||
|
||||
if (sizeChanged) {
|
||||
setSizeTo(newSize.width, newSize.height);
|
||||
if (!isSizeBeingConfigured()) {
|
||||
wlSize.deriveFromJavaSize(newSize.width, newSize.height);
|
||||
markResizePending();
|
||||
}
|
||||
if (log.isLoggable(PlatformLogger.Level.FINE)) {
|
||||
log.fine(String.format("%s is resizing its buffer to %dx%d pixels",
|
||||
this, getBufferWidth(), getBufferHeight()));
|
||||
@@ -558,18 +581,6 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
}
|
||||
}
|
||||
|
||||
private void setSizeTo(int newWidth, int newHeight) {
|
||||
if (isSizeBeingConfigured() && wlSize.hasPixelSizeSet()) {
|
||||
// Must be careful not to override the size of the Wayland surface because
|
||||
// some implementations (Weston) react badly when the size of the surface
|
||||
// mismatches the configured size. We can't always precisely derive the surface
|
||||
// size from the Java (client) size because of scaling rounding errors.
|
||||
wlSize.setJavaSize(newWidth, newHeight);
|
||||
} else {
|
||||
wlSize.deriveFromJavaSize(newWidth, newHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public int getBufferWidth() {
|
||||
return wlSize.getPixelWidth();
|
||||
}
|
||||
@@ -1454,6 +1465,16 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
}
|
||||
}
|
||||
|
||||
int surfaceUnitsToJavaSize(int value) {
|
||||
if (!WLGraphicsEnvironment.isDebugScaleEnabled()) {
|
||||
return value;
|
||||
} else {
|
||||
synchronized (dataLock) {
|
||||
return (int) Math.ceil(value * displayScale / effectiveScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a value in the Java coordinate system into the Wayland
|
||||
* surface-local coordinate system.
|
||||
@@ -1494,7 +1515,8 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
}
|
||||
|
||||
boolean isWlPopup = targetIsWlPopup();
|
||||
if (isWlPopup) { // Only popups provide (relative) location
|
||||
boolean acceptNewLocation = !popupNeedsReposition();
|
||||
if (isWlPopup && acceptNewLocation) { // Only popups provide (relative) location
|
||||
int newX = surfaceUnitsToJavaUnits(newSurfaceX);
|
||||
int newY = surfaceUnitsToJavaUnits(newSurfaceY);
|
||||
|
||||
@@ -1511,8 +1533,12 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
// From xdg-shell.xml: "If the width or height arguments are zero,
|
||||
// it means the client should decide its own window dimension".
|
||||
boolean clientDecidesDimension = newSurfaceWidth == 0 || newSurfaceHeight == 0;
|
||||
if (!clientDecidesDimension) {
|
||||
changeSizeToConfigured(newSurfaceWidth, newSurfaceHeight, maximized);
|
||||
boolean desiredSize =
|
||||
(wlSize.javaSize.width == surfaceUnitsToJavaSize(newSurfaceWidth)
|
||||
&& wlSize.javaSize.height == surfaceUnitsToJavaSize(newSurfaceHeight));
|
||||
boolean acceptNewSize = !resizePending() || maximized || desiredSize;
|
||||
if (!clientDecidesDimension && acceptNewSize) {
|
||||
changeSizeToConfigured(newSurfaceWidth, newSurfaceHeight);
|
||||
}
|
||||
|
||||
if (!surfaceAssigned) {
|
||||
@@ -1534,16 +1560,13 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
}
|
||||
}
|
||||
|
||||
private void changeSizeToConfigured(int newSurfaceWidth, int newSurfaceHeight, boolean honorSurfaceSize) {
|
||||
private void changeSizeToConfigured(int newSurfaceWidth, int newSurfaceHeight) {
|
||||
resizeCompleted();
|
||||
wlSize.deriveFromSurfaceSize(newSurfaceWidth, newSurfaceHeight);
|
||||
int newWidth = wlSize.getJavaWidth();
|
||||
int newHeight = wlSize.getJavaHeight();
|
||||
try {
|
||||
// When 'honorSurfaceSize' is in effect, we shall not confuse the size given by the server with
|
||||
// the size set by the user. The former originates from the surface size in surface-local coordinates,
|
||||
// while the latter is set in the client (Java) units. These are not always precisely convertible
|
||||
// when the scale differs from 100%.
|
||||
setSizeIsBeingConfigured(honorSurfaceSize);
|
||||
setSizeIsBeingConfigured(true);
|
||||
performUnlocked(() -> target.setSize(newWidth, newHeight));
|
||||
} finally {
|
||||
setSizeIsBeingConfigured(false);
|
||||
@@ -1748,8 +1771,8 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
|
||||
void deriveFromSurfaceSize(int width, int height) {
|
||||
synchronized (dataLock) {
|
||||
javaSize.width = surfaceUnitsToJavaUnits(width);
|
||||
javaSize.height = surfaceUnitsToJavaUnits(height);
|
||||
javaSize.width = surfaceUnitsToJavaSize(width);
|
||||
javaSize.height = surfaceUnitsToJavaSize(height);
|
||||
pixelSize.width = width * displayScale;
|
||||
pixelSize.height = height * displayScale;
|
||||
surfaceSize.width = width;
|
||||
|
||||
@@ -74,47 +74,59 @@ public class WLPopupLocation {
|
||||
SwingUtilities.invokeAndWait(WLPopupLocation::initPopup);
|
||||
pause(robot);
|
||||
|
||||
int w1 = 150, h1 = 200;
|
||||
int x1 = 100, y1 = 100;
|
||||
System.out.printf("Action: locate to (%d, %d), set size (%d, %d)\n", x1, y1, w1, h1);
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setVisible(true);
|
||||
popup.setSize(w1, h1);
|
||||
popup.setLocation(x1, y1);
|
||||
});
|
||||
if (popup.getSize().width != w1 || popup.getSize().height != h1) {
|
||||
throw new RuntimeException(String.format("Incorrect size (%d, %d), expected (%d, %d)", popup.getSize().width, popup.getSize().height, w1, h1));
|
||||
}
|
||||
if (popup.getBounds().x != x1 || popup.getBounds().y != y1) {
|
||||
throw new RuntimeException(String.format("Wrong location (via getBounds()): (%d, %d). Expected: (%d, %d)", popup.getBounds().x, popup.getBounds().y, x1, y1));
|
||||
}
|
||||
pause(robot);
|
||||
if (popup.getSize().width != h1 || popup.getSize().height != h1) {
|
||||
throw new RuntimeException(String.format("Incorrect size (%d, %d) after robot's wait for idle, expected (%d, %d)", popup.getSize().width, popup.getSize().height, w1, h1));
|
||||
}
|
||||
if (popup.getBounds().x != x1 || popup.getBounds().y != y1) {
|
||||
throw new RuntimeException(String.format("Wrong location (via getBounds()) after robot's wait for idle: (%d, %d). Expected: (%d, %d)", popup.getBounds().x, popup.getBounds().y, x1, y1));
|
||||
}
|
||||
try {
|
||||
int w1 = 150, h1 = 200;
|
||||
int x1 = 100, y1 = 100;
|
||||
System.out.printf("Action: locate to (%d, %d), set size (%d, %d)\n", x1, y1, w1, h1);
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setVisible(true);
|
||||
popup.setSize(2, 5);
|
||||
popup.setSize(89, 17);
|
||||
popup.setSize(11, 3);
|
||||
popup.setSize(w1, h1);
|
||||
popup.setLocation(x1, y1);
|
||||
});
|
||||
int toleranceLevel = getTolerance();
|
||||
|
||||
int x2 = 200, y2 = 200;
|
||||
System.out.printf("Action: set popup size to (%d, %d)\n", x2, y2);
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setLocation(x2, y2);
|
||||
});
|
||||
if (popup.getSize().width != w1 || popup.getSize().height != h1) {
|
||||
throw new RuntimeException(String.format("Incorrect size (%d, %d), expected (%d, %d)", popup.getSize().width, popup.getSize().height, w1, h1));
|
||||
System.out.printf("Real bounds: %s\n", popup.getBounds());
|
||||
if (isOutsideTolerance(w1, h1, popup.getSize().width, popup.getSize().height, toleranceLevel)) {
|
||||
throw new RuntimeException(String.format("Incorrect size (%d, %d), expected (%d, %d)", popup.getSize().width, popup.getSize().height, w1, h1));
|
||||
}
|
||||
if (isOutsideTolerance(x1, y1, popup.getBounds().x, popup.getBounds().y, toleranceLevel)) {
|
||||
throw new RuntimeException(String.format("Wrong location (via getBounds()): (%d, %d). Expected: (%d, %d)", popup.getBounds().x, popup.getBounds().y, x1, y1));
|
||||
}
|
||||
pause(robot);
|
||||
System.out.printf("Real bounds after a pause: %s\n", popup.getBounds());
|
||||
if (isOutsideTolerance(w1, h1, popup.getSize().width, popup.getSize().height, toleranceLevel)) {
|
||||
throw new RuntimeException(String.format("Incorrect size (%d, %d) after robot's wait for idle, expected (%d, %d)", popup.getSize().width, popup.getSize().height, w1, h1));
|
||||
}
|
||||
if (isOutsideTolerance(x1, y1, popup.getBounds().x, popup.getBounds().y, toleranceLevel)) {
|
||||
throw new RuntimeException(String.format("Wrong location (via getBounds()) after robot's wait for idle: (%d, %d). Expected: (%d, %d)", popup.getBounds().x, popup.getBounds().y, x1, y1));
|
||||
}
|
||||
|
||||
int x2 = 200, y2 = 200;
|
||||
System.out.printf("Action: set popup location to (%d, %d)\n", x2, y2);
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setLocation(x2, y2);
|
||||
});
|
||||
System.out.printf("Real bounds: %s\n", popup.getBounds());
|
||||
if (isOutsideTolerance(w1, h1, popup.getSize().width, popup.getSize().height, toleranceLevel)) {
|
||||
throw new RuntimeException(String.format("Incorrect size (%d, %d), expected (%d, %d)", popup.getSize().width, popup.getSize().height, w1, h1));
|
||||
}
|
||||
if (isOutsideTolerance(x2, y2, popup.getBounds().x, popup.getBounds().y, toleranceLevel)) {
|
||||
throw new RuntimeException(String.format("Wrong location (via getBounds()): (%d, %d). Expected: (%x, %d)", popup.getBounds().x, popup.getBounds().y, x2, y2));
|
||||
}
|
||||
pause(robot);
|
||||
System.out.printf("Real bounds after a pause: %s\n", popup.getBounds());
|
||||
if (isOutsideTolerance(w1, h1, popup.getSize().width, popup.getSize().height, toleranceLevel)) {
|
||||
throw new RuntimeException(String.format("Incorrect size (%d, %d) after robot's wait for idle, expected (%d, %d)", popup.getSize().width, popup.getSize().height, w1, h1));
|
||||
}
|
||||
if (isOutsideTolerance(x2, y2, popup.getBounds().x, popup.getBounds().y, toleranceLevel)) {
|
||||
throw new RuntimeException(String.format("Wrong location (via getBounds()) after robot's wait for idle: (%d, %d). Expected: (%d, %d)", popup.getBounds().x, popup.getBounds().y, x2, y2));
|
||||
}
|
||||
} finally {
|
||||
SwingUtilities.invokeAndWait(frame::dispose);
|
||||
}
|
||||
if (popup.getBounds().x != x2 || popup.getBounds().y != y2) {
|
||||
throw new RuntimeException(String.format("Wrong location (via getBounds()): (%d, %d). Expected: (%x, %d)", popup.getBounds().x, popup.getBounds().y, x2, y2));
|
||||
}
|
||||
pause(robot);
|
||||
if (popup.getSize().width != w1 || popup.getSize().height != h1) {
|
||||
throw new RuntimeException(String.format("Incorrect size (%d, %d) after robot's wait for idle, expected (%d, %d)", popup.getSize().width, popup.getSize().height, w1, h1));
|
||||
}
|
||||
if (popup.getBounds().x != x2 || popup.getBounds().y != y2) {
|
||||
throw new RuntimeException(String.format("Wrong location (via getBounds()) after robot's wait for idle: (%d, %d). Expected: (%d, %d)", popup.getBounds().x, popup.getBounds().y, x2, y2));
|
||||
}
|
||||
SwingUtilities.invokeAndWait(frame::dispose);
|
||||
}
|
||||
|
||||
private static void pause(Robot robot) {
|
||||
@@ -122,4 +134,14 @@ public class WLPopupLocation {
|
||||
robot.delay(500);
|
||||
}
|
||||
|
||||
private static int getTolerance() {
|
||||
String uiScaleString = System.getProperty("sun.java2d.uiScale");
|
||||
int tolerance = uiScaleString == null ? 0 : (int) Math.ceil(Double.parseDouble(uiScaleString));
|
||||
System.out.printf("Scale settings: debug scale: %s, tolerance level: %d\n", uiScaleString, tolerance);
|
||||
return tolerance;
|
||||
}
|
||||
|
||||
private static boolean isOutsideTolerance(int expectedX, int expectedY, int realX, int realY, int tolerance) {
|
||||
return Math.abs(realX - expectedX) > tolerance || Math.abs(realY - expectedY) > tolerance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,13 +68,14 @@ public class WLPopupMinSize {
|
||||
throw new RuntimeException("Popup minimum size is not 1000x100 but " + popupMinSize);
|
||||
}
|
||||
|
||||
int tolerance = getTolerance();
|
||||
Dimension popupSize = popup.getSize();
|
||||
System.out.println("Popup size: " + popupSize);
|
||||
if (popupSize.width != 1000 || popupSize.height != 1000) {
|
||||
if (isOutsideTolerance(1000, 1000, popupSize.width, popupSize.height, tolerance)) {
|
||||
throw new RuntimeException("Popup actual size is not 1000x100 but " + popupSize);
|
||||
}
|
||||
} finally {
|
||||
frame.dispose();
|
||||
SwingUtilities.invokeAndWait(frame::dispose);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,4 +96,15 @@ public class WLPopupMinSize {
|
||||
// Setting the minimum size at this point must resize the popup window
|
||||
popup.setMinimumSize(new Dimension(1000, 1000));
|
||||
}
|
||||
|
||||
private static int getTolerance() {
|
||||
String uiScaleString = System.getProperty("sun.java2d.uiScale");
|
||||
int tolerance = uiScaleString == null ? 0 : (int) Math.ceil(Double.parseDouble(uiScaleString));
|
||||
System.out.printf("Scale settings: debug scale: %s, tolerance level: %d\n", uiScaleString, tolerance);
|
||||
return tolerance;
|
||||
}
|
||||
|
||||
private static boolean isOutsideTolerance(int expectedX, int expectedY, int realX, int realY, int tolerance) {
|
||||
return Math.abs(realX - expectedX) > tolerance || Math.abs(realY - expectedY) > tolerance;
|
||||
}
|
||||
}
|
||||
@@ -76,65 +76,65 @@ public class WLPopupMoves {
|
||||
pause(robot);
|
||||
|
||||
double uiScale = getUiScale();
|
||||
System.out.printf("UI scale: %.2f.\n", uiScale);
|
||||
int pixelThreshold = uiScale == 1.0 ? 0 : (int) Math.ceil(uiScale);
|
||||
System.out.printf("Pixel threshold for verifications: %d\n", pixelThreshold);
|
||||
int tolerance = getTolerance();
|
||||
|
||||
int w = 120, h = 200;
|
||||
System.out.println("Set popup to (50, 50)");
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setBounds(50, 50, w, h);
|
||||
popup.setVisible(true);
|
||||
});
|
||||
verifyBounds("Popup position after setting to (50, 50)\n", 50, 50, w, h, pixelThreshold);
|
||||
pause(robot);
|
||||
verifyBounds("Popup position (50, 50) after robot's pause\n", 50, 50, w, h, pixelThreshold);
|
||||
try {
|
||||
int w = 120, h = 200;
|
||||
System.out.println("Set popup to (50, 50)");
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setBounds(50, 50, w, h);
|
||||
popup.setVisible(true);
|
||||
});
|
||||
verifyBounds("Popup position after setting to (50, 50)\n", 50, 50, w, h, tolerance);
|
||||
pause(robot);
|
||||
verifyBounds("Popup position (50, 50) after robot's pause\n", 50, 50, w, h, tolerance);
|
||||
|
||||
System.out.println("Set popup to (100, 100)");
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setBounds(100, 100, w, h);
|
||||
});
|
||||
verifyBounds("Popup position after setting to (100, 100)\n", 100, 100, w, h, pixelThreshold);
|
||||
pause(robot);
|
||||
verifyBounds("Popup position (100, 100) after robot's pause\n", 100, 100, w, h, pixelThreshold);
|
||||
System.out.println("Set popup to (100, 100)");
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setBounds(100, 100, w, h);
|
||||
});
|
||||
verifyBounds("Popup position after setting to (100, 100)\n", 100, 100, w, h, tolerance);
|
||||
pause(robot);
|
||||
verifyBounds("Popup position (100, 100) after robot's pause\n", 100, 100, w, h, tolerance);
|
||||
|
||||
int x1 = (int) (toolkit.getScreenSize().width / (2 * uiScale));
|
||||
int y1 = (int) (toolkit.getScreenSize().height / (2 * uiScale));
|
||||
System.out.printf("Set popup to (%d, %d)\n", x1, y1);
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setBounds(x1, y1, w, h);
|
||||
});
|
||||
verifyBounds(String.format("Popup position after setting to (%d, %d)\n", x1, y1), x1, y1, w, h, pixelThreshold);
|
||||
pause(robot);
|
||||
verifyBounds(String.format("Popup position (%d, %d) after robot's pause\n", x1, y1), x1, y1, w, h, pixelThreshold);
|
||||
|
||||
int x2 = (int) (toolkit.getScreenSize().width / uiScale - 10 - w);
|
||||
int y2 = (int) (toolkit.getScreenSize().height / uiScale - 10 - h);
|
||||
System.out.printf("Set popup to (%d, %d). (to the bottom right corner) \n", x2, y2);
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setBounds(x2, y2, w, h);
|
||||
});
|
||||
verifyBounds(String.format("Popup position after setting to (%d, %d)\n", x2, y2), x2, y2, w, h, pixelThreshold);
|
||||
pause(robot);
|
||||
verifyBounds(String.format("Popup position (%d, %d) after robot's pause\n", x2, y2), x2, y2, w, h, pixelThreshold);
|
||||
int x1 = (int) (toolkit.getScreenSize().width / (2 * uiScale));
|
||||
int y1 = (int) (toolkit.getScreenSize().height / (2 * uiScale));
|
||||
System.out.printf("Set popup to (%d, %d)\n", x1, y1);
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setBounds(x1, y1, w, h);
|
||||
});
|
||||
verifyBounds(String.format("Popup position after setting to (%d, %d)\n", x1, y1), x1, y1, w, h, tolerance);
|
||||
pause(robot);
|
||||
verifyBounds(String.format("Popup position (%d, %d) after robot's pause\n", x1, y1), x1, y1, w, h, tolerance);
|
||||
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice device = ge.getDefaultScreenDevice();
|
||||
GraphicsConfiguration gc = device.getDefaultConfiguration();
|
||||
Insets insets = toolkit.getScreenInsets(gc);
|
||||
int x3 = (int) (toolkit.getScreenSize().width / uiScale - 10 - insets.right);
|
||||
int y3 = (int) (toolkit.getScreenSize().height / uiScale - 10 - insets.bottom);
|
||||
System.out.printf("Set popup to (%d, %d). (to the bottom right corner) \n", x3, y3);
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setBounds(x2, y2, w, h);
|
||||
});
|
||||
int x3Relocated = x3 - w;
|
||||
int y3Relocated = y3 - h;
|
||||
verifyBounds(String.format("Popup position after setting to (%d, %d)\n", x3, y3), x3Relocated, y3Relocated, w, h, pixelThreshold);
|
||||
pause(robot);
|
||||
verifyBounds(String.format("Popup position (%d, %d) after robot's pause\n", x3, y3), x3Relocated, y3Relocated, w, h, pixelThreshold);
|
||||
int x2 = (int) (toolkit.getScreenSize().width / uiScale - 10 - w);
|
||||
int y2 = (int) (toolkit.getScreenSize().height / uiScale - 10 - h);
|
||||
System.out.printf("Set popup to (%d, %d). (to the bottom right corner) \n", x2, y2);
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setBounds(x2, y2, w, h);
|
||||
});
|
||||
verifyBounds(String.format("Popup position after setting to (%d, %d)\n", x2, y2), x2, y2, w, h, tolerance);
|
||||
pause(robot);
|
||||
verifyBounds(String.format("Popup position (%d, %d) after robot's pause\n", x2, y2), x2, y2, w, h, tolerance);
|
||||
|
||||
SwingUtilities.invokeAndWait(frame::dispose);
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice device = ge.getDefaultScreenDevice();
|
||||
GraphicsConfiguration gc = device.getDefaultConfiguration();
|
||||
Insets insets = toolkit.getScreenInsets(gc);
|
||||
int x3 = (int) (toolkit.getScreenSize().width / uiScale - 10 - insets.right);
|
||||
int y3 = (int) (toolkit.getScreenSize().height / uiScale - 10 - insets.bottom);
|
||||
System.out.printf("Set popup to (%d, %d). (to the bottom right corner) \n", x3, y3);
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setBounds(x2, y2, w, h);
|
||||
});
|
||||
int x3Relocated = x3 - w;
|
||||
int y3Relocated = y3 - h;
|
||||
verifyBounds(String.format("Popup position after setting to (%d, %d)\n", x3, y3), x3Relocated, y3Relocated, w, h, tolerance);
|
||||
pause(robot);
|
||||
verifyBounds(String.format("Popup position (%d, %d) after robot's pause\n", x3, y3), x3Relocated, y3Relocated, w, h, tolerance);
|
||||
} finally {
|
||||
SwingUtilities.invokeAndWait(frame::dispose);
|
||||
}
|
||||
}
|
||||
|
||||
private static Double getUiScale() {
|
||||
@@ -168,4 +168,15 @@ public class WLPopupMoves {
|
||||
robot.waitForIdle();
|
||||
robot.delay(500);
|
||||
}
|
||||
|
||||
private static int getTolerance() {
|
||||
String uiScaleString = System.getProperty("sun.java2d.uiScale");
|
||||
int tolerance = uiScaleString == null ? 0 : (int) Math.ceil(Double.parseDouble(uiScaleString));
|
||||
System.out.printf("Scale settings: debug scale: %s, tolerance level: %d\n", uiScaleString, tolerance);
|
||||
return tolerance;
|
||||
}
|
||||
|
||||
private static boolean isOutsideTolerance(int expectedX, int expectedY, int realX, int realY, int tolerance) {
|
||||
return Math.abs(realX - expectedX) > tolerance || Math.abs(realY - expectedY) > tolerance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,15 +73,18 @@ public class WLPopupNoSize {
|
||||
SwingUtilities.invokeAndWait(WLPopupNoSize::initPopup);
|
||||
pause(robot);
|
||||
|
||||
SwingUtilities.invokeAndWait(() -> popup.setVisible(true));
|
||||
boolean isVisible1 = popup.isVisible();
|
||||
pause(robot);
|
||||
boolean isVisible2 = popup.isVisible();
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(() -> popup.setVisible(true));
|
||||
boolean isVisible1 = popup.isVisible();
|
||||
pause(robot);
|
||||
boolean isVisible2 = popup.isVisible();
|
||||
|
||||
if (!isVisible1 || !isVisible2) {
|
||||
throw new RuntimeException("Expected result: popup is visible");
|
||||
if (!isVisible1 || !isVisible2) {
|
||||
throw new RuntimeException("Expected result: popup is visible");
|
||||
}
|
||||
} finally {
|
||||
SwingUtilities.invokeAndWait(frame::dispose);
|
||||
}
|
||||
SwingUtilities.invokeAndWait(frame::dispose);
|
||||
}
|
||||
|
||||
private static void pause(Robot robot) {
|
||||
|
||||
@@ -105,51 +105,45 @@ public class WLPopupResize {
|
||||
SwingUtilities.invokeAndWait(WLPopupResize::showPopup);
|
||||
pause(robot);
|
||||
|
||||
double uiScale = getUiScale();
|
||||
System.out.printf("UI scale: %.2f.\n", uiScale);
|
||||
int pixelThreshold = uiScale == 1.0 ? 0 : (int) Math.ceil(uiScale);
|
||||
System.out.printf("Pixel threshold for verifications: %d\n", pixelThreshold);
|
||||
try {
|
||||
int tolerance = getTolerance();
|
||||
|
||||
int x = 10, y = 20, w = 120, h = 80;
|
||||
System.out.println("Set popup size to (120, 80)");
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setBounds(x, y, w, h);
|
||||
});
|
||||
Rectangle bounds = popup.getBounds();
|
||||
boolean isCorrectPosition = x - pixelThreshold <= bounds.x && bounds.x <= x + pixelThreshold &&
|
||||
y - pixelThreshold <= bounds.y && bounds.y <= y + pixelThreshold;
|
||||
if (!isCorrectPosition) {
|
||||
throw new RuntimeException("Popup position has unexpectedly changed. Bounds: " + popup.getBounds());
|
||||
}
|
||||
if (popup.getBounds().width != w || popup.getBounds().height != h) {
|
||||
throw new RuntimeException("Popup size wasn't correctly changed. Bounds: " + popup.getBounds());
|
||||
}
|
||||
pause(robot);
|
||||
System.out.println("Next checks after robot's waiting for idle.");
|
||||
int x = 10, y = 20, w = 120, h = 80;
|
||||
System.out.println("Set popup size to (120, 80)");
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setBounds(x, y, w, h);
|
||||
});
|
||||
Rectangle bounds = popup.getBounds();
|
||||
if (isOutsideTolerance(x, y, bounds.x, bounds.y, tolerance)) {
|
||||
throw new RuntimeException("Popup position has unexpectedly changed. Bounds: " + popup.getBounds());
|
||||
}
|
||||
if (isOutsideTolerance(w, h, bounds.width, bounds.height, tolerance)) {
|
||||
throw new RuntimeException("Popup size wasn't correctly changed. Bounds: " + popup.getBounds());
|
||||
}
|
||||
pause(robot);
|
||||
System.out.println("Next checks after robot's waiting for idle.");
|
||||
|
||||
isCorrectPosition = x - pixelThreshold <= bounds.x && bounds.x <= x + pixelThreshold &&
|
||||
y - pixelThreshold <= bounds.y && bounds.y <= y + pixelThreshold;
|
||||
if (!isCorrectPosition) {
|
||||
throw new RuntimeException("Popup position has unexpectedly changed. Bounds: " + popup.getBounds());
|
||||
bounds = popup.getBounds();
|
||||
if (isOutsideTolerance(x, y, bounds.x, bounds.y, tolerance)) {
|
||||
throw new RuntimeException("Popup position has unexpectedly changed. Bounds: " + popup.getBounds());
|
||||
}
|
||||
if (isOutsideTolerance(w, h, bounds.width, bounds.height, tolerance)) {
|
||||
throw new RuntimeException("Popup size wasn't correctly changed. Bounds: " + popup.getBounds());
|
||||
}
|
||||
} finally {
|
||||
SwingUtilities.invokeAndWait(frame::dispose);
|
||||
}
|
||||
if (popup.getBounds().width != w || popup.getBounds().height != h) {
|
||||
throw new RuntimeException("Popup size wasn't correctly changed. Bounds: " + popup.getBounds());
|
||||
}
|
||||
SwingUtilities.invokeAndWait(frame::dispose);
|
||||
}
|
||||
|
||||
private static Double getUiScale() {
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice device = ge.getDefaultScreenDevice();
|
||||
GraphicsConfiguration gc = device.getDefaultConfiguration();
|
||||
AffineTransform transform = gc.getDefaultTransform();
|
||||
double scaleX = transform.getScaleX();
|
||||
double scaleY = transform.getScaleY();
|
||||
if (scaleX != scaleY) {
|
||||
System.out.println("Skip test due to non-uniform display scale");
|
||||
System.exit(0);
|
||||
}
|
||||
return scaleX;
|
||||
private static int getTolerance() {
|
||||
String uiScaleString = System.getProperty("sun.java2d.uiScale");
|
||||
int tolerance = uiScaleString == null ? 0 : (int) Math.ceil(Double.parseDouble(uiScaleString));
|
||||
System.out.printf("Scale settings: debug scale: %s, tolerance level: %d\n", uiScaleString, tolerance);
|
||||
return tolerance;
|
||||
}
|
||||
|
||||
private static boolean isOutsideTolerance(int expectedX, int expectedY, int realX, int realY, int tolerance) {
|
||||
return Math.abs(realX - expectedX) > tolerance || Math.abs(realY - expectedY) > tolerance;
|
||||
}
|
||||
|
||||
private static void pause(Robot robot) {
|
||||
|
||||
@@ -73,57 +73,59 @@ public class WLPopupVisibility {
|
||||
SwingUtilities.invokeAndWait(WLPopupVisibility::initPopup);
|
||||
pause(robot);
|
||||
|
||||
System.out.println("Action: set the popup visible");
|
||||
SwingUtilities.invokeAndWait(() -> popup.setVisible(true));
|
||||
boolean isVisible1 = popup.isVisible();
|
||||
pause(robot);
|
||||
boolean isVisible2 = popup.isVisible();
|
||||
try {
|
||||
System.out.println("Action: set the popup visible");
|
||||
SwingUtilities.invokeAndWait(() -> popup.setVisible(true));
|
||||
boolean isVisible1 = popup.isVisible();
|
||||
pause(robot);
|
||||
boolean isVisible2 = popup.isVisible();
|
||||
|
||||
if (!isVisible1 || !isVisible2) {
|
||||
throw new RuntimeException("Expected result: popup is visible");
|
||||
}
|
||||
if (!isVisible1 || !isVisible2) {
|
||||
throw new RuntimeException("Expected result: popup is visible");
|
||||
}
|
||||
|
||||
System.out.println("Action: set the popup disabled");
|
||||
SwingUtilities.invokeAndWait(() -> popup.setEnabled(false));
|
||||
boolean isEnabled3 = popup.isEnabled();
|
||||
boolean isVisible3 = popup.isVisible();
|
||||
pause(robot);
|
||||
boolean isEnabled4 = popup.isEnabled();
|
||||
boolean isVisible4 = popup.isVisible();
|
||||
if (isEnabled3 || isEnabled4) {
|
||||
throw new RuntimeException("Expected result: popup is disabled");
|
||||
}
|
||||
if (!isVisible3 || !isVisible4) {
|
||||
throw new RuntimeException("Expected result: disabled popup remains visible");
|
||||
}
|
||||
System.out.println("Action: set the popup disabled");
|
||||
SwingUtilities.invokeAndWait(() -> popup.setEnabled(false));
|
||||
boolean isEnabled3 = popup.isEnabled();
|
||||
boolean isVisible3 = popup.isVisible();
|
||||
pause(robot);
|
||||
boolean isEnabled4 = popup.isEnabled();
|
||||
boolean isVisible4 = popup.isVisible();
|
||||
if (isEnabled3 || isEnabled4) {
|
||||
throw new RuntimeException("Expected result: popup is disabled");
|
||||
}
|
||||
if (!isVisible3 || !isVisible4) {
|
||||
throw new RuntimeException("Expected result: disabled popup remains visible");
|
||||
}
|
||||
|
||||
System.out.println("Action: set the popup invisible");
|
||||
SwingUtilities.invokeAndWait(() -> popup.setVisible(false));
|
||||
boolean isVisible5 = popup.isVisible();
|
||||
pause(robot);
|
||||
boolean isVisible6 = popup.isVisible();
|
||||
if (isVisible5 && isVisible6) {
|
||||
throw new RuntimeException("Expected result: disabled popup remains visible");
|
||||
}
|
||||
System.out.println("Action: set the popup invisible");
|
||||
SwingUtilities.invokeAndWait(() -> popup.setVisible(false));
|
||||
boolean isVisible5 = popup.isVisible();
|
||||
pause(robot);
|
||||
boolean isVisible6 = popup.isVisible();
|
||||
if (isVisible5 && isVisible6) {
|
||||
throw new RuntimeException("Expected result: disabled popup remains visible");
|
||||
}
|
||||
|
||||
System.out.println("Action: set popup enabled and visible");
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setVisible(true);
|
||||
popup.setEnabled(true);
|
||||
});
|
||||
boolean isEnabled7 = popup.isEnabled();
|
||||
boolean isVisible7 = popup.isVisible();
|
||||
pause(robot);
|
||||
boolean isEnabled8 = popup.isEnabled();
|
||||
boolean isVisible8 = popup.isVisible();
|
||||
if (!isEnabled7 || !isEnabled8) {
|
||||
throw new RuntimeException("Expected result: popup is enabled");
|
||||
System.out.println("Action: set popup enabled and visible");
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
popup.setVisible(true);
|
||||
popup.setEnabled(true);
|
||||
});
|
||||
boolean isEnabled7 = popup.isEnabled();
|
||||
boolean isVisible7 = popup.isVisible();
|
||||
pause(robot);
|
||||
boolean isEnabled8 = popup.isEnabled();
|
||||
boolean isVisible8 = popup.isVisible();
|
||||
if (!isEnabled7 || !isEnabled8) {
|
||||
throw new RuntimeException("Expected result: popup is enabled");
|
||||
}
|
||||
if (!isVisible7 || !isVisible8) {
|
||||
throw new RuntimeException("Expected result: popup becoming visible");
|
||||
}
|
||||
} finally {
|
||||
SwingUtilities.invokeAndWait(frame::dispose);
|
||||
}
|
||||
if (!isVisible7 || !isVisible8) {
|
||||
throw new RuntimeException("Expected result: popup becoming visible");
|
||||
}
|
||||
|
||||
SwingUtilities.invokeAndWait(frame::dispose);
|
||||
}
|
||||
|
||||
private static void pause(Robot robot) {
|
||||
|
||||
Reference in New Issue
Block a user