Skip to content

Commit

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

Reviewed-by: andrew
Backport-of: 4940e2e8d85f2eef88c6132923b165253c13aa73
  • Loading branch information
mrserb committed Feb 13, 2023
1 parent 29a1b79 commit cbde744
Showing 1 changed file with 46 additions and 31 deletions.
77 changes: 46 additions & 31 deletions jdk/test/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 @@ -26,54 +26,68 @@
* @test
* @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 @@ -85,12 +99,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 cbde744

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