Skip to content
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

8266249: javax/swing/JPopupMenu/7156657/bug7156657.java fails on macOS #2209

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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