Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
azvegint committed Apr 27, 2024
1 parent 281f9bd commit c2f6315
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 114 deletions.
43 changes: 28 additions & 15 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 @@ -41,12 +41,26 @@
// 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 test.java.awt.regtesthelpers.Util;

public class Test1 {
Expand Down Expand Up @@ -81,6 +95,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 +105,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 +130,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 @@ -156,24 +172,21 @@ public static void test(Component compToClick) {
tracking = true;

robot.keyPress(KeyEvent.VK_TAB);
robot.delay(50);
robot.keyRelease(KeyEvent.VK_TAB);
robot.delay(50);

robot.keyPress(KeyEvent.VK_TAB);
robot.delay(50);
robot.keyRelease(KeyEvent.VK_TAB);
robot.delay(50);

robot.keyPress(KeyEvent.VK_TAB);
robot.delay(50);
robot.keyRelease(KeyEvent.VK_TAB);

robot.delay(50);
Util.clickOnComp(compToClick, robot);

robot.delay(50);
Util.clickOnTitle(f0, robot);
if (Util.isOnWayland()) {
Util.clickOnComp(f0, robot);
} else {
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 Down Expand Up @@ -31,8 +31,20 @@
@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.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 test.java.awt.regtesthelpers.Util;

public class ActualFocusedWindowBlockingTest {
Expand Down Expand Up @@ -99,7 +111,12 @@ public void start() {
clickOnCheckFocus(fButton);
clickOnCheckFocus(aButton);

Util.clickOnTitle(owner, robot);
if (Util.isOnWayland()) {
Util.clickOnComp(owner, robot);
} else {
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,10 +134,11 @@ void tuneAndShowWindows(Window[] arr) {
y += 200;
Util.waitForIdle(robot);
}
robot.delay(500);
}

void clickOnCheckFocus(Component c) {
if (c instanceof Frame) {
if (c instanceof Frame && !Util.isOnWayland()) {
Util.clickOnTitle((Frame)c, robot);
} else {
Util.clickOnComp(c, robot);
Expand Down
37 changes: 22 additions & 15 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
@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,22 @@ 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);
if (isOnWayland) {
EventQueue.invokeAndWait(frame::toFront);
} else {
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 +350,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

0 comments on commit c2f6315

Please sign in to comment.