changeset 59226:c3e80b0fa196

8244557: test/jdk/javax/swing/JTabbedPane/TestBackgroundScrollPolicy.java failed Reviewed-by: prr
author psadhukhan
date Thu, 07 May 2020 22:29:25 +0530
parents 94b1c5e6a889
children 31a4db8d2483
files test/jdk/javax/swing/JTabbedPane/TestBackgroundScrollPolicy.java
diffstat 1 files changed, 65 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/javax/swing/JTabbedPane/TestBackgroundScrollPolicy.java	Wed May 06 14:02:11 2020 +0530
+++ b/test/jdk/javax/swing/JTabbedPane/TestBackgroundScrollPolicy.java	Thu May 07 22:29:25 2020 +0530
@@ -27,113 +27,93 @@
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JTabbedPane;
-
-import static javax.swing.UIManager.*;
-import static javax.swing.SwingUtilities.*;
+import javax.swing.UIManager;
+import javax.swing.SwingUtilities;
+import javax.swing.UnsupportedLookAndFeelException;
 
 /*
  * @test
  * @key headful
- * @bug 8172269
+ * @bug 8172269 8244557
  * @summary Tests JTabbedPane background for SCROLL_TAB_LAYOUT
+ * @run main TestBackgroundScrollPolicy
  */
 
-public class TestBackgroundScrollPolicy implements Runnable {
-    private static final ArrayList<String> LIST = new ArrayList<>();
-    private static final LookAndFeelInfo[] INFO = getInstalledLookAndFeels();
-    private static final CountDownLatch LATCH = new CountDownLatch(INFO.length);
+public class TestBackgroundScrollPolicy {
     private static Robot ROBOT;
 
     public static void main(String[] args) throws Exception {
         ROBOT = new Robot();
-        invokeLater(new TestBackgroundScrollPolicy());
-        LATCH.await();
-        if (!LIST.isEmpty()) {
-            throw new RuntimeException(LIST.toString());
+        ROBOT.setAutoWaitForIdle(true);
+        ROBOT.setAutoDelay(100);
+        for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
+            System.out.println("Testing L&F: " + laf.getClassName());
+            SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));
+            try {
+                SwingUtilities.invokeAndWait(() -> createGUI());
+                ROBOT.waitForIdle();
+                ROBOT.delay(1000);
+                SwingUtilities.invokeAndWait(() -> test(laf));
+                ROBOT.delay(2000);
+            } finally {
+                if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
+            }
+            ROBOT.delay(1000);
         }
     }
 
-    private static void addOpaqueError(boolean opaque) {
-        LIST.add(getLookAndFeel().getName() + " background color wrong for opaque=" + opaque);
+    private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
+        try {
+            UIManager.setLookAndFeel(laf.getClassName());
+        } catch (UnsupportedLookAndFeelException ignored) {
+            System.out.println("Unsupported L&F: " + laf.getClassName());
+        } catch (ClassNotFoundException | InstantiationException
+                 | IllegalAccessException e) {
+            throw new RuntimeException(e);
+        }
     }
 
-    private static boolean updateLookAndFeel() {
-        int index = (int) LATCH.getCount() - 1;
-        if (index >= 0) {
-            try {
-                LookAndFeelInfo info = INFO[index];
-                System.err.println("L&F: " + info.getName());
-                setLookAndFeel(info.getClassName());
-                return true;
-            } catch (Exception exception) {
-                exception.printStackTrace();
-            }
-        }
-        return false;
+    private static void addOpaqueError(UIManager.LookAndFeelInfo laf, boolean opaque) {
+        throw new RuntimeException(laf.getClassName() + " background color wrong for opaque=" + opaque);
     }
 
-    private JFrame frame;
-    private JTabbedPane pane;
+    private static JFrame frame;
+    private static JTabbedPane pane;
 
-    public void run() {
-        if (this.frame == null) {
-            if (!updateLookAndFeel()) {
-                return;
-            }
-            this.pane = new JTabbedPane();
-            this.pane.setOpaque(false);
-            this.pane.setBackground(Color.RED);
-            for (int i = 0; i < 3; i++) {
-                this.pane.addTab("Tab " + i, new JLabel("Content area " + i));
-            }
-            this.pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
-            this.frame = new JFrame(getClass().getSimpleName());
-            this.frame.getContentPane().setBackground(Color.BLUE);
-            this.frame.add(this.pane);
-            this.frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
-            this.frame.setSize(400, 200);
-            this.frame.setLocationRelativeTo(null);
-            this.frame.setVisible(true);
-        } else {
-            Point point = new Point(this.pane.getWidth() - 2, 2);
-            convertPointToScreen(point, this.pane);
-            Color actual = ROBOT.getPixelColor(point.x, point.y);
+    public static void createGUI() {
+        pane = new JTabbedPane();
+        pane.setOpaque(true);
+        pane.setBackground(Color.RED);
+        for (int i = 0; i < 3; i++) {
+            pane.addTab("Tab " + i, new JLabel("Content area " + i));
+        }
+        pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
+        pane.repaint();
+        frame = new JFrame();
+        frame.getContentPane().setBackground(Color.BLUE);
+        frame.add(pane);
+        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+        frame.setSize(400, 200);
+        frame.setLocationRelativeTo(null);
+        frame.setVisible(true);
+        frame.toFront();
+    }
 
-            boolean opaque = this.pane.isOpaque();
-            Color expected = opaque
-                    ? this.pane.getBackground()
-                    : this.frame.getContentPane().getBackground();
+    public static void test(UIManager.LookAndFeelInfo laf) {
+        Point point = new Point(pane.getWidth() - 2, 2);
+        SwingUtilities.convertPointToScreen(point, pane);
+        Color actual = ROBOT.getPixelColor(point.x, point.y);
 
+        boolean opaque = pane.isOpaque();
+        Color expected = opaque
+                ? pane.getBackground()
+                : frame.getContentPane().getBackground();
+
+        if (!expected.equals(actual)){
             System.out.println("expected " + expected + " actual " + actual);
-            if (!expected.equals(actual)){
-                addOpaqueError(opaque);
-            }
-            if (!opaque) {
-                this.pane.setOpaque(true);
-                this.pane.repaint();
-            } else {
-                this.frame.dispose();
-                this.frame = null;
-                this.pane = null;
-                LATCH.countDown();
-            }
+            addOpaqueError(laf, opaque);
+        }
 
-        }
-        ROBOT.delay(2000);
-        SecondaryLoop secondaryLoop =
-                Toolkit.getDefaultToolkit().getSystemEventQueue()
-                        .createSecondaryLoop();
-        new Thread() {
-            @Override
-            public void run() {
-                try {
-                    Thread.sleep(200);
-                } catch (InterruptedException e) {
-                }
-                secondaryLoop.exit();
-                invokeLater(TestBackgroundScrollPolicy.this);
-            }
-        }.start();
-        secondaryLoop.enter();
     }
 }
+