RFR: JDK-8282046: Create a regression test for JDK-8000326 [v3]

Alexey Ivanov aivanov at openjdk.java.net
Wed Mar 16 14:50:45 UTC 2022


On Fri, 11 Mar 2022 14:38:28 GMT, Srinivas Mandalika <smandalika at openjdk.org> wrote:

>> Create a regression test for CCC8000326
>> 
>> Issue is identified by [JDK-8000326](https://bugs.openjdk.java.net/browse/JDK-8000326), which identifies that after focus moves into JMenuBar, whose focus traversal key is disabled by default, it never moves to other focusable component.
>>  
>> By default, pressing the Tab key does not transfer focus from a JMenuBar which is added to a container together with other Swing components, because the focusTraversalKeysEnabled property of JMenuBar is set to false. To resolve this, you should call the JMenuBar.setFocusTraversalKeysEnabled(true) method.
>>  
>> The test verifies focus traversal for the above described scenario.
>> This review is for migrating tests from a closed test suite to open.
>
> Srinivas Mandalika has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Added @bug keyword

You copied the test into the new folder but the old folder still remains. You have to remove it. We don't want two identical tests in different locations.

test/jdk/java/awt/Focus/8000326/SetFocusTraversalKeysEnabledTest.java line 51:

> 49:     private static volatile JFrame jFrame;
> 50:     private static volatile Component currentFocusOwner;
> 51:     private static Robot robot;

This field is unused.

test/jdk/java/awt/Focus/8000326/SetFocusTraversalKeysEnabledTest.java line 83:

> 81:     private static void createGUI() {
> 82:         jFrame = new JFrame("Focus Traversal Test");
> 83:         jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Suggestion:

        jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

jtreg tests should never call `System.exit`, it's safer to use `DISPOSE_ON_CLOSE`.

test/jdk/java/awt/Focus/8000326/SetFocusTraversalKeysEnabledTest.java line 101:

> 99:         jFrame.pack();
> 100:         northButton.requestFocusInWindow();
> 101:         jFrame.setVisible(true);

You can add

        jFrame.setLocationRelativeTo(null);

before calling `setVisible` to show the frame in the center of the screen, which is the recommended location for tests.

-------------

Changes requested by aivanov (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/7512



More information about the client-libs-dev mailing list