-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
srmandal
wants to merge
1
commit into
openjdk:master
Choose a base branch
from
srmandal:8339791
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+18
−36
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 | ||||||
|
@@ -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); | ||||||
private boolean passed = true; | ||||||
private final int delay = 150; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
|
@@ -93,13 +97,7 @@ private void initializeGUI() { | |||||
frame.addWindowFocusListener(new WindowFocusListener() { | ||||||
public void windowGainedFocus(WindowEvent event) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||||||
|
@@ -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"); | ||||||
|
@@ -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) { | ||||||
|
@@ -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) { | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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.