mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
JBR-6354 fix custom title bar tests to avoid failure in MacOS 14 fullscreen mode
- moved common logic to a separate part - moved parts of tests to swing package
This commit is contained in:
@@ -22,7 +22,11 @@
|
||||
*/
|
||||
|
||||
import com.jetbrains.JBR;
|
||||
import util.*;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
import test.jb.testhelpers.TitleBar.CommonAPISuite;
|
||||
import test.jb.testhelpers.utils.MouseUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -34,6 +38,8 @@ import java.util.List;
|
||||
* @test
|
||||
* @summary Verify mouse events in custom title bar's area added by ActionListener
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm ActionListenerTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 ActionListenerTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 ActionListenerTest
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
*/
|
||||
|
||||
import com.jetbrains.JBR;
|
||||
import util.CommonAPISuite;
|
||||
import util.Task;
|
||||
import util.TaskResult;
|
||||
import util.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.CommonAPISuite;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
|
||||
@@ -33,6 +33,8 @@ import java.lang.invoke.MethodHandles;
|
||||
* @test
|
||||
* @summary Verify modifying of title bar height
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm ChangeTitleBarHeightTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 ChangeTitleBarHeightTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 ChangeTitleBarHeightTest
|
||||
|
||||
@@ -1,6 +1,29 @@
|
||||
/*
|
||||
* Copyright 2000-2023 JetBrains s.r.o.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import com.jetbrains.JBR;
|
||||
import com.jetbrains.WindowDecorations;
|
||||
import util.ScreenShotHelpers;
|
||||
import test.jb.testhelpers.screenshot.ScreenShotHelpers;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Color;
|
||||
@@ -16,6 +39,8 @@ import java.io.IOException;
|
||||
* @test
|
||||
* @summary Verify modifying of title bar height
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm CheckFullScreen
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 CheckFullScreen
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 CheckFullScreen
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
*/
|
||||
|
||||
import com.jetbrains.JBR;
|
||||
import util.CommonAPISuite;
|
||||
import util.Task;
|
||||
import util.TaskResult;
|
||||
import util.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.CommonAPISuite;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
|
||||
@@ -33,6 +33,8 @@ import java.lang.invoke.MethodHandles;
|
||||
* @test
|
||||
* @summary Verify creating to a custom title bar
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm CreateTitleBarTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 CreateTitleBarTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 CreateTitleBarTest
|
||||
|
||||
@@ -21,7 +21,11 @@
|
||||
* questions.
|
||||
*/
|
||||
import com.jetbrains.JBR;
|
||||
import util.*;
|
||||
import test.jb.testhelpers.screenshot.ScreenShotHelpers;
|
||||
import test.jb.testhelpers.screenshot.Rect;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
@@ -36,6 +40,8 @@ import java.util.List;
|
||||
* @test
|
||||
* @summary Detect and check behavior of clicking to native controls
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm DialogNativeControlsTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 DialogNativeControlsTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 DialogNativeControlsTest
|
||||
|
||||
@@ -1,211 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2023 JetBrains s.r.o.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
import com.jetbrains.JBR;
|
||||
import com.jetbrains.WindowDecorations;
|
||||
import util.*;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
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;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Detect and check behavior of clicking to native controls
|
||||
* @requires (os.family == "mac")
|
||||
* @modules java.desktop/com.apple.eawt
|
||||
* java.desktop/com.apple.eawt.event
|
||||
* @run main/othervm FrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 FrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 FrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5 FrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0 FrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5 FrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0 FrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5 FrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0 FrameNativeControlsMacOSTest
|
||||
*/
|
||||
public class FrameNativeControlsMacOSTest {
|
||||
|
||||
public static void main(String... args) {
|
||||
List<Function<WindowDecorations.CustomTitleBar, Window>> functions =
|
||||
List.of(TestUtils::createFrameWithCustomTitleBar, TestUtils::createJFrameWithCustomTitleBar);
|
||||
TaskResult result = CommonAPISuite.runTestSuite(functions, frameNativeControlsClicks);
|
||||
|
||||
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") {
|
||||
private boolean closingActionCalled;
|
||||
private boolean iconifyingActionCalled;
|
||||
private boolean maximizingActionDetected;
|
||||
private boolean deiconifyindActionDetected;
|
||||
|
||||
private final WindowListener windowListener = new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
closingActionCalled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowIconified(WindowEvent e) {
|
||||
iconifyingActionCalled = true;
|
||||
|
||||
if (window.getName().equals("Frame")) {
|
||||
((Frame) window).setState(Frame.NORMAL);
|
||||
} else if (window.getName().equals("JFrame")) {
|
||||
((JFrame) window).setState(JFrame.NORMAL);
|
||||
}
|
||||
|
||||
window.setVisible(true);
|
||||
window.requestFocus();
|
||||
}
|
||||
};
|
||||
|
||||
private final WindowStateListener windowStateListener = new WindowAdapter() {
|
||||
@Override
|
||||
public void windowStateChanged(WindowEvent e) {
|
||||
System.out.println("change " + e.getOldState() + " -> " + e.getNewState());
|
||||
if (e.getNewState() == 6) {
|
||||
maximizingActionDetected = true;
|
||||
}
|
||||
if (e.getOldState() == 1 && e.getNewState() == 0) {
|
||||
deiconifyindActionDetected = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void prepareTitleBar() {
|
||||
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
|
||||
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
closingActionCalled = false;
|
||||
iconifyingActionCalled = false;
|
||||
maximizingActionDetected = false;
|
||||
deiconifyindActionDetected = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanup() {
|
||||
window.removeWindowListener(windowListener);
|
||||
window.removeWindowStateListener(windowStateListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customizeWindow() {
|
||||
window.addWindowListener(windowListener);
|
||||
window.addWindowStateListener(windowStateListener);
|
||||
|
||||
if (window.getName().equals("JFrame")) {
|
||||
com.apple.eawt.FullScreenUtilities.addFullScreenListenerTo(window, new com.apple.eawt.FullScreenListener() {
|
||||
@Override
|
||||
public void windowEnteringFullScreen(com.apple.eawt.event.FullScreenEvent fse) {
|
||||
maximizingActionDetected = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowEnteredFullScreen(com.apple.eawt.event.FullScreenEvent fse) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowExitingFullScreen(com.apple.eawt.event.FullScreenEvent fse) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowExitedFullScreen(com.apple.eawt.event.FullScreenEvent fse) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void test() throws Exception {
|
||||
robot.delay(500);
|
||||
robot.mouseMove(window.getLocationOnScreen().x + window.getWidth() / 2,
|
||||
window.getLocationOnScreen().y + window.getHeight() / 2);
|
||||
robot.delay(500);
|
||||
|
||||
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
|
||||
List<Rect> foundControls = ScreenShotHelpers.findControls(image, window, titleBar);
|
||||
|
||||
if (foundControls.size() == 0) {
|
||||
passed = false;
|
||||
System.out.println("Error: no controls found");
|
||||
}
|
||||
|
||||
foundControls.forEach(control -> {
|
||||
System.out.println("Using control: " + control);
|
||||
int x = window.getLocationOnScreen().x + control.getX1() + (control.getX2() - control.getX1()) / 2;
|
||||
int y = window.getLocationOnScreen().y + control.getY1() + (control.getY2() - control.getY1()) / 2;
|
||||
System.out.println("Click to (" + x + ", " + y + ")");
|
||||
|
||||
int screenX = window.getBounds().x;
|
||||
int screenY = window.getBounds().y;
|
||||
int h = window.getBounds().height;
|
||||
int w = window.getBounds().width;
|
||||
|
||||
robot.waitForIdle();
|
||||
robot.mouseMove(x, y);
|
||||
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
||||
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
||||
robot.waitForIdle();
|
||||
window.setBounds(screenX, screenY, w, h);
|
||||
window.setVisible(true);
|
||||
robot.waitForIdle();
|
||||
});
|
||||
|
||||
if (!maximizingActionDetected) {
|
||||
err("maximizing action was not detected");
|
||||
}
|
||||
|
||||
if (!closingActionCalled) {
|
||||
err("closing action was not detected");
|
||||
}
|
||||
|
||||
if (!iconifyingActionCalled) {
|
||||
err("iconifying action was not detected");
|
||||
}
|
||||
if (!deiconifyindActionDetected) {
|
||||
err("deiconifying action was not detected");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -22,13 +22,12 @@
|
||||
*/
|
||||
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.TaskResult;
|
||||
|
||||
import test.jb.testhelpers.screenshot.ScreenShotHelpers;
|
||||
import test.jb.testhelpers.screenshot.Rect;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
import test.jb.testhelpers.TitleBar.CommonAPISuite;
|
||||
import javax.swing.JFrame;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Window;
|
||||
@@ -45,7 +44,9 @@ import java.util.function.Function;
|
||||
/*
|
||||
* @test
|
||||
* @summary Detect and check behavior of clicking to native controls
|
||||
* @requires (os.family == "windows")
|
||||
* @requires (os.family == "windows") | (os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm FrameNativeControlsTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 FrameNativeControlsTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 FrameNativeControlsTest
|
||||
@@ -59,8 +60,7 @@ import java.util.function.Function;
|
||||
public class FrameNativeControlsTest {
|
||||
|
||||
public static void main(String... args) {
|
||||
List<Function<WindowDecorations.CustomTitleBar, Window>> functions =
|
||||
List.of(TestUtils::createFrameWithCustomTitleBar, TestUtils::createJFrameWithCustomTitleBar);
|
||||
List<Function<WindowDecorations.CustomTitleBar, Window>> functions = List.of(TestUtils::createFrameWithCustomTitleBar);
|
||||
TaskResult result = CommonAPISuite.runTestSuite(functions, frameNativeControlsClicks);
|
||||
|
||||
if (!result.isPassed()) {
|
||||
@@ -145,7 +145,7 @@ public class FrameNativeControlsTest {
|
||||
BufferedImage image = ScreenShotHelpers.takeScreenshot(window);
|
||||
List<Rect> foundControls = ScreenShotHelpers.findControls(image, window, titleBar);
|
||||
|
||||
if (foundControls.size() == 0) {
|
||||
if (foundControls.isEmpty()) {
|
||||
passed = false;
|
||||
System.out.println("Error: no controls found");
|
||||
}
|
||||
|
||||
@@ -21,7 +21,13 @@
|
||||
* questions.
|
||||
*/
|
||||
import com.jetbrains.JBR;
|
||||
import util.*;
|
||||
|
||||
import test.jb.testhelpers.screenshot.ScreenShotHelpers;
|
||||
import test.jb.testhelpers.screenshot.Rect;
|
||||
import test.jb.testhelpers.TitleBar.CommonAPISuite;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
|
||||
import java.awt.Robot;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -32,6 +38,8 @@ import java.util.List;
|
||||
* @test
|
||||
* @summary Verify a property to change visibility of native controls
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm HiddenNativeControlsTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 HiddenNativeControlsTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 HiddenNativeControlsTest
|
||||
@@ -89,7 +97,7 @@ public class HiddenNativeControlsTest {
|
||||
System.out.println("Found controls at the title bar:");
|
||||
foundControls.forEach(System.out::println);
|
||||
|
||||
if (foundControls.size() != 0) {
|
||||
if (!foundControls.isEmpty()) {
|
||||
err("controls are disabled, but found in the screenshot");
|
||||
}
|
||||
|
||||
|
||||
@@ -22,10 +22,15 @@
|
||||
*/
|
||||
|
||||
import com.jetbrains.JBR;
|
||||
import util.*;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
import test.jb.testhelpers.TitleBar.CommonAPISuite;
|
||||
import test.jb.testhelpers.utils.MouseUtils;
|
||||
import util.AWTTask;
|
||||
import util.SwingTask;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.*;
|
||||
import java.awt.event.InputEvent;
|
||||
@@ -39,6 +44,8 @@ import java.util.List;
|
||||
* @test
|
||||
* @summary Verify control under native actions in custom title bar
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm HitTestClientArea
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 HitTestClientArea
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 HitTestClientArea
|
||||
|
||||
@@ -23,7 +23,11 @@
|
||||
|
||||
import com.jetbrains.JBR;
|
||||
import util.*;
|
||||
|
||||
import test.jb.testhelpers.TitleBar.CommonAPISuite;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
import test.jb.testhelpers.utils.MouseUtils;
|
||||
import javax.swing.*;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Button;
|
||||
@@ -42,6 +46,8 @@ import java.util.List;
|
||||
* @test
|
||||
* @summary Verify control under native actions in custom title bar
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm HitTestNonClientArea
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 HitTestNonClientArea
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 HitTestNonClientArea
|
||||
|
||||
@@ -22,7 +22,12 @@
|
||||
*/
|
||||
import com.jetbrains.JBR;
|
||||
import util.*;
|
||||
|
||||
import test.jb.testhelpers.screenshot.ScreenShotHelpers;
|
||||
import test.jb.testhelpers.screenshot.Rect;
|
||||
import test.jb.testhelpers.TitleBar.CommonAPISuite;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
@@ -37,6 +42,8 @@ import java.util.List;
|
||||
* @test
|
||||
* @summary Detect and check behavior of clicking to native controls
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm JDialogNativeControlsTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 JDialogNativeControlsTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 JDialogNativeControlsTest
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
|
||||
import com.jetbrains.JBR;
|
||||
import com.jetbrains.WindowDecorations;
|
||||
import util.CommonAPISuite;
|
||||
import util.Task;
|
||||
import util.TaskResult;
|
||||
import util.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.CommonAPISuite;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Dialog;
|
||||
@@ -42,6 +42,8 @@ import java.util.function.Function;
|
||||
* @test
|
||||
* @summary Verify ability to maximize window by clicking to custom title bar area
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm MaximizeWindowTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 MaximizeWindowTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 MaximizeWindowTest
|
||||
|
||||
@@ -40,6 +40,8 @@ import java.util.concurrent.TimeUnit;
|
||||
* @test
|
||||
* @summary Regression test for JBR-3157 Maximized window with custom decorations isn't focused on showing
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm MaximizedWindowFocusTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 MaximizedWindowFocusTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0 MaximizedWindowFocusTest
|
||||
|
||||
@@ -23,7 +23,12 @@
|
||||
|
||||
import com.jetbrains.JBR;
|
||||
import util.*;
|
||||
|
||||
import test.jb.testhelpers.screenshot.ScreenShotHelpers;
|
||||
import test.jb.testhelpers.screenshot.Rect;
|
||||
import test.jb.testhelpers.TitleBar.CommonAPISuite;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
import java.awt.Frame;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
@@ -38,6 +43,8 @@ import java.util.List;
|
||||
* @test
|
||||
* @summary Detect and check behavior of clicking to native controls
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm MinimizingWindowTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 MinimizingWindowTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 MinimizingWindowTest
|
||||
|
||||
@@ -23,7 +23,10 @@
|
||||
import com.jetbrains.JBR;
|
||||
import com.jetbrains.WindowDecorations;
|
||||
import util.*;
|
||||
|
||||
import test.jb.testhelpers.TitleBar.CommonAPISuite;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.InputEvent;
|
||||
@@ -39,6 +42,8 @@ import java.util.concurrent.TimeUnit;
|
||||
* @test
|
||||
* @summary Verify mouse events on custom title bar area
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm MouseEventsOnClientArea
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 MouseEventsOnClientArea
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 MouseEventsOnClientArea
|
||||
|
||||
@@ -22,17 +22,23 @@
|
||||
*/
|
||||
|
||||
import com.jetbrains.JBR;
|
||||
import util.*;
|
||||
|
||||
import test.jb.testhelpers.screenshot.ScreenShotHelpers;
|
||||
import test.jb.testhelpers.screenshot.Rect;
|
||||
import test.jb.testhelpers.TitleBar.CommonAPISuite;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
import java.awt.Robot;
|
||||
import java.util.List;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verify a property to change visibility of native controls
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm NativeControlsVisibilityTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 NativeControlsVisibilityTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 NativeControlsVisibilityTest
|
||||
|
||||
@@ -21,7 +21,13 @@
|
||||
* questions.
|
||||
*/
|
||||
import com.jetbrains.JBR;
|
||||
import util.*;
|
||||
import test.jb.testhelpers.screenshot.ScreenShotHelpers;
|
||||
import test.jb.testhelpers.screenshot.Rect;
|
||||
import test.jb.testhelpers.screenshot.RectCoordinates;
|
||||
import test.jb.testhelpers.TitleBar.CommonAPISuite;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Robot;
|
||||
@@ -33,6 +39,8 @@ import java.lang.invoke.MethodHandles;
|
||||
* @test
|
||||
* @summary Verify custom title bar in case of window resizing
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm WindowResizeTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 WindowResizeTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 WindowResizeTest
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
* questions.
|
||||
*/
|
||||
import com.jetbrains.JBR;
|
||||
import util.CommonAPISuite;
|
||||
import util.Task;
|
||||
import util.TaskResult;
|
||||
import util.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.CommonAPISuite;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
|
||||
import java.awt.Robot;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
@@ -33,6 +33,8 @@ import java.lang.invoke.MethodHandles;
|
||||
* @test
|
||||
* @summary Verify custom title bar in case of changing visibility of a window
|
||||
* @requires (os.family == "windows" | os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm WindowVisibilityTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 WindowVisibilityTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 WindowVisibilityTest
|
||||
|
||||
@@ -22,7 +22,12 @@
|
||||
*/
|
||||
|
||||
import com.jetbrains.JBR;
|
||||
import util.*;
|
||||
import test.jb.testhelpers.screenshot.ScreenShotHelpers;
|
||||
import test.jb.testhelpers.screenshot.Rect;
|
||||
import test.jb.testhelpers.TitleBar.CommonAPISuite;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Robot;
|
||||
@@ -34,6 +39,8 @@ import java.util.List;
|
||||
* @test
|
||||
* @summary Verify a property to change visibility of native controls
|
||||
* @requires os.family == "windows"
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar ../../../testhelpers/utils
|
||||
* @build TestUtils TaskResult Task CommonAPISuite MouseUtils ScreenShotHelpers Rect RectCoordinates MouseUtils
|
||||
* @run main/othervm 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
|
||||
|
||||
@@ -2,6 +2,9 @@ package util;
|
||||
|
||||
import com.jetbrains.WindowDecorations;
|
||||
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import java.awt.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@ package util;
|
||||
|
||||
import com.jetbrains.WindowDecorations;
|
||||
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Copyright 2000-2023 JetBrains s.r.o.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
import com.apple.eawt.FullScreenListener;
|
||||
import com.apple.eawt.FullScreenUtilities;
|
||||
import com.apple.eawt.event.FullScreenEvent;
|
||||
import com.jetbrains.JBR;
|
||||
import com.jetbrains.WindowDecorations;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import test.jb.testhelpers.screenshot.ScreenShotHelpers;
|
||||
import test.jb.testhelpers.screenshot.Rect;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Detect and check behavior of clicking to native controls
|
||||
* @requires (os.family == "mac")
|
||||
* @library ../../../testhelpers/screenshot ../../../testhelpers/TitleBar
|
||||
* @build TestUtils ScreenShotHelpers Rect RectCoordinates
|
||||
* @modules java.desktop/com.apple.eawt
|
||||
* java.desktop/com.apple.eawt.event
|
||||
* @run main/othervm JFrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.0 JFrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.25 JFrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=1.5 JFrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.0 JFrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=2.5 JFrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.0 JFrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=3.5 JFrameNativeControlsMacOSTest
|
||||
* @run main/othervm -Dsun.java2d.uiScale.enabled=true -Dsun.java2d.uiScale=4.0 JFrameNativeControlsMacOSTest
|
||||
*/
|
||||
public class JFrameNativeControlsMacOSTest {
|
||||
|
||||
private static WindowDecorations.CustomTitleBar titleBar;
|
||||
private static JFrame jFrame;
|
||||
private static WindowListener windowListener;
|
||||
private static WindowStateListener windowStateListener;
|
||||
private static FullScreenListener fullScreenListener;
|
||||
|
||||
private static boolean closingActionCalled = false;
|
||||
private static boolean iconifyingActionCalled = false;
|
||||
private static volatile boolean maximizingActionDetected = false;
|
||||
private static boolean deiconifyindActionDetected = false;
|
||||
private static boolean passed = true;
|
||||
private static String error = "";
|
||||
|
||||
private static Robot robot;
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
robot = new Robot();
|
||||
robot.setAutoDelay(50);
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(JFrameNativeControlsMacOSTest::prepareUI);
|
||||
|
||||
robot.delay(500);
|
||||
robot.mouseMove(jFrame.getLocationOnScreen().x + jFrame.getWidth() / 2,
|
||||
jFrame.getLocationOnScreen().y + jFrame.getHeight() / 2);
|
||||
robot.delay(500);
|
||||
|
||||
BufferedImage image = ScreenShotHelpers.takeScreenshot(jFrame);
|
||||
List<Rect> foundControls = ScreenShotHelpers.findControls(image, jFrame, titleBar);
|
||||
|
||||
if (foundControls.isEmpty()) {
|
||||
System.out.println("Error: no controls found");
|
||||
}
|
||||
foundControls.forEach(control -> {
|
||||
System.out.println("Using control: " + control);
|
||||
int x = jFrame.getLocationOnScreen().x + control.getX1() + (control.getX2() - control.getX1()) / 2;
|
||||
int y = jFrame.getLocationOnScreen().y + control.getY1() + (control.getY2() - control.getY1()) / 2;
|
||||
System.out.println("Click to (" + x + ", " + y + ")");
|
||||
|
||||
int screenX = jFrame.getBounds().x;
|
||||
int screenY = jFrame.getBounds().y;
|
||||
int h = jFrame.getBounds().height;
|
||||
int w = jFrame.getBounds().width;
|
||||
|
||||
robot.waitForIdle();
|
||||
robot.mouseMove(x, y);
|
||||
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
||||
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
||||
robot.waitForIdle();
|
||||
if (maximizingActionDetected) {
|
||||
robot.keyPress(KeyEvent.VK_META);
|
||||
robot.keyPress(KeyEvent.VK_CONTROL);
|
||||
robot.keyPress(KeyEvent.VK_F);
|
||||
robot.keyRelease(KeyEvent.VK_META);
|
||||
robot.keyRelease(KeyEvent.VK_CONTROL);
|
||||
robot.keyRelease(KeyEvent.VK_F);
|
||||
robot.delay(500);
|
||||
}
|
||||
jFrame.setBounds(screenX, screenY, w, h);
|
||||
jFrame.setVisible(true);
|
||||
robot.waitForIdle();
|
||||
});
|
||||
} finally {
|
||||
SwingUtilities.invokeAndWait(JFrameNativeControlsMacOSTest::disposeUI);
|
||||
}
|
||||
|
||||
if (!maximizingActionDetected) {
|
||||
err("maximizing action was not detected");
|
||||
}
|
||||
|
||||
if (!closingActionCalled) {
|
||||
err("closing action was not detected");
|
||||
}
|
||||
|
||||
if (!iconifyingActionCalled) {
|
||||
err("iconifying action was not detected");
|
||||
}
|
||||
if (!deiconifyindActionDetected) {
|
||||
err("deiconifying action was not detected");
|
||||
}
|
||||
if (!passed) {
|
||||
System.out.println("TEST FAILED");
|
||||
} else {
|
||||
System.out.println("TEST PASSED");
|
||||
}
|
||||
}
|
||||
|
||||
private static void prepareUI() {
|
||||
titleBar = JBR.getWindowDecorations().createCustomTitleBar();
|
||||
titleBar.setHeight(TestUtils.TITLE_BAR_HEIGHT);
|
||||
jFrame = TestUtils.createJFrameWithCustomTitleBar(titleBar);
|
||||
|
||||
addWindowListener();
|
||||
addWindowStateListener();
|
||||
addMacOsFullScreenListener();
|
||||
jFrame.setVisible(true);
|
||||
jFrame.setAlwaysOnTop(true);
|
||||
jFrame.requestFocus();
|
||||
}
|
||||
|
||||
private static void disposeUI() {
|
||||
jFrame.removeWindowListener(windowListener);
|
||||
jFrame.removeWindowStateListener(windowStateListener);
|
||||
FullScreenUtilities.removeFullScreenListenerFrom(jFrame, fullScreenListener);
|
||||
if (jFrame != null) {
|
||||
jFrame.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static void addWindowListener() {
|
||||
windowListener = new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
closingActionCalled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowIconified(WindowEvent e) {
|
||||
iconifyingActionCalled = true;
|
||||
|
||||
jFrame.setState(JFrame.NORMAL);
|
||||
jFrame.setVisible(true);
|
||||
jFrame.requestFocus();
|
||||
}
|
||||
};
|
||||
jFrame.addWindowListener(windowListener);
|
||||
}
|
||||
|
||||
private static void addWindowStateListener() {
|
||||
windowStateListener = new WindowAdapter() {
|
||||
@Override
|
||||
public void windowStateChanged(WindowEvent e) {
|
||||
System.out.println("change " + e.getOldState() + " -> " + e.getNewState());
|
||||
if (e.getNewState() == 6) {
|
||||
maximizingActionDetected = true;
|
||||
}
|
||||
if (e.getOldState() == 1 && e.getNewState() == 0) {
|
||||
deiconifyindActionDetected = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
jFrame.addWindowStateListener(windowStateListener);
|
||||
}
|
||||
|
||||
private static void addMacOsFullScreenListener() {
|
||||
fullScreenListener = new FullScreenListener() {
|
||||
@Override
|
||||
public void windowEnteringFullScreen(FullScreenEvent fse) {
|
||||
maximizingActionDetected = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowEnteredFullScreen(FullScreenEvent fse) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowExitingFullScreen(FullScreenEvent fse) {
|
||||
System.out.println("Exiting fullscreen");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowExitedFullScreen(FullScreenEvent fse) {
|
||||
System.out.println("Exited fullscreen");
|
||||
}
|
||||
};
|
||||
FullScreenUtilities.addFullScreenListenerTo(jFrame, fullScreenListener);
|
||||
}
|
||||
|
||||
private static void err(String message) {
|
||||
error = error + message + "\n";
|
||||
passed = false;
|
||||
System.out.println(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,11 +20,12 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package util;
|
||||
package test.jb.testhelpers.TitleBar;
|
||||
|
||||
import com.jetbrains.WindowDecorations;
|
||||
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.Task;
|
||||
import java.awt.Window;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -20,13 +20,15 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package util;
|
||||
package test.jb.testhelpers.TitleBar;
|
||||
|
||||
import com.jetbrains.WindowDecorations;
|
||||
import test.jb.testhelpers.TitleBar.TaskResult;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
|
||||
import java.awt.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Robot;
|
||||
import java.awt.Window;
|
||||
import java.util.function.Function;
|
||||
|
||||
abstract public class Task {
|
||||
56
test/jdk/jb/testhelpers/TitleBar/TaskResult.java
Normal file
56
test/jdk/jb/testhelpers/TitleBar/TaskResult.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2000-2023 JetBrains s.r.o.
|
||||
* 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.
|
||||
*
|
||||
* 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.jb.testhelpers.TitleBar;
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,24 +20,13 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package util;
|
||||
package test.jb.testhelpers.TitleBar;
|
||||
|
||||
import com.jetbrains.JBR;
|
||||
import com.jetbrains.WindowDecorations;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package util;
|
||||
package test.jb.testhelpers.screenshot;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Rect {
|
||||
@@ -20,7 +20,7 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package util;
|
||||
package test.jb.testhelpers.screenshot;
|
||||
|
||||
public record RectCoordinates(int x1, int y1, int x2, int y2) {
|
||||
|
||||
@@ -20,11 +20,15 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package util;
|
||||
package test.jb.testhelpers.screenshot;
|
||||
|
||||
import com.jetbrains.WindowDecorations;
|
||||
|
||||
import test.jb.testhelpers.screenshot.Rect;
|
||||
import test.jb.testhelpers.screenshot.RectCoordinates;
|
||||
import test.jb.testhelpers.TitleBar.TestUtils;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Color;
|
||||
import java.awt.Rectangle;
|
||||
@@ -46,10 +50,9 @@ public class ScreenShotHelpers {
|
||||
Robot robot = new Robot();
|
||||
robot.delay(1000);
|
||||
|
||||
final BufferedImage screenShot = robot.createScreenCapture(
|
||||
return robot.createScreenCapture(
|
||||
new Rectangle(window.getLocationOnScreen().x, window.getLocationOnScreen().y,
|
||||
window.getWidth(), window.getHeight()));
|
||||
return screenShot;
|
||||
}
|
||||
|
||||
public static String storeScreenshot(String namePrefix, BufferedImage image) throws IOException {
|
||||
@@ -277,7 +280,7 @@ public class ScreenShotHelpers {
|
||||
}
|
||||
|
||||
public static List<Rect> detectControls(BufferedImage image, int titleBarHeight, int leftInset, int rightInset) {
|
||||
RectCoordinates coords = ScreenShotHelpers.findRectangleTitleBar(image, titleBarHeight);
|
||||
RectCoordinates coords = findRectangleTitleBar(image, titleBarHeight);
|
||||
System.out.println("Detect controls");
|
||||
System.out.println(coords);
|
||||
|
||||
@@ -400,4 +403,4 @@ public class ScreenShotHelpers {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,29 @@
|
||||
package util;
|
||||
/*
|
||||
* Copyright 2000-2023 JetBrains s.r.o.
|
||||
* 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.
|
||||
*
|
||||
* 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.jb.testhelpers.utils;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Robot;
|
||||
import java.awt.Window;
|
||||
|
||||
public class MouseUtils {
|
||||
|
||||
Reference in New Issue
Block a user