Skip to content

8332901: Select{Current,New}ItemTest.java for Choice don't open popup on macOS #20601

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

Conversation

aivanov-jdk
Copy link
Member

@aivanov-jdk aivanov-jdk commented Aug 15, 2024

I looked at java/awt/Choice/SelectCurrentItemTest/SelectCurrentItemTest.java, ran it and noticed that the test does not open the popup of the Choice component on macOS 14.x.

If the popup does not open, the test does not verify anything — it always passes.

I refactored the test and added a mouse listener to the Choice component. If mouse click isn't registered, the test fails.

Later, I found a similar test: test/jdk/java/awt/Choice/SelectNewItemTest/SelectNewItemTest.java. It clicks on another item in the Choice popup and expects to receive ItemEvent.

I refactored both tests and moved them into Choice/SelectItem folder.

SelectCurrentItemTest encapsulates the common test logic and provides overridable methods to customise conditions for SelectNewItemTest.

Now, SelectNewItemTest extends SelectCurrentItemTest and overrides the conditions as well as the coordinates for clicking the popup of the Choice component.

The updated test fails for me locally on macOS Sonoma 14.5. This is likely the result of JDK-8322653: [macos14] : Mouse clicks are not received within 3 pixels of the window boundary.

To work around JDK-8322653, both tests use non-resizable frame. Both updated tests pass on CI and locally on macOS 14.5. This is why I removed SelectNewItemTest from problem-list.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8332901: Select{Current,New}ItemTest.java for Choice don't open popup on macOS (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/20601/head:pull/20601
$ git checkout pull/20601

Update a local copy of the PR:
$ git checkout pull/20601
$ git pull https://git.openjdk.org/jdk.git pull/20601/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 20601

View PR using the GUI difftool:
$ git pr show -t 20601

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/20601.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 15, 2024

👋 Welcome back aivanov! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Aug 15, 2024

@aivanov-jdk This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8332901: Select{Current,New}ItemTest.java for Choice don't open popup on macOS

Move SelectCurrentItemTest.java to java/awt/Choice/SelectItem/.
Move SelectNewItemTest.java to java/awt/Choice/SelectItem/.
Use latches to control test flow instead of delays.
Encapsulate the common logic in SelectCurrentItemTest.
Provide overridable checkXXX() methods to modify conditions.
Provide an overridable method which defines where to click
in the choice popup to select an item.

Reviewed-by: honkar, prr, dnguyen

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 147 new commits pushed to the master branch:

  • 2fb8305: 8339319: ProblemList runtime/exceptionMsgs/NoClassDefFoundError/NoClassDefFoundErrorTest.java
  • 3a352b8: 8339191: JFR: Bulk read support for ChunkInputStream
  • 92c4704: 8339166: java/lang/String/concat/HiddenClassUnloading.java fails on AIX and Linux ppc64le after JDK-8336856
  • 2abe2ff: 8339235: Fix indentation in build system
  • bb28b0d: 8338404: Cross-compilation to different endianness fails after JDK-8318913
  • b872718: 8338301: Error recovery and reporting should be improved for erroneous implicitly declared classes
  • b9e65f9: 8337662: Improve os::print_hex_dump for printing Instructions sections
  • f927c12: 8339154: Cleanups and JUnit conversion of test/jdk/java/util/zip/Available.java
  • 4675913: 8339237: RISC-V: Builds fail after JDK-8339120
  • b711c41: 8339196: Optimize BufWriterImpl#writeU1/U2/Int/Long
  • ... and 137 more: https://git.openjdk.org/jdk/compare/f308b2d59672b39ddca502baff50ab20ab781047...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 15, 2024
@openjdk
Copy link

openjdk bot commented Aug 15, 2024

@aivanov-jdk The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Aug 15, 2024
@mlbridge
Copy link

mlbridge bot commented Aug 15, 2024

Webrevs

Copy link
Contributor

@honkar-jdk honkar-jdk left a comment

Choose a reason for hiding this comment

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

@aivanov-jdk As you mentioned earlier this test fails on macOS 14.5 due to JDK-8322653, since it passes on CI (14.3 and 14.4) do we skip problemlisting the test for now ?

frame.addWindowListener(this);

frame.setLocation(1,20);
robot.mouseMove(10, 30);
frame.setLocationRelativeTo(null);
frame.pack();
Copy link
Contributor

@honkar-jdk honkar-jdk Aug 16, 2024

Choose a reason for hiding this comment

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

When frame.setSize() is used, the mouse pointer on the choice drop-down button is no longer a resize indicator and the click event is received. But I guess you are planning to leave this as-is for now to test when the external fix is available for JDK-8322653

Copy link
Member Author

Choose a reason for hiding this comment

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

When frame.setSize() is used, the mouse pointer on the choice drop-down button is no longer a resize indicator and the click event is received.

I don't understand how using frame.setSize resolve the problem? Both pack and setSize call reshape to apply the new location and size.

Did you mean frame.setResizable(false)?

But I guess you are planning to leave this as-is for now to test when the external fix is available for JDK-8322653

We can modify this test to avoid JDK-8322653.

I added a panel to the frame to move the mouse cursor away from the edge of the frame while I verified the test would pass.

Copy link
Contributor

@honkar-jdk honkar-jdk Aug 16, 2024

Choose a reason for hiding this comment

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

I don't understand how using frame.setSize resolve the problem? Both pack and setSize call reshape to apply the new location and size.

When the frame width and height is increased then the mouse is no longer a resize indicator which makes the 1st click (on the choice dropdown button) work but the 2nd click on the choice item needs to be adjusted accordingly.

I believe frame.setResizable(false) or adding a panel as you suggested is a better and easier option.

We can modify this test to avoid JDK-8322653

Since there are already few tests problemlisted to track the external issue JDK-8322653, I think any of the above workarounds that you suggested can be added to avoid JDK-8322653. What do you think?

@aivanov-jdk
Copy link
Member Author

since it passes on CI (14.3 and 14.4) do we skip problemlisting the test for now ?

I'm unsure whether the test has ever run on 14.x in CI.

The test has never failed for me when I submitted test jobs. As such, I have no reasons to problem-list it.

Copy link
Contributor

@honkar-jdk honkar-jdk left a comment

Choose a reason for hiding this comment

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

LGTM

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 19, 2024
Copy link
Contributor

@DamonGuy DamonGuy left a comment

Choose a reason for hiding this comment

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

LGTM as well

Use latches to control test flow instead of delays
and volatile variables.
Encapsulate the common logic in SelectCurrentItemTest.
Provide overridable checkXXX() methods to modify
  conditions.
Provide an overridable method which defines where
  to click in the choice popup to select an item.
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Aug 20, 2024
@aivanov-jdk
Copy link
Member Author

aivanov-jdk commented Aug 20, 2024

While I worked on another backport, I found SelectNewItemTest.java. This test is basically the same: the only difference is that it selects a new item in the choice popup and expects ItemEvent.

I updated the other test too and refactored both of them to re-use common functionality.

I moved both tests — test/jdk/java/awt/Choice/SelectCurrentItemTest/SelectCurrentItemTest.java and test/jdk/java/awt/Choice/SelectNewItemTest/SelectNewItemTest.java — to test/jdk/java/awt/Choice/SelectItem/ folder. The SelectCurrentItemTest is the main one as the oldest; and SelectNewItemTest now extends SelectCurrentItemTest.

Both updated tests pass in CI and locally on macOS 14.x. Non-resizable frame is used to work around JDK-8322653.

I will update JBS issue and the description of the PR accordingly.

@aivanov-jdk aivanov-jdk changed the title 8332901: Choice/SelectCurrentItemTest/SelectCurrentItemTest.java doesn't open popup on macOS Select{Current,New}ItemTest.java for Choice don't open popup on macOS Aug 20, 2024
@openjdk openjdk bot removed the rfr Pull request is ready for review label Aug 20, 2024
@aivanov-jdk aivanov-jdk changed the title Select{Current,New}ItemTest.java for Choice don't open popup on macOS 8332901: Select{Current,New}ItemTest.java for Choice don't open popup on macOS Aug 20, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 20, 2024
@aivanov-jdk
Copy link
Member Author

Unfortunately, Git does not recognise the files are moved with so many additional changes.

As a workaround, I can submit a new issue and integrate it where the files are moved only. This way we could preserve the history of the changes to the tests.

Do you have any opinions?

@honkar-jdk
Copy link
Contributor

honkar-jdk commented Aug 20, 2024

Unfortunately, Git does not recognise the files are moved with so many additional changes.

As a workaround, I can submit a new issue and integrate it where the files are moved only. This way we could preserve the history of the changes to the tests.

Do you have any opinions?

@aivanov-jdk Does it work if you move the test files using git mv, commit it and in the next commit modify the files
I mean 2 separate commits - one for move and another one that modifies the files.

@aivanov-jdk
Copy link
Member Author

@aivanov-jdk Does it work if you move the test files using git mv, commit it and in the next commit modify the files
I mean 2 separate commits - one for move and another one that modifies the files.

That's exactly what I did if you look at the history of the commits.

It doesn't work in the code review. It won't work after integration either.

After integration, individual commits are lost, everything is squashed into one changeset.

The only reliable way to preserve the history across renames (and modification) is to integrate a separate changeset where the files are only renamed without any modifications.

Copy link
Contributor

@honkar-jdk honkar-jdk left a comment

Choose a reason for hiding this comment

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

LGTM

Ideally these two tests can be combined since they are very similar and it also means one test less to run on CI.
But since you are reusing the SelectCurrentItemTest test code and overriding the methods, this approach is cleaner and doesn't make the test complicated.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 20, 2024
@aivanov-jdk
Copy link
Member Author

aivanov-jdk commented Aug 20, 2024

Ideally these two tests can be combined since they are very similar and it also means one test less to run on CI.

I believe the difference is close to negligible. Creating UI and waiting for it to be displayed likely takes more than compiling the test source code and starting a new JVM process.

But since you are reusing the SelectCurrentItemTest test code and overriding the methods, this approach is cleaner and doesn't make the test complicated.

Yes, I think it's cleaner this way. Each test does one thing and tests its own scenario.

The old SelectNewItemTest also verified the case where the same item was selected from the popup again. Thus, it repeated what SelectCurrentItemTest did for a long time. So I removed it.

I found another test which tests the same scenario as SelectNewItemTest, it's test/jdk/java/awt/event/ComponentEvent/ComponentItemEventTest.java. It was added in #11786. I'm going to submit a bug to remove this scenario from the ComponentItemEventTest test.

@aivanov-jdk
Copy link
Member Author

/summary
Move SelectCurrentItemTest.java to java/awt/Choice/SelectItem/.
Move SelectNewItemTest.java to java/awt/Choice/SelectItem/.
Use latches to control test flow instead of delays.
Encapsulate the common logic in SelectCurrentItemTest.
Provide overridable checkXXX() methods to modify conditions.
Provide an overridable method which defines where to click
in the choice popup to select an item.

@openjdk
Copy link

openjdk bot commented Aug 30, 2024

@aivanov-jdk Setting summary to:

Move SelectCurrentItemTest.java to java/awt/Choice/SelectItem/.
Move SelectNewItemTest.java to java/awt/Choice/SelectItem/.
Use latches to control test flow instead of delays.
Encapsulate the common logic in SelectCurrentItemTest.
Provide overridable checkXXX() methods to modify conditions.
Provide an overridable method which defines where to click
in the choice popup to select an item.

Copy link
Contributor

@honkar-jdk honkar-jdk left a comment

Choose a reason for hiding this comment

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

Updated changes and summary looks good.

@aivanov-jdk
Copy link
Member Author

I found another test which tests the same scenario as SelectNewItemTest, it's test/jdk/java/awt/event/ComponentEvent/ComponentItemEventTest.java. It was added in #11786. I'm going to submit a bug to remove this scenario from the ComponentItemEventTest test.

I submitted JDK-8339338 to remove Choice from ComponentItemEventTest.

@aivanov-jdk
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Sep 4, 2024

Going to push as commit ef96a7b.
Since your change was applied there have been 194 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Sep 4, 2024
@openjdk openjdk bot closed this Sep 4, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 4, 2024
@openjdk
Copy link

openjdk bot commented Sep 4, 2024

@aivanov-jdk Pushed as commit ef96a7b.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@aivanov-jdk aivanov-jdk deleted the 8332901-SelectCurrentItemTest-popup branch October 8, 2024 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants