JBR-5345 native controls detection and scale fixes

(cherry picked from commit e191789794)
This commit is contained in:
Sergey Shelomentsev
2023-03-16 00:00:24 +02:00
committed by Vitaly Provodin
parent d424556784
commit 22e495e051
22 changed files with 458 additions and 230 deletions

View File

@@ -24,12 +24,14 @@
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Task;
import util.TaskResult;
import util.TestUtils;
import java.awt.AWTException;
import java.awt.Button;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.lang.invoke.MethodHandles;
/*
* @test
@@ -48,10 +50,11 @@ import java.awt.event.InputEvent;
public class ActionListenerTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), actionListener);
TaskResult result = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), actionListener);
if (!status) {
throw new RuntimeException("ActionListenerTest FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
@@ -74,7 +77,7 @@ public class ActionListenerTest {
@Override
public void customizeWindow() {
button = new Button();
button.setBounds(200, 20, 50, 50);
button.setBounds(window.getWidth() / 2, 0, 50, 50);
button.addActionListener(a -> {
actionListenerGotEvent = true;
});
@@ -93,9 +96,15 @@ public class ActionListenerTest {
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.waitForIdle();
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.waitForIdle();
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.waitForIdle();
if (!actionListenerGotEvent) {
System.out.println("Error: button didn't get event by action listener");
err("button didn't get event by action listener");
}
}
};

View File

@@ -24,8 +24,11 @@
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Task;
import util.TaskResult;
import util.TestUtils;
import java.lang.invoke.MethodHandles;
/*
* @test
* @summary Verify modifying of title bar height
@@ -43,11 +46,13 @@ import util.TestUtils;
public class ChangeTitleBarHeightTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), changeTitleBarHeight);
TaskResult result = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), changeTitleBarHeight);
if (!status) {
throw new RuntimeException("ChangeTitleBarHeightTest FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
private static final Task changeTitleBarHeight = new Task("Changing of title bar height") {

View File

@@ -24,8 +24,11 @@
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Task;
import util.TaskResult;
import util.TestUtils;
import java.lang.invoke.MethodHandles;
/*
* @test
* @summary Verify creating to a custom title bar
@@ -43,11 +46,13 @@ import util.TestUtils;
public class CreateTitleBarTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), createTitleBar);
TaskResult result = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), createTitleBar);
if (!status) {
throw new RuntimeException("CreateTitleBarTest FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
private static final Task createTitleBar = new Task("Create title bar with default settings") {
@@ -64,8 +69,7 @@ public class CreateTitleBarTest {
passed = passed && TestUtils.checkFrameInsets(window);
if (titleBar.getLeftInset() == 0 && titleBar.getRightInset() == 0) {
passed = false;
System.out.println("Left or right space must be occupied by system controls");
err("Left or right space must be occupied by system controls");
}
}
};

View File

@@ -21,10 +21,7 @@
* questions.
*/
import com.jetbrains.JBR;
import util.Rect;
import util.ScreenShotHelpers;
import util.Task;
import util.TestUtils;
import util.*;
import java.awt.event.InputEvent;
import java.awt.event.WindowAdapter;
@@ -32,6 +29,7 @@ import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import java.awt.image.BufferedImage;
import java.lang.invoke.MethodHandles;
import java.util.List;
/*
@@ -51,11 +49,13 @@ import java.util.List;
public class DialogNativeControlsTest {
public static void main(String... args) {
boolean status = nativeControlClicks.run(TestUtils::createDialogWithCustomTitleBar);
TaskResult result = nativeControlClicks.run(TestUtils::createDialogWithCustomTitleBar);
if (!status) {
throw new RuntimeException("DialogNativeControlsTest FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
private static final Task nativeControlClicks = new Task("Native controls clicks") {
@@ -111,7 +111,7 @@ public class DialogNativeControlsTest {
robot.waitForIdle();
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
List<Rect> foundControls = ScreenShotHelpers.detectControlsByBackground(image, (int) titleBar.getHeight(), TestUtils.TITLE_BAR_COLOR);
List<Rect> foundControls = ScreenShotHelpers.findControls(image, window, titleBar);
if (foundControls.size() == 0) {
passed = false;
@@ -140,13 +140,11 @@ public class DialogNativeControlsTest {
});
if (System.getProperty("os.name").toLowerCase().startsWith("mac") && !maximizingActionDetected) {
passed = false;
System.out.println("Error: maximizing action was not detected");
err("maximizing action was not detected");
}
if (!closingActionCalled) {
passed = false;
System.out.println("Error: closing action was not detected");
err("closing action was not detected");
}
}

View File

@@ -22,11 +22,7 @@
*/
import com.jetbrains.JBR;
import com.jetbrains.WindowDecorations;
import util.CommonAPISuite;
import util.Rect;
import util.ScreenShotHelpers;
import util.Task;
import util.TestUtils;
import util.*;
import javax.swing.JFrame;
import java.awt.Frame;
@@ -37,6 +33,7 @@ import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import java.awt.image.BufferedImage;
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.function.Function;
@@ -61,11 +58,13 @@ public class FrameNativeControlsMacOSTest {
public static void main(String... args) {
List<Function<WindowDecorations.CustomTitleBar, Window>> functions =
List.of(TestUtils::createFrameWithCustomTitleBar, TestUtils::createJFrameWithCustomTitleBar);
boolean status = CommonAPISuite.runTestSuite(functions, frameNativeControlsClicks);
TaskResult result = CommonAPISuite.runTestSuite(functions, frameNativeControlsClicks);
if (!status) {
throw new RuntimeException("FrameNativeControlsMacOSTest FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
private static final Task frameNativeControlsClicks = new Task("Frame native controls clicks") {
@@ -164,7 +163,7 @@ public class FrameNativeControlsMacOSTest {
robot.delay(500);
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
List<Rect> foundControls = ScreenShotHelpers.detectControlsByBackground(image, (int) titleBar.getHeight(), TestUtils.TITLE_BAR_COLOR);
List<Rect> foundControls = ScreenShotHelpers.findControls(image, window, titleBar);
if (foundControls.size() == 0) {
passed = false;
@@ -193,22 +192,18 @@ public class FrameNativeControlsMacOSTest {
});
if (!maximizingActionDetected) {
passed = false;
System.out.println("Error: maximizing action was not detected");
err("maximizing action was not detected");
}
if (!closingActionCalled) {
passed = false;
System.out.println("Error: closing action was not detected");
err("closing action was not detected");
}
if (!iconifyingActionCalled) {
passed = false;
System.out.println("Error: iconifying action was not detected");
err("iconifying action was not detected");
}
if (!deiconifyindActionDetected) {
passed = false;
System.out.println("Error: deiconifying action was not detected");
err("deiconifying action was not detected");
}
}
};

View File

@@ -22,11 +22,7 @@
*/
import com.jetbrains.JBR;
import com.jetbrains.WindowDecorations;
import util.CommonAPISuite;
import util.Rect;
import util.ScreenShotHelpers;
import util.Task;
import util.TestUtils;
import util.*;
import javax.swing.JFrame;
import java.awt.Frame;
@@ -37,6 +33,7 @@ import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import java.awt.image.BufferedImage;
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.function.Function;
@@ -59,10 +56,11 @@ public class FrameNativeControlsTest {
public static void main(String... args) {
List<Function<WindowDecorations.CustomTitleBar, Window>> functions =
List.of(TestUtils::createFrameWithCustomTitleBar, TestUtils::createJFrameWithCustomTitleBar);
boolean status = CommonAPISuite.runTestSuite(functions, frameNativeControlsClicks);
TaskResult result = CommonAPISuite.runTestSuite(functions, frameNativeControlsClicks);
if (!status) {
throw new RuntimeException("FrameNativeControlsTest FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
@@ -140,7 +138,7 @@ public class FrameNativeControlsTest {
robot.delay(500);
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
List<Rect> foundControls = ScreenShotHelpers.detectControlsByBackground(image, (int) titleBar.getHeight(), TestUtils.TITLE_BAR_COLOR);
List<Rect> foundControls = ScreenShotHelpers.findControls(image, window, titleBar);
if (foundControls.size() == 0) {
passed = false;
@@ -169,22 +167,18 @@ public class FrameNativeControlsTest {
});
if (!maximizingActionDetected) {
passed = false;
System.out.println("Error: maximizing action was not detected");
err("maximizing action was not detected");
}
if (!closingActionCalled) {
passed = false;
System.out.println("Error: closing action was not detected");
err("closing action was not detected");
}
if (!iconifyingActionCalled) {
passed = false;
System.out.println("Error: iconifying action was not detected");
err("iconifying action was not detected");
}
if (!deiconifyindActionDetected) {
passed = false;
System.out.println("Error: deiconifying action was not detected");
err("deiconifying action was not detected");
}
}
};

View File

@@ -21,14 +21,11 @@
* questions.
*/
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Rect;
import util.ScreenShotHelpers;
import util.Task;
import util.TestUtils;
import util.*;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.lang.invoke.MethodHandles;
import java.util.List;
/*
@@ -48,10 +45,11 @@ import java.util.List;
public class HiddenNativeControlsTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), hiddenControls);
TaskResult result = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), hiddenControls);
if (!status) {
throw new RuntimeException("HiddenNativeControlsTest FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
@@ -77,25 +75,22 @@ public class HiddenNativeControlsTest {
passed = passed && TestUtils.checkFrameInsets(window);
if (!"false".equals(titleBar.getProperties().get(PROPERTY_NAME).toString())) {
passed = false;
System.out.println("controls.visible isn't false");
err("controls.visible isn't false");
}
if (titleBar.getLeftInset() != 0 || titleBar.getRightInset() != 0) {
passed = false;
System.out.println("System controls are hidden so insets must be zero");
err("System controls are hidden so insets must be zero");
}
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
System.out.println("image w = " + image.getWidth() + " h = " + image.getHeight());
List<Rect> foundControls = ScreenShotHelpers.detectControlsByBackground(image, (int) titleBar.getHeight(), TestUtils.TITLE_BAR_COLOR);
List<Rect> foundControls = ScreenShotHelpers.findControls(image, window, titleBar, true);
System.out.println("Found controls at the title bar:");
foundControls.forEach(System.out::println);
if (foundControls.size() != 0) {
passed = false;
System.out.println("Error: there are must be 0 controls");
err("controls are disabled, but found in the screenshot");
}
if (!passed) {

View File

@@ -24,6 +24,7 @@
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Task;
import util.TaskResult;
import util.TestUtils;
import javax.swing.JDialog;
@@ -39,6 +40,7 @@ import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.List;
@@ -59,13 +61,13 @@ import java.util.List;
public class HitTestClientArea {
public static void main(String... args) {
boolean awtStatus = CommonAPISuite.runTestSuite(List.of(TestUtils::createFrameWithCustomTitleBar, TestUtils::createDialogWithCustomTitleBar), hitTestClientAreaAWT);
boolean swingStatus = CommonAPISuite.runTestSuite(List.of(TestUtils::createJFrameWithCustomTitleBar, TestUtils::createJFrameWithCustomTitleBar), hitTestClientAreaSwing);
TaskResult awtResult = CommonAPISuite.runTestSuite(List.of(TestUtils::createFrameWithCustomTitleBar, TestUtils::createDialogWithCustomTitleBar), hitTestClientAreaAWT);
TaskResult swingResult = CommonAPISuite.runTestSuite(List.of(TestUtils::createJFrameWithCustomTitleBar, TestUtils::createJFrameWithCustomTitleBar), hitTestClientAreaSwing);
boolean status = awtStatus && swingStatus;
if (!status) {
throw new RuntimeException("HitTestClientArea FAILED");
TaskResult result = awtResult.merge(swingResult);
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
@@ -147,6 +149,7 @@ public class HitTestClientArea {
int initialX = window.getLocationOnScreen().x + PANEL_WIDTH / 2;
int initialY = window.getLocationOnScreen().y + PANEL_HEIGHT / 2;
window.requestFocus();
for (Integer mask: BUTTON_MASKS) {
robot.waitForIdle();
@@ -174,24 +177,20 @@ public class HitTestClientArea {
for (int i = 0; i < BUTTON_MASKS.size(); i++) {
System.out.println("Button no " + (i+1) + " clicks count = " + gotClicks[i]);
if (gotClicks[i] == 0) {
System.out.println("Mouse click to button no " + (i+1) + " was not registered");
passed = false;
err("Mouse click to button no " + (i+1) + " was not registered");
}
}
boolean moved = initialLocation.x < newLocation.x && initialLocation.y < newLocation.y;
if (moved) {
System.out.println("Window was moved, but drag'n drop action must be disabled in the client area");
passed = false;
err("Window was moved, but drag'n drop action must be disabled in the client area");
}
if (!mousePressed) {
System.out.println("Mouse press to the client area wasn't detected");
passed = false;
err("Mouse press to the client area wasn't detected");
}
if (!mouseReleased) {
System.out.println("Mouse release to the client area wasn't detected");
passed = false;
err("Mouse release to the client area wasn't detected");
}
}
@@ -308,24 +307,20 @@ public class HitTestClientArea {
for (int i = 0; i < BUTTON_MASKS.size(); i++) {
System.out.println("Button no " + (i+1) + " clicks count = " + gotClicks[i]);
if (gotClicks[i] == 0) {
System.out.println("Mouse click to button no " + (i+1) + " was not registered");
passed = false;
err("Mouse click to button no " + (i+1) + " was not registered");
}
}
boolean moved = initialLocation.x < newLocation.x && initialLocation.y < newLocation.y;
if (moved) {
System.out.println("Window was moved, but drag'n drop action must be disabled in the client area");
passed = false;
err("Window was moved, but drag'n drop action must be disabled in the client area");
}
if (!mousePressed) {
System.out.println("Mouse press to the client area wasn't detected");
passed = false;
err("Mouse press to the client area wasn't detected");
}
if (!mouseReleased) {
System.out.println("Mouse release to the client area wasn't detected");
passed = false;
err("Mouse release to the client area wasn't detected");
}
}

View File

@@ -24,6 +24,7 @@
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Task;
import util.TaskResult;
import util.TestUtils;
import java.awt.AWTException;
@@ -35,6 +36,7 @@ import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.List;
@@ -55,10 +57,11 @@ import java.util.List;
public class HitTestNonClientArea {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), hitTestNonClientArea);
TaskResult result = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), hitTestNonClientArea);
if (!status) {
throw new RuntimeException("HitTestNonClientArea FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
@@ -162,8 +165,7 @@ public class HitTestNonClientArea {
}
for (int i = 0; i < BUTTON_MASKS.size(); i++) {
if (!gotClicks[i]) {
System.out.println("Mouse click to button no " + (i+1) + " was not registered");
passed = false;
err("Mouse click to button no " + (i+1) + " was not registered");
}
}
}

View File

@@ -21,10 +21,7 @@
* questions.
*/
import com.jetbrains.JBR;
import util.Rect;
import util.ScreenShotHelpers;
import util.Task;
import util.TestUtils;
import util.*;
import java.awt.Robot;
import java.awt.event.InputEvent;
@@ -33,6 +30,7 @@ import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import java.awt.image.BufferedImage;
import java.lang.invoke.MethodHandles;
import java.util.List;
/*
@@ -52,10 +50,11 @@ import java.util.List;
public class JDialogNativeControlsTest {
public static void main(String... args) {
boolean status = nativeControlClicks.run(TestUtils::createJDialogWithCustomTitleBar);
TaskResult result = nativeControlClicks.run(TestUtils::createJDialogWithCustomTitleBar);
if (!status) {
throw new RuntimeException("JDialogNativeControlsTest FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
@@ -112,7 +111,7 @@ public class JDialogNativeControlsTest {
robot.delay(500);
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
List<Rect> foundControls = ScreenShotHelpers.detectControlsByBackground(image, (int) titleBar.getHeight(), TestUtils.TITLE_BAR_COLOR);
List<Rect> foundControls = ScreenShotHelpers.findControls(image, window, titleBar);
if (foundControls.size() == 0) {
passed = false;
@@ -143,14 +142,12 @@ public class JDialogNativeControlsTest {
final String os = System.getProperty("os.name").toLowerCase();
if (os.startsWith("mac os")) {
if (!maximizingActionDetected) {
passed = false;
System.out.println("Error: maximizing action was not detected");
err("maximizing action was not detected");
}
}
if (!closingActionCalled) {
passed = false;
System.out.println("Error: closing action was not detected");
err("closing action was not detected");
}
}

View File

@@ -25,6 +25,7 @@ import com.jetbrains.JBR;
import com.jetbrains.WindowDecorations;
import util.CommonAPISuite;
import util.Task;
import util.TaskResult;
import util.TestUtils;
import java.awt.AWTException;
@@ -35,6 +36,7 @@ import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.InputEvent;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
@@ -64,14 +66,15 @@ public class MaximizeWindowTest {
functions = TestUtils.getWindowCreationFunctions();
}
boolean status = CommonAPISuite.runTestSuite(functions, maximizeWindow);
TaskResult result = CommonAPISuite.runTestSuite(functions, maximizeWindow);
if (!status) {
throw new RuntimeException("MaximizeWindowTest FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
private static final Task maximizeWindow = new Task("Maximize frame") {
private static final Task maximizeWindow = new Task("Maximize window") {
@Override
public void prepareTitleBar() {
@@ -90,8 +93,7 @@ public class MaximizeWindowTest {
System.out.printf(String.format("Initial size (w = %d, h = %d)%n", window.getWidth(), window.getHeight()));
System.out.printf(String.format("New size (w = %d, h = %d)%n", window.getWidth(), window.getHeight()));
if (initialHeight == window.getHeight() && initialWidth == window.getWidth()) {
passed = false;
System.out.println("Frame size wasn't changed");
err("Frame size wasn't changed after double click to title bar");
}
setResizable(false);
@@ -102,8 +104,7 @@ public class MaximizeWindowTest {
System.out.printf(String.format("Initial size (w = %d, h = %d)%n", window.getWidth(), window.getHeight()));
System.out.printf(String.format("New size (w = %d, h = %d)%n", window.getWidth(), window.getHeight()));
if (initialHeight != window.getHeight() || initialWidth != window.getWidth()) {
passed = false;
System.out.println("Frame size was changed");
err("Frame size was changed after double click to title bar, but resize is disabled");
}
}
@@ -121,7 +122,7 @@ public class MaximizeWindowTest {
System.out.println("Window was created with bounds: " + window.getBounds());
int w = window.getBounds().width / 2;
int h = window.getBounds().height / 2;
int h = Math.max(window.getBounds().height / 2, 20 + (int) titleBar.getHeight());
window.setBounds(window.getBounds().x, window.getBounds().y, w, h);
System.out.println("New window bounds: " + window.getBounds());
@@ -154,4 +155,4 @@ public class MaximizeWindowTest {
robot.delay(1000);
}
}
}

View File

@@ -22,10 +22,7 @@
*/
import com.jetbrains.JBR;
import util.Rect;
import util.ScreenShotHelpers;
import util.Task;
import util.TestUtils;
import util.*;
import java.awt.Frame;
import java.awt.event.InputEvent;
@@ -34,6 +31,7 @@ import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import java.awt.image.BufferedImage;
import java.lang.invoke.MethodHandles;
import java.util.List;
/*
@@ -53,10 +51,11 @@ import java.util.List;
public class MinimizingWindowTest {
public static void main(String... args) {
boolean status = minimizingWindowTest.run(TestUtils::createFrameWithCustomTitleBar);
TaskResult result = minimizingWindowTest.run(TestUtils::createFrameWithCustomTitleBar);
if (!status) {
throw new RuntimeException("MinimizingWindowTest FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
@@ -116,11 +115,10 @@ public class MinimizingWindowTest {
robot.waitForIdle();
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
List<Rect> foundControls = ScreenShotHelpers.detectControlsByBackground(image, (int) titleBar.getHeight(), TestUtils.TITLE_BAR_COLOR);
List<Rect> foundControls = ScreenShotHelpers.findControls(image, window, titleBar);
if (foundControls.size() == 0) {
passed = false;
System.out.println("Error: no controls found");
err("no controls found");
}
foundControls.forEach(control -> {
@@ -145,8 +143,7 @@ public class MinimizingWindowTest {
});
if (!iconifyingActionCalled || !iconifyingActionDetected) {
passed = false;
System.out.println("Error: iconifying action was not detected");
err("iconifying action was not detected");
}
if (!passed) {

View File

@@ -23,6 +23,7 @@
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Task;
import util.TaskResult;
import util.TestUtils;
import java.awt.AWTException;
@@ -34,6 +35,7 @@ import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.List;
@@ -54,10 +56,11 @@ import java.util.List;
public class MouseEventsOnClientArea {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), mouseClicks);
TaskResult result = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), mouseClicks);
if (!status) {
throw new RuntimeException("MouseEventsOnClientArea FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
@@ -133,31 +136,29 @@ public class MouseEventsOnClientArea {
public void test() throws AWTException {
Robot robot = new Robot();
int x = panel.getLocationOnScreen().x + panel.getWidth() / 2;
int y = panel.getLocationOnScreen().y + panel.getHeight() / 2;
BUTTON_MASKS.forEach(mask -> {
robot.delay(500);
robot.mouseMove(panel.getLocationOnScreen().x + panel.getWidth() / 2,
panel.getLocationOnScreen().y + panel.getHeight() / 2);
robot.mouseMove(x, y);
robot.mousePress(mask);
robot.mouseRelease(mask);
robot.delay(500);
});
robot.delay(500);
robot.mouseMove(panel.getLocationOnScreen().x + panel.getWidth() / 2,
panel.getLocationOnScreen().y + panel.getHeight() / 2);
robot.delay(500);
robot.mouseMove(panel.getLocationOnScreen().x + panel.getWidth() + 10,
panel.getLocationOnScreen().y + panel.getWidth() + 10);
robot.delay(500);
boolean status = true;
for (int i = 0; i < BUTTON_MASKS.size(); i++) {
System.out.println("Button mask: " + BUTTON_MASKS.get(i));
System.out.println("pressed = " + buttonsPressed[i]);
System.out.println("released = " + buttonsReleased[i]);
System.out.println("clicked = " + buttonsClicked[i]);
passed = buttonsPressed[i] && buttonsReleased[i] && buttonsClicked[i];
status = status && buttonsPressed[i] && buttonsReleased[i] && buttonsClicked[i];
}
if (!status) {
err("some of mouse events weren't registered");
}
}
};

View File

@@ -22,14 +22,11 @@
*/
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Rect;
import util.Task;
import util.ScreenShotHelpers;
import util.TestUtils;
import util.*;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.lang.invoke.MethodHandles;
import java.util.List;
/*
@@ -49,15 +46,15 @@ import java.util.List;
public class NativeControlsVisibilityTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), visibleControls);
TaskResult result = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), visibleControls);
if (!status) {
throw new RuntimeException("NativeControlsVisibilityTest FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
private static final Task visibleControls = new Task("Visible native controls") {
private static final String PROPERTY_NAME = "controls.visible";
@Override
public void prepareTitleBar() {
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
@@ -82,7 +79,7 @@ public class NativeControlsVisibilityTest {
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
List<Rect> foundControls = ScreenShotHelpers.detectControlsByBackground(image, (int) titleBar.getHeight(), TestUtils.TITLE_BAR_COLOR);
List<Rect> foundControls = ScreenShotHelpers.findControls(image, window, titleBar, false);
System.out.println("Found controls at the title bar:");
foundControls.forEach(System.out::println);

View File

@@ -21,16 +21,13 @@
* questions.
*/
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.RectCoordinates;
import util.Task;
import util.ScreenShotHelpers;
import util.TestUtils;
import util.*;
import java.awt.Dimension;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.lang.invoke.MethodHandles;
/*
* @test
@@ -49,10 +46,11 @@ import java.awt.image.BufferedImage;
public class WindowResizeTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), windowResizeTest);
TaskResult result = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), windowResizeTest);
if (!status) {
throw new RuntimeException("WindowResizeTest FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
@@ -78,8 +76,7 @@ public class WindowResizeTest {
robot.delay(1000);
if (titleBar.getHeight() != initialTitleBarHeight) {
passed = false;
System.out.println("Error: title bar height has been changed");
err("title bar height has been changed");
}
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);

View File

@@ -23,9 +23,11 @@
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Task;
import util.TaskResult;
import util.TestUtils;
import java.awt.Robot;
import java.lang.invoke.MethodHandles;
/*
* @test
@@ -44,10 +46,11 @@ import java.awt.Robot;
public class WindowVisibilityTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), visibilityTest);
TaskResult result = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), visibilityTest);
if (!status) {
throw new RuntimeException("WindowVisibilityTest FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
@@ -72,12 +75,10 @@ public class WindowVisibilityTest {
robot.delay(1000);
if (titleBarHeight != titleBar.getHeight()) {
passed = false;
System.out.println("Error: title bar height has been changed");
err("Error: title bar height has been changed");
}
if (!titleBar.getContainingWindow().equals(window)) {
passed = false;
System.out.println("Error: wrong containing window");
err("wrong containing window");
}
}

View File

@@ -22,15 +22,12 @@
*/
import com.jetbrains.JBR;
import util.CommonAPISuite;
import util.Rect;
import util.ScreenShotHelpers;
import util.Task;
import util.TestUtils;
import util.*;
import java.awt.Color;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.lang.invoke.MethodHandles;
import java.util.List;
/*
@@ -38,30 +35,23 @@ import java.util.List;
* @summary Verify a property to change visibility of native controls
* @requires os.family == "windows"
* @run main/othervm WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5 WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5 WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0 WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0 WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5 WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5 WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0 WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0 WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5 WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5 WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 10" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0 WindowsControlWidthTest
* @run main/othervm -Dos.version=10 -Dos.name="Windows 11" -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0 WindowsControlWidthTest
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 WindowsControlWidthTest
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 WindowsControlWidthTest
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5 WindowsControlWidthTest
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0 WindowsControlWidthTest
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5 WindowsControlWidthTest
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0 WindowsControlWidthTest
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5 WindowsControlWidthTest
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0 WindowsControlWidthTest
*/
public class WindowsControlWidthTest {
public static void main(String... args) {
boolean status = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), nativeControlsWidth);
TaskResult result = CommonAPISuite.runTestSuite(TestUtils.getWindowCreationFunctions(), nativeControlsWidth);
if (!status) {
throw new RuntimeException("WindowsControlWidthTest FAILED");
if (!result.isPassed()) {
final String message = String.format("%s FAILED. %s", MethodHandles.lookup().lookupClass().getName(), result.getError());
throw new RuntimeException(message);
}
}
@@ -83,17 +73,15 @@ public class WindowsControlWidthTest {
passed = passed && TestUtils.checkFrameInsets(window);
if (titleBar.getLeftInset() == 0 && titleBar.getRightInset() == 0) {
passed = false;
System.out.println("Left or right inset must be non-zero");
err("Left or right inset must be non-zero");
}
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
List<Rect> foundControls = ScreenShotHelpers.detectControlsByBackground(image, (int) titleBar.getHeight(), TestUtils.TITLE_BAR_COLOR);
List<Rect> foundControls = ScreenShotHelpers.findControls(image, window, titleBar);
if (foundControls.size() == 0) {
System.out.println("Error: controls not found");
passed = false;
err("controls not found");
} else if (foundControls.size() == 3) {
System.out.println("3 controls found");
int minX = foundControls.get(0).getX1();
@@ -102,19 +90,16 @@ public class WindowsControlWidthTest {
int calculatedWidth = maxX - minX + dist;
float diff = (float) calculatedWidth / CONTROLS_WIDTH;
if (diff < 0.95 || diff > 1.05) {
System.out.println("Error: control's width is much differ than the expected value");
passed = false;
err("control's width is much differ than the expected value");
}
} else if (foundControls.size() == 1){
System.out.println("1 control found");
int calculatedWidth = foundControls.get(0).getX2() - foundControls.get(0).getX1();
if (calculatedWidth < 0.5) {
System.out.println("Error: control's width is much differ than the expected value");
passed = false;
err("control's width is much differ than the expected value");
}
} else {
System.out.println("Error: unexpected controls count = " + foundControls.size());
passed = false;
err("unexpected controls count = " + foundControls.size());
}
}

View File

@@ -26,17 +26,24 @@ package util;
import com.jetbrains.WindowDecorations;
import java.awt.Window;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.stream.Collectors;
public class CommonAPISuite {
public static boolean runTestSuite(List<Function<WindowDecorations.CustomTitleBar, Window>> functions, Task task) {
public static TaskResult runTestSuite(List<Function<WindowDecorations.CustomTitleBar, Window>> functions, Task task) {
AtomicBoolean testPassed = new AtomicBoolean(true);
functions.forEach(function -> testPassed.set(testPassed.get() && task.run(function)));
List<String> errors = new ArrayList<>();
functions.forEach(function -> {
TaskResult result = task.run(function);
testPassed.set(testPassed.get() && result.isPassed());
errors.add(result.getError());
});
return testPassed.get();
return new TaskResult(testPassed.get(), errors.stream().collect(Collectors.joining("\n")));
}
}

View File

@@ -22,6 +22,8 @@
*/
package util;
import com.jetbrains.WindowDecorations;
import javax.imageio.ImageIO;
import java.awt.AWTException;
import java.awt.Color;
@@ -57,6 +59,88 @@ public class ScreenShotHelpers {
return file.getAbsolutePath();
}
public static List<Rect> findControls(BufferedImage image, Window window, WindowDecorations.CustomTitleBar titleBar) {
return findControls(image, window, titleBar, false);
}
public static List<Rect> findControls(BufferedImage image, Window window, WindowDecorations.CustomTitleBar titleBar, boolean disabledControls) {
final int windowWidth = window.getWidth();
final int windowHeight = window.getHeight();
final int titleBarHeight = (int) titleBar.getHeight();
final int leftInset = Math.round(titleBar.getLeftInset());
final int rightInset = Math.round(titleBar.getRightInset());
System.out.println("Image w = " + image.getWidth() + " height = " + image.getHeight());
System.out.println("Window w = " + windowWidth + " height = " + window.getHeight());
// option 1
List<Rect> controls1 = detectControlsByBackground(image, titleBarHeight, TestUtils.TITLE_BAR_COLOR);
System.out.println("Option1 for " + window.getName());
controls1.forEach(System.out::println);
if (isMatchCondition(window, controls1.size(), disabledControls)) {
return controls1;
}
// option2
List<Rect> controls2 = detectControlsByBackground2(image, windowWidth, windowHeight, titleBarHeight, leftInset, rightInset, TestUtils.TITLE_BAR_COLOR);
System.out.println("Option2 for " + window.getName());
controls2.forEach(System.out::println);
if (isMatchCondition(window, controls2.size(), disabledControls)) {
return controls2;
}
// option3
List<Rect> controls3 = detectControls(image, titleBarHeight, leftInset, rightInset);
System.out.println("Option3 for " + window.getName());
controls3.forEach(System.out::println);
if (isMatchCondition(window, controls3.size(), disabledControls)) {
return controls3;
}
// option4
List<Rect> controls4 = detectControls2(image, windowWidth, windowHeight, titleBarHeight, leftInset, rightInset);
System.out.println("Option4 for " + window.getName());
controls4.forEach(System.out::println);
return controls4;
}
private static boolean isMatchCondition(Window window, int size, boolean disabledControls) {
if (!disabledControls) {
if (window.getName().equals("Frame") || window.getName().equals("JFrame")) {
return size == 3;
}
if (window.getName().equals("Dialog") || window.getName().equals("JDialog")) {
final String os = System.getProperty("os.name").toLowerCase();
if (os.startsWith("windows")) {
return size == 1;
}
return size == 3;
}
}
return size == 0;
}
public static RectCoordinates calculateControlsRect(BufferedImage image, int windowWidth, int windowHeight, int titleBarHeight, int leftInset, int rightInset) {
final int shiftW = (image.getWidth() - windowWidth) / 2;
final int shiftH = (image.getHeight() - windowHeight) / 2;
int x1;
int y1 = shiftH;
int x2;
int y2 = shiftH + titleBarHeight;
if (leftInset > rightInset) {
x1 = shiftW;
x2 = shiftW + leftInset;
} else {
x1 = shiftW + windowWidth - rightInset;
x2 = windowWidth - shiftW;
}
return new RectCoordinates(x1, y1, x2, y2);
}
public static RectCoordinates findRectangleTitleBar(BufferedImage image, int titleBarHeight) {
int centerX = image.getWidth() / 2;
int centerY = titleBarHeight / 2;
@@ -106,6 +190,7 @@ public class ScreenShotHelpers {
RectCoordinates coords = findRectangleTitleBar(image, titleBarHeight);
List<Rect> result = new ArrayList<>();
System.out.println("Detect controls by background");
System.out.println(coords);
List<Integer> lefts = new ArrayList<>();
@@ -114,9 +199,54 @@ public class ScreenShotHelpers {
int leftX = -1;
int rightX = -1;
for (int x = coords.x1(); x <= coords.x2(); x++) {
for (int x = coords.x1(); x < coords.x2(); x++) {
boolean isBackground = true;
for (int y = coords.y1(); y <= coords.y2(); y++) {
for (int y = coords.y1(); y < coords.y2(); y++) {
Color color = adjustColor(new Color(image.getRGB(x, y)));
if (!color.equals(backgroundColor)) {
isBackground = false;
break;
}
}
if (!isBackground) {
if (leftX == -1) {
leftX = x;
}
rightX = x;
} else if (leftX != -1) {
lefts.add(leftX);
rights.add(rightX);
leftX = -1;
rightX = -1;
}
}
for (int i = 0; i < lefts.size(); i++) {
int lx = lefts.get(i);
int rx = rights.get(i);
System.out.println("lx = " + lx + " rx = " + rx);
result.add(new Rect(lx, coords.y1(), rx, coords.y2(), 0, Color.BLACK));
}
return result;
}
public static List<Rect> detectControlsByBackground2(BufferedImage image, int windowWidth, int windowHeight, int titleBarHeight, int leftInset, int rightInset, Color backgroundColor) {
RectCoordinates coords = calculateControlsRect(image, windowWidth, windowHeight, titleBarHeight, leftInset, rightInset);
List<Rect> result = new ArrayList<>();
System.out.println("Detect controls by background2");
System.out.println(coords);
List<Integer> lefts = new ArrayList<>();
List<Integer> rights = new ArrayList<>();
int leftX = -1;
int rightX = -1;
for (int x = coords.x1(); x < coords.x2(); x++) {
boolean isBackground = true;
for (int y = coords.y1(); y < coords.y2(); y++) {
Color color = adjustColor(new Color(image.getRGB(x, y)));
if (!color.equals(backgroundColor)) {
isBackground = false;
@@ -148,11 +278,41 @@ public class ScreenShotHelpers {
public static List<Rect> detectControls(BufferedImage image, int titleBarHeight, int leftInset, int rightInset) {
RectCoordinates coords = ScreenShotHelpers.findRectangleTitleBar(image, titleBarHeight);
System.out.println("Detect controls");
System.out.println(coords);
Map<Color, Rect> map = new HashMap<>();
for (int x = coords.x1(); x <= coords.x2(); x++) {
for (int y = coords.y1(); y <= coords.y2(); y++) {
for (int x = coords.x1(); x < coords.x2(); x++) {
for (int y = coords.y1(); y < coords.y2(); y++) {
Color color = new Color(image.getRGB(x, y));
Color adjustedColor = adjustColor(color);
Rect rect = map.getOrDefault(adjustedColor, new Rect(adjustedColor));
rect.addPoint(x, y);
map.put(adjustedColor, rect);
}
}
int checkedHeight = coords.y2() - coords.y1() + 1;
int checkedWidth = coords.x2() - coords.x1() + 1;
int pixels = checkedWidth * checkedHeight;
int nonCoveredAreaApprox = pixels - (leftInset * checkedHeight + rightInset * checkedHeight);
List<Rect> rects = map.values().stream().filter(v -> v.getPixelCount() < nonCoveredAreaApprox).toList();
return groupRects(rects);
}
public static List<Rect> detectControls2(BufferedImage image, int windowWidth, int windowHeight, int titleBarHeight, int leftInset, int rightInset) {
RectCoordinates coords = calculateControlsRect(image, windowWidth, windowHeight, titleBarHeight, leftInset, rightInset);
System.out.println("Detect controls 2");
System.out.println(coords);
Map<Color, Rect> map = new HashMap<>();
for (int x = coords.x1(); x < coords.x2(); x++) {
for (int y = coords.y1(); y < coords.y2(); y++) {
Color color = new Color(image.getRGB(x, y));
Color adjustedColor = adjustColor(color);
Rect rect = map.getOrDefault(adjustedColor, new Rect(adjustedColor));

View File

@@ -36,23 +36,25 @@ abstract public class Task {
protected Window window;
protected boolean passed = true;
protected Robot robot;
protected String error;
public Task(String name) {
this.name = name;
}
public final boolean run(Function<WindowDecorations.CustomTitleBar, Window> windowCreator) {
public final TaskResult run(Function<WindowDecorations.CustomTitleBar, Window> windowCreator) {
try {
robot = new Robot();
} catch (AWTException e) {
System.out.println("ERROR: unable to initialize robot");
final String message = "ERROR: unable to initialize robot";
e.printStackTrace();
return false;
return new TaskResult(false, message);
}
init();
System.out.printf("RUN TEST CASE: %s%n", name);
passed = true;
error = "";
prepareTitleBar();
window = windowCreator.apply(titleBar);
System.out.println("Created a window with the custom title bar. Window name: " + window.getName());
@@ -71,12 +73,21 @@ abstract public class Task {
titleBar = null;
window.dispose();
if (passed) {
System.out.println("State: PASSED");
} else {
System.out.println("State: FAILED");
if (!TestUtils.isBasicTestCase()) {
boolean isMetConditions = TestUtils.checkScreenSizeConditions(window);
if (!isMetConditions) {
error += "SKIPPED: environment don't match screen size conditions";
return new TaskResult(false, true, error);
}
}
return passed;
return new TaskResult(passed, error);
}
protected void err(String message) {
this.error = error + message + "\n";
passed = false;
System.out.println(message);
}
protected void init() {

View File

@@ -0,0 +1,35 @@
package util;
public class TaskResult {
private final boolean passed;
private final boolean metConditions;
private final String error;
public TaskResult(boolean passed, String error) {
this.passed = passed;
this.metConditions = true;
this.error = error;
}
public TaskResult(boolean metConditions, boolean passed, String error) {
this.metConditions = metConditions;
this.passed = passed;
this.error = error;
}
public boolean isPassed() {
return passed;
}
public String getError() {
return error;
}
public TaskResult merge(TaskResult another) {
final String error = this.error + "\n" + another.error;
final boolean status = this.passed && another.passed;
return new TaskResult(status, error);
}
}

View File

@@ -160,14 +160,56 @@ public class TestUtils {
return dialog;
}
private static Rectangle calculateWindowBounds(Window window) {
public static boolean isBasicTestCase() {
return getUIScale() == 1.0;
}
public static boolean checkScreenSizeConditions(Window window) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Insets scnMax = Toolkit.getDefaultToolkit().
getScreenInsets(window.getGraphicsConfiguration());
int maxHeight = screenSize.height - scnMax.top - scnMax.bottom;
int maxWidth = screenSize.width - scnMax.left - scnMax.right;
System.out.println("Screen size: " + screenSize);
System.out.println("Screen insets: " + scnMax);
final int width = screenSize.width - scnMax.left - scnMax.right;
final int height = screenSize.height - scnMax.top - scnMax.bottom;
System.out.println("Max width = " + width + " max height = " + height);
return new Rectangle(scnMax.left + 2, scnMax.top + 2, (int) (maxWidth * 0.8), (int) (maxHeight * 0.8));
double uiScale = getUIScale();
final int effectiveWidth = (int) (width / uiScale);
final int effectiveHeight = (int) (height / uiScale);
if (effectiveWidth < 200 || effectiveHeight < 200) {
return false;
}
return true;
}
private static Rectangle calculateWindowBounds(Window window) {
double uiScale = getUIScale();
System.out.println("UI Scale: " + uiScale);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
System.out.println("Screen size: " + screenSize);
Insets scnMax = Toolkit.getDefaultToolkit().
getScreenInsets(window.getGraphicsConfiguration());
int maxHeight = (int) ((screenSize.height - scnMax.top - scnMax.bottom) / uiScale);
int maxWidth = (int) ((screenSize.width - scnMax.left - scnMax.right) / uiScale);
Rectangle bounds = new Rectangle(scnMax.left + 2, scnMax.top + 2, (int) (maxWidth * 0.95), (int) (maxHeight * 0.95));
System.out.println("Window bounds: " + bounds);
return bounds;
}
public static double getUIScale() {
boolean scaleEnabled = "true".equals(System.getProperty("sun.java2d.uiScale.enabled"));
double uiScale = 1.0;
if (scaleEnabled) {
uiScale = Float.parseFloat(System.getProperty("sun.java2d.uiScale"));
}
return uiScale;
}
}