Skip to content

Commit

Permalink
8280988: [XWayland] Click on title to request focus test failures
Browse files Browse the repository at this point in the history
Backport-of: f6cdcc6f65f2a436906541bb8266e69ded17e2e3
  • Loading branch information
Andrew Lu committed Jul 4, 2024
1 parent b6be31a commit 306aeab
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 125 deletions.
57 changes: 38 additions & 19 deletions test/jdk/java/awt/Focus/6981400/Test1.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
*/

Expand All @@ -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 {
Expand All @@ -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);
Expand All @@ -81,6 +97,7 @@ public void eventDispatched(AWTEvent e) {

try {
robot = new Robot();
robot.setAutoDelay(50);
} catch (AWTException ex) {
throw new RuntimeException("Error: can't create Robot");
}
Expand All @@ -90,13 +107,13 @@ public void eventDispatched(AWTEvent e) {
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
Expand All @@ -115,6 +132,7 @@ public void focusLost(FocusEvent e) {
f0.setVisible(true);

Util.waitForIdle(robot);
robot.delay(500);

if (!f0b0.isFocusOwner()) {
Util.clickOnComp(f0b0, robot);
Expand Down Expand Up @@ -152,28 +170,29 @@ public void focusLost(FocusEvent e) {
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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand All @@ -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();
Expand All @@ -68,7 +82,7 @@ public void eventDispatched(AWTEvent e) {
tuneAndShowWindows(new Window[] {owner, win, frame});
}

public void start() {
public void start() throws Exception {
System.out.println("\nTest started:\n");

// Test 1.
Expand Down Expand Up @@ -99,7 +113,12 @@ public void start() {
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");
}
Expand All @@ -117,11 +136,15 @@ void tuneAndShowWindows(Window[] arr) {
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);
}
Expand Down
38 changes: 22 additions & 16 deletions test/jdk/java/awt/Focus/ModalDialogInFocusEventTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -209,18 +211,21 @@ public void windowLostFocus(WindowEvent e) {

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);
}

Expand Down Expand Up @@ -344,6 +349,7 @@ public void focusLost(FocusEvent e) {

public static void main(String[] args) throws InterruptedException,
InvocationTargetException {
isOnWayland = System.getenv("WAYLAND_DISPLAY") != null;
ModalDialogInFocusEventTest test = new ModalDialogInFocusEventTest();
test.start();
}
Expand Down
Loading

1 comment on commit 306aeab

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.