Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8137101: [TEST_BUG] javax/swing/plaf/basic/BasicHTML/4251579/bug42515…
…79.java failure due to timing

Reviewed-by: mdoerr
Backport-of: dcdb1b6
  • Loading branch information
GoeLin committed Oct 13, 2021
1 parent 0a71d8e commit 4940e2e
Showing 1 changed file with 46 additions and 31 deletions.
77 changes: 46 additions & 31 deletions test/jdk/javax/swing/plaf/basic/BasicHTML/4251579/bug4251579.java
@@ -1,6 +1,6 @@

/*
* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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 All @@ -27,54 +27,68 @@
* @key headful
* @bug 4251579
* @summary Tests if style sheets are working in JLabel
* @author Denis Sharypov
* @run main bug4251579
*/
import java.awt.*;
import javax.swing.*;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Robot;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.JLabel;

public class bug4251579 {

private static JLabel htmlComponent;
private static JFrame mainFrame;

public static void main(String[] args) throws Exception {
final Robot robot = new Robot();
robot.setAutoDelay(50);

SwingUtilities.invokeAndWait(new Runnable() {
try {
SwingUtilities.invokeAndWait(new Runnable() {

@Override
public void run() {
createAndShowGUI();
}
});
@Override
public void run() {
createAndShowGUI();
}
});

robot.waitForIdle();
robot.waitForIdle();
robot.delay(1000);

SwingUtilities.invokeAndWait(new Runnable() {
SwingUtilities.invokeAndWait(new Runnable() {

@Override
public void run() {
boolean passed = false;
@Override
public void run() {
boolean passed = false;

Point p = htmlComponent.getLocationOnScreen();
Dimension d = htmlComponent.getSize();
int x0 = p.x;
int y = p.y + d.height / 2;
Point p = htmlComponent.getLocationOnScreen();
Dimension d = htmlComponent.getSize();
int x0 = p.x;
int y = p.y + d.height / 2;

for (int x = x0; x < x0 + d.width; x++) {
if (robot.getPixelColor(x, y).equals(Color.blue)) {
passed = true;
break;
for (int x = x0; x < x0 + d.width; x++) {
if (robot.getPixelColor(x, y).equals(Color.blue)) {
passed = true;
break;
}
}
}

if (!passed) {
throw new RuntimeException("Test failed.");
}
if (!passed) {
throw new RuntimeException("Test failed.");
}

}
});
}
});
} finally {
SwingUtilities.invokeAndWait(() -> {
if (mainFrame != null) {
mainFrame.dispose();
}
});
}
}

private static void createAndShowGUI() {
Expand All @@ -86,12 +100,13 @@ private static void createAndShowGUI() {
+ "<P class=\"blue\"> should be rendered with BLUE class definition</P>"
+ "</body>";

JFrame mainFrame = new JFrame("bug4251579");
mainFrame = new JFrame("bug4251579");
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

htmlComponent = new JLabel(htmlText);
mainFrame.getContentPane().add(htmlComponent);

mainFrame.setLocationRelativeTo(null);
mainFrame.pack();
mainFrame.setVisible(true);
}
Expand Down

1 comment on commit 4940e2e

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