8280988: [XWayland] Click on title to request focus test failures

Reviewed-by: honkar, serb
This commit is contained in:
Alexander Zvegintsev 2024-05-02 20:18:25 +00:00
parent 99654ec3fb
commit f6cdcc6f65
5 changed files with 213 additions and 122 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,8 +27,8 @@
* @bug 6981400
* @summary Tabbing between textfiled do not work properly when ALT+TAB
* @author anton.tarasov
* @library ../../regtesthelpers
* @build Util
* @library /java/awt/regtesthelpers /test/lib
* @build Util jdk.test.lib.Platform
* @run main Test1
*/
@ -41,12 +41,28 @@
// The FOCUS_LOST/FOCUS_GAINED events order in the original frame is tracked and should be:
// b0 -> b1 -> b2 -> b3.
import java.awt.*;
import java.awt.event.*;
import java.awt.AWTEvent;
import java.awt.AWTException;
import java.awt.Button;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import jdk.test.lib.Platform;
import test.java.awt.regtesthelpers.Util;
public class Test1 {
@ -72,7 +88,7 @@ public class Test1 {
static boolean tracking;
public static void main(String[] args) {
public static void main(String[] args) throws Exception {
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
public void eventDispatched(AWTEvent e) {
System.out.println(e);
@ -81,6 +97,7 @@ public class Test1 {
try {
robot = new Robot();
robot.setAutoDelay(50);
} catch (AWTException ex) {
throw new RuntimeException("Error: can't create Robot");
}
@ -90,13 +107,13 @@ public class Test1 {
f0.add(f0b2);
f0.add(f0b3);
f0.setLayout(new FlowLayout());
f0.setBounds(0, 100, 400, 200);
f0.setBounds(100, 100, 400, 200);
f1.add(f1b0);
f1.setBounds(0, 400, 400, 200);
f1.setBounds(100, 400, 400, 200);
f2.add(f2b0);
f2.setBounds(0, 400, 400, 200);
f2.setBounds(100, 400, 400, 200);
f0b0.addFocusListener(new FocusAdapter() {
@Override
@ -115,6 +132,7 @@ public class Test1 {
f0.setVisible(true);
Util.waitForIdle(robot);
robot.delay(500);
if (!f0b0.isFocusOwner()) {
Util.clickOnComp(f0b0, robot);
@ -152,28 +170,29 @@ public class Test1 {
System.out.println("\nTest passed.");
}
public static void test(Component compToClick) {
public static void test(Component compToClick) throws Exception {
tracking = true;
robot.keyPress(KeyEvent.VK_TAB);
robot.delay(50);
robot.keyRelease(KeyEvent.VK_TAB);
robot.delay(50);
robot.waitForIdle();
robot.keyPress(KeyEvent.VK_TAB);
robot.delay(50);
robot.keyRelease(KeyEvent.VK_TAB);
robot.delay(50);
robot.waitForIdle();
robot.keyPress(KeyEvent.VK_TAB);
robot.delay(50);
robot.keyRelease(KeyEvent.VK_TAB);
robot.waitForIdle();
robot.delay(50);
Util.clickOnComp(compToClick, robot);
robot.delay(50);
Util.clickOnTitle(f0, robot);
robot.waitForIdle();
SwingUtilities.invokeAndWait(f0::toFront);
if (!Platform.isOnWayland()) {
Util.clickOnTitle(f0, robot);
}
Util.waitForIdle(robot);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,13 +26,27 @@
@key headful
@bug 6314575
@summary Tests that previosly focused owned window doesn't steal focus when an owner's component requests focus.
@library ../../regtesthelpers
@build Util
@library /java/awt/regtesthelpers /test/lib
@build Util jdk.test.lib.Platform
@run main ActualFocusedWindowBlockingTest
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.AWTEvent;
import java.awt.Button;
import java.awt.Color;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.KeyboardFocusManager;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.AWTEventListener;
import java.awt.event.FocusEvent;
import java.awt.event.WindowEvent;
import jdk.test.lib.Platform;
import test.java.awt.regtesthelpers.Util;
public class ActualFocusedWindowBlockingTest {
@ -44,7 +58,7 @@ public class ActualFocusedWindowBlockingTest {
Button wButton = new Button("window button") {public String toString() {return "Window_Button";}};
Button aButton = new Button("auxiliary button") {public String toString() {return "Auxiliary_Button";}};
public static void main(String[] args) {
public static void main(String[] args) throws Exception {
ActualFocusedWindowBlockingTest app = new ActualFocusedWindowBlockingTest();
app.init();
app.start();
@ -68,7 +82,7 @@ public class ActualFocusedWindowBlockingTest {
tuneAndShowWindows(new Window[] {owner, win, frame});
}
public void start() {
public void start() throws Exception {
System.out.println("\nTest started:\n");
// Test 1.
@ -99,7 +113,12 @@ public class ActualFocusedWindowBlockingTest {
clickOnCheckFocus(fButton);
clickOnCheckFocus(aButton);
Util.clickOnTitle(owner, robot);
EventQueue.invokeAndWait(owner::toFront);
if (!Platform.isOnWayland()) {
Util.clickOnTitle(owner, robot);
}
if (!testFocused(fButton)) {
throw new TestFailedException("The owner's component [" + fButton + "] couldn't be focused as the most recent focus owner");
}
@ -117,11 +136,15 @@ public class ActualFocusedWindowBlockingTest {
y += 200;
Util.waitForIdle(robot);
}
robot.delay(500);
}
void clickOnCheckFocus(Component c) {
void clickOnCheckFocus(Component c) throws Exception {
if (c instanceof Frame) {
Util.clickOnTitle((Frame)c, robot);
EventQueue.invokeAndWait(() -> ((Frame) c).toFront());
if (!Platform.isOnWayland()) {
Util.clickOnTitle((Frame) c, robot);
}
} else {
Util.clickOnComp(c, robot);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,11 +22,11 @@
*/
/*
test
@test
@key headful
@bug 4531693 4636269 4681908 4688142 4691646 4721470
@summary Showing modal dialog during dispatching SequencedEvent
@key headful
@run main AutomaticAppletTest
@run main ModalDialogInFocusEventTest
*/
import java.awt.AWTEvent;
@ -68,6 +68,8 @@ public class ModalDialogInFocusEventTest
static final int MAX_STAGE_NUM = stages.length;
static final Object stageMonitor = new Object();
static boolean isOnWayland;
Robot robot = null;
Frame frame;
Frame oppositeFrame;
@ -209,18 +211,21 @@ public class ModalDialogInFocusEventTest
void clickOnFrameTitle(Frame frame) throws InterruptedException,
InvocationTargetException {
System.out.println("click on title of " + frame.getName());
int[] point = new int[2];
EventQueue.invokeAndWait(() -> {
Point location = frame.getLocationOnScreen();
Insets insets = frame.getInsets();
int width = frame.getWidth();
point[0] = location.x + width / 2;
point[1] = location.y + insets.top / 2;
});
robot.mouseMove(point[0], point[1]);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
EventQueue.invokeAndWait(frame::toFront);
if (!isOnWayland) {
System.out.println("click on title of " + frame.getName());
int[] point = new int[2];
EventQueue.invokeAndWait(() -> {
Point location = frame.getLocationOnScreen();
Insets insets = frame.getInsets();
int width = frame.getWidth();
point[0] = location.x + width / 2;
point[1] = location.y + insets.top / 2;
});
robot.mouseMove(point[0], point[1]);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
}
EventQueue.invokeAndWait(frame::requestFocusInWindow);
}
@ -344,6 +349,7 @@ public class ModalDialogInFocusEventTest
public static void main(String[] args) throws InterruptedException,
InvocationTargetException {
isOnWayland = System.getenv("WAYLAND_DISPLAY") != null;
ModalDialogInFocusEventTest test = new ModalDialogInFocusEventTest();
test.start();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,12 +21,33 @@
* questions.
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.List;
import java.awt.Panel;
import java.awt.Robot;
import java.awt.Scrollbar;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.HierarchyBoundsListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.InputEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import javax.swing.SwingUtilities;
import java.io.*;
import jdk.test.lib.Platform;
/**
* AWT Mixing test for HierarchyBoundsListener ancestors.
@ -37,7 +58,8 @@ import java.io.*;
* @key headful
* @bug 6768230 8221823
* @summary Mixing test for HierarchyBoundsListener ancestors
* @build FrameBorderCounter
* @library /test/lib
* @build FrameBorderCounter jdk.test.lib.Platform
* @run main HierarchyBoundsListenerMixingTest
*/
public class HierarchyBoundsListenerMixingTest {
@ -137,9 +159,9 @@ public class HierarchyBoundsListenerMixingTest {
robot.mouseMove((int) components[0].getLocationOnScreen().x + components[0].getSize().width / 2,
(int) components[0].getLocationOnScreen().y + components[0].getSize().height / 2);
robot.delay(delay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(delay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(delay);
resetValues();
@ -177,45 +199,54 @@ public class HierarchyBoundsListenerMixingTest {
robot.delay(delay * 5);
resetValues();
int x = (int) frame.getLocationOnScreen().x;
int y = (int) frame.getLocationOnScreen().y;
int w = frame.getSize().width;
int h = frame.getSize().height;
robot.mouseMove(x + w + BORDER_SHIFT, y + h / 2);
robot.delay(delay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(delay);
for (int i = 0; i < 20; i++) {
robot.mouseMove(x + w + i + BORDER_SHIFT, y + h / 2);
robot.delay(50);
}
robot.delay(delay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
int x;
int y;
int w;
int h;
if (! resizeTriggered) {
synchronized (resizeLock) {
try {
resizeLock.wait(delay * 10);
} catch (Exception e) {
if (!Platform.isOnWayland()) {
x = frame.getLocationOnScreen().x;
y = frame.getLocationOnScreen().y;
w = frame.getSize().width;
h = frame.getSize().height;
robot.mouseMove(x + w + BORDER_SHIFT, y + h / 2);
robot.delay(delay);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(delay);
for (int i = 0; i < 20; i++) {
robot.mouseMove(x + w + i + BORDER_SHIFT, y + h / 2);
robot.delay(50);
}
robot.delay(delay);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
if (!resizeTriggered) {
synchronized (resizeLock) {
try {
resizeLock.wait(delay * 10);
} catch (Exception e) {
}
}
}
}
for (int i = 0; i < components.length; i++) {
if (! ancestorResized[i]) {
System.err.println("FAIL: Frame resized using mouse action. " +
"Ancestor resized event did not occur for " +
components[i].getClass());
for (int i = 0; i < components.length; i++) {
if (!ancestorResized[i]) {
System.err.println("FAIL: Frame resized using mouse action. " +
"Ancestor resized event did not occur for " +
components[i].getClass());
passed = false;
}
}
if (moveCount > 0) {
System.err.println("FAIL: Ancestor moved event occurred when Frame resized using mouse");
passed = false;
}
}
if (moveCount > 0) {
System.err.println("FAIL: Ancestor moved event occured when Frame resized using mouse");
passed = false;
resetValues();
}
resetValues();
try {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
@ -250,52 +281,55 @@ public class HierarchyBoundsListenerMixingTest {
robot.delay(delay * 10);
resetValues();
x = (int) frame.getLocationOnScreen().x;
y = (int) frame.getLocationOnScreen().y;
w = frame.getSize().width;
h = frame.getSize().height;
//Click on the dummy frame so that the test frame loses focus. This is to workaround
//a bug in Linux AS.
robot.mouseMove((int) dummy.getLocationOnScreen().x + dummy.getSize().width / 2,
(int) dummy.getLocationOnScreen().y + dummy.getSize().height / 2);
robot.delay(delay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(delay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(delay);
if (!Platform.isOnWayland()) {
x = frame.getLocationOnScreen().x;
y = frame.getLocationOnScreen().y;
w = frame.getSize().width;
h = frame.getSize().height;
robot.mouseMove(x + w / 2, y + 10);
robot.delay(delay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(delay);
for (int i = 1; i <= 20; i++) {
robot.mouseMove(x + w / 2 + i, y + 10);
robot.delay(50);
}
robot.delay(delay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
//Click on the dummy frame so that the test frame loses focus. This is to workaround
//a bug in Linux AS.
robot.mouseMove((int) dummy.getLocationOnScreen().x + dummy.getSize().width / 2,
(int) dummy.getLocationOnScreen().y + dummy.getSize().height / 2);
robot.delay(delay);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(delay);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(delay);
if (! moveTriggered) {
synchronized (moveLock) {
try {
moveLock.wait(delay * 10);
} catch (Exception e) {
robot.mouseMove(x + w / 2, y + 10);
robot.delay(delay);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(delay);
for (int i = 1; i <= 20; i++) {
robot.mouseMove(x + w / 2 + i, y + 10);
robot.delay(50);
}
robot.delay(delay);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
if (! moveTriggered) {
synchronized (moveLock) {
try {
moveLock.wait(delay * 10);
} catch (Exception e) {
}
}
}
}
for (int i = 0; i < components.length; i++) {
if (! ancestorMoved[i]) {
System.err.println("FAIL: Frame moved using mouse action. " +
"Ancestor moved event did not occur for " + components[i].getClass());
for (int i = 0; i < components.length; i++) {
if (! ancestorMoved[i]) {
System.err.println("FAIL: Frame moved using mouse action. " +
"Ancestor moved event did not occur for " + components[i].getClass());
passed = false;
}
}
if (resizeCount > 0) {
System.err.println("FAIL: Ancestor resized event occured when Frame moved using mouse");
passed = false;
}
}
if (resizeCount > 0) {
System.err.println("FAIL: Ancestor resized event occured when Frame moved using mouse");
passed = false;
}
return passed;
}
@ -450,7 +484,7 @@ public class HierarchyBoundsListenerMixingTest {
// instantiated in the same VM. Being static (and using
// static vars), it aint gonna work. Not worrying about
// it for now.
public static void main(String args[]) throws InterruptedException {
public static void main(String[] args) throws InterruptedException {
mainThread = Thread.currentThread();
try {
init();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -473,4 +473,13 @@ public class Platform {
public static boolean areCustomLoadersSupportedForCDS() {
return (is64bit() && (isLinux() || isOSX() || isWindows()));
}
/**
* Checks if the current system is running on Wayland display server on Linux.
*
* @return {@code true} if the system is running on Wayland display server
*/
public static boolean isOnWayland() {
return System.getenv("WAYLAND_DISPLAY") != null;
}
}