Skip to content

Commit

Permalink
8266249: javax/swing/JPopupMenu/7156657/bug7156657.java fails on macOS
Browse files Browse the repository at this point in the history
Reviewed-by: jdv, pbansal, azvegint
  • Loading branch information
Alexander Zuev committed May 10, 2021
1 parent 3af4efd commit 9b76955
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions test/jdk/javax/swing/JPopupMenu/7156657/bug7156657.java
Expand Up @@ -25,12 +25,18 @@
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Window;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.concurrent.Callable;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
Expand Down Expand Up @@ -103,24 +109,56 @@ public void run() {
Rectangle popupRectangle = Util.invokeOnEDT(new Callable<Rectangle>() {
@Override
public Rectangle call() throws Exception {
return popupMenu.getBounds();
return new Rectangle(popupMenu.getLocationOnScreen(),
popupMenu.getSize());
}
});

BufferedImage redBackgroundCapture = robot.createScreenCapture(popupRectangle);
BufferedImage redFrame = robot.createScreenCapture(frame.getBounds());

SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
lowerFrame.getContentPane().setBackground(Color.GREEN);
lowerFrame.invalidate();
}
});

robot.waitForIdle();
robot.delay(1000); // Give frame time to repaint

BufferedImage greenBackgroundCapture = robot.createScreenCapture(popupRectangle);
BufferedImage greenFrame = robot.createScreenCapture(frame.getBounds());

if (Util.compareBufferedImages(redBackgroundCapture, greenBackgroundCapture)) {
try {
GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
for (int i = 0; i < devices.length; i++) {
GraphicsConfiguration[] screens = devices[i].getConfigurations();
for (int j = 0; j < screens.length; j++) {
BufferedImage fullScreen = robot.createScreenCapture(screens[j].getBounds());
if (screens[j].getBounds().intersects(popupRectangle)) {
Graphics g = fullScreen.getGraphics();
g.setColor(Color.CYAN);
g.drawRect(popupRectangle.x - 1, popupRectangle.y - 1,
popupRectangle.width + 2, popupRectangle.height + 2);
g.dispose();
}
ImageIO.write(fullScreen, "png", new File("dev" + i + "scr" + j + ".png"));
}
}
ImageIO.write(redFrame, "png", new File("redframe.png"));
ImageIO.write(redBackgroundCapture, "png", new File("redbg.png"));
ImageIO.write(greenFrame, "png", new File("greenframe.png"));
ImageIO.write(greenBackgroundCapture, "png", new File("greenbg.png"));
} finally {
SwingUtilities.invokeAndWait(() -> {
frame.dispose();
lowerFrame.dispose();
});
}
robot.waitForIdle();
throw new RuntimeException("The test failed");
}

Expand Down Expand Up @@ -148,8 +186,8 @@ public static void setOpaque(Window window, boolean opaque) {
private static JFrame createFrame() {
JFrame result = new JFrame();

result.setLocation(0, 0);
result.setSize(400, 300);
result.setLocationRelativeTo(null);
result.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
result.setUndecorated(true);

Expand Down

4 comments on commit 9b76955

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@openjdk
Copy link

@openjdk openjdk bot commented on 9b76955 Oct 24, 2023

Choose a reason for hiding this comment

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

@GoeLin Could not apply backport 9b769550 to openjdk/jdk17u-dev because the change is already present in the target.

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 9b76955 Oct 24, 2023

Choose a reason for hiding this comment

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

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 9b76955 Oct 24, 2023

Choose a reason for hiding this comment

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

@GoeLin the backport was successfully created on the branch GoeLin-backport-9b769550 in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 9b769550 from the openjdk/jdk repository.

The commit being backported was authored by Alexander Zuev on 10 May 2021 and was reviewed by Jayathirth D V, Pankaj Bansal and Alexander Zvegintsev.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev.git GoeLin-backport-9b769550:GoeLin-backport-9b769550
$ git checkout GoeLin-backport-9b769550
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev.git GoeLin-backport-9b769550

Please sign in to comment.