Skip to content

8339791: Refactor MiscUndecorated/ActiveAWTWindowTest.java #26471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 18 additions & 36 deletions test/jdk/java/awt/Frame/MiscUndecorated/ActiveAWTWindowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
/*
* @test
* @key headful
* @summary To check proper WINDOW_EVENTS are triggered when Frame gains or losses the focus
* @summary To check proper WINDOW_EVENTS are triggered when Frame gains
* or looses the focus
* @library /lib/client
* @build ExtendedRobot
* @run main ActiveAWTWindowTest
Expand All @@ -44,15 +45,18 @@
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class ActiveAWTWindowTest {

private Frame frame, frame2;
private Button button, button2;
private TextField textField, textField2;
private volatile int eventType;
private final Object lock1 = new Object();
private final Object lock2 = new Object();
private final Object lock3 = new Object();
private static final CountDownLatch windowActivatedLatch = new CountDownLatch(1);
private static final CountDownLatch windowDeactivatedLatch = new CountDownLatch(1);
private static final CountDownLatch windowFocusGainedLatch = new CountDownLatch(1);
Copy link
Member

Choose a reason for hiding this comment

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

I see where we decrement this latch but i do not see where we check it or wait on it. Is it really needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

also no need to use ExtendedRobot as all I can see is mousePress/mouseRelease which can be used from java.awt.Robot class itself..

Copy link
Contributor

Choose a reason for hiding this comment

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

static final variables can be capitalized.

private boolean passed = true;
private final int delay = 150;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private final int delay = 150;
private final int DELAY = 150;


Expand Down Expand Up @@ -93,13 +97,7 @@ private void initializeGUI() {
frame.addWindowFocusListener(new WindowFocusListener() {
public void windowGainedFocus(WindowEvent event) {
Copy link
Contributor

Choose a reason for hiding this comment

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

add @OverRide for all overridden methods.

System.out.println("Frame Focus gained");
synchronized (lock3) {
try {
lock3.notifyAll();
} catch (Exception ex) {
ex.printStackTrace();
}
}
windowFocusGainedLatch.countDown();
}

public void windowLostFocus(WindowEvent event) {
Expand All @@ -110,25 +108,13 @@ public void windowLostFocus(WindowEvent event) {
public void windowActivated(WindowEvent e) {
eventType = WindowEvent.WINDOW_ACTIVATED;
System.out.println("Undecorated Frame is activated\n");
synchronized (lock1) {
try {
lock1.notifyAll();
} catch (Exception ex) {
ex.printStackTrace();
}
}
windowActivatedLatch.countDown();
}

public void windowDeactivated(WindowEvent e) {
eventType = WindowEvent.WINDOW_DEACTIVATED;
System.out.println("Undecorated Frame got Deactivated\n");
synchronized (lock2) {
try {
lock2.notifyAll();
} catch (Exception ex) {
ex.printStackTrace();
}
}
windowDeactivatedLatch.countDown();
}
});
textField = new TextField("TextField");
Expand Down Expand Up @@ -183,12 +169,10 @@ public void doTest() {
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

if (eventType != WindowEvent.WINDOW_ACTIVATED) {
synchronized (lock1) {
try {
lock1.wait(delay * 10);
} catch (Exception e) {
e.printStackTrace();
}
try {
windowActivatedLatch.await(delay * 10, TimeUnit.MILLISECONDS);
} catch (Exception e) {
e.printStackTrace();
}
}
if (eventType != WindowEvent.WINDOW_ACTIVATED) {
Expand All @@ -205,11 +189,9 @@ public void doTest() {
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

if (eventType != WindowEvent.WINDOW_DEACTIVATED) {
synchronized (lock2) {
try {
lock2.wait(delay * 10);
} catch (Exception e) {
}
try {
windowDeactivatedLatch.await(delay * 10, TimeUnit.MILLISECONDS);
} catch (Exception e) {
}
}
if (eventType != WindowEvent.WINDOW_DEACTIVATED) {
Expand Down