mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
JBR-4880 Fix DeadKeySystemAssertionDialog to avoid receiving key event out of the window
This commit is contained in:
committed by
jbrbot
parent
299c01deb0
commit
46b9c485e8
@@ -21,6 +21,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Robot;
|
||||
import java.awt.TextField;
|
||||
@@ -36,29 +37,48 @@ import java.awt.event.KeyEvent;
|
||||
|
||||
public class DeadKeySystemAssertionDialog {
|
||||
|
||||
private static Robot robot;
|
||||
private static Frame frame;
|
||||
private static TextField textField;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Frame frame = new Frame();
|
||||
frame.setSize(300, 200);
|
||||
|
||||
TextField textField = new TextField();
|
||||
frame.add(textField);
|
||||
|
||||
Robot robot = new Robot();
|
||||
robot = new Robot();
|
||||
robot.setAutoDelay(50);
|
||||
|
||||
frame.setVisible(true);
|
||||
robot.waitForIdle();
|
||||
try {
|
||||
EventQueue.invokeAndWait(DeadKeySystemAssertionDialog::initUI);
|
||||
|
||||
textField.requestFocus();
|
||||
robot.waitForIdle();
|
||||
robot.waitForIdle();
|
||||
textField.requestFocus();
|
||||
robot.waitForIdle();
|
||||
|
||||
// Check that the system assertion dialog does not block Java
|
||||
robot.keyPress(KeyEvent.VK_A);
|
||||
robot.keyRelease(KeyEvent.VK_A);
|
||||
robot.waitForIdle();
|
||||
if (!textField.isFocusOwner()) {
|
||||
throw new RuntimeException("TEST ERROR: Text field isn't a focus owner. Can't continue test");
|
||||
}
|
||||
|
||||
frame.setVisible(false);
|
||||
frame.dispose();
|
||||
// Check that the system assertion dialog does not block Java
|
||||
robot.keyPress(KeyEvent.VK_A);
|
||||
robot.keyRelease(KeyEvent.VK_A);
|
||||
robot.waitForIdle();
|
||||
} finally {
|
||||
EventQueue.invokeAndWait(DeadKeySystemAssertionDialog::disposeUI);
|
||||
}
|
||||
}
|
||||
|
||||
private static void initUI() {
|
||||
frame = new Frame();
|
||||
frame.setSize(300, 200);
|
||||
|
||||
textField = new TextField();
|
||||
frame.add(textField);
|
||||
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
private static void disposeUI() {
|
||||
if (frame != null) {
|
||||
frame.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user