diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index a9b130d4c0202..e0f760a52d451 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -152,12 +152,7 @@ java/awt/event/InputEvent/EventWhenTest/EventWhenTest.java 8168646 generic-all java/awt/List/KeyEventsTest/KeyEventsTest.java 8201307 linux-all java/awt/Paint/ListRepaint.java 8201307 linux-all java/awt/Mixing/AWT_Mixing/OpaqueOverlappingChoice.java 8048171 generic-all -java/awt/Mixing/AWT_Mixing/JMenuBarOverlapping.java 8159451 linux-all,windows-all,macosx-all -java/awt/Mixing/AWT_Mixing/JSplitPaneOverlapping.java 6986109 generic-all java/awt/Mixing/AWT_Mixing/JInternalFrameMoveOverlapping.java 6986109 windows-all -java/awt/Mixing/AWT_Mixing/MixingPanelsResizing.java 8049405 generic-all -java/awt/Mixing/AWT_Mixing/JComboBoxOverlapping.java 8049405 macosx-all -java/awt/Mixing/AWT_Mixing/JPopupMenuOverlapping.java 8049405 macosx-all java/awt/Mixing/NonOpaqueInternalFrame.java 7124549 macosx-all java/awt/Mouse/EnterExitEvents/DragWindowTest.java 8298823 macosx-all java/awt/Focus/ActualFocusedWindowTest/ActualFocusedWindowRetaining.java 6829264 generic-all diff --git a/test/jdk/java/awt/Mixing/AWT_Mixing/GlassPaneOverlappingTestBase.java b/test/jdk/java/awt/Mixing/AWT_Mixing/GlassPaneOverlappingTestBase.java index 71e45ccd73402..4942700e2dd0b 100644 --- a/test/jdk/java/awt/Mixing/AWT_Mixing/GlassPaneOverlappingTestBase.java +++ b/test/jdk/java/awt/Mixing/AWT_Mixing/GlassPaneOverlappingTestBase.java @@ -21,12 +21,27 @@ * questions. */ +import java.awt.Component; import java.awt.Container; +import java.awt.KeyboardFocusManager; import java.awt.Point; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; + +import java.awt.event.InputEvent; +import java.awt.event.WindowEvent; +import java.awt.event.WindowFocusListener; +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import javax.swing.FocusManager; + import java.lang.reflect.InvocationTargetException; + import javax.swing.JFrame; import javax.swing.SpringLayout; import javax.swing.SwingUtilities; @@ -110,8 +125,53 @@ protected boolean performTest() { if (!super.performTest()) { return false; } + final CountDownLatch latch = new CountDownLatch(1); + f.addFocusListener(new FocusAdapter() { + @Override public void focusGained(FocusEvent e) { + latch.countDown(); + } + }); + if (testResize) { + wasLWClicked = false; + try { + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + testedComponent.setBounds(0, 0, + testedComponent.getPreferredSize().width, + testedComponent.getPreferredSize().height + 20); + Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager() + .getFocusOwner(); + if (focusOwner == f) { + // frame already had focus + latch.countDown(); + } else { + f.requestFocusInWindow(); + } + } + }); + } catch (InterruptedException ex) { + fail(ex.getMessage()); + } catch (InvocationTargetException ex) { + fail(ex.getMessage()); + } + Point lLoc = testedComponent.getLocationOnScreen(); + lLoc.translate(1, testedComponent.getPreferredSize().height + 1); + try { + if (!latch.await(1, TimeUnit.SECONDS)) { + throw new RuntimeException("Ancestor frame didn't receive focus"); + } + clickAndBlink(robot, lLoc); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + return wasLWClicked; + } else { + latch.countDown(); + if (!testResize) { + return true; } diff --git a/test/jdk/java/awt/Mixing/AWT_Mixing/JComboBoxOverlapping.java b/test/jdk/java/awt/Mixing/AWT_Mixing/JComboBoxOverlapping.java index d71fa7b3522a3..3350f1029ee06 100644 --- a/test/jdk/java/awt/Mixing/AWT_Mixing/JComboBoxOverlapping.java +++ b/test/jdk/java/awt/Mixing/AWT_Mixing/JComboBoxOverlapping.java @@ -64,6 +64,9 @@ protected void prepareControls() { frame = new JFrame("Mixing : Dropdown Overlapping test"); frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS)); frame.setSize(200, 200); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + cb = new JComboBox(petStrings); cb.setPreferredSize(new Dimension(frame.getContentPane().getWidth(), 20)); diff --git a/test/jdk/java/awt/Mixing/AWT_Mixing/JMenuBarOverlapping.java b/test/jdk/java/awt/Mixing/AWT_Mixing/JMenuBarOverlapping.java index f3a213e514461..fd45573854eb6 100644 --- a/test/jdk/java/awt/Mixing/AWT_Mixing/JMenuBarOverlapping.java +++ b/test/jdk/java/awt/Mixing/AWT_Mixing/JMenuBarOverlapping.java @@ -54,7 +54,7 @@ * java.desktop/java.awt.peer * @build java.desktop/java.awt.Helper * @build Util - * @run main JMenuBarOverlapping + * @run main/timeout=180 JMenuBarOverlapping */ public class JMenuBarOverlapping extends OverlappingTestBase { @@ -73,7 +73,8 @@ protected void prepareControls() { frame = new JFrame("Mixing : Dropdown Overlapping test"); frame.setLayout(new GridLayout(0,1)); frame.setSize(200, 200); - + frame.setLocationRelativeTo(null); + frame.setVisible(true); menuBar = new JMenuBar(); JMenu menu = new JMenu("Test Menu"); ActionListener menuListener = new ActionListener() { diff --git a/test/jdk/java/awt/Mixing/AWT_Mixing/JPopupMenuOverlapping.java b/test/jdk/java/awt/Mixing/AWT_Mixing/JPopupMenuOverlapping.java index e80475088acf9..b7ec026ffd15e 100644 --- a/test/jdk/java/awt/Mixing/AWT_Mixing/JPopupMenuOverlapping.java +++ b/test/jdk/java/awt/Mixing/AWT_Mixing/JPopupMenuOverlapping.java @@ -69,12 +69,14 @@ protected void prepareControls() { frame = new JFrame("Mixing : Dropdown Overlapping test"); frame.setLayout(new SpringLayout()); frame.setSize(200, 200); + frame.setLocationRelativeTo(null); popup = new JPopupMenu(); ActionListener menuListener = new ActionListener() { public void actionPerformed(ActionEvent event) { lwClicked = true; + frame.setVisible(false); } }; JMenuItem item; diff --git a/test/jdk/java/awt/Mixing/AWT_Mixing/JSplitPaneOverlapping.java b/test/jdk/java/awt/Mixing/AWT_Mixing/JSplitPaneOverlapping.java index 5875a04b62b80..0148bba237be2 100644 --- a/test/jdk/java/awt/Mixing/AWT_Mixing/JSplitPaneOverlapping.java +++ b/test/jdk/java/awt/Mixing/AWT_Mixing/JSplitPaneOverlapping.java @@ -70,6 +70,8 @@ protected void prepareControls() { p.setPreferredSize(new Dimension(500, 500)); propagateAWTControls(p); sp1 = new JScrollPane(p); + currentAwtControl.setForeground(Color.white); + currentAwtControl.setBackground(Color.white); JButton button = new JButton("JButton"); button.setBackground(Color.RED); diff --git a/test/jdk/java/awt/Mixing/AWT_Mixing/MixingPanelsResizing.java b/test/jdk/java/awt/Mixing/AWT_Mixing/MixingPanelsResizing.java index 1bb9b442dd85a..a50d65d4af35f 100644 --- a/test/jdk/java/awt/Mixing/AWT_Mixing/MixingPanelsResizing.java +++ b/test/jdk/java/awt/Mixing/AWT_Mixing/MixingPanelsResizing.java @@ -39,6 +39,8 @@ import javax.swing.JPanel; import javax.swing.SwingUtilities; +import javax.swing.UIManager; + import test.java.awt.regtesthelpers.Util; /** @@ -58,6 +60,7 @@ */ public class MixingPanelsResizing { + static final int TOLERANCE_MACOSX = 15; static volatile boolean failed = false; private static JFrame frame; @@ -75,9 +78,11 @@ public class MixingPanelsResizing { private static int borderShift; private static int frameBorderCounter() { + String JAVA_HOME = System.getProperty("java.home"); try { - Process p = Runtime.getRuntime().exec(JAVA_HOME + "/bin/java FrameBorderCounter"); + Process p = Runtime.getRuntime() + .exec(JAVA_HOME + "/bin/java FrameBorderCounter"); try { p.waitFor(); } catch (InterruptedException e) { @@ -85,7 +90,9 @@ private static int frameBorderCounter() { throw new RuntimeException(e); } if (p.exitValue() != 0) { - throw new RuntimeException("FrameBorderCounter exited with not null code!\n" + readInputStream(p.getErrorStream())); + throw new RuntimeException( + "FrameBorderCounter exited with not null code!\n" + + readInputStream(p.getErrorStream())); } return Integer.parseInt(readInputStream(p.getInputStream()).trim()); } catch (IOException e) { @@ -95,6 +102,7 @@ private static int frameBorderCounter() { } private static String readInputStream(InputStream is) throws IOException { + byte[] buffer = new byte[4096]; int len = 0; StringBuilder sb = new StringBuilder(); @@ -110,7 +118,8 @@ private static void init() throws Exception { //*** Create instructions for the user here *** borderShift = frameBorderCounter(); - borderShift = Math.abs(borderShift) == 1 ? borderShift : (borderShift / 2); + borderShift = + Math.abs(borderShift) == 1 ? borderShift : (borderShift / 2); SwingUtilities.invokeAndWait(new Runnable() { public void run() { // prepare controls @@ -133,6 +142,7 @@ public void run() { jPanel.add(jbutton2); jbutton2.setForeground(jb2Color); jbutton2.setBackground(jb2Color); + awtButton2 = new Button("AWT Button2"); jPanel.add(awtButton2); awtButton2.setForeground(awt2Color); @@ -157,8 +167,10 @@ public void run() { SwingUtilities.invokeAndWait(new Runnable() { public void run() { + lLoc = frame.getLocationOnScreen(); - lLoc.translate(frame.getWidth() + borderShift, frame.getHeight() + borderShift); + lLoc.translate(frame.getWidth() + borderShift, + frame.getHeight() + borderShift); } }); @@ -169,27 +181,32 @@ public void run() { Runnable test = new Runnable() { public void run() { + Point btnLoc = jbutton.getLocationOnScreen(); Color c = robot.getPixelColor(btnLoc.x + 5, btnLoc.y + 5); - if (!c.equals(jbColor)) { + System.out.println("Color picked for jbutton: " + c); + if (!isAlmostEqualColor(c, jbColor)) { fail("JButton was not redrawn properly on AWT Panel during move"); } btnLoc = awtButton.getLocationOnScreen(); c = robot.getPixelColor(btnLoc.x + 5, btnLoc.y + 5); - if (!c.equals(awtColor)) { + System.out.println("Color picked for awtButton: " + c); + if (!isAlmostEqualColor(c, awtColor)) { fail("AWT Button was not redrawn properly on AWT Panel during move"); } btnLoc = jbutton2.getLocationOnScreen(); c = robot.getPixelColor(btnLoc.x + 5, btnLoc.y + 5); - if (!c.equals(jb2Color)) { + System.out.println("Color picked for jbutton2: " + c); + if (!isAlmostEqualColor(c, jb2Color)) { fail("JButton was not redrawn properly on JPanel during move"); } btnLoc = awtButton2.getLocationOnScreen(); c = robot.getPixelColor(btnLoc.x + 5, btnLoc.y + 5); - if (!c.equals(awt2Color)) { + System.out.println("Color picked for awtButton2: " + c); + if (!isAlmostEqualColor(c, awt2Color)) { fail("ATW Button was not redrawn properly on JPanel during move"); } } @@ -212,6 +229,7 @@ public void run() { pass(); }//End init() + /***************************************************** * Standard Test Machinery Section * DO NOT modify anything in this section -- it's a @@ -235,6 +253,14 @@ public void run() { // static vars), it aint gonna work. Not worrying about // it for now. public static void main(String args[]) throws Exception { + + try { + UIManager.setLookAndFeel( + UIManager.getCrossPlatformLookAndFeelClassName()); + } catch (Exception e) { + throw new RuntimeException(e); + } + if (!Toolkit.getDefaultToolkit().isDynamicLayoutActive()) { System.out.println("Dynamic layout is not active. Test passes."); return; @@ -256,7 +282,8 @@ public static void main(String args[]) throws Exception { try { Thread.sleep(sleepTime); //Timed out, so fail the test - throw new RuntimeException("Timed out after " + sleepTime / 1000 + " seconds"); + throw new RuntimeException( + "Timed out after " + sleepTime / 1000 + " seconds"); } catch (InterruptedException e) { //The test harness may have interrupted the test. If so, rethrow the exception // so that the harness gets it and deals with it. @@ -275,10 +302,12 @@ public static void main(String args[]) throws Exception { }//main public static synchronized void setTimeoutTo(int seconds) { + sleepTime = seconds * 1000; } public static synchronized void pass() { + System.out.println("The test passed."); System.out.println("The test is over, hit Ctl-C to stop Java VM"); //first check if this is executing in main thread @@ -300,6 +329,7 @@ public static synchronized void fail() { } public static synchronized void fail(String whyFailed) { + System.out.println("The test failed: " + whyFailed); System.out.println("The test is over, hit Ctl-C to stop Java VM"); //check if this called from main thread @@ -313,6 +343,21 @@ public static synchronized void fail(String whyFailed) { mainThread.interrupt(); }//fail() + private static boolean isAlmostEqualColor(Color color, Color refColor) { + + System.out.println("Comparing color: " + color + " with reference " + + "color: " + refColor); + return color.equals(refColor) || + Math.abs(color.getRed() - refColor.getRed()) < + TOLERANCE_MACOSX && + Math.abs(color.getGreen() - refColor.getGreen()) < + TOLERANCE_MACOSX && + Math.abs(color.getBlue() - refColor.getBlue()) < + TOLERANCE_MACOSX; + } + static class TestPassedException extends RuntimeException { + } + }// class JButtonInGlassPane diff --git a/test/jdk/java/awt/Mixing/AWT_Mixing/OverlappingTestBase.java b/test/jdk/java/awt/Mixing/AWT_Mixing/OverlappingTestBase.java index 3d4adecbd17e3..41ab7d36dc058 100644 --- a/test/jdk/java/awt/Mixing/AWT_Mixing/OverlappingTestBase.java +++ b/test/jdk/java/awt/Mixing/AWT_Mixing/OverlappingTestBase.java @@ -382,10 +382,9 @@ protected void clickAndBlink(Robot robot, Point lLoc) { protected String failMessage = "The LW component did not received the click."; private static boolean isValidForPixelCheck(Component component) { - if ((component instanceof java.awt.Scrollbar) || isMac && (component instanceof java.awt.Button)) { - return false; - } - return true; + return !(component == null || + (component instanceof java.awt.Scrollbar) || + (isMac && (component instanceof java.awt.Button))); } /** diff --git a/test/jdk/java/awt/Mixing/AWT_Mixing/SimpleOverlappingTestBase.java b/test/jdk/java/awt/Mixing/AWT_Mixing/SimpleOverlappingTestBase.java index 0dd42a36cd050..957cd2b10d403 100644 --- a/test/jdk/java/awt/Mixing/AWT_Mixing/SimpleOverlappingTestBase.java +++ b/test/jdk/java/awt/Mixing/AWT_Mixing/SimpleOverlappingTestBase.java @@ -159,12 +159,27 @@ protected boolean performTest() { JFrame ancestor = (JFrame) (testedComponent.getTopLevelAncestor()); if (ancestor != null) { final CountDownLatch latch = new CountDownLatch(1); + ancestor.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { latch.countDown(); } }); ancestor.requestFocus(); + } else { + latch.countDown(); + } + try { + boolean await = latch.await(1, TimeUnit.SECONDS); + if (!await) { + throw new RuntimeException("Ancestor frame didn't receive " + + "focus"); + } + clickAndBlink(robot, lLoc); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + try { if (!latch.await(1L, TimeUnit.SECONDS)) { throw new RuntimeException( @@ -180,6 +195,7 @@ protected boolean performTest() { ancestor.dispose(); } + return wasLWClicked; }