Skip to content

Commit

Permalink
8079267: [TEST_BUG] Test java/awt/Frame/MiscUndecorated/RepaintTest.j…
Browse files Browse the repository at this point in the history
…ava fails

Backport-of: 6f35eede4576b6252544f553c3651312b024e7ea
  • Loading branch information
GoeLin committed Jun 22, 2022
1 parent 1584ddc commit f5e1c3f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ java/awt/Choice/ChoiceMouseWheelTest/ChoiceMouseWheelTest.java 7100044 macosx-al
java/awt/Component/GetScreenLocTest/GetScreenLocTest.java 4753654 generic-all
java/awt/Component/SetEnabledPerformance/SetEnabledPerformance.java 8165863 macosx-all
java/awt/Clipboard/HTMLTransferTest/HTMLTransferTest.java 8017454 macosx-all
java/awt/Frame/MiscUndecorated/RepaintTest.java 8079267 windows-all,linux-all
java/awt/Robot/ModifierRobotKey/ModifierRobotKeyTest.java 8157173 generic-all
java/awt/Modal/FileDialog/FileDialogAppModal1Test.java 7186009 macosx-all
java/awt/Modal/FileDialog/FileDialogAppModal2Test.java 7186009 macosx-all
Expand Down
54 changes: 22 additions & 32 deletions test/jdk/java/awt/Frame/MiscUndecorated/RepaintTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 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 Down Expand Up @@ -33,27 +33,38 @@
* @run main RepaintTest
*/

import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.*;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPanel;
import java.io.*;
import java.awt.image.*;
import java.awt.image.BufferedImage;
import java.awt.image.PixelGrabber;
import java.io.File;

public class RepaintTest {
private static int delay = 150;
private static final int delay = 150;

private Frame frame;
private Container panel1, panel2;
private Component button;
private Component textField;
private ExtendedRobot robot;
private Object buttonLock = new Object();
private final Object buttonLock = new Object();
private boolean passed = true;
private boolean buttonClicked = false;
private int MAX_TOLERANCE_LEVEL = 10;
private final int MAX_TOLERANCE_LEVEL = 10;

public static void main(String[] args) {
RepaintTest test = new RepaintTest();
Expand Down Expand Up @@ -81,25 +92,6 @@ public void run() {
}
}

/**
* Do screen capture and save it as image
*/
private static void captureScreenAndSave() {

try {
Robot robot = new Robot();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle rectangle = new Rectangle(0, 0, screenSize.width, screenSize.height);
System.out.println("About to screen capture - " + rectangle);
BufferedImage image = robot.createScreenCapture(rectangle);
javax.imageio.ImageIO.write(image, "jpg", new File("ScreenImage.jpg"));
robot.delay(3000);
} catch (Throwable t) {
System.out.println("WARNING: Exception thrown while screen capture!");
t.printStackTrace();
}
}

private void initializeGUI(boolean swingControl) {
frame = swingControl ? new JFrame() : new Frame();
frame.setLayout(new BorderLayout());
Expand All @@ -115,10 +107,10 @@ private void initializeGUI(boolean swingControl) {
panel2.add(textField);
frame.add(panel2, BorderLayout.SOUTH);
frame.add(panel1, BorderLayout.NORTH);
frame.setLocationRelativeTo(null);

frame.setBackground(Color.green);
frame.setVisible(true);
frame.toFront();
}
private Component createButton(boolean swingControl, String txt) {
if(swingControl) {
Expand All @@ -136,7 +128,7 @@ public void actionPerformed(ActionEvent e) {
}
});
return jbtn;
}else {
} else {
Button btn = new Button(txt);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Expand Down Expand Up @@ -175,10 +167,9 @@ public void run() {

robot.mouseMove(button.getLocationOnScreen().x + button.getSize().width / 2,
button.getLocationOnScreen().y + button.getSize().height / 2);

robot.click();
robot.waitForIdle(delay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.waitForIdle(delay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);

if (! buttonClicked) {
synchronized (buttonLock) {
Expand Down Expand Up @@ -230,7 +221,6 @@ public void run() {
Toolkit.getDefaultToolkit().getSystemEventQueue().invokeAndWait(new Runnable() {
public void run() {
frame.setExtendedState(Frame.NORMAL);
frame.toFront();
}
});
} catch (Exception e) {
Expand Down

1 comment on commit f5e1c3f

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