From 3b50c4809deef109c4d5dfab04e81d01d8f1a5ff Mon Sep 17 00:00:00 2001 From: Sarvesh Kumar Jain Date: Mon, 4 May 2026 08:34:02 +0000 Subject: [PATCH] 8177841: Some java/awt/Robot tests can be improved Reviewed-by: mvs, prr --- .../HiDPIMouseClick/HiDPIRobotMouseClick.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/test/jdk/java/awt/Robot/HiDPIMouseClick/HiDPIRobotMouseClick.java b/test/jdk/java/awt/Robot/HiDPIMouseClick/HiDPIRobotMouseClick.java index 25c40cc707d..99604b0d8f3 100644 --- a/test/jdk/java/awt/Robot/HiDPIMouseClick/HiDPIRobotMouseClick.java +++ b/test/jdk/java/awt/Robot/HiDPIMouseClick/HiDPIRobotMouseClick.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -33,10 +33,13 @@ import javax.swing.UIManager; * @test * @key headful * @bug 8073320 - * @summary Windows HiDPI support - * @author Alexander Scherbatiy + * @summary Windows HiDPI support (multi-scale) * @requires (os.family == "windows") - * @run main/othervm -Dsun.java2d.win.uiScale=2 HiDPIRobotMouseClick + * @run main/othervm -Dsun.java2d.win.uiScale=1 HiDPIRobotMouseClick + * @run main/othervm -Dsun.java2d.win.uiScale=1.25 HiDPIRobotMouseClick + * @run main/othervm -Dsun.java2d.win.uiScale=1.5 HiDPIRobotMouseClick + * @run main/othervm -Dsun.java2d.win.uiScale=2 HiDPIRobotMouseClick + * @run main/othervm -Dsun.java2d.win.uiScale=2.5 HiDPIRobotMouseClick */ public class HiDPIRobotMouseClick { @@ -46,9 +49,12 @@ public class HiDPIRobotMouseClick { public static void main(String[] args) throws Exception { + String scale = System.getProperty("sun.java2d.win.uiScale", "default"); + System.out.println("Running with DPI scale: " + scale); + try { UIManager.setLookAndFeel( - "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); + "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception e) { return; } @@ -58,7 +64,6 @@ public class HiDPIRobotMouseClick { frame.setUndecorated(true); frame.addMouseListener(new MouseAdapter() { - @Override public void mouseClicked(MouseEvent e) { mouseX = e.getXOnScreen(); @@ -79,12 +84,16 @@ public class HiDPIRobotMouseClick { int y = (int) rect.getCenterY(); robot.mouseMove(x, y); - robot.mousePress(InputEvent.BUTTON1_MASK); - robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); robot.waitForIdle(); if (x != mouseX || y != mouseY) { - throw new RuntimeException("Wrong mouse click point!"); + throw new RuntimeException( + "Wrong mouse click point at scale %s! Expected: (%d,%d) Got: (%d,%d)" + .formatted(scale, x, y, mouseX, mouseY)); } + + System.out.println("PASS at scale: " + scale); } }