Skip to content

Commit

Permalink
8273578: javax/swing/JMenu/4515762/bug4515762.java fails on macOS 12
Browse files Browse the repository at this point in the history
Reviewed-by: phh
Backport-of: 45adc9227a28c8d614c41ac496bbeaa752e5fd7b
  • Loading branch information
caojoshua authored and Paul Hohensee committed Oct 30, 2022
1 parent 0698930 commit 5fa5392
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions test/jdk/javax/swing/JMenu/4515762/bug4515762.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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 @@ -21,9 +21,15 @@
* questions.
*/

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;

/**
* @test
Expand All @@ -37,8 +43,8 @@
*/
public class bug4515762 {

private static volatile boolean actionExpected = false;
private static volatile boolean actionRecieved = false;
private static volatile boolean actionExpected;
private static volatile boolean actionRecieved;
private static JFrame frame;

/**
Expand Down Expand Up @@ -99,18 +105,18 @@ public void actionPerformed(ActionEvent evt) {
return menuItem;
}

public static void checkAction() {
public static void checkAction(String str) {
if (actionRecieved == true) {
actionRecieved = false;
} else {
throw new RuntimeException("Action has not been received");
throw new RuntimeException("Action has not been received: " + str);
}
}

public static void main(String[] args) throws Throwable {
try {
Robot robot = new Robot();
robot.setAutoDelay(250);
robot.setAutoDelay(100);

SwingUtilities.invokeAndWait(new Runnable() {

Expand All @@ -119,21 +125,25 @@ public void run() {
frame = new JFrame("Test");
frame.setJMenuBar(createMenuBar());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.pack();
frame.setVisible(true);
frame.toFront();
}
});

robot.waitForIdle();
robot.delay(1000);

Util.hitMnemonics(robot, KeyEvent.VK_D);
robot.waitForIdle();

// Press the S key many times (should not cause an action peformed)
int TIMES = 5;
for (int i = 0; i < TIMES; i++) {
Util.hitKeys(robot, KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_S);
robot.waitForIdle();
}
robot.waitForIdle();

Expand All @@ -146,7 +156,7 @@ public void run() {
robot.keyRelease(KeyEvent.VK_S);
robot.waitForIdle();

checkAction();
checkAction("pressing VK_S");

Util.hitMnemonics(robot, KeyEvent.VK_U);
robot.waitForIdle();
Expand All @@ -155,28 +165,31 @@ public void run() {
robot.keyRelease(KeyEvent.VK_M);
robot.waitForIdle();

checkAction();
checkAction("pressing VK_M");

Util.hitMnemonics(robot, KeyEvent.VK_U);
robot.waitForIdle();
Util.hitKeys(robot, KeyEvent.VK_T);
robot.keyPress(KeyEvent.VK_T);
robot.keyRelease(KeyEvent.VK_T);
robot.waitForIdle();

checkAction();
checkAction("pressing VK_T");

Util.hitMnemonics(robot, KeyEvent.VK_U);
robot.waitForIdle();
Util.hitKeys(robot, KeyEvent.VK_W);
robot.keyPress(KeyEvent.VK_W);
robot.keyRelease(KeyEvent.VK_W);
robot.waitForIdle();

checkAction();
checkAction("pressing VK_W");

Util.hitMnemonics(robot, KeyEvent.VK_U);
robot.waitForIdle();
Util.hitKeys(robot, KeyEvent.VK_U);
robot.keyPress(KeyEvent.VK_U);
robot.keyRelease(KeyEvent.VK_U);
robot.waitForIdle();

checkAction();
checkAction("pressing VK_U");
} finally {
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
}
Expand Down

1 comment on commit 5fa5392

@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.