From 005c56c6e3a42d9ac7ba1c31809146649021d180 Mon Sep 17 00:00:00 2001 From: Yuri Nesterenko Date: Fri, 21 Nov 2014 16:11:03 +0300 Subject: [PATCH] 8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2 8064573: [TEST_BUG] javax/swing/text/AbstractDocument/6968363/Test6968363.java is asocial pressing VK_LEFT and not releasing 8064575: [TEST_BUG] javax/swing/JEditorPane/6917744/bug6917744.java 100 times press keys and never releases 8064809: [TEST_BUG] javax/swing/JComboBox/4199622/bug4199622.java contains a lot of keyPress and not a single keyRelease Reviewed-by: alexsch, pchelko --- .../AbstractButton/6711682/bug6711682.java | 5 +- .../swing/JButton/4368790/bug4368790.java | 71 ++++++ .../swing/JColorChooser/Test6541987.java | 9 +- .../swing/JColorChooser/Test6827032.java | 5 +- .../swing/JColorChooser/Test7194184.java | 9 +- .../swing/JComboBox/4199622/bug4199622.java | 38 ++-- .../JComboBox/4515752/DefaultButtonTest.java | 214 ++++++++++++++++++ .../swing/JComboBox/4743225/bug4743225.java | 8 +- .../swing/JComboBox/6236162/bug6236162.java | 15 +- .../swing/JComboBox/6559152/bug6559152.java | 101 +++++++++ .../swing/JComboBox/6607130/bug6607130.java | 32 ++- .../swing/JComboBox/8032878/bug8032878.java | 12 +- .../swing/JComboBox/8057893/bug8057893.java | 6 +- .../swing/JComponent/6683775/bug6683775.java | 4 +- .../swing/JComponent/7154030/bug7154030.java | 21 +- .../swing/JEditorPane/6917744/bug6917744.java | 13 +- .../JFileChooser/4524490/bug4524490.java | 11 +- .../JFileChooser/7199708/bug7199708.java | 8 +- .../JFileChooser/8002077/bug8002077.java | 10 +- .../JFileChooser/8021253/bug8021253.java | 8 +- .../swing/JFrame/4962534/bug4962534.java | 10 +- .../NSTexturedJFrame/NSTexturedJFrame.java | 23 +- .../JInternalFrame/5066752/bug5066752.java | 4 +- .../JInternalFrame/8020708/bug8020708.java | 13 +- .../InternalFrameIsNotCollectedTest.java | 12 +- .../javax/swing/JList/6462008/bug6462008.java | 69 +++--- .../javax/swing/JList/6510999/bug6510999.java | 74 ++++++ .../javax/swing/JMenu/4417601/bug4417601.java | 79 +++++++ .../javax/swing/JMenu/4515762/bug4515762.java | 18 +- .../javax/swing/JMenu/4692443/bug4692443.java | 35 ++- .../javax/swing/JMenu/6359669/bug6359669.java | 84 +++++++ .../javax/swing/JMenu/6470128/bug6470128.java | 84 +++++++ .../javax/swing/JMenu/6538132/bug6538132.java | 131 +++++++++++ .../swing/JMenuBar/4750590/bug4750590.java | 7 +- .../swing/JMenuItem/4171437/bug4171437.java | 7 +- .../swing/JMenuItem/4654927/bug4654927.java | 12 +- .../swing/JMenuItem/6209975/bug6209975.java | 10 +- .../swing/JMenuItem/6249972/bug6249972.java | 105 +++++++++ .../ActionListenerCalledTwiceTest.java | 9 +- .../swing/JOptionPane/6428694/bug6428694.java | 114 ++++++++++ .../swing/JOptionPane/7138665/bug7138665.java | 10 +- .../swing/JPopupMenu/4458079/bug4458079.java | 10 +- .../swing/JPopupMenu/4634626/bug4634626.html | 8 + .../swing/JPopupMenu/4634626/bug4634626.java | 205 +++++++++++++++++ .../swing/JPopupMenu/4966112/bug4966112.java | 22 +- .../swing/JPopupMenu/6217905/bug6217905.java | 114 ++++++++++ .../swing/JPopupMenu/6415145/bug6415145.java | 121 ++++++++++ .../swing/JPopupMenu/6515446/bug6515446.java | 91 ++++++++ .../swing/JPopupMenu/6544309/bug6544309.java | 105 +++++++++ .../swing/JPopupMenu/6580930/bug6580930.java | 148 ++++++++++++ .../swing/JPopupMenu/6800513/bug6800513.java | 12 +- .../swing/JPopupMenu/6827786/bug6827786.java | 12 +- .../swing/JPopupMenu/6987844/bug6987844.java | 7 +- .../swing/JPopupMenu/7154841/bug7154841.java | 19 +- .../JRadioButton/8033699/bug8033699.java | 7 +- .../JRadioButton/8041561/bug8041561.java | 4 +- .../swing/JRootPane/4670486/bug4670486.java | 8 +- .../swing/JScrollBar/4708809/bug4708809.java | 14 +- .../swing/JScrollBar/6542335/bug6542335.java | 8 +- .../swing/JScrollBar/7163696/Test7163696.java | 8 +- .../JScrollBar/bug4202954/bug4202954.java | 12 +- .../swing/JSlider/6348946/bug6348946.java | 14 +- .../swing/JSlider/6401380/bug6401380.java | 82 +++++++ .../swing/JSlider/6848475/bug6848475.java | 9 +- .../swing/JSpinner/4973721/bug4973721.java | 7 +- .../swing/JSpinner/5012888/bug5012888.java | 4 +- .../swing/JSplitPane/4885629/bug4885629.java | 5 +- .../swing/JTabbedPane/4361477/bug4361477.java | 4 +- .../swing/JTabbedPane/4624207/bug4624207.java | 15 +- .../swing/JTabbedPane/6495408/bug6495408.java | 4 +- .../swing/JTabbedPane/7161568/bug7161568.java | 8 +- .../swing/JTable/4220171/bug4220171.java | 13 +- .../swing/JTable/6263446/bug6263446.java | 34 ++- .../swing/JTable/6777378/bug6777378.java | 5 +- .../swing/JTable/7055065/bug7055065.java | 9 +- .../swing/JTable/7068740/bug7068740.java | 13 +- .../JTableHeader/6884066/bug6884066.java | 5 +- .../JTableHeader/6889007/bug6889007.java | 7 +- .../swing/JTextArea/4697612/bug4697612.java | 15 +- .../swing/JTextField/8036819/bug8036819.java | 6 +- .../swing/JToolBar/4247996/bug4247996.java | 6 +- .../swing/JToolTip/4846413/bug4846413.java | 6 +- .../javax/swing/JTree/4330357/bug4330357.java | 10 +- .../javax/swing/JTree/4908142/bug4908142.java | 8 +- .../javax/swing/JTree/4927934/bug4927934.java | 20 +- .../javax/swing/JTree/6263446/bug6263446.java | 9 +- .../javax/swing/JTree/6505523/bug6505523.java | 9 +- .../javax/swing/JTree/6578666/bug6578666.java | 80 +++++++ .../swing/JTree/8003400/Test8003400.java | 15 +- .../javax/swing/JTree/8004298/bug8004298.java | 6 +- .../swing/Popup/TaskbarPositionTest.java | 11 +- .../6276087/NonOpaquePopupMenuTest.java | 6 +- .../SwingUtilities/4917669/bug4917669.java | 8 +- .../SwingUtilities/7146377/bug7146377.java | 9 +- .../swing/ToolTipManager/Test6256140.java | 11 +- .../javax/swing/dnd/7171812/bug7171812.java | 5 +- .../basic/BasicHTML/4251579/bug4251579.java | 5 +- .../basic/BasicMenuUI/4983388/bug4983388.java | 7 +- .../basic/BasicTreeUI/8023474/bug8023474.java | 7 +- .../swing/plaf/synth/7158712/bug7158712.java | 4 +- .../SynthButtonUI/6276188/bug6276188.java | 4 +- .../WrongAltProcessing.java | 11 +- .../AbstractDocument/6968363/Test6968363.java | 15 +- .../text/CSSBorder/6796710/bug6796710.java | 5 +- .../DefaultEditorKit/4278839/bug4278839.java | 12 +- .../JTextComponent/5074573/bug5074573.java | 13 +- .../StyledEditorKit/4506788/bug4506788.java | 8 +- .../swing/text/View/8014863/bug8014863.java | 12 +- .../text/html/CSS/4530474/bug4530474.java | 6 +- .../HTMLEditorKit/5043626/bug5043626.java | 8 +- 110 files changed, 2418 insertions(+), 622 deletions(-) create mode 100644 jdk/test/javax/swing/JButton/4368790/bug4368790.java create mode 100644 jdk/test/javax/swing/JComboBox/4515752/DefaultButtonTest.java create mode 100644 jdk/test/javax/swing/JComboBox/6559152/bug6559152.java create mode 100644 jdk/test/javax/swing/JList/6510999/bug6510999.java create mode 100644 jdk/test/javax/swing/JMenu/4417601/bug4417601.java create mode 100644 jdk/test/javax/swing/JMenu/6359669/bug6359669.java create mode 100644 jdk/test/javax/swing/JMenu/6470128/bug6470128.java create mode 100644 jdk/test/javax/swing/JMenu/6538132/bug6538132.java create mode 100644 jdk/test/javax/swing/JMenuItem/6249972/bug6249972.java create mode 100644 jdk/test/javax/swing/JOptionPane/6428694/bug6428694.java create mode 100644 jdk/test/javax/swing/JPopupMenu/4634626/bug4634626.html create mode 100644 jdk/test/javax/swing/JPopupMenu/4634626/bug4634626.java create mode 100644 jdk/test/javax/swing/JPopupMenu/6217905/bug6217905.java create mode 100644 jdk/test/javax/swing/JPopupMenu/6415145/bug6415145.java create mode 100644 jdk/test/javax/swing/JPopupMenu/6515446/bug6515446.java create mode 100644 jdk/test/javax/swing/JPopupMenu/6544309/bug6544309.java create mode 100644 jdk/test/javax/swing/JPopupMenu/6580930/bug6580930.java create mode 100644 jdk/test/javax/swing/JSlider/6401380/bug6401380.java create mode 100644 jdk/test/javax/swing/JTree/6578666/bug6578666.java diff --git a/jdk/test/javax/swing/AbstractButton/6711682/bug6711682.java b/jdk/test/javax/swing/AbstractButton/6711682/bug6711682.java index bc6b36b1f14..3e1553799a8 100644 --- a/jdk/test/javax/swing/AbstractButton/6711682/bug6711682.java +++ b/jdk/test/javax/swing/AbstractButton/6711682/bug6711682.java @@ -28,8 +28,6 @@ @run main bug6711682 */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.event.CellEditorListener; import javax.swing.table.TableCellEditor; @@ -47,13 +45,12 @@ public class bug6711682 { public static void main(String[] args) throws Exception { Robot robot = new Robot(); robot.setAutoDelay(50); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { createAndShowGUI(); } }); - toolkit.realSync(); + robot.waitForIdle(); Point l = table.getLocationOnScreen(); int h = table.getRowHeight(); for (int i = 0; i < 3; i++) { diff --git a/jdk/test/javax/swing/JButton/4368790/bug4368790.java b/jdk/test/javax/swing/JButton/4368790/bug4368790.java new file mode 100644 index 00000000000..9a90fb7ab05 --- /dev/null +++ b/jdk/test/javax/swing/JButton/4368790/bug4368790.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2009, 2010, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* @test + @bug 4368790 + @summary JButton stays pressed when focus stolen + @author Alexander Potochkin + @run main bug4368790 +*/ + +import javax.swing.*; +import java.awt.*; +import java.awt.event.KeyEvent; + +public class bug4368790 { + private static JButton b1; + + private static void createGui() { + final JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLayout(new FlowLayout()); + + b1 = new JButton("Button1"); + frame.add(b1); + frame.add(new JButton("Button2")); + + frame.setSize(200, 200); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + b1.requestFocus(); + } + + public static void main(String[] args) throws Exception { + Robot robot = new Robot(); + robot.setAutoDelay(50); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + bug4368790.createGui(); + } + }); + robot.waitForIdle(); + robot.keyPress(KeyEvent.VK_SPACE); + robot.keyPress(KeyEvent.VK_TAB); + robot.keyRelease(KeyEvent.VK_TAB); + robot.keyRelease(KeyEvent.VK_SPACE); + robot.waitForIdle(); + if (b1.getModel().isPressed()) { + throw new RuntimeException("The button is unexpectedly pressed"); + } + } +} diff --git a/jdk/test/javax/swing/JColorChooser/Test6541987.java b/jdk/test/javax/swing/JColorChooser/Test6541987.java index 6a8f67ccb74..7a946e1b25d 100644 --- a/jdk/test/javax/swing/JColorChooser/Test6541987.java +++ b/jdk/test/javax/swing/JColorChooser/Test6541987.java @@ -39,10 +39,7 @@ import javax.swing.JColorChooser; import javax.swing.JFrame; import javax.swing.SwingUtilities; -import sun.awt.SunToolkit; - public class Test6541987 implements Runnable { - private static final SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); private static Robot robot; public static void main(String[] args) throws AWTException { @@ -50,14 +47,14 @@ public class Test6541987 implements Runnable { // test escape after selection start(); click(KeyEvent.VK_ESCAPE); - toolkit.realSync(); + robot.waitForIdle(); // test double escape after editing start(); click(KeyEvent.VK_1); click(KeyEvent.VK_0); click(KeyEvent.VK_ESCAPE); click(KeyEvent.VK_ESCAPE); - toolkit.realSync(); + robot.waitForIdle(); // all windows should be closed for (Window window : Window.getWindows()) { if (window.isVisible()) { @@ -76,7 +73,7 @@ public class Test6541987 implements Runnable { } private static void click(int...keys) { - toolkit.realSync(); + robot.waitForIdle(); for (int key : keys) { robot.keyPress(key); } diff --git a/jdk/test/javax/swing/JColorChooser/Test6827032.java b/jdk/test/javax/swing/JColorChooser/Test6827032.java index 0cb82347bfd..4d8998793e9 100644 --- a/jdk/test/javax/swing/JColorChooser/Test6827032.java +++ b/jdk/test/javax/swing/JColorChooser/Test6827032.java @@ -29,8 +29,6 @@ * @library ../regtesthelpers */ -import sun.awt.SunToolkit; - import java.awt.*; import java.awt.event.*; @@ -49,7 +47,6 @@ public class Test6827032 { Robot robot = new Robot(); robot.setAutoDelay(50); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -57,7 +54,7 @@ public class Test6827032 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { diff --git a/jdk/test/javax/swing/JColorChooser/Test7194184.java b/jdk/test/javax/swing/JColorChooser/Test7194184.java index 97599b12696..70201764032 100644 --- a/jdk/test/javax/swing/JColorChooser/Test7194184.java +++ b/jdk/test/javax/swing/JColorChooser/Test7194184.java @@ -39,7 +39,6 @@ import java.awt.Component; import java.awt.AWTException; import java.awt.Color; import java.awt.Robot; -import java.awt.Toolkit; import java.awt.event.KeyEvent; import javax.swing.JColorChooser; @@ -47,7 +46,6 @@ import javax.swing.JFrame; import javax.swing.SwingUtilities; import java.util.concurrent.Callable; -import sun.awt.SunToolkit; public class Test7194184 implements Runnable { private static JFrame frame; @@ -60,10 +58,9 @@ public class Test7194184 implements Runnable { private static void testKeyBoardAccess() throws Exception { Robot robot = new Robot(); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); SwingUtilities.invokeLater(new Test7194184()); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeLater(new Runnable() { @Override @@ -78,7 +75,7 @@ public class Test7194184 implements Runnable { } }); - toolkit.realSync(); + robot.waitForIdle(); // Tab to move the focus to MainSwatch Util.hitKeys(robot, KeyEvent.VK_SHIFT, KeyEvent.VK_TAB); @@ -87,7 +84,7 @@ public class Test7194184 implements Runnable { Util.hitKeys(robot, KeyEvent.VK_RIGHT); Util.hitKeys(robot, KeyEvent.VK_RIGHT); Util.hitKeys(robot, KeyEvent.VK_SPACE); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override diff --git a/jdk/test/javax/swing/JComboBox/4199622/bug4199622.java b/jdk/test/javax/swing/JComboBox/4199622/bug4199622.java index 2c7deddb31b..83392bae45b 100644 --- a/jdk/test/javax/swing/JComboBox/4199622/bug4199622.java +++ b/jdk/test/javax/swing/JComboBox/4199622/bug4199622.java @@ -25,12 +25,13 @@ @bug 4199622 @summary RFE: JComboBox shouldn't send ActionEvents for keyboard navigation @author Vladislav Karnaukhov + @library ../../../../lib/testlibrary + @build jdk.testlibrary.OSInfo @run main bug4199622 */ import com.sun.java.swing.plaf.windows.WindowsLookAndFeel; -import sun.awt.OSInfo; -import sun.awt.SunToolkit; +import jdk.testlibrary.OSInfo; import javax.swing.*; import javax.swing.plaf.metal.MetalLookAndFeel; @@ -74,7 +75,6 @@ public class bug4199622 extends JFrame implements ActionListener { } static Robot robot = null; - static SunToolkit toolkit = null; static void doTest() { if (robot == null) { @@ -86,11 +86,7 @@ public class bug4199622 extends JFrame implements ActionListener { } } - toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - if (toolkit == null) { - throw new RuntimeException("Can't get the toolkit. Test failed"); - } - toolkit.realSync(); + robot.waitForIdle(); doActualTest(); @@ -109,7 +105,7 @@ public class bug4199622 extends JFrame implements ActionListener { throw new RuntimeException("Test failed", e); } - toolkit.realSync(); + robot.waitForIdle(); doActualTest(); } @@ -144,12 +140,14 @@ public class bug4199622 extends JFrame implements ActionListener { } catch (InvocationTargetException e) { throw new RuntimeException("Test failed", e); } - toolkit.realSync(); + robot.waitForIdle(); robot.keyPress(KeyEvent.VK_END); - toolkit.realSync(); + robot.keyRelease(KeyEvent.VK_END); + robot.waitForIdle(); robot.keyPress(KeyEvent.VK_HOME); - toolkit.realSync(); + robot.keyRelease(KeyEvent.VK_HOME); + robot.waitForIdle(); } static void doTestUpDown() { @@ -166,16 +164,18 @@ public class bug4199622 extends JFrame implements ActionListener { } catch (InvocationTargetException e) { throw new RuntimeException("Test failed", e); } - toolkit.realSync(); + robot.waitForIdle(); for (int i = 0; i < nElems; i++) { robot.keyPress(KeyEvent.VK_DOWN); - toolkit.realSync(); + robot.keyRelease(KeyEvent.VK_DOWN); + robot.waitForIdle(); } for (int i = 0; i < nElems; i++) { robot.keyPress(KeyEvent.VK_UP); - toolkit.realSync(); + robot.keyRelease(KeyEvent.VK_UP); + robot.waitForIdle(); } } @@ -193,17 +193,19 @@ public class bug4199622 extends JFrame implements ActionListener { } catch (InvocationTargetException e) { throw new RuntimeException("Test failed", e); } - toolkit.realSync(); + robot.waitForIdle(); int listHeight = cb.getMaximumRowCount(); for (int i = 0; i < nElems; i += listHeight) { robot.keyPress(KeyEvent.VK_PAGE_DOWN); - toolkit.realSync(); + robot.keyRelease(KeyEvent.VK_PAGE_DOWN); + robot.waitForIdle(); } for (int i = 0; i < nElems; i += listHeight) { robot.keyPress(KeyEvent.VK_PAGE_UP); - toolkit.realSync(); + robot.keyRelease(KeyEvent.VK_PAGE_UP); + robot.waitForIdle(); } } diff --git a/jdk/test/javax/swing/JComboBox/4515752/DefaultButtonTest.java b/jdk/test/javax/swing/JComboBox/4515752/DefaultButtonTest.java new file mode 100644 index 00000000000..88abb7b574b --- /dev/null +++ b/jdk/test/javax/swing/JComboBox/4515752/DefaultButtonTest.java @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2002, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +import java.awt.*; +import java.awt.event.*; + +import javax.swing.*; + +/** + * @test + * @bug 4515752 4337071 + * @author Mark Davidson + * @summary Tests the invocation of the default button within the JComboBox. + */ +public class DefaultButtonTest extends JFrame implements ActionListener { + + private static boolean defaultButtonPressed = false; + private static boolean editChanged = false; + + private static String[] strData = { + "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" + }; + + private static String[] strData2 = { + "One", "Two", "Three", "Four", "Five", "Six", "Seven" + }; + + public static void main(String[] args) throws Throwable { + SwingUtilities.invokeAndWait(new Runnable(){ + public void run() { + new DefaultButtonTest(); + } + }); + test(); + System.out.println("Test Passed"); + } + + public DefaultButtonTest() { + getContentPane().add(new DefaultPanel(this)); + pack(); + setVisible(true); + } + + public static void test() { + // Use Robot to automate the test + Robot robot = null; + try { + robot = new Robot(); + } catch (Exception ex) { + ex.printStackTrace(); + } + robot.setAutoDelay(125); + + for (int i = 0; i < 3; i++) { + // Test ENTER press on the non editable combo. + robot.waitForIdle(); + robot.keyPress(KeyEvent.VK_ENTER); + robot.waitForIdle(); + robot.keyRelease(KeyEvent.VK_ENTER); + robot.waitForIdle(); + testDefaultButton(true); + + // Test the ENTER press on the editable combo box + robot.keyPress(KeyEvent.VK_TAB); + robot.waitForIdle(); + robot.keyRelease(KeyEvent.VK_TAB); + robot.waitForIdle(); + robot.keyPress(KeyEvent.VK_ENTER); + robot.waitForIdle(); + robot.keyRelease(KeyEvent.VK_ENTER); + robot.waitForIdle(); + testDefaultButton(true); + + // Change the value, should generate a change but not a Default Button press. + robot.waitForIdle(); + robot.keyPress(KeyEvent.VK_D); + robot.waitForIdle(); + robot.keyRelease(KeyEvent.VK_D); + robot.waitForIdle(); + robot.keyPress(KeyEvent.VK_ENTER); + robot.waitForIdle(); + robot.keyRelease(KeyEvent.VK_ENTER); + robot.waitForIdle(); + testEditChange(true); + robot.waitForIdle(); + testDefaultButton(true); + + // Change value, changing focus should fire an ActionEvent. + robot.waitForIdle(); + robot.keyPress(KeyEvent.VK_BACK_SPACE); + robot.waitForIdle(); + robot.keyRelease(KeyEvent.VK_BACK_SPACE); + robot.waitForIdle(); + robot.keyPress(KeyEvent.VK_SHIFT); + robot.waitForIdle(); + robot.keyPress(KeyEvent.VK_TAB); + robot.waitForIdle(); + robot.keyRelease(KeyEvent.VK_SHIFT); + robot.waitForIdle(); + robot.keyRelease(KeyEvent.VK_TAB); + robot.waitForIdle(); + testEditChange(true); + robot.waitForIdle(); + testDefaultButton(false); + } + } + + public void actionPerformed(ActionEvent evt) { + String cmd = evt.getActionCommand(); + System.out.println("ActionEvent: " + cmd); + + if (cmd.equals("OK")) { + defaultButtonPressed = true; + } + + if (cmd.equals("comboBoxChanged")) { + editChanged = true; + } + } + + public static void testDefaultButton(boolean flag) { + if (defaultButtonPressed != flag) { + new RuntimeException("defaultButtonPressed unexpectedly = " + defaultButtonPressed); + } + // reset + defaultButtonPressed = false; + } + + public static void testEditChange(boolean flag) { + if (editChanged != flag) { + new RuntimeException("editChanged unexpectedly = " + editChanged); + } + // reset + editChanged = false; + } + + class DefaultPanel extends JPanel { + + public JComboBox combo; + public JComboBox combo2; + + private JButton okButton = new JButton("OK"); + private JButton cancelButton = new JButton("Cancel"); + + public DefaultPanel(JFrame root) { + setLayout(new BorderLayout()); + add(createPanel(), BorderLayout.NORTH); + add(createInfoPanel(), BorderLayout.CENTER); + add(createButtonPanel(root), BorderLayout.SOUTH); + } + + private JPanel createPanel() { + combo = new JComboBox(strData); + combo.addActionListener(DefaultButtonTest.this); + combo2 = new JComboBox(strData2); + combo2.setEditable(true); + combo2.addActionListener(DefaultButtonTest.this); + + JPanel panel = new JPanel(); + + panel.add(combo); + panel.add(combo2); + + return panel; + } + + private JScrollPane createInfoPanel() { + StringBuffer txt = new StringBuffer("Test for 4337071:\n"); + txt.append("ENTER pressed in NON-EDITABLE combo box should be passed to the OK button.\n"); + txt.append("For an EDITABLE combo box, the combo box should fire an action event."); + txt.append("\n\nTest for 4515752:\n"); + txt.append("ENTER on an EDITABLE combo box in which the contents has not changed\n"); + txt.append("should be passed to the default button"); + + JTextArea text = new JTextArea(txt.toString()); + text.setEditable(false); + + return new JScrollPane(text); + } + + + private JPanel createButtonPanel(JFrame frame) { + frame.getRootPane().setDefaultButton(okButton); + + // This is just to check when the OK Button was pressed. + okButton.addActionListener(DefaultButtonTest.this); + + JPanel panel = new JPanel(); + panel.add(okButton); + panel.add(cancelButton); + return panel; + } + } + +} diff --git a/jdk/test/javax/swing/JComboBox/4743225/bug4743225.java b/jdk/test/javax/swing/JComboBox/4743225/bug4743225.java index 2a41b3075ac..76c2f1cea27 100644 --- a/jdk/test/javax/swing/JComboBox/4743225/bug4743225.java +++ b/jdk/test/javax/swing/JComboBox/4743225/bug4743225.java @@ -27,8 +27,6 @@ * @author Alexander Potochkin */ -import sun.awt.SunToolkit; - import javax.accessibility.AccessibleContext; import javax.swing.JComboBox; import javax.swing.JFrame; @@ -39,7 +37,6 @@ import javax.swing.plaf.basic.BasicComboPopup; import java.awt.FlowLayout; import java.awt.Point; import java.awt.Robot; -import java.awt.Toolkit; import java.awt.event.InputEvent; public class bug4743225 extends JFrame { @@ -80,21 +77,20 @@ public class bug4743225 extends JFrame { Robot robot = new Robot(); robot.setAutoDelay(20); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { new bug4743225().setVisible(true); } }); - toolkit.realSync(); + robot.waitForIdle(); // calling this method from main thread is ok Point point = cb.getLocationOnScreen(); robot.mouseMove(point.x + 10, point.y + 10); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { diff --git a/jdk/test/javax/swing/JComboBox/6236162/bug6236162.java b/jdk/test/javax/swing/JComboBox/6236162/bug6236162.java index 6e0ad44e734..66d6cb73282 100644 --- a/jdk/test/javax/swing/JComboBox/6236162/bug6236162.java +++ b/jdk/test/javax/swing/JComboBox/6236162/bug6236162.java @@ -31,8 +31,6 @@ @run main bug6236162 */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.plaf.basic.*; import javax.swing.plaf.metal.MetalComboBoxUI; @@ -40,7 +38,6 @@ import java.awt.*; import java.awt.event.KeyEvent; public class bug6236162 { - private static final SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); private static JFrame frame; private static JComboBox combo; private static MyComboUI comboUI; @@ -52,7 +49,6 @@ public class bug6236162 { createAndShowGUI(); } }); - toolkit.realSync(); test(); System.out.println("Test passed"); } @@ -78,11 +74,11 @@ public class bug6236162 { robot.setAutoDelay(50); // Open popup menu - realSync(); + robot.waitForIdle(); Util.hitKeys(robot, KeyEvent.VK_DOWN); // Move mouse to the first popup menu item - realSync(); + robot.waitForIdle(); Point p = combo.getLocationOnScreen(); Dimension size = combo.getSize(); p.x += size.width / 2; @@ -94,10 +90,10 @@ public class bug6236162 { } // Select the second popup menu item - realSync(); + robot.waitForIdle(); Util.hitKeys(robot, KeyEvent.VK_DOWN); - realSync(); + robot.waitForIdle(); JList list = comboUI.getComboPopup().getList(); if (list.getSelectedIndex() != 1) { throw new RuntimeException("There is an inconsistence in combo box " + @@ -106,9 +102,6 @@ public class bug6236162 { } } - private static void realSync() { - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); - } // Gives access to BasicComboBoxUI.popup field private static class MyComboUI extends MetalComboBoxUI { diff --git a/jdk/test/javax/swing/JComboBox/6559152/bug6559152.java b/jdk/test/javax/swing/JComboBox/6559152/bug6559152.java new file mode 100644 index 00000000000..d04e6004a8f --- /dev/null +++ b/jdk/test/javax/swing/JComboBox/6559152/bug6559152.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2011, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* @test + @bug 6559152 + @summary Checks that you can select an item in JComboBox with keyboard + when it is a JTable cell editor. + @author Mikhail Lapshin + @library ../../../../lib/testlibrary + @build ExtendedRobot + @run main bug6559152 +*/ + +import javax.swing.*; +import javax.swing.table.DefaultTableModel; +import java.awt.*; +import java.awt.event.KeyEvent; + +public class bug6559152 { + private JFrame frame; + private JComboBox cb; + private ExtendedRobot robot; + + public static void main(String[] args) throws Exception { + final bug6559152 test = new bug6559152(); + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + test.setupUI(); + } + }); + test.test(); + } finally { + if (test.frame != null) { + test.frame.dispose(); + } + } + } + + private void setupUI() { + frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + DefaultTableModel model = new DefaultTableModel(1, 1); + JTable table = new JTable(model); + + cb = new JComboBox(new String[]{"one", "two", "three"}); + cb.setEditable(true); + table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(cb)); + frame.add(cb); + + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + private void test() throws Exception { + robot = new ExtendedRobot(); + robot.waitForIdle(); + testImpl(); + robot.waitForIdle(); + checkResult(); + } + + private void testImpl() throws Exception { + robot.type(KeyEvent.VK_DOWN); + robot.waitForIdle(); + robot.type(KeyEvent.VK_DOWN); + robot.waitForIdle(); + robot.type(KeyEvent.VK_ENTER); + } + + private void checkResult() { + if (cb.getSelectedItem().equals("two")) { + System.out.println("Test passed"); + } else { + System.out.println("Test failed"); + throw new RuntimeException("Cannot select an item " + + "from popup with the ENTER key."); + } + } +} diff --git a/jdk/test/javax/swing/JComboBox/6607130/bug6607130.java b/jdk/test/javax/swing/JComboBox/6607130/bug6607130.java index 77587852af2..86850f308b7 100644 --- a/jdk/test/javax/swing/JComboBox/6607130/bug6607130.java +++ b/jdk/test/javax/swing/JComboBox/6607130/bug6607130.java @@ -30,8 +30,6 @@ * @author Mikhail Lapshin */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.*; @@ -79,44 +77,44 @@ public class bug6607130 { } private void test() throws Exception { - realSync(); + robot.waitForIdle(); test1(); - realSync(); + robot.waitForIdle(); checkResult("First test"); test2(); - realSync(); + robot.waitForIdle(); checkResult("Second test"); } private void test1() throws Exception { // Select 'one' hitKey(KeyEvent.VK_TAB); - realSync(); + robot.waitForIdle(); hitKey(KeyEvent.VK_F2); - realSync(); + robot.waitForIdle(); hitKey(KeyEvent.VK_DOWN); - realSync(); + robot.waitForIdle(); hitKey(KeyEvent.VK_DOWN); - realSync(); + robot.waitForIdle(); hitKey(KeyEvent.VK_ENTER); - realSync(); + robot.waitForIdle(); // Select 'one' again hitKey(KeyEvent.VK_F2); - realSync(); + robot.waitForIdle(); hitKey(KeyEvent.VK_DOWN); - realSync(); + robot.waitForIdle(); hitKey(KeyEvent.VK_ENTER); - realSync(); + robot.waitForIdle(); } private void test2() throws Exception { // Press F2 and then press ENTER // Editor should be shown and then closed hitKey(KeyEvent.VK_F2); - realSync(); + robot.waitForIdle(); hitKey(KeyEvent.VK_ENTER); - realSync(); + robot.waitForIdle(); } private void checkResult(String testName) { @@ -129,10 +127,6 @@ public class bug6607130 { } } - private static void realSync() { - ((SunToolkit) (Toolkit.getDefaultToolkit())).realSync(); - } - public void hitKey(int keycode) { robot.keyPress(keycode); robot.keyRelease(keycode); diff --git a/jdk/test/javax/swing/JComboBox/8032878/bug8032878.java b/jdk/test/javax/swing/JComboBox/8032878/bug8032878.java index f5c9c88ca63..32db0d8666f 100644 --- a/jdk/test/javax/swing/JComboBox/8032878/bug8032878.java +++ b/jdk/test/javax/swing/JComboBox/8032878/bug8032878.java @@ -29,6 +29,7 @@ * @library ../../regtesthelpers * @build Util * @author Alexey Ivanov + * @run main bug8032878 */ import java.awt.*; @@ -36,8 +37,6 @@ import java.awt.event.KeyEvent; import javax.swing.*; import javax.swing.text.JTextComponent; -import sun.awt.SunToolkit; - public class bug8032878 implements Runnable { private static final String ONE = "one"; private static final String TWO = "two"; @@ -99,15 +98,15 @@ public class bug8032878 implements Runnable { } private void runTest() throws Exception { - realSync(); + robot.waitForIdle(); // Select 'one' Util.hitKeys(robot, KeyEvent.VK_TAB); - realSync(); + robot.waitForIdle(); Util.hitKeys(robot, KeyEvent.VK_1); Util.hitKeys(robot, KeyEvent.VK_2); Util.hitKeys(robot, KeyEvent.VK_3); Util.hitKeys(robot, KeyEvent.VK_ENTER); - realSync(); + robot.waitForIdle(); } private void checkResult() throws Exception { @@ -125,9 +124,6 @@ public class bug8032878 implements Runnable { } } - private static void realSync() { - ((SunToolkit) (Toolkit.getDefaultToolkit())).realSync(); - } @Override public void run() { diff --git a/jdk/test/javax/swing/JComboBox/8057893/bug8057893.java b/jdk/test/javax/swing/JComboBox/8057893/bug8057893.java index 5f58d3dd664..76944ed902c 100644 --- a/jdk/test/javax/swing/JComboBox/8057893/bug8057893.java +++ b/jdk/test/javax/swing/JComboBox/8057893/bug8057893.java @@ -30,7 +30,6 @@ import java.awt.event.KeyEvent; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.WindowConstants; -import sun.awt.SunToolkit; /** * @test @@ -47,7 +46,6 @@ public class bug8057893 { public static void main(String[] args) throws Exception { Robot robot = new Robot(); robot.setAutoDelay(50); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); EventQueue.invokeAndWait(() -> { JFrame frame = new JFrame(); @@ -69,13 +67,13 @@ public class bug8057893 { comboBox.requestFocusInWindow(); }); - toolkit.realSync(); + robot.waitForIdle(); robot.keyPress(KeyEvent.VK_A); robot.keyRelease(KeyEvent.VK_A); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); - toolkit.realSync(); + robot.waitForIdle(); if(!isComboBoxEdited){ throw new RuntimeException("ComboBoxEdited event is not fired!"); diff --git a/jdk/test/javax/swing/JComponent/6683775/bug6683775.java b/jdk/test/javax/swing/JComponent/6683775/bug6683775.java index 9b1178d69fc..190d0463e21 100644 --- a/jdk/test/javax/swing/JComponent/6683775/bug6683775.java +++ b/jdk/test/javax/swing/JComponent/6683775/bug6683775.java @@ -38,8 +38,8 @@ import java.awt.image.BufferedImage; public class bug6683775 { public static void main(String[] args) throws Exception { GraphicsConfiguration gc = getGC(); - if (!AWTUtilities.isTranslucencySupported( - AWTUtilities.Translucency.PERPIXEL_TRANSLUCENT) + if (!AWTUtilities.isTranslucencySupported( + AWTUtilities.Translucency.PERPIXEL_TRANSLUCENT) || gc == null) { return; } diff --git a/jdk/test/javax/swing/JComponent/7154030/bug7154030.java b/jdk/test/javax/swing/JComponent/7154030/bug7154030.java index ade828061ff..dab2d3c9ba9 100644 --- a/jdk/test/javax/swing/JComponent/7154030/bug7154030.java +++ b/jdk/test/javax/swing/JComponent/7154030/bug7154030.java @@ -29,7 +29,6 @@ import javax.swing.JButton; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.SwingUtilities; -import sun.awt.SunToolkit; import java.awt.AWTException; import java.awt.AlphaComposite; @@ -46,7 +45,9 @@ import java.awt.image.BufferedImage; * @summary Swing components fail to hide after calling hide() * @author Jonathan Lu * @library ../../regtesthelpers/ + * @library ../../../../lib/testlibrary/ * @build Util + * @build ExtendedRobot * @run main bug7154030 */ @@ -61,9 +62,7 @@ public class bug7154030 { BufferedImage imageHide = null; - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - - Robot robot = new Robot(); + ExtendedRobot robot = new ExtendedRobot(); SwingUtilities.invokeAndWait(new Runnable() { @@ -89,7 +88,7 @@ public class bug7154030 { } }); - toolkit.realSync(); + robot.waitForIdle(500); imageInit = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); SwingUtilities.invokeAndWait(new Runnable() { @@ -100,13 +99,13 @@ public class bug7154030 { } }); - toolkit.realSync(); + robot.waitForIdle(500); imageShow = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); if (Util.compareBufferedImages(imageInit, imageShow)) { throw new Exception("Failed to show opaque button"); } - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @@ -116,7 +115,7 @@ public class bug7154030 { } }); - toolkit.realSync(); + robot.waitForIdle(500); imageHide = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); if (!Util.compareBufferedImages(imageInit, imageHide)) { @@ -133,7 +132,7 @@ public class bug7154030 { } }); - toolkit.realSync(); + robot.waitForIdle(500); imageInit = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); SwingUtilities.invokeAndWait(new Runnable() { @@ -144,7 +143,7 @@ public class bug7154030 { } }); - toolkit.realSync(); + robot.waitForIdle(500); imageShow = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); SwingUtilities.invokeAndWait(new Runnable() { @@ -159,7 +158,7 @@ public class bug7154030 { throw new Exception("Failed to show non-opaque button"); } - toolkit.realSync(); + robot.waitForIdle(500); imageHide = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); if (!Util.compareBufferedImages(imageInit, imageHide)) { diff --git a/jdk/test/javax/swing/JEditorPane/6917744/bug6917744.java b/jdk/test/javax/swing/JEditorPane/6917744/bug6917744.java index eec3946e36c..75af9834b91 100644 --- a/jdk/test/javax/swing/JEditorPane/6917744/bug6917744.java +++ b/jdk/test/javax/swing/JEditorPane/6917744/bug6917744.java @@ -33,8 +33,6 @@ import java.awt.event.KeyEvent; import java.io.IOException; import javax.swing.*; -import sun.awt.SunToolkit; - public class bug6917744 { private static JFrame frame; @@ -45,7 +43,6 @@ public class bug6917744 { private static Robot robot; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); robot = new Robot(); robot.setAutoDelay(100); @@ -70,13 +67,14 @@ public class bug6917744 { } }); - toolkit.realSync(); + robot.waitForIdle(); for (int i = 0; i < 50; i++) { robot.keyPress(KeyEvent.VK_PAGE_DOWN); + robot.keyRelease(KeyEvent.VK_PAGE_DOWN); } - toolkit.realSync(); + robot.waitForIdle(); // Check that we at the end of document SwingUtilities.invokeAndWait(new Runnable() { @@ -89,13 +87,14 @@ public class bug6917744 { } }); - toolkit.realSync(); + robot.waitForIdle(); for (int i = 0; i < 50; i++) { robot.keyPress(KeyEvent.VK_PAGE_UP); + robot.keyRelease(KeyEvent.VK_PAGE_UP); } - toolkit.realSync(); + robot.waitForIdle(); // Check that we at the begin of document SwingUtilities.invokeAndWait(new Runnable() { diff --git a/jdk/test/javax/swing/JFileChooser/4524490/bug4524490.java b/jdk/test/javax/swing/JFileChooser/4524490/bug4524490.java index aedfdc1f9c1..81a5259e420 100644 --- a/jdk/test/javax/swing/JFileChooser/4524490/bug4524490.java +++ b/jdk/test/javax/swing/JFileChooser/4524490/bug4524490.java @@ -25,24 +25,23 @@ * @test * @bug 4524490 * @summary Tests if in JFileChooser, ALT+L does not bring focus to 'Files' selection list in Motif LAF - * @library ../../regtesthelpers - * @build Util * @author Konstantin Eremin + * @library ../../regtesthelpers + * @library ../../../../lib/testlibrary + * @build Util jdk.testlibrary.OSInfo * @run main bug4524490 */ import java.awt.Robot; import java.awt.Toolkit; import java.awt.event.KeyEvent; import javax.swing.*; -import sun.awt.OSInfo; -import sun.awt.SunToolkit; +import jdk.testlibrary.OSInfo; public class bug4524490 { private static JFileChooser fileChooser; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -56,7 +55,7 @@ public class bug4524490 { } }); - toolkit.realSync(); + robot.waitForIdle(); if (OSInfo.OSType.MACOSX.equals(OSInfo.getOSType())) { Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_L); diff --git a/jdk/test/javax/swing/JFileChooser/7199708/bug7199708.java b/jdk/test/javax/swing/JFileChooser/7199708/bug7199708.java index 339c6553a18..2b10137366a 100644 --- a/jdk/test/javax/swing/JFileChooser/7199708/bug7199708.java +++ b/jdk/test/javax/swing/JFileChooser/7199708/bug7199708.java @@ -37,7 +37,6 @@ import java.nio.file.Files; import javax.swing.AbstractButton; import javax.swing.JTable; import javax.swing.UIManager; -import sun.awt.SunToolkit; /** * @test @@ -56,7 +55,6 @@ public class bug7199708 { public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -70,7 +68,7 @@ public class bug7199708 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeLater(new Runnable() { public void run() { @@ -108,14 +106,14 @@ public class bug7199708 { } }); - toolkit.realSync(); + robot.waitForIdle(); int d = 25; for (int i = 0; i < width / d; i++) { robot.mouseMove(locationX + i * d, locationY + 5); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); } robot.keyPress(KeyEvent.VK_ESCAPE); diff --git a/jdk/test/javax/swing/JFileChooser/8002077/bug8002077.java b/jdk/test/javax/swing/JFileChooser/8002077/bug8002077.java index ea1470d4ed5..47ab24a57b8 100644 --- a/jdk/test/javax/swing/JFileChooser/8002077/bug8002077.java +++ b/jdk/test/javax/swing/JFileChooser/8002077/bug8002077.java @@ -28,7 +28,6 @@ import javax.swing.JFileChooser; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UIManager.LookAndFeelInfo; -import sun.awt.SunToolkit; /** * @test @@ -54,7 +53,6 @@ public class bug8002077 { } private static void runTest() throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -63,17 +61,17 @@ public class bug8002077 { fileChooserState = new JFileChooser().showSaveDialog(null); } }); - toolkit.realSync(); + robot.waitForIdle(); Util.hitMnemonics(robot, KeyEvent.VK_N); - toolkit.realSync(); + robot.waitForIdle(); robot.keyPress(KeyEvent.VK_A); robot.keyRelease(KeyEvent.VK_A); - toolkit.realSync(); + robot.waitForIdle(); Util.hitMnemonics(robot, KeyEvent.VK_S); - toolkit.realSync(); + robot.waitForIdle(); if (fileChooserState != JFileChooser.APPROVE_OPTION) { throw new RuntimeException("Save button is not pressed!"); diff --git a/jdk/test/javax/swing/JFileChooser/8021253/bug8021253.java b/jdk/test/javax/swing/JFileChooser/8021253/bug8021253.java index 5e833926a00..3839c5abf9e 100644 --- a/jdk/test/javax/swing/JFileChooser/8021253/bug8021253.java +++ b/jdk/test/javax/swing/JFileChooser/8021253/bug8021253.java @@ -32,7 +32,6 @@ import java.awt.event.KeyEvent; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.SwingUtilities; -import sun.awt.SunToolkit; /** * @test @@ -50,7 +49,6 @@ public class bug8021253 { public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -60,7 +58,7 @@ public class bug8021253 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -68,11 +66,11 @@ public class bug8021253 { } }); - toolkit.realSync(); + robot.waitForIdle(); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); - toolkit.realSync(); + robot.waitForIdle(); if (!defaultKeyPressed) { throw new RuntimeException("Default button is not pressed"); diff --git a/jdk/test/javax/swing/JFrame/4962534/bug4962534.java b/jdk/test/javax/swing/JFrame/4962534/bug4962534.java index 4b50a06e44d..ebf96201037 100644 --- a/jdk/test/javax/swing/JFrame/4962534/bug4962534.java +++ b/jdk/test/javax/swing/JFrame/4962534/bug4962534.java @@ -33,7 +33,6 @@ import java.awt.*; import java.awt.event.*; import java.util.Random; import javax.swing.*; -import sun.awt.SunToolkit; public class bug4962534 extends Applet { @@ -45,7 +44,6 @@ public class bug4962534 extends Applet { Component titleComponent; JLayeredPane lPane; volatile boolean titleFound = false; - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); public static Object LOCK = new Object(); @Override @@ -91,13 +89,13 @@ public class bug4962534 extends Applet { robot = new Robot(); robot.setAutoDelay(70); - toolkit.realSync(); + robot.waitForIdle(); robot.mouseMove(framePosition.x + getJFrameWidthEDT() / 2, framePosition.y + titleComponent.getHeight() / 2); robot.mousePress(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); gcBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0].getConfigurations()[0].getBounds(); @@ -105,7 +103,7 @@ public class bug4962534 extends Applet { robot.mouseMove(framePosition.x + getJFrameWidthEDT() / 2, framePosition.y + titleComponent.getHeight() / 2); - toolkit.realSync(); + robot.waitForIdle(); int multier = gcBounds.height / 2 - 10; //we will not go out the borders for (int i = 0; i < 10; i++) { @@ -113,7 +111,7 @@ public class bug4962534 extends Applet { } robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); } catch (AWTException e) { throw new RuntimeException("Test Failed. AWTException thrown." + e.getMessage()); diff --git a/jdk/test/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java b/jdk/test/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java index f3dd87cb335..79cc40e5a7e 100644 --- a/jdk/test/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java +++ b/jdk/test/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java @@ -22,21 +22,21 @@ */ import java.awt.Rectangle; -import java.awt.Robot; import java.awt.Toolkit; import java.awt.image.BufferedImage; import javax.swing.JFrame; import javax.swing.SwingUtilities; - -import sun.awt.OSInfo; -import sun.awt.SunToolkit; +import jdk.testlibrary.OSInfo; /** * @test * @bug 7124513 * @summary We should support NSTexturedBackgroundWindowMask style on OSX. * @author Sergey Bylokhov + * @library ../../../../lib/testlibrary + * @build ExtendedRobot jdk.testlibrary.OSInfo + * @run main NSTexturedJFrame */ public final class NSTexturedJFrame { @@ -46,12 +46,15 @@ public final class NSTexturedJFrame { private static Rectangle bounds; private static volatile int step; private static JFrame frame; + private static ExtendedRobot robot; public static void main(final String[] args) throws Exception { if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) { System.out.println("This test is for OSX, considered passed."); return; } + robot = new ExtendedRobot(); + robot.setAutoDelay(50); // Default window appearance showFrame(); step++; @@ -84,12 +87,10 @@ public final class NSTexturedJFrame { } private static void showFrame() throws Exception { - final Robot robot = new Robot(); - robot.setAutoDelay(50); createUI(); images[step] = robot.createScreenCapture(bounds); SwingUtilities.invokeAndWait(frame::dispose); - sleep(); + robot.waitForIdle(1000); } private static void createUI() throws Exception { @@ -107,15 +108,11 @@ public final class NSTexturedJFrame { } frame.setVisible(true); }); - sleep(); + robot.waitForIdle(1000); SwingUtilities.invokeAndWait(() -> { bounds = frame.getBounds(); }); - sleep(); + robot.waitForIdle(1000); } - private static void sleep() throws InterruptedException { - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); - Thread.sleep(1000); - } } diff --git a/jdk/test/javax/swing/JInternalFrame/5066752/bug5066752.java b/jdk/test/javax/swing/JInternalFrame/5066752/bug5066752.java index 09a8a7bd28f..3ed42fc59ec 100644 --- a/jdk/test/javax/swing/JInternalFrame/5066752/bug5066752.java +++ b/jdk/test/javax/swing/JInternalFrame/5066752/bug5066752.java @@ -32,21 +32,19 @@ import java.awt.*; import javax.swing.*; -import sun.awt.*; public class bug5066752 { private static JFrame frame; public static void main(String[] args) throws Exception { - SunToolkit tk = (SunToolkit)Toolkit.getDefaultToolkit(); Robot r = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { createAndShowGUI(); } }); - tk.realSync(); + r.waitForIdle(); r.delay(600); diff --git a/jdk/test/javax/swing/JInternalFrame/8020708/bug8020708.java b/jdk/test/javax/swing/JInternalFrame/8020708/bug8020708.java index c40678d88bf..9aaa5afe2e0 100644 --- a/jdk/test/javax/swing/JInternalFrame/8020708/bug8020708.java +++ b/jdk/test/javax/swing/JInternalFrame/8020708/bug8020708.java @@ -32,7 +32,6 @@ import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.SwingUtilities; import javax.swing.UIManager; -import sun.awt.SunToolkit; /** * @test @@ -79,7 +78,6 @@ public class bug8020708 { } static void testInternalFrameMnemonic() throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -103,25 +101,26 @@ public class bug8020708 { } }); - toolkit.realSync(); + robot.waitForIdle(); Point clickPoint = Util.getCenterPoint(internalFrame); robot.mouseMove(clickPoint.x, clickPoint.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_SPACE); - toolkit.realSync(); + robot.waitForIdle(); Util.hitKeys(robot, KeyEvent.VK_C); - toolkit.realSync(); + robot.waitForIdle(); + robot.delay(500); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { if (internalFrame.isVisible()) { - throw new RuntimeException("Close mnemonic does not work"); + throw new RuntimeException("Close mnemonic does not work in "+UIManager.getLookAndFeel()); } frame.dispose(); } diff --git a/jdk/test/javax/swing/JInternalFrame/InternalFrameIsNotCollectedTest.java b/jdk/test/javax/swing/JInternalFrame/InternalFrameIsNotCollectedTest.java index fff9c8e1d94..a00812602fd 100644 --- a/jdk/test/javax/swing/JInternalFrame/InternalFrameIsNotCollectedTest.java +++ b/jdk/test/javax/swing/JInternalFrame/InternalFrameIsNotCollectedTest.java @@ -27,8 +27,6 @@ @author mcherkas @run main InternalFrameIsNotCollectedTest */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; import java.beans.PropertyVetoException; @@ -41,12 +39,6 @@ public class InternalFrameIsNotCollectedTest { private static Robot robot; private static CustomInternalFrame iFrame; - public static void sync() { - - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - toolkit.realSync(); - } - public static void main(String[] args) throws Exception { initRobot(); SwingUtilities.invokeAndWait(new Runnable() { @@ -60,7 +52,7 @@ public class InternalFrameIsNotCollectedTest { } } }); - sync(); + robot.waitForIdle(); invokeGC(); System.runFinalization(); Thread.sleep(1000); // it's better to wait 1 sec now then 10 sec later @@ -134,4 +126,4 @@ public class InternalFrameIsNotCollectedTest { waiter.notifyAll(); } } -} \ No newline at end of file +} diff --git a/jdk/test/javax/swing/JList/6462008/bug6462008.java b/jdk/test/javax/swing/JList/6462008/bug6462008.java index 12adaed9bb6..9ecd674b0ce 100644 --- a/jdk/test/javax/swing/JList/6462008/bug6462008.java +++ b/jdk/test/javax/swing/JList/6462008/bug6462008.java @@ -32,7 +32,6 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; -import sun.awt.SunToolkit; public class bug6462008 { @@ -41,11 +40,9 @@ public class bug6462008 { private static boolean isAquaLAF; private static int controlKey; private static JList list; - private static SunToolkit toolkit; private static Robot robot; public static void main(String[] args) throws Exception { - toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); robot = new Robot(); robot.setAutoDelay(100); @@ -60,15 +57,15 @@ public class bug6462008 { } }); - toolkit.realSync(); + robot.waitForIdle(); setAnchorLead(-1); - toolkit.realSync(); + robot.waitForIdle(); testListSelection(); setAnchorLead(100); - toolkit.realSync(); + robot.waitForIdle(); testListSelection(); } @@ -79,10 +76,10 @@ public class bug6462008 { robot.keyPress(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_SPACE); - toolkit.realSync(); + robot.waitForIdle(); checkSelection(); resetList(); - toolkit.realSync(); + robot.waitForIdle(); // Control + Space robot.keyPress(KeyEvent.VK_CONTROL); @@ -90,10 +87,10 @@ public class bug6462008 { robot.keyRelease(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_CONTROL); - toolkit.realSync(); + robot.waitForIdle(); checkSelection(); resetList(); - toolkit.realSync(); + robot.waitForIdle(); // Shift + Space robot.keyPress(KeyEvent.VK_SHIFT); @@ -101,10 +98,10 @@ public class bug6462008 { robot.keyRelease(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_SHIFT); - toolkit.realSync(); + robot.waitForIdle(); checkSelection(); resetList(); - toolkit.realSync(); + robot.waitForIdle(); // Control + Shift + Space robot.keyPress(KeyEvent.VK_CONTROL); @@ -114,10 +111,10 @@ public class bug6462008 { robot.keyRelease(KeyEvent.VK_SHIFT); robot.keyRelease(KeyEvent.VK_CONTROL); - toolkit.realSync(); + robot.waitForIdle(); checkSelection(); resetList(); - toolkit.realSync(); + robot.waitForIdle(); // Control + A Multiple Selection @@ -127,11 +124,11 @@ public class bug6462008 { robot.keyRelease(KeyEvent.VK_A); robot.keyRelease(controlKey); - toolkit.realSync(); + robot.waitForIdle(); checkSelectionAL(-1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9); resetList(); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - toolkit.realSync(); + robot.waitForIdle(); // Control + A Single Selection robot.keyPress(controlKey); @@ -139,12 +136,12 @@ public class bug6462008 { robot.keyRelease(KeyEvent.VK_A); robot.keyRelease(controlKey); - toolkit.realSync(); + robot.waitForIdle(); checkSelectionAL(0, 0, 0); resetList(); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setSelectionInterval(5, 5); - toolkit.realSync(); + robot.waitForIdle(); // Control + A Selection interval (5, 5) @@ -153,10 +150,10 @@ public class bug6462008 { robot.keyRelease(KeyEvent.VK_A); robot.keyRelease(controlKey); - toolkit.realSync(); + robot.waitForIdle(); checkSelection(5); resetList(); - toolkit.realSync(); + robot.waitForIdle(); // Page Down // Not applicable for the Aqua L&F @@ -164,10 +161,10 @@ public class bug6462008 { robot.keyPress(KeyEvent.VK_PAGE_DOWN); robot.keyRelease(KeyEvent.VK_PAGE_DOWN); - toolkit.realSync(); + robot.waitForIdle(); checkSelection(9, 9, 9); resetList(); - toolkit.realSync(); + robot.waitForIdle(); } // Shift + Page Down @@ -184,28 +181,28 @@ public class bug6462008 { scrollDownExtendSelection(); - toolkit.realSync(); + robot.waitForIdle(); checkSelection(0, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9); resetList(); - toolkit.realSync(); + robot.waitForIdle(); // Down robot.keyPress(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_DOWN); - toolkit.realSync(); + robot.waitForIdle(); checkSelectionAL(0, 0, 0); resetList(); - toolkit.realSync(); + robot.waitForIdle(); // L robot.keyPress(KeyEvent.VK_L); robot.keyRelease(KeyEvent.VK_L); - toolkit.realSync(); + robot.waitForIdle(); checkSelectionAL(0, 0, 0); resetList(); - toolkit.realSync(); + robot.waitForIdle(); // Click item 4 Point p = clickItem4(); @@ -214,10 +211,10 @@ public class bug6462008 { robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); checkSelectionAL(4, 4, 4); resetList(); - toolkit.realSync(); + robot.waitForIdle(); // Control + Click item 4 @@ -229,10 +226,10 @@ public class bug6462008 { robot.keyRelease(controlKey); - toolkit.realSync(); + robot.waitForIdle(); checkSelectionAL(4, 4, 4); resetList(); - toolkit.realSync(); + robot.waitForIdle(); // Shift + Click item 4 robot.keyPress(KeyEvent.VK_SHIFT); @@ -243,10 +240,10 @@ public class bug6462008 { robot.keyRelease(KeyEvent.VK_SHIFT); - toolkit.realSync(); + robot.waitForIdle(); checkSelectionAL(0, 4, 0, 1, 2, 3, 4); resetList(); - toolkit.realSync(); + robot.waitForIdle(); // Control + Shift + Click item 4 @@ -259,10 +256,10 @@ public class bug6462008 { robot.keyRelease(KeyEvent.VK_SHIFT); robot.keyRelease(controlKey); - toolkit.realSync(); + robot.waitForIdle(); checkSelectionAL(0, 4); resetList(); - toolkit.realSync(); + robot.waitForIdle(); } private static DefaultListModel getModel() { diff --git a/jdk/test/javax/swing/JList/6510999/bug6510999.java b/jdk/test/javax/swing/JList/6510999/bug6510999.java new file mode 100644 index 00000000000..76c871b158d --- /dev/null +++ b/jdk/test/javax/swing/JList/6510999/bug6510999.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2011, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* @test + @bug 6510999 + @summary Selection in a JList with both scrollbars visible jumps on arrowkey-down + @author Alexander Potochkin + @run main bug6510999 +*/ + +import javax.swing.*; +import java.awt.*; +import java.awt.event.KeyEvent; + +public class bug6510999 { + private static JScrollPane s; + + private static void createGui() { + final JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + DefaultListModel dlm = new DefaultListModel(); + for (int i = 0; i < 100; i++) + dlm + .addElement(i + " listItemlistItemlistItemlistItemItem"); + JList l = new JList(); + l.setModel(dlm); + s = new JScrollPane(l); + l.setSelectedIndex(50); + l.ensureIndexIsVisible(50); + + frame.add(s); + frame.setSize(200, 200); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + public static void main(String[] args) throws Exception { + Robot robot = new Robot(); + robot.setAutoDelay(10); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + bug6510999.createGui(); + } + }); + robot.waitForIdle(); + Point viewPosition = s.getViewport().getViewPosition(); + robot.keyPress(KeyEvent.VK_DOWN); + robot.keyRelease(KeyEvent.VK_DOWN); + robot.waitForIdle(); + if (!s.getViewport().getViewPosition().equals(viewPosition)) { + throw new RuntimeException("JScrollPane was unexpectedly scrolled"); + } + } +} diff --git a/jdk/test/javax/swing/JMenu/4417601/bug4417601.java b/jdk/test/javax/swing/JMenu/4417601/bug4417601.java new file mode 100644 index 00000000000..44c10f80ab0 --- /dev/null +++ b/jdk/test/javax/swing/JMenu/4417601/bug4417601.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2011, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* @test + @bug 4417601 + @summary JMenus with no items paint a tiny menu. + @author Alexander Potochkin + @library ../../../../lib/testlibrary + @build ExtendedRobot + @run main bug4417601 +*/ + +import javax.swing.*; +import java.awt.event.*; +import java.awt.*; + +public class bug4417601 { + static JMenu menu; + static volatile boolean flag; + + public static void main(String[] args) throws Exception { + + ExtendedRobot robot = new ExtendedRobot(); + robot.setAutoDelay(10); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + menu = new JMenu("Menu"); + JMenuBar bar = new JMenuBar(); + bar.add(menu); + frame.setJMenuBar(bar); + + frame.getLayeredPane().addContainerListener(new ContainerAdapter() { + public void componentAdded(ContainerEvent e) { + flag = true; + } + }); + + frame.pack(); + frame.setSize(200, 200); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + }); + robot.waitForIdle(); + Point p = menu.getLocationOnScreen(); + Dimension size = menu.getSize(); + p.x += size.width / 2; + p.y += size.height / 2; + robot.mouseMove(p.x, p.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.waitForIdle(); + if (flag) { + throw new RuntimeException("Empty popup was shown"); + } + } +} diff --git a/jdk/test/javax/swing/JMenu/4515762/bug4515762.java b/jdk/test/javax/swing/JMenu/4515762/bug4515762.java index cb86ac168fa..8b0cae273a4 100644 --- a/jdk/test/javax/swing/JMenu/4515762/bug4515762.java +++ b/jdk/test/javax/swing/JMenu/4515762/bug4515762.java @@ -24,7 +24,6 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; -import sun.awt.SunToolkit; /** * @test @@ -107,7 +106,6 @@ public class bug4515762 { } public static void main(String[] args) throws Throwable { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(250); @@ -123,17 +121,17 @@ public class bug4515762 { } }); - toolkit.realSync(); + robot.waitForIdle(); Util.hitMnemonics(robot, KeyEvent.VK_D); - toolkit.realSync(); + robot.waitForIdle(); // Press the S key many times (should not cause an action peformed) int TIMES = 5; for (int i = 0; i < TIMES; i++) { Util.hitKeys(robot, KeyEvent.VK_S); } - toolkit.realSync(); + robot.waitForIdle(); // Unique menu items. actionExpected = true; @@ -141,31 +139,31 @@ public class bug4515762 { robot.keyPress(KeyEvent.VK_S); robot.keyRelease(KeyEvent.VK_S); - toolkit.realSync(); + robot.waitForIdle(); checkAction(); Util.hitMnemonics(robot, KeyEvent.VK_U); robot.keyPress(KeyEvent.VK_M); robot.keyRelease(KeyEvent.VK_M); - toolkit.realSync(); + robot.waitForIdle(); checkAction(); Util.hitMnemonics(robot, KeyEvent.VK_U); Util.hitKeys(robot, KeyEvent.VK_T); - toolkit.realSync(); + robot.waitForIdle(); checkAction(); Util.hitMnemonics(robot, KeyEvent.VK_U); Util.hitKeys(robot, KeyEvent.VK_W); - toolkit.realSync(); + robot.waitForIdle(); checkAction(); Util.hitMnemonics(robot, KeyEvent.VK_U); Util.hitKeys(robot, KeyEvent.VK_U); - toolkit.realSync(); + robot.waitForIdle(); checkAction(); } diff --git a/jdk/test/javax/swing/JMenu/4692443/bug4692443.java b/jdk/test/javax/swing/JMenu/4692443/bug4692443.java index 6032287e534..ac61b72899b 100644 --- a/jdk/test/javax/swing/JMenu/4692443/bug4692443.java +++ b/jdk/test/javax/swing/JMenu/4692443/bug4692443.java @@ -35,7 +35,6 @@ import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; import java.awt.*; -import sun.awt.SunToolkit; public class bug4692443 { @@ -56,29 +55,23 @@ public class bug4692443 { } }); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - toolkit.realSync(); + robo.waitForIdle(); - try { - robo = new Robot(); - } catch (AWTException e) { - throw new RuntimeException("Robot could not be created"); - } - int altKey = java.awt.event.KeyEvent.VK_ALT; - robo.setAutoDelay(100); - Util.hitMnemonics(robo, KeyEvent.VK_F); // Enter File menu - robo.keyPress(KeyEvent.VK_S); // Enter submenu - robo.keyRelease(KeyEvent.VK_S); - robo.keyPress(KeyEvent.VK_O); // Launch "One" action - robo.keyRelease(KeyEvent.VK_O); - robo.keyPress(KeyEvent.VK_M); // Launch "One" action - robo.keyRelease(KeyEvent.VK_M); + int altKey = java.awt.event.KeyEvent.VK_ALT; + robo.setAutoDelay(100); + Util.hitMnemonics(robo, KeyEvent.VK_F); // Enter File menu + robo.keyPress(KeyEvent.VK_S); // Enter submenu + robo.keyRelease(KeyEvent.VK_S); + robo.keyPress(KeyEvent.VK_O); // Launch "One" action + robo.keyRelease(KeyEvent.VK_O); + robo.keyPress(KeyEvent.VK_M); // Launch "One" action + robo.keyRelease(KeyEvent.VK_M); - toolkit.realSync(); + robo.waitForIdle(); - if (!passed) { - throw new RuntimeException("Test failed."); - } + if (!passed) { + throw new RuntimeException("Test failed."); + } } diff --git a/jdk/test/javax/swing/JMenu/6359669/bug6359669.java b/jdk/test/javax/swing/JMenu/6359669/bug6359669.java new file mode 100644 index 00000000000..1dc562eb706 --- /dev/null +++ b/jdk/test/javax/swing/JMenu/6359669/bug6359669.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2006, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* @test + @bug 6359669 + @summary REGRESSION: Submenu does not work if populated in PopupMenuListener.popupMenuWillBecomeVisible + @author Alexander Potochkin + @library ../../../../lib/testlibrary + @build ExtendedRobot + @run main bug6359669 +*/ + +import javax.swing.*; +import javax.swing.event.PopupMenuListener; +import javax.swing.event.PopupMenuEvent; +import java.awt.*; +import java.awt.event.InputEvent; + +public class bug6359669 { + static JMenu menu; + + public static void main(String[] args) throws Exception { + + ExtendedRobot robot = new ExtendedRobot(); + robot.setAutoDelay(10); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + JFrame f = new JFrame(); + JMenuBar menuBar = new JMenuBar(); + menu = new JMenu("Test"); + menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { + public void popupMenuCanceled(PopupMenuEvent e) { + } + + public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { + } + + public void popupMenuWillBecomeVisible(PopupMenuEvent e) { + menu.add(new JMenuItem("An item")); + } + }); + + menuBar.add(menu); + f.setJMenuBar(menuBar); + + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.setSize(200, 200); + f.setVisible(true); + } + }); + robot.waitForIdle(); + Point p = menu.getLocationOnScreen(); + Dimension size = menu.getSize(); + p.x += size.width / 2; + p.y += size.height / 2; + robot.mouseMove(p.x, p.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.waitForIdle(); + if (menu.getPopupMenu().getComponentCount() == 0) { + throw new RuntimeException("Where is a menuItem ?"); + } + } +} diff --git a/jdk/test/javax/swing/JMenu/6470128/bug6470128.java b/jdk/test/javax/swing/JMenu/6470128/bug6470128.java new file mode 100644 index 00000000000..20a298dbed2 --- /dev/null +++ b/jdk/test/javax/swing/JMenu/6470128/bug6470128.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2011, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* @test + @bug 6470128 + @summary Escape Key causes JMenu Selection to Disappear + @author Alexander Potochkin + @library ../../../../lib/testlibrary + @build jdk.testlibrary.OSInfo + @run main bug6470128 +*/ +import javax.swing.*; +import java.awt.*; +import java.awt.event.KeyEvent; +import jdk.testlibrary.OSInfo; + +public class bug6470128 { + static JFrame frame; + static JMenu subMenu; + + public static void main(String[] args) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + JMenuBar bar = new JMenuBar(); + JMenu menu = new JMenu("Menu"); + menu.setMnemonic('m'); + subMenu = new JMenu("SubMenu"); + JMenuItem item = new JMenuItem("Item"); + + frame.setJMenuBar(bar); + bar.add(menu); + menu.add(subMenu); + subMenu.add(item); + + frame.setSize(200, 200); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + }); + Robot robot = new Robot(); + robot.setAutoDelay(10); + robot.waitForIdle(); + if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) { + robot.keyPress(KeyEvent.VK_CONTROL); + } + robot.keyPress(KeyEvent.VK_ALT); + robot.keyPress(KeyEvent.VK_M); + robot.keyRelease(KeyEvent.VK_M); + robot.keyRelease(KeyEvent.VK_ALT); + if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) { + robot.keyRelease(KeyEvent.VK_CONTROL); + } + robot.keyPress(KeyEvent.VK_ENTER); + robot.keyRelease(KeyEvent.VK_ENTER); + robot.keyPress(KeyEvent.VK_ESCAPE); + robot.keyRelease(KeyEvent.VK_ESCAPE); + robot.waitForIdle(); + if (!subMenu.isSelected()) { + throw new RuntimeException("Submenu is unexpectedly unselected"); + } + } +} diff --git a/jdk/test/javax/swing/JMenu/6538132/bug6538132.java b/jdk/test/javax/swing/JMenu/6538132/bug6538132.java new file mode 100644 index 00000000000..73a61eaa6c9 --- /dev/null +++ b/jdk/test/javax/swing/JMenu/6538132/bug6538132.java @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2011, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* @test + @bug 6538132 + @summary Regression: Pressing Escape key don't close the menu items from jdk7.0 b07 onwards + @author Alexander Potochkin + @library ../../../../lib/testlibrary + @build ExtendedRobot + @run main bug6538132 +*/ + +import javax.swing.*; +import java.awt.*; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; + +public class bug6538132 { + private static JMenu menu1; + private static JMenu menu2; + private static volatile boolean isWinLaf; + + private static void createGui() { + try { + UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); + isWinLaf = true; + } catch (Exception e) { + // If we can't set WinLaf it means we are not under Windows + // make the test pass + isWinLaf = false; + return; + } + JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + JMenuBar menuBar = new JMenuBar(); + menu1 = createMenu(); + menuBar.add(menu1); + menu2 = createMenu(); + menuBar.add(menu2); + frame.setJMenuBar(menuBar); + + frame.setSize(200, 200); + frame.setVisible(true); + } + + static JMenu createMenu() { + JMenu menu = new JMenu("Menu"); + menu.add(new JMenuItem("MenuItem")); + menu.add(new JMenuItem("MenuItem")); + menu.add(new JMenuItem("MenuItem")); + return menu; + } + + public static void main(String[] args) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + bug6538132.createGui(); + } + }); + if(isWinLaf) { + ExtendedRobot robot = new ExtendedRobot(); + robot.setAutoDelay(10); + robot.waitForIdle(); + Point p1 = menu1.getLocationOnScreen(); + final int x1 = p1.x + menu1.getWidth() / 2; + final int y1 = p1.y + menu1.getHeight() / 2; + robot.glide(0, 0, x1, y1); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + assertPopupOpen(); + Point p2 = menu2.getLocationOnScreen(); + final int x2 = p2.x + menu2.getWidth() / 2; + final int y2 = p2.y + menu2.getHeight() / 2; + robot.glide(x1, y1, x2, y2); + assertPopupOpen(); + robot.keyPress(KeyEvent.VK_ESCAPE); + robot.keyRelease(KeyEvent.VK_ESCAPE); + assertPopupNotOpen(); + robot.glide(x2, y2, x1, y1); + assertPopupNotOpen(); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + assertPopupOpen(); + } + } + + static void assertPopupOpen() { + if (getLastPopup() == null) { + throw new RuntimeException("PopupMenu is not open"); + } + } + + static void assertPopupNotOpen() { + if (getLastPopup() != null) { + throw new RuntimeException("PopupMenu is unexpectedly open"); + } + } + + // copied from BasicPopupMenuUI + static JPopupMenu getLastPopup() { + MenuSelectionManager msm = MenuSelectionManager.defaultManager(); + MenuElement[] p = msm.getSelectedPath(); + JPopupMenu popup = null; + + for (int i = p.length - 1; popup == null && i >= 0; i--) { + if (p[i] instanceof JPopupMenu) + popup = (JPopupMenu) p[i]; + } + return popup; + } +} diff --git a/jdk/test/javax/swing/JMenuBar/4750590/bug4750590.java b/jdk/test/javax/swing/JMenuBar/4750590/bug4750590.java index 2ba8a51ebae..7e249d3737d 100644 --- a/jdk/test/javax/swing/JMenuBar/4750590/bug4750590.java +++ b/jdk/test/javax/swing/JMenuBar/4750590/bug4750590.java @@ -48,16 +48,15 @@ public class bug4750590 { } }); - sun.awt.SunToolkit toolkit = (sun.awt.SunToolkit) Toolkit.getDefaultToolkit(); - toolkit.realSync(); - Robot robo = new Robot(); robo.setAutoDelay(500); + robo.waitForIdle(); + Util.hitMnemonics(robo, KeyEvent.VK_F); robo.keyPress(KeyEvent.VK_M); robo.keyRelease(KeyEvent.VK_M); - toolkit.realSync(); + robo.waitForIdle(); if (passed) { System.out.println("Test passed!"); diff --git a/jdk/test/javax/swing/JMenuItem/4171437/bug4171437.java b/jdk/test/javax/swing/JMenuItem/4171437/bug4171437.java index 378bd2a3c66..29d1736b783 100644 --- a/jdk/test/javax/swing/JMenuItem/4171437/bug4171437.java +++ b/jdk/test/javax/swing/JMenuItem/4171437/bug4171437.java @@ -32,7 +32,6 @@ import java.awt.event.*; import java.util.ArrayList; import javax.swing.*; import javax.swing.event.*; -import sun.awt.SunToolkit; public class bug4171437 { static volatile boolean closeActivated = false; @@ -45,16 +44,14 @@ public class bug4171437 { } }); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - toolkit.realSync(); - Robot robot = new Robot(); robot.setAutoDelay(50); + robot.waitForIdle(); Util.hitMnemonics(robot, KeyEvent.VK_F); Util.hitKeys(robot, KeyEvent.VK_C); - toolkit.realSync(); + robot.waitForIdle(); Thread.sleep(1000); if (!closeActivated || customActivated) { diff --git a/jdk/test/javax/swing/JMenuItem/4654927/bug4654927.java b/jdk/test/javax/swing/JMenuItem/4654927/bug4654927.java index cac3386567a..34abf3ffd40 100644 --- a/jdk/test/javax/swing/JMenuItem/4654927/bug4654927.java +++ b/jdk/test/javax/swing/JMenuItem/4654927/bug4654927.java @@ -36,7 +36,6 @@ import javax.swing.*; import java.awt.*; import java.awt.event.InputEvent; import java.util.concurrent.Callable; -import sun.awt.SunToolkit; public class bug4654927 { @@ -51,7 +50,6 @@ public class bug4654927 { } UIManager.setLookAndFeel(systemLAF); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(10); @@ -61,20 +59,20 @@ public class bug4654927 { createAndShowUI(); } }); - toolkit.realSync(); + robot.waitForIdle(); // test mouse press Point point = Util.getCenterPoint(menu); robot.mouseMove(point.x, point.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); point = Util.getCenterPoint(menuItem); robot.mouseMove(point.x, point.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); if (!isMenuItemShowing()) { throw new RuntimeException("Popup is unexpectedly closed"); @@ -107,12 +105,12 @@ public class bug4654927 { // close menu robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); robot.mousePress(InputEvent.BUTTON1_MASK); Util.glide(robot, x0, y0, x1, y1); robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); if (!isMenuItemShowing()) { throw new RuntimeException("Popup is unexpectedly closed"); diff --git a/jdk/test/javax/swing/JMenuItem/6209975/bug6209975.java b/jdk/test/javax/swing/JMenuItem/6209975/bug6209975.java index fc75658fb5f..a2f13ab6433 100644 --- a/jdk/test/javax/swing/JMenuItem/6209975/bug6209975.java +++ b/jdk/test/javax/swing/JMenuItem/6209975/bug6209975.java @@ -25,15 +25,12 @@ * @test * @bug 6209975 * @summary regression: JMenuItem icons overimposed on JMenuItem labels under Metal LAF - * @library ../../regtesthelpers - * @build Util * @author Alexander Zuev * @run main bug6209975 */ import javax.swing.*; import java.awt.*; import java.awt.event.InputEvent; -import sun.awt.SunToolkit; public class bug6209975 { @@ -45,7 +42,6 @@ public class bug6209975 { public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(500); @@ -58,19 +54,19 @@ public class bug6209975 { } }); - toolkit.realSync(); + robot.waitForIdle(); Point clickPoint = getButtonClickPoint(); robot.mouseMove(clickPoint.x, clickPoint.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); clickPoint = getMenuClickPoint(); robot.mouseMove(clickPoint.x, clickPoint.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); if (RO1.itsValue <= RO2.itsValue) { throw new RuntimeException("Offset if the second icon is invalid."); diff --git a/jdk/test/javax/swing/JMenuItem/6249972/bug6249972.java b/jdk/test/javax/swing/JMenuItem/6249972/bug6249972.java new file mode 100644 index 00000000000..5139e26c600 --- /dev/null +++ b/jdk/test/javax/swing/JMenuItem/6249972/bug6249972.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2006, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* @test + @bug 6249972 + @summary Tests that JMenuItem(String,int) handles lower-case mnemonics properly. + @library ../../../../lib/testlibrary + @build ExtendedRobot + @author Mikhail Lapshin + @run main bug6249972 + */ + +import javax.swing.*; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; + +public class bug6249972 implements ActionListener { + + + private JFrame frame; + private JMenu menu; + private volatile boolean testPassed = false; + + public static void main(String[] args) throws Exception { + bug6249972 bugTest = new bug6249972(); + bugTest.test(); + } + + public bug6249972() throws Exception { + SwingUtilities.invokeAndWait( + new Runnable() { + public void run() { + frame = new JFrame("bug6249972"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + JMenuBar bar = new JMenuBar(); + frame.setJMenuBar(bar); + + menu = new JMenu("Problem"); + bar.add(menu); + + JMenuItem item = new JMenuItem("JMenuItem(String,'z')", 'z'); + item.addActionListener(bug6249972.this); + menu.add(item); + + frame.setLocationRelativeTo(null); + frame.pack(); + frame.setVisible(true); + } + } + ); + } + + + private void test() throws Exception { + ExtendedRobot robot = new ExtendedRobot(); + robot.waitForIdle(); + java.awt.Point p = menu.getLocationOnScreen(); + java.awt.Dimension size = menu.getSize(); + p.x += size.width / 2; + p.y += size.height / 2; + robot.mouseMove(p.x, p.y); + robot.click(); + robot.delay(100); + + robot.waitForIdle(); + robot.type(KeyEvent.VK_Z); + + robot.waitForIdle(); + frame.dispose(); // Try to stop the event dispatch thread + + if (!testPassed) { + throw new RuntimeException("JMenuItem(String,int) does not handle " + + "lower-case mnemonics properly."); + } + + System.out.println("Test passed"); + } + + public void actionPerformed(ActionEvent e) { + // We are in the actionPerformed() method - + // JMenuItem(String,int) handles lower-case mnemonics properly + testPassed = true; + } +} diff --git a/jdk/test/javax/swing/JMenuItem/ActionListenerCalledTwice/ActionListenerCalledTwiceTest.java b/jdk/test/javax/swing/JMenuItem/ActionListenerCalledTwice/ActionListenerCalledTwiceTest.java index c2af8c0751a..1a9f42120e2 100644 --- a/jdk/test/javax/swing/JMenuItem/ActionListenerCalledTwice/ActionListenerCalledTwiceTest.java +++ b/jdk/test/javax/swing/JMenuItem/ActionListenerCalledTwice/ActionListenerCalledTwiceTest.java @@ -26,10 +26,12 @@ * @bug 7160951 * @summary [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar * @author vera.akulova@oracle.com + * @library ../../../../lib/testlibrary + * @build jdk.testlibrary.OSInfo * @run main ActionListenerCalledTwiceTest */ -import sun.awt.*; +import jdk.testlibrary.OSInfo; import java.awt.*; import java.awt.event.*; import javax.swing.*; @@ -47,7 +49,7 @@ public class ActionListenerCalledTwiceTest { static volatile int listenerCallCounter = 0; public static void main(String[] args) throws Exception { - if (sun.awt.OSInfo.getOSType() != sun.awt.OSInfo.OSType.MACOSX) { + if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) { System.out.println("This test is for MacOS only. Automatically passed on other platforms."); return; } @@ -59,7 +61,6 @@ public class ActionListenerCalledTwiceTest { } }); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(100); @@ -78,7 +79,7 @@ public class ActionListenerCalledTwiceTest { robot.keyRelease(modKeyCode); } - toolkit.realSync(); + robot.waitForIdle(); if (listenerCallCounter != 1) { throw new Exception("Test failed: ActionListener for " + menuItems[i] + diff --git a/jdk/test/javax/swing/JOptionPane/6428694/bug6428694.java b/jdk/test/javax/swing/JOptionPane/6428694/bug6428694.java new file mode 100644 index 00000000000..fa065af15e7 --- /dev/null +++ b/jdk/test/javax/swing/JOptionPane/6428694/bug6428694.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2011, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* +@test +@bug 6428694 +@summary Checks that double click closes JOptionPane's input dialog. +@library ../../../../lib/testlibrary +@build ExtendedRobot +@author Mikhail Lapshin +@run main bug6428694 +*/ + +import javax.swing.JFrame; +import javax.swing.SwingUtilities; +import javax.swing.JOptionPane; +import java.awt.*; +import java.awt.event.InputEvent; + +public class bug6428694 { + private static JFrame frame; + private static boolean mainIsWaitingForDialogClosing; + private static ExtendedRobot robot; + private static volatile boolean testPassed; + + public static void main(String[] args) throws Exception { + robot = new ExtendedRobot(); + try { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + bug6428694.setupUI(); + } + }); + robot.waitForIdle(); + test(); + } finally { + stopEDT(); + } + + if (testPassed) { + System.out.println("Test passed"); + } else { + throw new RuntimeException("JOptionPane doesn't close input dialog " + + "by double click!"); + } + } + + private static void setupUI() { + frame = new JFrame("bug6428694 test"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + + Object[] selectedItems = new Object[40]; + for (int i = 0; i < 39; i++) { + selectedItems[i] = ("item: " + i); + } + JOptionPane.showInputDialog(frame, + "Double click on selected item then click cancel", + "Test Option Dialog", JOptionPane.WARNING_MESSAGE, null, + selectedItems, selectedItems[0]); + + // We are here if double click has closed the dialog + // or when the EDT is stopping + testPassed = mainIsWaitingForDialogClosing; + } + + private static void test() { + + mainIsWaitingForDialogClosing = true; + + // Perform double click on an item + int frameLeftX = frame.getLocationOnScreen().x; + int frameUpperY = frame.getLocationOnScreen().y; + robot.mouseMove(frameLeftX + 150, frameUpperY + 120); + robot.waitForIdle(); + robot.delay(100); + robot.setAutoDelay(50); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + // Wait for the input dialog closing + robot.waitForIdle(); + robot.delay(2000); + + mainIsWaitingForDialogClosing = false; + } + + private static void stopEDT() { + if (frame != null) { + frame.dispose(); + } + } +} diff --git a/jdk/test/javax/swing/JOptionPane/7138665/bug7138665.java b/jdk/test/javax/swing/JOptionPane/7138665/bug7138665.java index 44d4084536b..16b4228cdfe 100644 --- a/jdk/test/javax/swing/JOptionPane/7138665/bug7138665.java +++ b/jdk/test/javax/swing/JOptionPane/7138665/bug7138665.java @@ -27,8 +27,6 @@ @author Pavel Porvatov */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; import java.awt.event.KeyEvent; @@ -55,16 +53,14 @@ public class bug7138665 { } }); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - - toolkit.realSync(); - Robot robot = new Robot(); + robot.waitForIdle(); + robot.setAutoDelay(100); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); - toolkit.realSync(); + robot.waitForIdle(); } } diff --git a/jdk/test/javax/swing/JPopupMenu/4458079/bug4458079.java b/jdk/test/javax/swing/JPopupMenu/4458079/bug4458079.java index a9807d316c1..3dc95fcfa4b 100644 --- a/jdk/test/javax/swing/JPopupMenu/4458079/bug4458079.java +++ b/jdk/test/javax/swing/JPopupMenu/4458079/bug4458079.java @@ -35,7 +35,6 @@ import javax.swing.*; import javax.swing.event.*; import java.awt.event.KeyEvent; import java.util.ArrayList; -import sun.awt.SunToolkit; public class bug4458079 extends JFrame implements PopupMenuListener { public JMenu menu; @@ -47,21 +46,20 @@ public class bug4458079 extends JFrame implements PopupMenuListener { new bug4458079().createAndShowGUI(); } }); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - toolkit.realSync(); - Robot robot = new Robot(); + robot.waitForIdle(); + robot.setAutoDelay(50); Util.hitMnemonics(robot, KeyEvent.VK_M); - toolkit.realSync(); + robot.waitForIdle(); Thread.sleep(1000); Util.hitKeys(robot, KeyEvent.VK_DOWN); Util.hitKeys(robot, KeyEvent.VK_ENTER); - toolkit.realSync(); + robot.waitForIdle(); Thread.sleep(1000); if (!itemASelected) { diff --git a/jdk/test/javax/swing/JPopupMenu/4634626/bug4634626.html b/jdk/test/javax/swing/JPopupMenu/4634626/bug4634626.html new file mode 100644 index 00000000000..3fd4703cb2f --- /dev/null +++ b/jdk/test/javax/swing/JPopupMenu/4634626/bug4634626.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/jdk/test/javax/swing/JPopupMenu/4634626/bug4634626.java b/jdk/test/javax/swing/JPopupMenu/4634626/bug4634626.java new file mode 100644 index 00000000000..ead465a8eca --- /dev/null +++ b/jdk/test/javax/swing/JPopupMenu/4634626/bug4634626.java @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2003, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* @test + @bug 4634626 + @summary Implement context popup menus for components + @author Alexander Zuev + @library ../../../../lib/testlibrary + @build ExtendedRobot + @run applet bug4634626.html +*/ +import javax.swing.*; +import java.awt.event.*; +import java.awt.*; + +public class bug4634626 extends JApplet { + + public boolean passed = true; + public boolean done = false; + + public JFrame mainFrame = new JFrame("Bug4634626"); + public JRootPane rootPane = mainFrame.getRootPane(); + public JPanel contentPane = new JPanel(); + public JButton nopButton = new JButton("No popup button"); + public JTextArea someText = new JTextArea("Some text here", 20, 10); + public JButton popButton = new JButton("Button with the popup"); + + public JPopupMenu btnPopup = new JPopupMenu(); + public JPopupMenu commonPopup = new JPopupMenu(); + static public Error toBeThrown = null; + static int popTrig = MouseEvent.BUTTON3_MASK; + static boolean popt = false; + + public static class MouseWatcher extends MouseAdapter { + public void mousePressed(MouseEvent e) { + if(e.isPopupTrigger()) popt = true; + if(e.getComponent() != null && + e.getComponent() instanceof JComponent && + e.isPopupTrigger() && + ((JComponent)e.getComponent()).getComponentPopupMenu() != null) { + toBeThrown = + new Error("The event got thru the component with popup: " + + e); + } + } + public void mouseReleased(MouseEvent e) { + if(e.isPopupTrigger()) popt = true; + if(e.getComponent() != null && + e.getComponent() instanceof JComponent && + e.isPopupTrigger() && + ((JComponent)e.getComponent()).getComponentPopupMenu() != null) { + toBeThrown = + new Error("The event got thru the component with popup: " + + e); + } + if(toBeThrown != null) { + throw(toBeThrown); + } + } + } + + public static MouseWatcher mouser = new MouseWatcher(); + + public void init() { + + try { + popButton.setComponentPopupMenu(null); + popButton.setComponentPopupMenu(null); + popButton.setComponentPopupMenu(btnPopup); + popButton.setComponentPopupMenu(null); + } catch(Exception ex) { + System.err.println("Unexpected exception was thrown by " + + "setComponentPopupMenu() method: " + ex); + } + btnPopup.add("Button 1"); + btnPopup.add("Button 2"); + btnPopup.add("Button 3"); + popButton.setComponentPopupMenu(btnPopup); + popButton.addMouseListener(mouser); + commonPopup.add("One"); + commonPopup.add("Two"); + commonPopup.add("Three"); + + contentPane.setLayout(new BorderLayout()); + contentPane.setComponentPopupMenu(commonPopup); + contentPane.addMouseListener(mouser); + contentPane.add(nopButton, BorderLayout.NORTH); + nopButton.addMouseListener(mouser); + contentPane.add(popButton, BorderLayout.SOUTH); + someText.addMouseListener(mouser); + contentPane.add(someText, BorderLayout.CENTER); + mainFrame.setContentPane(contentPane); + + mainFrame.pack(); + mainFrame.setLocation(50, 50); + + mainFrame.addWindowListener(new TestStateListener()); + mainFrame.setVisible(true); + + while(!done) Thread.yield(); + + if(!passed) { + throw new RuntimeException("Test failed"); + } + + } + + public class TestStateListener extends WindowAdapter { + public void windowOpened(WindowEvent ev) { + try { + ev.getWindow().toFront(); + ev.getWindow().requestFocus(); + new Thread(new RobotThread()).start(); + } catch (Exception ex) { + throw new RuntimeException("Thread Exception"); + } + } + } + + class RobotThread implements Runnable { + public void run() { + ExtendedRobot robo; + try { + robo = new ExtendedRobot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Cannot create Robot"); + } + robo.setAutoDelay(100); + robo.waitForIdle(); + + // Determine working popup trigger event + clickMouseOn(robo, nopButton, popTrig); + robo.waitForIdle(); + robo.delay(500); + if(!popt) popTrig = MouseEvent.BUTTON2_MASK; + + // Inheritance is OFF by default. Popup should not appear. + clickMouseOn(robo, someText, popTrig); + + // Set inheritance ON watch for popup. + someText.setInheritsPopupMenu(true); + clickMouseOn(robo, someText, popTrig); + robo.waitForIdle(); + robo.delay(500); + if(!commonPopup.isVisible()) { + toBeThrown = new Error("Popup should be visible"); + passed = false; + } + // Dispose popup. + robo.type(KeyEvent.VK_ESCAPE); + robo.waitForIdle(); + someText.setInheritsPopupMenu(false); + + // Button with popup assigned. Wathch for popup. + clickMouseOn(robo, popButton, popTrig); + robo.waitForIdle(); + robo.delay(500); + if(!btnPopup.isVisible()) { + toBeThrown = new Error("Popup should be visible"); + passed = false; + } + // Dispose popup. + robo.type(KeyEvent.VK_ESCAPE); + // Test finished. + done = true; + } + } + + + + public void destroy() { + if(!passed) { + throw(toBeThrown); + } + } + private void clickMouseOn(ExtendedRobot robot, Component c, int button) { + java.awt.Point p = c.getLocationOnScreen(); + java.awt.Dimension size = c.getSize(); + p.x += size.width / 2; + p.y += size.height / 2; + robot.mouseMove(p.x, p.y); + robot.delay(100); + robot.click(button); + } +} diff --git a/jdk/test/javax/swing/JPopupMenu/4966112/bug4966112.java b/jdk/test/javax/swing/JPopupMenu/4966112/bug4966112.java index 0852b6d5f56..3d1727400a2 100644 --- a/jdk/test/javax/swing/JPopupMenu/4966112/bug4966112.java +++ b/jdk/test/javax/swing/JPopupMenu/4966112/bug4966112.java @@ -35,7 +35,6 @@ import javax.swing.event.PopupMenuListener; import javax.swing.event.PopupMenuEvent; import java.awt.*; import java.awt.event.*; -import sun.awt.SunToolkit; public class bug4966112 { @@ -50,19 +49,18 @@ public class bug4966112 { private static Robot robot; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); robot = new Robot(); robot.setAutoDelay(100); createAndShowButton(); - toolkit.realSync(); + robot.waitForIdle(); setClickPoint(testButton); clickMouse(InputEvent.BUTTON1_MASK); clickMouse(InputEvent.BUTTON2_MASK); clickMouse(InputEvent.BUTTON3_MASK); - toolkit.realSync(); + robot.waitForIdle(); closeFrame(); if (popupButton == NO_MOUSE_BUTTON) { @@ -74,10 +72,10 @@ public class bug4966112 { // Test Split Pane createAndShowSplitPane(); - toolkit.realSync(); + robot.waitForIdle(); clickMouse(jsp); - toolkit.realSync(); + robot.waitForIdle(); closeFrame(); if (!shown) { @@ -86,10 +84,10 @@ public class bug4966112 { // Test Spinner createAndShowSpinner(); - toolkit.realSync(); + robot.waitForIdle(); clickMouse(spin); - toolkit.realSync(); + robot.waitForIdle(); closeFrame(); if (!shown) { @@ -98,16 +96,16 @@ public class bug4966112 { // Test File Chooser createAndShowFileChooser(); - toolkit.realSync(); + robot.waitForIdle(); clickMouse(filec); - toolkit.realSync(); + robot.waitForIdle(); Util.hitKeys(robot, KeyEvent.VK_ESCAPE); - toolkit.realSync(); + robot.waitForIdle(); Util.hitKeys(robot, KeyEvent.VK_ESCAPE); - toolkit.realSync(); + robot.waitForIdle(); closeFrame(); if (!shown) { diff --git a/jdk/test/javax/swing/JPopupMenu/6217905/bug6217905.java b/jdk/test/javax/swing/JPopupMenu/6217905/bug6217905.java new file mode 100644 index 00000000000..dcfab1da775 --- /dev/null +++ b/jdk/test/javax/swing/JPopupMenu/6217905/bug6217905.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2011, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* +@test +@bug 6217905 +@summary JPopupMenu keyboard navigation stops working +@author Alexander Potochkin +@library ../../../../lib/testlibrary +@build ExtendedRobot +@run main bug6217905 +*/ + +import javax.swing.*; +import java.awt.*; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; + +public class bug6217905 { + private static JPanel popupPanel; + private static JMenuItem firstItem; + private static JMenuItem lastItem; + + private static void createGui() { + final JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + JPopupMenu popup = new JPopupMenu("Menu"); + firstItem = new JMenuItem("MenuItem"); + popup.add(firstItem); + popup.add(new JMenuItem("MenuItem")); + lastItem = new JMenuItem("MenuItem"); + popup.add(lastItem); + + popupPanel = new JPanel(); + popupPanel.setComponentPopupMenu(popup); + frame.add(popupPanel); + frame.setSize(100, 100); + frame.setVisible(true); + } + + public static void main(String[] args) throws Exception { + try { + UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); + } catch (Exception e) { + // This test is for WinLaf only + System.out.println("This test is for Windows LaF only."); + return; + } + + ExtendedRobot robot = new ExtendedRobot(); + robot.setAutoDelay(10); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + bug6217905.createGui(); + } + }); + robot.waitForIdle(); + Point loc = popupPanel.getLocationOnScreen(); + int x = loc.x + popupPanel.getWidth()/2; + int y = loc.y + popupPanel.getHeight()/2; + robot.glide(0, 0, x, y); + robot.mousePress(InputEvent.BUTTON3_MASK); + robot.mouseRelease(InputEvent.BUTTON3_MASK); + robot.waitForIdle(); + if (getSelectedPathLength() != 1) { + throw new RuntimeException("Only popup must be selected"); + } + robot.glide(x, y, 0, 0); + robot.type(KeyEvent.VK_DOWN); + robot.waitForIdle(); + if (getSelectedPathLength() != 2 || !firstItem.isArmed()) { + throw new RuntimeException("First item must be selected"); + } + robot.type(KeyEvent.VK_ESCAPE); + robot.waitForIdle(); + if (getSelectedPathLength() != 0) { + throw new RuntimeException("There must be no selected items"); + } + robot.glide(0, 0, x, y); + robot.mousePress(InputEvent.BUTTON3_MASK); + robot.mouseRelease(InputEvent.BUTTON3_MASK); + robot.waitForIdle(); + robot.glide(x, y, 0, 0); + robot.type(KeyEvent.VK_UP); + robot.waitForIdle(); + if (getSelectedPathLength() != 2 || !lastItem.isArmed()) { + throw new RuntimeException("Last item must be selected"); + } + } + + private static int getSelectedPathLength() { + return MenuSelectionManager.defaultManager().getSelectedPath().length; + } +} diff --git a/jdk/test/javax/swing/JPopupMenu/6415145/bug6415145.java b/jdk/test/javax/swing/JPopupMenu/6415145/bug6415145.java new file mode 100644 index 00000000000..c288300e94d --- /dev/null +++ b/jdk/test/javax/swing/JPopupMenu/6415145/bug6415145.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2006, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* +@test +@bug 6415145 +@summary REGRESSION: Selected item is not being updated while dragging above popup menu +@library ../../../../lib/testlibrary +@build ExtendedRobot +@author Mikhail Lapshin +@run main bug6415145 +*/ + +import javax.swing.*; +import java.awt.event.*; +import java.awt.AWTException; +import java.awt.Component; + +public class bug6415145 { + private JFrame frame; + private JButton button; + private JPopupMenu popupMenu; + private JMenuItem item1; + private JMenuItem item2; + private static ExtendedRobot robot; + + public static void main(String[] args) throws Exception { + robot = new ExtendedRobot(); + final bug6415145 bugTest = new bug6415145(); + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + bugTest.init(); + } + }); + + robot.waitForIdle(); + bugTest.test(); + } finally { + bugTest.stopEDT(); + } + } + + private void stopEDT() { + if (frame != null) { + frame.dispose(); + } + } + + private void init() { + popupMenu = new JPopupMenu("test menu"); + item1 = new JMenuItem("item 1"); + item2 = new JMenuItem("item 2"); + popupMenu.add(item1); + popupMenu.add(item2); + + button = new JButton("test button"); + button.addMouseListener(new MouseListener()); + + frame = new JFrame("test frame"); + frame.add(popupMenu); + frame.add(button); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(200, 200); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + private class MouseListener extends MouseAdapter { + public void mousePressed(MouseEvent e) { + popupMenu.show(button, e.getX(), e.getY()); + } + } + + private void test() throws AWTException { + try { + moveMouseTo(robot, button); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.waitForIdle(); + + moveMouseTo(robot, item1); + robot.waitForIdle(); + + moveMouseTo(robot, item2); + robot.waitForIdle(); + if ( (item1.isArmed()) || (!item2.isArmed()) ) { + throw new RuntimeException("Selected item is not being updated" + + " while dragging above popup menu."); + } + } finally { + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + } + private void moveMouseTo(ExtendedRobot robot, Component c) { + java.awt.Point p = c.getLocationOnScreen(); + java.awt.Dimension size = c.getSize(); + p.x += size.width / 2; + p.y += size.height / 2; + robot.mouseMove(p.x, p.y); + robot.delay(100); + } +} diff --git a/jdk/test/javax/swing/JPopupMenu/6515446/bug6515446.java b/jdk/test/javax/swing/JPopupMenu/6515446/bug6515446.java new file mode 100644 index 00000000000..b26aa0395a4 --- /dev/null +++ b/jdk/test/javax/swing/JPopupMenu/6515446/bug6515446.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2007, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* +@test +@bug 6515446 +@summary JMenuItems in JPopupMenus not receiving ActionEvents - incompat with 1.5 +@author Alexander Potochkin +@library ../../../../lib/testlibrary +@build ExtendedRobot +@run main bug6515446 +*/ + +import javax.swing.*; +import java.awt.event.*; +import java.awt.*; + +public class bug6515446 { + private static JPanel panel; + private static volatile boolean flag; + + public static void main(String[] args) throws Exception { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + final JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + final JPopupMenu popup = new JPopupMenu("Menu"); + JMenuItem item = new JMenuItem("MenuItem"); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + flag = true; + } + }); + popup.add(item); + + panel = new JPanel(); + panel.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) { + popup.show(panel, e.getX(), e.getY()); + } + + public void mouseReleased(MouseEvent e) { + popup.setVisible(false); + } + }); + frame.add(panel); + frame.setSize(200, 200); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + }); + + ExtendedRobot robot = new ExtendedRobot(); + robot.setAutoDelay(10); + robot.waitForIdle(); + + Point l = panel.getLocationOnScreen(); + + int x = l.x + panel.getWidth() / 2; + int y = l.y + panel.getHeight() / 2; + robot.mouseMove(x, y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.glide(x, y, x + 10, y + 10); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.waitForIdle(); + + if (!flag) { + throw new RuntimeException("ActionEvent wasn't fired"); + } + } +} diff --git a/jdk/test/javax/swing/JPopupMenu/6544309/bug6544309.java b/jdk/test/javax/swing/JPopupMenu/6544309/bug6544309.java new file mode 100644 index 00000000000..ee30642f069 --- /dev/null +++ b/jdk/test/javax/swing/JPopupMenu/6544309/bug6544309.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2011, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* @test + @bug 6544309 + @summary Checks that 'Select Input Method' popup menu allows to select + items with keyboard. + @author Mikhail Lapshin + @library ../../../../lib/testlibrary + @build ExtendedRobot + @run main bug6544309 +*/ + +import javax.swing.*; +import java.awt.event.*; +import java.awt.*; + +public class bug6544309 { + private JDialog dialog; + private boolean passed; + private static ExtendedRobot robot; + + public static void main(String[] args) throws Exception { + robot = new ExtendedRobot(); + final bug6544309 test = new bug6544309(); + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + test.setupUI(); + } + }); + test.test(); + System.out.println("Test passed"); + } finally { + if (test.dialog != null) { + test.dialog.dispose(); + } + } + } + + private void setupUI() { + dialog = new JDialog(); + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + dialog.setSize(200, 100); + dialog.setLocationRelativeTo(null); + dialog.setVisible(true); + + JPopupMenu popup = new JPopupMenu(); + popup.add(new JMenuItem("one")); + JMenuItem two = new JMenuItem("two"); + two.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + passed = true; + } + }); + popup.add(two); + popup.add(new JMenuItem("three")); + popup.show(dialog, 50, 50); + } + + private void test() throws Exception { + testImpl(); + checkResult(); + } + + + private void testImpl() throws Exception { + robot.waitForIdle(); + System.out.println("Pressing DOWN ARROW"); + robot.type(KeyEvent.VK_DOWN); + robot.waitForIdle(); + System.out.println("Pressing DOWN ARROW"); + robot.type(KeyEvent.VK_DOWN); + robot.waitForIdle(); + System.out.println("Pressing SPACE"); + robot.type(KeyEvent.VK_SPACE); + } + + private void checkResult() { + robot.waitForIdle(); + if (!passed) { + throw new RuntimeException("If a JDialog is invoker for JPopupMenu, " + + "the menu cannot be handled by keyboard."); + } + } +} diff --git a/jdk/test/javax/swing/JPopupMenu/6580930/bug6580930.java b/jdk/test/javax/swing/JPopupMenu/6580930/bug6580930.java new file mode 100644 index 00000000000..cbc805c01c9 --- /dev/null +++ b/jdk/test/javax/swing/JPopupMenu/6580930/bug6580930.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2007, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* +@test +@bug 6580930 7184956 +@summary Swing Popups should overlap taskbar +@author Alexander Potochkin +@library ../../../../lib/testlibrary +@build ExtendedRobot +@run main bug6580930 +*/ + +import javax.swing.*; +import java.awt.*; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; + +public class bug6580930 { + private static ExtendedRobot robot; + private static JFrame frame; + private static JPopupMenu popup; + private static Toolkit toolkit; + private static volatile boolean skipTest = false; + + private static void createGui() { + frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setUndecorated(true); + + popup = new JPopupMenu("Menu"); + for (int i = 0; i < 7; i++) { + popup.add(new JMenuItem("MenuItem")); + } + JPanel panel = new JPanel(); + panel.setComponentPopupMenu(popup); + frame.add(panel); + + frame.setSize(200, 200); + } + + + public static void main(String[] args) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + JPopupMenu.setDefaultLightWeightPopupEnabled(true); + bug6580930.createGui(); + } + }); + + toolkit = Toolkit.getDefaultToolkit(); + robot = new ExtendedRobot(); + robot.setAutoDelay(10); + robot.waitForIdle(); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + Insets insets = toolkit.getScreenInsets(frame.getGraphicsConfiguration()); + if (insets.bottom == 0) { + System.out.println("This test is only for configurations with taskbar on the bottom"); + + skipTest = true; + } + + Dimension screenSize = toolkit.getScreenSize(); + frame.setLocation(screenSize.width/2, screenSize.height - frame.getHeight() - insets.bottom + 10); + frame.setVisible(true); + } + }); + + robot.waitForIdle(); + + if(skipTest) { + return; + } + Point loc = frame.getLocationOnScreen(); + + robot.mouseMove(loc.x, loc.y); + showPopup(); + robot.waitForIdle(); + if (isHeavyWeightMenuVisible()) { + throw new RuntimeException("HeavyWeightPopup is unexpectedly visible"); + } + + robot.keyPress(KeyEvent.VK_ESCAPE); + robot.keyRelease(KeyEvent.VK_ESCAPE); + + int x = loc.x; + int y = loc.y + (frame.getHeight() - popup.getPreferredSize().height) + 1; + robot.mouseMove(x, y); + + showPopup(); + + if (!popup.getLocationOnScreen().equals(new Point(x, y))) { + throw new RuntimeException("Popup is unexpectedly shifted"); + } + + if (!isHeavyWeightMenuVisible()) { + throw new RuntimeException("HeavyWeightPopup is unexpectedly hidden"); + } + } + + private static void showPopup() { + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.waitForIdle(); + if (!popup.isShowing()) { + robot.mousePress(InputEvent.BUTTON2_MASK); + robot.mouseRelease(InputEvent.BUTTON2_MASK); + robot.waitForIdle(); + if (!popup.isShowing()) { + robot.mousePress(InputEvent.BUTTON3_MASK); + robot.mouseRelease(InputEvent.BUTTON3_MASK); + robot.waitForIdle(); + } + } + } + + private static boolean isHeavyWeightMenuVisible() { + Window[] windows = Window.getWindows(); + for (Window window : windows) { + if (window.getClass().getSimpleName().equals("HeavyWeightWindow") + && window.isVisible()) { + return true; + } + } + return false; + } +} diff --git a/jdk/test/javax/swing/JPopupMenu/6800513/bug6800513.java b/jdk/test/javax/swing/JPopupMenu/6800513/bug6800513.java index c44e0584fde..097e28ddd9a 100644 --- a/jdk/test/javax/swing/JPopupMenu/6800513/bug6800513.java +++ b/jdk/test/javax/swing/JPopupMenu/6800513/bug6800513.java @@ -32,8 +32,6 @@ * @run main bug6800513 */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; import java.awt.event.InputEvent; @@ -47,10 +45,10 @@ public class bug6800513 { private static JPopupMenu popupMenu; private static JMenu menu; private static JFrame frame; + private static Robot robot; public static void testFrame(final boolean defaultLightWeightPopupEnabled, String expectedPopupClass) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -59,11 +57,11 @@ public class bug6800513 { } }); - toolkit.realSync(); + robot.waitForIdle(); clickOnMenu(); - toolkit.realSync(); + robot.waitForIdle(); Field getPopup = JPopupMenu.class.getDeclaredField("popup"); getPopup.setAccessible(true); @@ -87,7 +85,7 @@ public class bug6800513 { } }); - toolkit.realSync(); + robot.waitForIdle(); } @@ -99,7 +97,6 @@ public class bug6800513 { } }); - Robot robot = new Robot(); robot.setAutoDelay(100); robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2); @@ -140,6 +137,7 @@ public class bug6800513 { } public static void main(String[] args) throws Exception { + robot = new Robot(); testFrame(false, "javax.swing.PopupFactory$HeavyWeightPopup"); testFrame(true, "javax.swing.PopupFactory$LightWeightPopup"); diff --git a/jdk/test/javax/swing/JPopupMenu/6827786/bug6827786.java b/jdk/test/javax/swing/JPopupMenu/6827786/bug6827786.java index 075f60032c2..77c05fe206e 100644 --- a/jdk/test/javax/swing/JPopupMenu/6827786/bug6827786.java +++ b/jdk/test/javax/swing/JPopupMenu/6827786/bug6827786.java @@ -33,7 +33,6 @@ import java.awt.*; import java.awt.event.KeyEvent; import javax.swing.*; -import sun.awt.SunToolkit; public class bug6827786 { @@ -41,7 +40,6 @@ public class bug6827786 { private static Component focusable; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -52,7 +50,7 @@ public class bug6827786 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @@ -61,7 +59,7 @@ public class bug6827786 { } }); - toolkit.realSync(); + robot.waitForIdle(); checkfocus(); // select menu @@ -72,17 +70,17 @@ public class bug6827786 { } // select submenu Util.hitKeys(robot, KeyEvent.VK_S); - toolkit.realSync(); + robot.waitForIdle(); // verify submenu is selected verify(1); Util.hitKeys(robot, KeyEvent.VK_S); - toolkit.realSync(); + robot.waitForIdle(); // verify last item is selected verify(2); Util.hitKeys(robot, KeyEvent.VK_S); - toolkit.realSync(); + robot.waitForIdle(); // selection should wrap to first item verify(0); diff --git a/jdk/test/javax/swing/JPopupMenu/6987844/bug6987844.java b/jdk/test/javax/swing/JPopupMenu/6987844/bug6987844.java index d8802351bcb..2fd16e214db 100644 --- a/jdk/test/javax/swing/JPopupMenu/6987844/bug6987844.java +++ b/jdk/test/javax/swing/JPopupMenu/6987844/bug6987844.java @@ -29,8 +29,6 @@ * @run main bug6987844 */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; import java.awt.event.InputEvent; @@ -40,7 +38,6 @@ public class bug6987844 { static JMenu menu2; public static void main(String... args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(200); @@ -64,7 +61,7 @@ public class bug6987844 { frame.setVisible(true); } }); - toolkit.realSync(); + robot.waitForIdle(); Point point1 = menu1.getLocationOnScreen(); Point point2 = menu2.getLocationOnScreen(); @@ -79,7 +76,7 @@ public class bug6987844 { robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.mouseMove(point1.x + 1, point1.y + 1); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { diff --git a/jdk/test/javax/swing/JPopupMenu/7154841/bug7154841.java b/jdk/test/javax/swing/JPopupMenu/7154841/bug7154841.java index c1e6ac86e3a..e6cd6e1b843 100644 --- a/jdk/test/javax/swing/JPopupMenu/7154841/bug7154841.java +++ b/jdk/test/javax/swing/JPopupMenu/7154841/bug7154841.java @@ -26,16 +26,17 @@ @bug 7154841 @summary JPopupMenu is overlapped by a Dock on Mac OS X @author Petr Pchelko + @library ../../../../lib/testlibrary + @build ExtendedRobot jdk.testlibrary.OSInfo + @run main bug7154841 */ -import sun.awt.OSInfo; -import sun.awt.SunToolkit; - import java.awt.*; import javax.swing.*; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; import java.util.concurrent.atomic.AtomicReference; +import jdk.testlibrary.OSInfo; public class bug7154841 { @@ -71,20 +72,20 @@ public class bug7154841 { } try { - Robot r = new Robot(); + ExtendedRobot r = new ExtendedRobot(); r.setAutoDelay(100); r.setAutoWaitForIdle(true); r.mouseMove(0, 0); SwingUtilities.invokeAndWait(bug7154841::initAndShowUI); - sleep(); + r.waitForIdle(200); SwingUtilities.invokeAndWait(() -> { popupMenu.show(frame, frame.getX() + frame.getWidth() / 2, frame.getY() + frame.getHeight() / 2); }); - sleep(); + r.waitForIdle(200); int y = (int)screenBounds.get().getY() + (int)screenBounds.get().getHeight() - 10; int center = (int)(screenBounds.get().getX() + screenBounds.get().getWidth() / 2); @@ -112,10 +113,4 @@ public class bug7154841 { .getBounds(); } - private static void sleep() { - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); - try { - Thread.sleep(200); - } catch (InterruptedException ignored) { } - } } diff --git a/jdk/test/javax/swing/JRadioButton/8033699/bug8033699.java b/jdk/test/javax/swing/JRadioButton/8033699/bug8033699.java index 63409dead6d..212b442b9ab 100644 --- a/jdk/test/javax/swing/JRadioButton/8033699/bug8033699.java +++ b/jdk/test/javax/swing/JRadioButton/8033699/bug8033699.java @@ -35,11 +35,9 @@ import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; import java.awt.*; -import sun.awt.SunToolkit; public class bug8033699 { private static Robot robot; - private static SunToolkit toolkit; private static JButton btnStart; private static ButtonGroup btnGrp; @@ -61,7 +59,6 @@ public class bug8033699 { Thread.sleep(100); robot.setAutoDelay(100); - toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); // tab key test grouped radio button runTest1(); @@ -242,7 +239,7 @@ public class bug8033699 { private static void hitKey(Robot robot, int keycode) { robot.keyPress(keycode); robot.keyRelease(keycode); - toolkit.realSync(); + robot.waitForIdle(); } private static void hitKey(Robot robot, int mode, int keycode) { @@ -250,6 +247,6 @@ public class bug8033699 { robot.keyPress(keycode); robot.keyRelease(mode); robot.keyRelease(keycode); - toolkit.realSync(); + robot.waitForIdle(); } } diff --git a/jdk/test/javax/swing/JRadioButton/8041561/bug8041561.java b/jdk/test/javax/swing/JRadioButton/8041561/bug8041561.java index 79f737ba248..9a7e3bd2d0b 100644 --- a/jdk/test/javax/swing/JRadioButton/8041561/bug8041561.java +++ b/jdk/test/javax/swing/JRadioButton/8041561/bug8041561.java @@ -25,7 +25,6 @@ import java.awt.AWTException; import java.awt.Color; import java.awt.Point; import java.awt.Robot; -import java.awt.Toolkit; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JRadioButton; @@ -34,7 +33,6 @@ import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.plaf.metal.DefaultMetalTheme; import javax.swing.plaf.metal.MetalLookAndFeel; -import sun.awt.SunToolkit; /** * @test @@ -62,7 +60,7 @@ public class bug8041561 { } }); - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + new Robot().waitForIdle(); Thread.sleep(500); SwingUtilities.invokeAndWait(new Runnable() { diff --git a/jdk/test/javax/swing/JRootPane/4670486/bug4670486.java b/jdk/test/javax/swing/JRootPane/4670486/bug4670486.java index 6682f8afccf..d967d4527df 100644 --- a/jdk/test/javax/swing/JRootPane/4670486/bug4670486.java +++ b/jdk/test/javax/swing/JRootPane/4670486/bug4670486.java @@ -24,7 +24,6 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; -import sun.awt.SunToolkit; /** * @test @@ -101,7 +100,6 @@ public class bug4670486 { } public static void main(String[] args) throws Throwable { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(250); @@ -120,7 +118,7 @@ public class bug4670486 { } }); - toolkit.realSync(); + robot.waitForIdle(); // Change the default button to // force a call to BasicRootPaneUI.updateDefaultButtonBindings() @@ -131,14 +129,14 @@ public class bug4670486 { // effect. Util.hitMnemonics(robot, KeyEvent.VK_U); Util.hitKeys(robot, KeyEvent.VK_ENTER); - toolkit.realSync(); + robot.waitForIdle(); checkAction(); Util.hitMnemonics(robot, KeyEvent.VK_U); Util.hitKeys(robot, KeyEvent.VK_DOWN); Util.hitKeys(robot, KeyEvent.VK_ENTER); - toolkit.realSync(); + robot.waitForIdle(); checkAction(); } diff --git a/jdk/test/javax/swing/JScrollBar/4708809/bug4708809.java b/jdk/test/javax/swing/JScrollBar/4708809/bug4708809.java index d8d34ec001e..144b22881ee 100644 --- a/jdk/test/javax/swing/JScrollBar/4708809/bug4708809.java +++ b/jdk/test/javax/swing/JScrollBar/4708809/bug4708809.java @@ -32,7 +32,6 @@ import javax.swing.*; import java.awt.*; import java.awt.Point; import java.awt.event.*; -import sun.awt.SunToolkit; public class bug4708809 { @@ -42,7 +41,6 @@ public class bug4708809 { private static JScrollBar sbar; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(350); @@ -53,7 +51,7 @@ public class bug4708809 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @@ -63,13 +61,13 @@ public class bug4708809 { } }); - toolkit.realSync(); + robot.waitForIdle(); Point point = getClickPoint(0.5, 0.5); robot.mouseMove(point.x, point.y); robot.mousePress(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @@ -88,12 +86,12 @@ public class bug4708809 { } }); - toolkit.realSync(); + robot.waitForIdle(); point = getClickPoint(0.5, 0.2); robot.mouseMove(point.x, point.y); robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); if (!do_test || !passed) { throw new Exception("The scrollbar moved with incorrect direction"); @@ -131,4 +129,4 @@ public class bug4708809 { fr.setSize(200, 200); fr.setVisible(true); } -} \ No newline at end of file +} diff --git a/jdk/test/javax/swing/JScrollBar/6542335/bug6542335.java b/jdk/test/javax/swing/JScrollBar/6542335/bug6542335.java index 1aa5ba18ad9..2f0346390d9 100644 --- a/jdk/test/javax/swing/JScrollBar/6542335/bug6542335.java +++ b/jdk/test/javax/swing/JScrollBar/6542335/bug6542335.java @@ -28,8 +28,6 @@ @run main bug6542335 */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.plaf.basic.BasicScrollBarUI; import java.awt.*; @@ -43,8 +41,6 @@ public class bug6542335 { final Robot robot = new Robot(); robot.setAutoDelay(10); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - final Rectangle[] thumbBounds = new Rectangle[1]; SwingUtilities.invokeAndWait(new Runnable() { @@ -72,7 +68,7 @@ public class bug6542335 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -86,7 +82,7 @@ public class bug6542335 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { diff --git a/jdk/test/javax/swing/JScrollBar/7163696/Test7163696.java b/jdk/test/javax/swing/JScrollBar/7163696/Test7163696.java index 759012ebe74..2ca34b52136 100644 --- a/jdk/test/javax/swing/JScrollBar/7163696/Test7163696.java +++ b/jdk/test/javax/swing/JScrollBar/7163696/Test7163696.java @@ -28,12 +28,9 @@ * @author Sergey Malenkov */ -import sun.awt.SunToolkit; - import java.awt.Dimension; import java.awt.Point; import java.awt.Robot; -import java.awt.Toolkit; import java.awt.event.InputEvent; import javax.swing.JFrame; @@ -54,12 +51,11 @@ public class Test7163696 implements Runnable { private void test() throws Exception { Robot robot = new Robot(); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { UIManager.setLookAndFeel(info.getClassName()); SwingUtilities.invokeAndWait(this); - toolkit.realSync(); // after creation + robot.waitForIdle(); // after creation Thread.sleep(1000); Point point = this.bar.getLocation(); @@ -70,7 +66,7 @@ public class Test7163696 implements Runnable { robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); // before validation + robot.waitForIdle(); // before validation Thread.sleep(1000); SwingUtilities.invokeAndWait(this); diff --git a/jdk/test/javax/swing/JScrollBar/bug4202954/bug4202954.java b/jdk/test/javax/swing/JScrollBar/bug4202954/bug4202954.java index cf5b572906e..07f5988556b 100644 --- a/jdk/test/javax/swing/JScrollBar/bug4202954/bug4202954.java +++ b/jdk/test/javax/swing/JScrollBar/bug4202954/bug4202954.java @@ -22,8 +22,9 @@ */ /* @test @bug 4202954 + @library ../../../../lib/testlibrary @library ../../regtesthelpers - @build Util + @build Util jdk.testlibrary.OSInfo @author Michael C. Albers @run main bug4202954 */ @@ -31,11 +32,10 @@ import java.awt.*; import java.awt.event.InputEvent; import javax.swing.*; -import sun.awt.*; +import jdk.testlibrary.OSInfo; public class bug4202954 { static JScrollPane buttonScrollPane; - private static final SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); static Robot robot; public static void main(String[] args) throws Exception { if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) { @@ -138,13 +138,17 @@ public class bug4202954 { } }; Integer oldHValue = Util.invokeOnEDT(horizontalValue); + robot.waitForIdle(); Integer oldVValue = Util.invokeOnEDT(verticalValue); + robot.waitForIdle(); clickMouseOnComponent(scrollButton, buttons); - toolkit.realSync(); + robot.waitForIdle(); int newHValue = Util.invokeOnEDT(horizontalValue); + robot.waitForIdle(); int newVValue = Util.invokeOnEDT(verticalValue); + robot.waitForIdle(); return (oldHValue != newHValue || oldVValue != newVValue) == expectScroll; } diff --git a/jdk/test/javax/swing/JSlider/6348946/bug6348946.java b/jdk/test/javax/swing/JSlider/6348946/bug6348946.java index 7183debcb5e..588097a1a87 100644 --- a/jdk/test/javax/swing/JSlider/6348946/bug6348946.java +++ b/jdk/test/javax/swing/JSlider/6348946/bug6348946.java @@ -29,8 +29,6 @@ * @author Mikhail Lapshin */ -import sun.awt.SunToolkit; - import java.awt.*; import java.awt.event.InputEvent; import javax.swing.*; @@ -42,13 +40,16 @@ public class bug6348946 { private static JFrame frame; private static JPanel panel; + private static Robot robot; private static volatile boolean passed = false; public static void main(String[] args) throws Exception { + robot = new Robot(); + robot.setAutoDelay(10); + String lf = "javax.swing.plaf.metal.MetalLookAndFeel"; UIManager.setLookAndFeel(lf); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); try { SwingUtilities.invokeAndWait(new Runnable() { @@ -56,9 +57,9 @@ public class bug6348946 { setupUI(); } }); - toolkit.realSync(); + robot.waitForIdle(); clickOnSlider(); - toolkit.realSync(); + robot.waitForIdle(); checkResult(); } finally { stopEDT(); @@ -79,9 +80,6 @@ public class bug6348946 { } private static void clickOnSlider() throws Exception { - Robot robot = new Robot(); - robot.setAutoDelay(10); - Rectangle rect = getPanelRectangle(); double clickX = rect.getX() + rect.getWidth() / 4; diff --git a/jdk/test/javax/swing/JSlider/6401380/bug6401380.java b/jdk/test/javax/swing/JSlider/6401380/bug6401380.java new file mode 100644 index 00000000000..8cb70db5f93 --- /dev/null +++ b/jdk/test/javax/swing/JSlider/6401380/bug6401380.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2011, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* @test + @bug 6401380 + @summary JSlider - mouse click ont the left side of the knob is ignored. + @library ../../../../lib/testlibrary + @build ExtendedRobot + @author Alexander Potochkin + @run main bug6401380 +*/ + +import javax.swing.*; +import javax.swing.plaf.basic.BasicSliderUI; +import java.awt.*; +import java.awt.event.InputEvent; + +public class bug6401380 extends JFrame { + private static JSlider slider; + + public bug6401380() { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + slider = new JSlider(); + slider.setMajorTickSpacing(0); + slider.setMaximum(50); + slider.setMinorTickSpacing(10); + slider.setPaintLabels(true); + slider.setPaintTicks(true); + slider.setSnapToTicks(true); + + // MetalSliderUI overrides scrollDueToClickInTrack() method + // so this test doens't work for Metal + slider.setUI(new BasicSliderUI(slider)); + + add(slider); + setSize(200, 200); + } + + public static void main(String[] args) throws Exception { + + ExtendedRobot robot = new ExtendedRobot(); + robot.setAutoDelay(10); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + new bug6401380().setVisible(true); + } + }); + robot.waitForIdle(); + + Point l = slider.getLocationOnScreen(); + robot.glide(0, 0, l.x + slider.getWidth() / 2, l.y + slider.getHeight() / 2); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + robot.waitForIdle(); + + if (slider.getValue() == slider.getMaximum()) { + throw new RuntimeException("Slider value unchanged"); + } + } +} diff --git a/jdk/test/javax/swing/JSlider/6848475/bug6848475.java b/jdk/test/javax/swing/JSlider/6848475/bug6848475.java index dd8995152a0..a27f02499fa 100644 --- a/jdk/test/javax/swing/JSlider/6848475/bug6848475.java +++ b/jdk/test/javax/swing/JSlider/6848475/bug6848475.java @@ -28,8 +28,6 @@ * @run main bug6848475 */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.plaf.SliderUI; import javax.swing.plaf.basic.BasicSliderUI; @@ -47,7 +45,6 @@ public class bug6848475 { private static int thumbRectX; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); robot = new Robot(); robot.setAutoDelay(100); @@ -70,7 +67,7 @@ public class bug6848475 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -80,7 +77,7 @@ public class bug6848475 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -95,7 +92,7 @@ public class bug6848475 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { diff --git a/jdk/test/javax/swing/JSpinner/4973721/bug4973721.java b/jdk/test/javax/swing/JSpinner/4973721/bug4973721.java index f94ce860eed..9bbc381d568 100644 --- a/jdk/test/javax/swing/JSpinner/4973721/bug4973721.java +++ b/jdk/test/javax/swing/JSpinner/4973721/bug4973721.java @@ -30,21 +30,18 @@ */ import java.awt.Robot; -import java.awt.Toolkit; import javax.swing.event.ChangeListener; import javax.swing.event.ChangeEvent; import java.awt.event.KeyEvent; import java.awt.event.FocusListener; import java.awt.event.FocusEvent; import javax.swing.*; -import sun.awt.SunToolkit; public class bug4973721 implements ChangeListener, FocusListener { static volatile boolean bStateChanged = false; static volatile boolean bFocusGained = false; static JSpinner spinner; static final Object listener = new bug4973721(); - private static final SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); public void focusLost(FocusEvent e) {} @@ -100,7 +97,7 @@ public class bug4973721 implements ChangeListener, FocusListener { robot.setAutoDelay(50); Util.hitKeys(robot, KeyEvent.VK_UP); - toolkit.realSync(); + robot.waitForIdle(); Thread.sleep(1000); if (!bStateChanged) { @@ -110,7 +107,7 @@ public class bug4973721 implements ChangeListener, FocusListener { bStateChanged = false; Util.hitKeys(robot, KeyEvent.VK_DOWN); - toolkit.realSync(); + robot.waitForIdle(); Thread.sleep(1000); if (!bStateChanged) { diff --git a/jdk/test/javax/swing/JSpinner/5012888/bug5012888.java b/jdk/test/javax/swing/JSpinner/5012888/bug5012888.java index 7898de4382c..c98b46a1a41 100644 --- a/jdk/test/javax/swing/JSpinner/5012888/bug5012888.java +++ b/jdk/test/javax/swing/JSpinner/5012888/bug5012888.java @@ -43,10 +43,10 @@ public class bug5012888 extends JFrame { pane.add(spinner2, BorderLayout.SOUTH); } public void doTest() throws Exception { - ((sun.awt.SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + Robot robot = new Robot(); + robot.waitForIdle(); Point p = spinner2.getLocationOnScreen(); Rectangle rect = spinner2.getBounds(); - Robot robot = new Robot(); robot.mouseMove(p.x+rect.width-5, p.y+5); robot.mousePress(InputEvent.BUTTON1_MASK); Thread.sleep(1000); diff --git a/jdk/test/javax/swing/JSplitPane/4885629/bug4885629.java b/jdk/test/javax/swing/JSplitPane/4885629/bug4885629.java index f3348d0f3b1..97fc5c7beb5 100644 --- a/jdk/test/javax/swing/JSplitPane/4885629/bug4885629.java +++ b/jdk/test/javax/swing/JSplitPane/4885629/bug4885629.java @@ -28,8 +28,6 @@ * @author Andrey Pikalev */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; @@ -91,9 +89,8 @@ public class bug4885629 { } }); - ((SunToolkit) SunToolkit.getDefaultToolkit()).realSync(); - final Robot robot = new Robot(); + robot.waitForIdle(); robot.delay(1000); SwingUtilities.invokeAndWait(new Runnable() { diff --git a/jdk/test/javax/swing/JTabbedPane/4361477/bug4361477.java b/jdk/test/javax/swing/JTabbedPane/4361477/bug4361477.java index f41d240c5bc..a617ccccd11 100644 --- a/jdk/test/javax/swing/JTabbedPane/4361477/bug4361477.java +++ b/jdk/test/javax/swing/JTabbedPane/4361477/bug4361477.java @@ -25,7 +25,6 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; -import sun.awt.SunToolkit; /* * @test @@ -42,7 +41,6 @@ public class bug4361477 { public static void main(String args[]) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -54,7 +52,7 @@ public class bug4361477 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { diff --git a/jdk/test/javax/swing/JTabbedPane/4624207/bug4624207.java b/jdk/test/javax/swing/JTabbedPane/4624207/bug4624207.java index d8bf8f621ba..9476df05902 100644 --- a/jdk/test/javax/swing/JTabbedPane/4624207/bug4624207.java +++ b/jdk/test/javax/swing/JTabbedPane/4624207/bug4624207.java @@ -26,8 +26,9 @@ * @bug 4624207 * @summary JTabbedPane mnemonics don't work from outside the tabbed pane * @author Oleg Mokhovikov + * @library ../../../../lib/testlibrary * @library ../../regtesthelpers - * @build Util + * @build Util jdk.testlibrary.OSInfo * @run main bug4624207 */ import javax.swing.*; @@ -38,8 +39,7 @@ import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.awt.event.KeyEvent; -import sun.awt.OSInfo; -import sun.awt.SunToolkit; +import jdk.testlibrary.OSInfo; public class bug4624207 implements ChangeListener, FocusListener { @@ -65,7 +65,6 @@ public class bug4624207 implements ChangeListener, FocusListener { } public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -76,7 +75,7 @@ public class bug4624207 implements ChangeListener, FocusListener { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @@ -85,7 +84,7 @@ public class bug4624207 implements ChangeListener, FocusListener { } }); - toolkit.realSync(); + robot.waitForIdle(); if (!focusGained) { throw new RuntimeException("Couldn't gain focus for text field"); @@ -99,7 +98,7 @@ public class bug4624207 implements ChangeListener, FocusListener { } }); - toolkit.realSync(); + robot.waitForIdle(); if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) { Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_B); @@ -107,7 +106,7 @@ public class bug4624207 implements ChangeListener, FocusListener { Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_B); } - toolkit.realSync(); + robot.waitForIdle(); if (!stateChanged || tab.getSelectedIndex() != 1) { throw new RuntimeException("JTabbedPane mnemonics don't work from outside the tabbed pane"); diff --git a/jdk/test/javax/swing/JTabbedPane/6495408/bug6495408.java b/jdk/test/javax/swing/JTabbedPane/6495408/bug6495408.java index 40f69d53fe9..8f7f6678827 100644 --- a/jdk/test/javax/swing/JTabbedPane/6495408/bug6495408.java +++ b/jdk/test/javax/swing/JTabbedPane/6495408/bug6495408.java @@ -23,7 +23,6 @@ import javax.swing.*; import java.awt.*; -import sun.awt.SunToolkit; /* * @test * @bug 6495408 @@ -37,7 +36,6 @@ public class bug6495408 { static JTabbedPane tabbedPane; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); final Robot robot = new Robot(); robot.setAutoDelay(50); @@ -56,7 +54,7 @@ public class bug6495408 { } }); - toolkit.realSync(); + robot.waitForIdle(); final Rectangle d = new Rectangle(); final Point p = new Point(); diff --git a/jdk/test/javax/swing/JTabbedPane/7161568/bug7161568.java b/jdk/test/javax/swing/JTabbedPane/7161568/bug7161568.java index 73ecbf9ddc9..46571abd93a 100644 --- a/jdk/test/javax/swing/JTabbedPane/7161568/bug7161568.java +++ b/jdk/test/javax/swing/JTabbedPane/7161568/bug7161568.java @@ -23,7 +23,6 @@ import java.awt.*; import javax.swing.*; import java.awt.event.*; -import sun.awt.SunToolkit; /** * @test @@ -40,7 +39,6 @@ public class bug7161568 { public static void main(String[] args) throws Exception { UIManager.put("TabbedPane.selectionFollowsFocus", Boolean.FALSE); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -52,7 +50,7 @@ public class bug7161568 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @@ -62,12 +60,12 @@ public class bug7161568 { } }); - toolkit.realSync(); + robot.waitForIdle(); for (int i = 0; i < N; i++) { robot.keyPress(KeyEvent.VK_LEFT); robot.keyRelease(KeyEvent.VK_LEFT); - toolkit.realSync(); + robot.waitForIdle(); } } diff --git a/jdk/test/javax/swing/JTable/4220171/bug4220171.java b/jdk/test/javax/swing/JTable/4220171/bug4220171.java index acaf05ee696..2b4ecb5baa6 100644 --- a/jdk/test/javax/swing/JTable/4220171/bug4220171.java +++ b/jdk/test/javax/swing/JTable/4220171/bug4220171.java @@ -34,12 +34,10 @@ import java.awt.Color; import java.awt.Point; import java.awt.Rectangle; import java.awt.Robot; -import java.awt.Toolkit; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import javax.swing.*; import javax.swing.border.LineBorder; -import sun.awt.SunToolkit; public class bug4220171 { @@ -47,7 +45,6 @@ public class bug4220171 { public static void main(String args[]) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -58,26 +55,26 @@ public class bug4220171 { } }); - toolkit.realSync(); + robot.waitForIdle(); clickMouse(robot, 0, 0); Util.hitKeys(robot, KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_ENTER); - toolkit.realSync(); + robot.waitForIdle(); checkCell(0, 0); clickMouse(robot, 0, 1); Util.hitKeys(robot, KeyEvent.VK_D, KeyEvent.VK_E, KeyEvent.VK_ENTER); - toolkit.realSync(); + robot.waitForIdle(); checkCell(0, 1); clickMouse(robot, 1, 0); Util.hitKeys(robot, KeyEvent.VK_1, KeyEvent.VK_2, KeyEvent.VK_ENTER); - toolkit.realSync(); + robot.waitForIdle(); checkCell(1, 0); clickMouse(robot, 1, 1); Util.hitKeys(robot, KeyEvent.VK_4, KeyEvent.VK_5, KeyEvent.VK_ENTER); - toolkit.realSync(); + robot.waitForIdle(); checkCell(1, 1); } diff --git a/jdk/test/javax/swing/JTable/6263446/bug6263446.java b/jdk/test/javax/swing/JTable/6263446/bug6263446.java index 6d4c235dfff..9089e3f1c5e 100644 --- a/jdk/test/javax/swing/JTable/6263446/bug6263446.java +++ b/jdk/test/javax/swing/JTable/6263446/bug6263446.java @@ -32,7 +32,6 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; -import sun.awt.SunToolkit; public class bug6263446 { @@ -43,7 +42,6 @@ public class bug6263446 { private static Robot robot; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); robot = new Robot(); robot.setAutoDelay(50); @@ -55,63 +53,63 @@ public class bug6263446 { }); - toolkit.realSync(); + robot.waitForIdle(); Point point = getClickPoint(); robot.mouseMove(point.x, point.y); - toolkit.realSync(); + robot.waitForIdle(); click(1); - toolkit.realSync(); + robot.waitForIdle(); assertEditing(false); click(2); - toolkit.realSync(); + robot.waitForIdle(); checkSelectedText(null); click(3); - toolkit.realSync(); + robot.waitForIdle(); checkSelectedText(FIRST); click(4); - toolkit.realSync(); + robot.waitForIdle(); checkSelectedText(ALL); setClickCountToStart(1); click(1); - toolkit.realSync(); + robot.waitForIdle(); checkSelectedText(null); click(2); - toolkit.realSync(); + robot.waitForIdle(); checkSelectedText(FIRST); click(3); - toolkit.realSync(); + robot.waitForIdle(); checkSelectedText(ALL); setClickCountToStart(3); click(1); - toolkit.realSync(); + robot.waitForIdle(); assertEditing(false); click(2); - toolkit.realSync(); + robot.waitForIdle(); assertEditing(false); click(3); - toolkit.realSync(); + robot.waitForIdle(); checkSelectedText(null); click(4); - toolkit.realSync(); + robot.waitForIdle(); checkSelectedText(FIRST); click(5); - toolkit.realSync(); + robot.waitForIdle(); checkSelectedText(ALL); @@ -123,11 +121,11 @@ public class bug6263446 { } }); - toolkit.realSync(); + robot.waitForIdle(); assertEditing(true); click(2); - toolkit.realSync(); + robot.waitForIdle(); checkSelectedText(FIRST); } diff --git a/jdk/test/javax/swing/JTable/6777378/bug6777378.java b/jdk/test/javax/swing/JTable/6777378/bug6777378.java index dc0230c1187..973da5af995 100644 --- a/jdk/test/javax/swing/JTable/6777378/bug6777378.java +++ b/jdk/test/javax/swing/JTable/6777378/bug6777378.java @@ -28,8 +28,6 @@ @run main bug6777378 */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.table.AbstractTableModel; import javax.swing.table.JTableHeader; @@ -43,7 +41,6 @@ public class bug6777378 { private static JTableHeader header; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(20); SwingUtilities.invokeAndWait(new Runnable() { @@ -78,7 +75,7 @@ public class bug6777378 { frame.setVisible(true); } }); - toolkit.realSync(); + robot.waitForIdle(); Point point = header.getLocationOnScreen(); robot.mouseMove(point.x + 20, point.y + 50); robot.mouseMove(point.x + 30, point.y + 50); diff --git a/jdk/test/javax/swing/JTable/7055065/bug7055065.java b/jdk/test/javax/swing/JTable/7055065/bug7055065.java index 0e611e42a56..4b589715bdf 100644 --- a/jdk/test/javax/swing/JTable/7055065/bug7055065.java +++ b/jdk/test/javax/swing/JTable/7055065/bug7055065.java @@ -38,7 +38,6 @@ import java.awt.Dimension; import java.awt.Point; import java.awt.Rectangle; import java.awt.Robot; -import java.awt.Toolkit; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import javax.swing.JFrame; @@ -49,7 +48,6 @@ import javax.swing.SwingUtilities; import javax.swing.table.AbstractTableModel; import javax.swing.table.TableModel; import javax.swing.table.TableRowSorter; -import sun.awt.SunToolkit; import java.util.concurrent.Callable; public class bug7055065 { @@ -57,7 +55,6 @@ public class bug7055065 { private static JTable table; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { @@ -67,15 +64,15 @@ public class bug7055065 { } }); - toolkit.realSync(); + robot.waitForIdle(); clickCell(robot, 1, 1); Util.hitKeys(robot, KeyEvent.VK_BACK_SPACE, KeyEvent.VK_BACK_SPACE, KeyEvent.VK_BACK_SPACE); - toolkit.realSync(); + robot.waitForIdle(); clickColumnHeader(robot, 1); - toolkit.realSync(); + robot.waitForIdle(); clickColumnHeader(robot, 1); } diff --git a/jdk/test/javax/swing/JTable/7068740/bug7068740.java b/jdk/test/javax/swing/JTable/7068740/bug7068740.java index 4dac9cd288c..d0c8fbd814f 100644 --- a/jdk/test/javax/swing/JTable/7068740/bug7068740.java +++ b/jdk/test/javax/swing/JTable/7068740/bug7068740.java @@ -28,8 +28,6 @@ @run main bug7068740 */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.plaf.LayerUI; import javax.swing.plaf.metal.MetalLookAndFeel; @@ -43,7 +41,6 @@ public class bug7068740 extends JFrame { private static Robot robot = null; private static JTable table = null; - private static SunToolkit toolkit = null; bug7068740() { super(); @@ -83,10 +80,6 @@ public class bug7068740 extends JFrame { robot.setAutoDelay(50); } - if (toolkit == null) { - toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - } - SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { @@ -118,11 +111,11 @@ public class bug7068740 extends JFrame { } private static void doTest() throws Exception { - toolkit.realSync(); + robot.waitForIdle(); robot.keyPress(KeyEvent.VK_PAGE_DOWN); robot.keyRelease(KeyEvent.VK_PAGE_DOWN); - toolkit.realSync(); + robot.waitForIdle(); if (getSelectedRow() != 19) { throw new RuntimeException("Test failed"); @@ -130,7 +123,7 @@ public class bug7068740 extends JFrame { robot.keyPress(KeyEvent.VK_PAGE_UP); robot.keyRelease(KeyEvent.VK_PAGE_UP); - toolkit.realSync(); + robot.waitForIdle(); if (getSelectedRow() != 0) { throw new RuntimeException("Test failed"); } diff --git a/jdk/test/javax/swing/JTableHeader/6884066/bug6884066.java b/jdk/test/javax/swing/JTableHeader/6884066/bug6884066.java index 1b9ee135c67..3e1fe84c1d5 100644 --- a/jdk/test/javax/swing/JTableHeader/6884066/bug6884066.java +++ b/jdk/test/javax/swing/JTableHeader/6884066/bug6884066.java @@ -28,8 +28,6 @@ @run main bug6884066 */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.table.JTableHeader; import javax.swing.table.TableColumnModel; @@ -46,7 +44,6 @@ public class bug6884066 { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(20); SwingUtilities.invokeAndWait(new Runnable() { @@ -62,7 +59,7 @@ public class bug6884066 { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }); - toolkit.realSync(); + robot.waitForIdle(); Point point = header.getLocationOnScreen(); robot.mouseMove(point.x + 3, point.y + 3); robot.mousePress(InputEvent.BUTTON1_MASK); diff --git a/jdk/test/javax/swing/JTableHeader/6889007/bug6889007.java b/jdk/test/javax/swing/JTableHeader/6889007/bug6889007.java index f9ee4850377..c416d634472 100644 --- a/jdk/test/javax/swing/JTableHeader/6889007/bug6889007.java +++ b/jdk/test/javax/swing/JTableHeader/6889007/bug6889007.java @@ -27,8 +27,6 @@ @author Alexander Potochkin */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.plaf.basic.BasicTableHeaderUI; import javax.swing.table.JTableHeader; @@ -37,7 +35,6 @@ import java.awt.*; public class bug6889007 { public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(20); @@ -59,7 +56,7 @@ public class bug6889007 { frame.setVisible(true); } }); - toolkit.realSync(); + robot.waitForIdle(); Point point = frame.getLocationOnScreen(); int shift = 10; int x = point.x; @@ -67,7 +64,7 @@ public class bug6889007 { for(int i = -shift; i < frame.getWidth() + 2*shift; i++) { robot.mouseMove(x++, y); } - toolkit.realSync(); + robot.waitForIdle(); // 9 is a magic test number if (MyTableHeaderUI.getTestValue() != 9) { throw new RuntimeException("Unexpected test number " diff --git a/jdk/test/javax/swing/JTextArea/4697612/bug4697612.java b/jdk/test/javax/swing/JTextArea/4697612/bug4697612.java index 54cd12cb225..715da745071 100644 --- a/jdk/test/javax/swing/JTextArea/4697612/bug4697612.java +++ b/jdk/test/javax/swing/JTextArea/4697612/bug4697612.java @@ -35,7 +35,6 @@ import java.awt.event.*; import javax.swing.*; import javax.swing.text.BadLocationException; -import sun.awt.SunToolkit; public class bug4697612 { @@ -49,7 +48,6 @@ public class bug4697612 { private static JScrollPane scroller; public static void main(String[] args) throws Throwable { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(100); @@ -61,7 +59,7 @@ public class bug4697612 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @@ -71,7 +69,7 @@ public class bug4697612 { } }); - toolkit.realSync(); + robot.waitForIdle(); // 4697612: pressing PgDn + PgUp should not alter caret position Util.hitKeys(robot, KeyEvent.VK_HOME); @@ -102,11 +100,11 @@ public class bug4697612 { } }); - toolkit.realSync(); + robot.waitForIdle(); Util.hitKeys(robot, KeyEvent.VK_PAGE_DOWN); Util.hitKeys(robot, KeyEvent.VK_PAGE_UP); - toolkit.realSync(); + robot.waitForIdle(); int pos = getTextCaretPosition(); if (pos0 != pos) { @@ -126,11 +124,11 @@ public class bug4697612 { Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_END); } - toolkit.realSync(); + robot.waitForIdle(); pos0 = getScrollerViewPosition(); Util.hitKeys(robot, KeyEvent.VK_PAGE_DOWN); - toolkit.realSync(); + robot.waitForIdle(); int pos = getScrollerViewPosition(); @@ -187,6 +185,7 @@ public class bug4697612 { private static void createAndShowGUI() { frame = new JFrame(); frame.setSize(FRAME_WIDTH, FRAME_HEIGHT); + frame.setPreferredSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); text = new JTextArea(); diff --git a/jdk/test/javax/swing/JTextField/8036819/bug8036819.java b/jdk/test/javax/swing/JTextField/8036819/bug8036819.java index 558be4c9769..214f13cd19b 100644 --- a/jdk/test/javax/swing/JTextField/8036819/bug8036819.java +++ b/jdk/test/javax/swing/JTextField/8036819/bug8036819.java @@ -35,7 +35,6 @@ import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; import java.awt.*; -import sun.awt.SunToolkit; import javax.accessibility.*; public class bug8036819 { @@ -49,15 +48,14 @@ public class bug8036819 { } }); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - toolkit.realSync(); Robot robo = new Robot(); robo.setAutoDelay(300); + robo.waitForIdle(); // Using mnemonic key to focus on the textfield Util.hitMnemonics(robo, KeyEvent.VK_P); - toolkit.realSync(); + robo.waitForIdle(); if (!passed){ throw new RuntimeException("Test failed."); diff --git a/jdk/test/javax/swing/JToolBar/4247996/bug4247996.java b/jdk/test/javax/swing/JToolBar/4247996/bug4247996.java index e389a4b5dc4..63eaccbac99 100644 --- a/jdk/test/javax/swing/JToolBar/4247996/bug4247996.java +++ b/jdk/test/javax/swing/JToolBar/4247996/bug4247996.java @@ -29,7 +29,6 @@ */ import java.awt.*; import javax.swing.*; -import sun.awt.SunToolkit; public class bug4247996 { @@ -38,7 +37,6 @@ public class bug4247996 { public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -51,11 +49,11 @@ public class bug4247996 { } }); - toolkit.realSync(); + robot.waitForIdle(); Point point = getButtonCenter(); robot.mouseMove(point.x, point.y); - toolkit.realSync(); + robot.waitForIdle(); checkButtonsSize(); diff --git a/jdk/test/javax/swing/JToolTip/4846413/bug4846413.java b/jdk/test/javax/swing/JToolTip/4846413/bug4846413.java index 3195e919fc4..a18b2bee37b 100644 --- a/jdk/test/javax/swing/JToolTip/4846413/bug4846413.java +++ b/jdk/test/javax/swing/JToolTip/4846413/bug4846413.java @@ -37,7 +37,6 @@ import java.awt.Toolkit; import javax.swing.*; import java.awt.event.*; import javax.swing.plaf.metal.MetalToolTipUI; -import sun.awt.SunToolkit; public class bug4846413 { @@ -46,7 +45,6 @@ public class bug4846413 { public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -59,11 +57,11 @@ public class bug4846413 { } }); - toolkit.realSync(); + robot.waitForIdle(); Point movePoint = getButtonPoint(); robot.mouseMove(movePoint.x, movePoint.y); - toolkit.realSync(); + robot.waitForIdle(); long timeout = System.currentTimeMillis() + 9000; while (!isTooltipAdded && (System.currentTimeMillis() < timeout)) { diff --git a/jdk/test/javax/swing/JTree/4330357/bug4330357.java b/jdk/test/javax/swing/JTree/4330357/bug4330357.java index 599706be055..810c88666fb 100644 --- a/jdk/test/javax/swing/JTree/4330357/bug4330357.java +++ b/jdk/test/javax/swing/JTree/4330357/bug4330357.java @@ -34,7 +34,6 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.tree.*; -import sun.awt.SunToolkit; public class bug4330357 { @@ -43,7 +42,6 @@ public class bug4330357 { private static Robot robot; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); robot = new Robot(); robot.setAutoDelay(50); @@ -56,12 +54,12 @@ public class bug4330357 { } }); - toolkit.realSync(); + robot.waitForIdle(); clickMouse(getTreeRowClickPoint(1)); Util.hitKeys(robot, KeyEvent.VK_F2); Util.hitKeys(robot, KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_C); - toolkit.realSync(); + robot.waitForIdle(); if (!hasComponent(JTextField.class)) { throw new RuntimeException("Cell editor is missed for path: color"); @@ -69,11 +67,11 @@ public class bug4330357 { clickMouse(getButtonClickPoint()); - toolkit.realSync(); + robot.waitForIdle(); clickMouse(getTreeRowClickPoint(2)); Util.hitKeys(robot, KeyEvent.VK_F2); - toolkit.realSync(); + robot.waitForIdle(); if (!hasComponent(JComboBox.class)) { throw new RuntimeException("Cell editor is missed for path: sports"); diff --git a/jdk/test/javax/swing/JTree/4908142/bug4908142.java b/jdk/test/javax/swing/JTree/4908142/bug4908142.java index df18d0801b5..2b6fbd7a8b3 100644 --- a/jdk/test/javax/swing/JTree/4908142/bug4908142.java +++ b/jdk/test/javax/swing/JTree/4908142/bug4908142.java @@ -36,7 +36,6 @@ import javax.swing.tree.*; import java.awt.*; import java.awt.event.*; import java.util.concurrent.Callable; -import sun.awt.SunToolkit; public class bug4908142 { @@ -44,7 +43,6 @@ public class bug4908142 { public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -55,7 +53,7 @@ public class bug4908142 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @@ -65,7 +63,7 @@ public class bug4908142 { } }); - toolkit.realSync(); + robot.waitForIdle(); robot.keyPress(KeyEvent.VK_A); @@ -74,7 +72,7 @@ public class bug4908142 { robot.keyRelease(KeyEvent.VK_A); robot.keyPress(KeyEvent.VK_D); robot.keyRelease(KeyEvent.VK_D); - toolkit.realSync(); + robot.waitForIdle(); String sel = Util.invokeOnEDT(new Callable() { diff --git a/jdk/test/javax/swing/JTree/4927934/bug4927934.java b/jdk/test/javax/swing/JTree/4927934/bug4927934.java index b242e57ce46..c4f739e6bdd 100644 --- a/jdk/test/javax/swing/JTree/4927934/bug4927934.java +++ b/jdk/test/javax/swing/JTree/4927934/bug4927934.java @@ -33,7 +33,6 @@ import javax.swing.tree.*; import java.awt.*; import java.awt.event.*; import java.lang.reflect.InvocationTargetException; -import sun.awt.*; public class bug4927934 implements TreeSelectionListener, TreeExpansionListener, FocusListener { @@ -73,8 +72,7 @@ public class bug4927934 implements TreeSelectionListener, TreeExpansionListener, } }); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - toolkit.realSync(); + robot.waitForIdle(); Thread.sleep(1000); SwingUtilities.invokeLater(new Runnable() { @@ -97,35 +95,35 @@ public class bug4927934 implements TreeSelectionListener, TreeExpansionListener, // GO TO RIGHT selectionChanged = false; hitKey(KeyEvent.VK_RIGHT); - toolkit.realSync(); + robot.waitForIdle(); if (!checkSelectionChanged(tree, 0)) { throw new RuntimeException("Root should be selected"); } selectionChanged = false; hitKey(KeyEvent.VK_RIGHT); - toolkit.realSync(); + robot.waitForIdle(); if (!checkSelectionChanged(tree, 1)) { throw new RuntimeException("Node should be selected"); } treeExpanded = false; hitKey(KeyEvent.VK_RIGHT); - toolkit.realSync(); + robot.waitForIdle(); if (!isTreeExpanded()) { throw new RuntimeException("Node should be expanded"); } selectionChanged = false; hitKey(KeyEvent.VK_RIGHT); - toolkit.realSync(); + robot.waitForIdle(); if (!checkSelectionChanged(tree, 2)) { throw new RuntimeException("Leaf1 should be selected"); } selectionChanged = false; hitKey(KeyEvent.VK_RIGHT); - toolkit.realSync(); + robot.waitForIdle(); if (!checkSelectionChanged(tree, 2)) { throw new RuntimeException("Leaf1 should be selected"); } @@ -133,7 +131,7 @@ public class bug4927934 implements TreeSelectionListener, TreeExpansionListener, // GO TO LEFT selectionChanged = false; hitKey(KeyEvent.VK_LEFT); - toolkit.realSync(); + robot.waitForIdle(); if (!checkSelectionChanged(tree, 1)) { throw new RuntimeException("Node should be selected"); } @@ -146,14 +144,14 @@ public class bug4927934 implements TreeSelectionListener, TreeExpansionListener, selectionChanged = false; hitKey(KeyEvent.VK_LEFT); - toolkit.realSync(); + robot.waitForIdle(); if (!checkSelectionChanged(tree, 0)) { throw new RuntimeException("Root should be selected"); } treeCollapsed = false; hitKey(KeyEvent.VK_LEFT); - toolkit.realSync(); + robot.waitForIdle(); if (!isTreeCollapsed()) { throw new RuntimeException("Root should be collapsed"); } diff --git a/jdk/test/javax/swing/JTree/6263446/bug6263446.java b/jdk/test/javax/swing/JTree/6263446/bug6263446.java index b8e0dee4c6d..2e13599b540 100644 --- a/jdk/test/javax/swing/JTree/6263446/bug6263446.java +++ b/jdk/test/javax/swing/JTree/6263446/bug6263446.java @@ -33,7 +33,6 @@ import java.awt.event.InputEvent; import java.lang.reflect.Field; import javax.swing.*; import javax.swing.tree.*; -import sun.awt.SunToolkit; public class bug6263446 { @@ -42,10 +41,8 @@ public class bug6263446 { private static final String ALL = FIRST + " " + SECOND; private static JTree tree; private static Robot robot; - private static SunToolkit toolkit; public static void main(String[] args) throws Exception { - toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); robot = new Robot(); robot.setAutoDelay(50); @@ -56,7 +53,7 @@ public class bug6263446 { } }); - toolkit.realSync(); + robot.waitForIdle(); Point point = getClickPoint(); robot.mouseMove(point.x, point.y); @@ -182,7 +179,7 @@ public class bug6263446 { } }); - toolkit.realSync(); + robot.waitForIdle(); } @@ -252,7 +249,7 @@ public class bug6263446 { } private static void assertEditingNoTreeLock(final boolean editing) throws Exception { - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { diff --git a/jdk/test/javax/swing/JTree/6505523/bug6505523.java b/jdk/test/javax/swing/JTree/6505523/bug6505523.java index 40357dee6c9..21a1043257f 100644 --- a/jdk/test/javax/swing/JTree/6505523/bug6505523.java +++ b/jdk/test/javax/swing/JTree/6505523/bug6505523.java @@ -31,7 +31,6 @@ import java.awt.Point; import java.awt.Rectangle; import java.awt.Robot; -import java.awt.Toolkit; import java.awt.event.InputEvent; import javax.swing.JFrame; import javax.swing.JScrollPane; @@ -42,14 +41,12 @@ import javax.swing.event.TreeExpansionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeNode; -import sun.awt.SunToolkit; public class bug6505523 { private static JTree tree; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -61,14 +58,14 @@ public class bug6505523 { } }); - toolkit.realSync(); + robot.waitForIdle(); Point point = getRowPointToClick(2); robot.mouseMove(point.x, point.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); } @@ -129,4 +126,4 @@ public class bug6505523 { frame.setLocationRelativeTo(null); frame.setVisible(true); } -} \ No newline at end of file +} diff --git a/jdk/test/javax/swing/JTree/6578666/bug6578666.java b/jdk/test/javax/swing/JTree/6578666/bug6578666.java new file mode 100644 index 00000000000..708ce548ebb --- /dev/null +++ b/jdk/test/javax/swing/JTree/6578666/bug6578666.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2011, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* + * @test + * @bug 6578666 + * @summary REGRESSION: Exception occurs when updateUI for JTree is triggered by KeyEvent + * @run main bug6578666 + * @author Alexander Potochkin + */ + +import javax.swing.*; +import java.awt.*; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; + +public class bug6578666 { + + private static JTree tree; + + private static void createGui() { + final JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + tree = new JTree(); + frame.add(tree); + + tree.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + tree.updateUI(); + } + }); + + frame.setSize(200, 200); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + public static void main(String[] args) throws Exception { + Robot robot = new Robot(); + robot.setAutoDelay(10); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + bug6578666.createGui(); + } + }); + + robot.waitForIdle(); + + tree.requestFocus(); + robot.waitForIdle(); + + robot.keyPress(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_SPACE); + robot.waitForIdle(); + robot.keyPress(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_SPACE); + + } +} diff --git a/jdk/test/javax/swing/JTree/8003400/Test8003400.java b/jdk/test/javax/swing/JTree/8003400/Test8003400.java index f2102f8b1e4..7f09751b4d3 100644 --- a/jdk/test/javax/swing/JTree/8003400/Test8003400.java +++ b/jdk/test/javax/swing/JTree/8003400/Test8003400.java @@ -26,17 +26,16 @@ * @bug 8003400 * @summary Tests that JTree shows the last row * @author Sergey Malenkov + * @library ../../../../lib/testlibrary + * @build ExtendedRobot * @run main/othervm Test8003400 * @run main/othervm Test8003400 reverse * @run main/othervm Test8003400 system * @run main/othervm Test8003400 system reverse */ -import sun.awt.SunToolkit; - import java.awt.Rectangle; import java.awt.Robot; -import java.awt.Toolkit; import java.awt.event.KeyEvent; import java.util.Arrays; import java.util.Collections; @@ -85,10 +84,12 @@ public class Test8003400 { } }); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - toolkit.realSync(500); - new Robot().keyPress(KeyEvent.VK_END); - toolkit.realSync(500); + ExtendedRobot robot = new ExtendedRobot(); + robot.waitForIdle(500); + robot.keyPress(KeyEvent.VK_END); + robot.waitForIdle(500); + robot.keyRelease(KeyEvent.VK_END); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { diff --git a/jdk/test/javax/swing/JTree/8004298/bug8004298.java b/jdk/test/javax/swing/JTree/8004298/bug8004298.java index bafdee7d3e3..ae2251ced5e 100644 --- a/jdk/test/javax/swing/JTree/8004298/bug8004298.java +++ b/jdk/test/javax/swing/JTree/8004298/bug8004298.java @@ -36,7 +36,6 @@ import java.awt.event.InputEvent; import javax.swing.*; import javax.swing.tree.*; import java.util.concurrent.Callable; -import sun.awt.SunToolkit; import com.sun.java.swing.plaf.windows.WindowsLookAndFeel; import com.sun.java.swing.plaf.windows.WindowsTreeUI; @@ -47,7 +46,6 @@ public class bug8004298 { public static void main(String[] args) throws Exception { Robot robot = new Robot(); robot.setAutoDelay(50); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); try { UIManager.setLookAndFeel(new WindowsLookAndFeel()); } catch (javax.swing.UnsupportedLookAndFeelException ulafe) { @@ -63,7 +61,7 @@ public class bug8004298 { } }); - toolkit.realSync(); + robot.waitForIdle(); Point point = Util.invokeOnEDT(new Callable() { @@ -81,7 +79,7 @@ public class bug8004298 { robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); } diff --git a/jdk/test/javax/swing/Popup/TaskbarPositionTest.java b/jdk/test/javax/swing/Popup/TaskbarPositionTest.java index b4f8989c9db..0f30c2ae745 100644 --- a/jdk/test/javax/swing/Popup/TaskbarPositionTest.java +++ b/jdk/test/javax/swing/Popup/TaskbarPositionTest.java @@ -259,7 +259,6 @@ public class TaskbarPositionTest extends JFrame implements ActionListener { public static void main(String[] args) throws Throwable { - sun.awt.SunToolkit toolkit = (sun.awt.SunToolkit) Toolkit.getDefaultToolkit(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -275,7 +274,7 @@ public class TaskbarPositionTest extends JFrame implements ActionListener { // 1 - menu Util.hitMnemonics(robot, KeyEvent.VK_1); - toolkit.realSync(); + robot.waitForIdle(); isPopupOnScreen(menu1.getPopupMenu(), screenBounds); // 2 menu with sub menu @@ -283,14 +282,14 @@ public class TaskbarPositionTest extends JFrame implements ActionListener { robot.keyRelease(KeyEvent.VK_RIGHT); Util.hitMnemonics(robot, KeyEvent.VK_S); - toolkit.realSync(); + robot.waitForIdle(); isPopupOnScreen(menu2.getPopupMenu(), screenBounds); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); // Focus should go to non editable combo box - toolkit.realSync(); + robot.waitForIdle(); Thread.sleep(500); robot.keyPress(KeyEvent.VK_DOWN); @@ -320,7 +319,7 @@ public class TaskbarPositionTest extends JFrame implements ActionListener { robot.mousePress(InputEvent.BUTTON3_MASK); robot.mouseRelease(InputEvent.BUTTON3_MASK); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { test.setLocation(-30, 100); @@ -334,7 +333,7 @@ public class TaskbarPositionTest extends JFrame implements ActionListener { robot.keyPress(KeyEvent.VK_ESCAPE); robot.keyRelease(KeyEvent.VK_ESCAPE); - toolkit.realSync(); + robot.waitForIdle(); Thread.sleep(500); } } diff --git a/jdk/test/javax/swing/PopupFactory/6276087/NonOpaquePopupMenuTest.java b/jdk/test/javax/swing/PopupFactory/6276087/NonOpaquePopupMenuTest.java index 467aee5fc54..256ad4ef818 100644 --- a/jdk/test/javax/swing/PopupFactory/6276087/NonOpaquePopupMenuTest.java +++ b/jdk/test/javax/swing/PopupFactory/6276087/NonOpaquePopupMenuTest.java @@ -31,7 +31,6 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; -import sun.awt.SunToolkit; public class NonOpaquePopupMenuTest extends JFrame { @@ -53,7 +52,6 @@ public class NonOpaquePopupMenuTest extends JFrame { } public static void main(String[] args) throws Throwable { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(250); @@ -65,14 +63,14 @@ public class NonOpaquePopupMenuTest extends JFrame { } }); - toolkit.realSync(); + robot.waitForIdle(); Point p = getMenuClickPoint(); robot.mouseMove(p.x, p.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); if (isParentOpaque()) { throw new RuntimeException("Popup menu parent is opaque"); diff --git a/jdk/test/javax/swing/SwingUtilities/4917669/bug4917669.java b/jdk/test/javax/swing/SwingUtilities/4917669/bug4917669.java index fcfbb1715d7..ed438928be4 100644 --- a/jdk/test/javax/swing/SwingUtilities/4917669/bug4917669.java +++ b/jdk/test/javax/swing/SwingUtilities/4917669/bug4917669.java @@ -34,7 +34,6 @@ import javax.swing.*; import java.awt.event.*; import java.awt.*; -import sun.awt.SunToolkit; public class bug4917669 { @@ -42,7 +41,6 @@ public class bug4917669 { private static JFrame mainFrame; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(500); @@ -54,7 +52,7 @@ public class bug4917669 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @@ -64,10 +62,10 @@ public class bug4917669 { } }); - toolkit.realSync(); + robot.waitForIdle(); Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_O); - toolkit.realSync(); + robot.waitForIdle(); if (!passed) { throw new RuntimeException("Action did not received by menu item."); diff --git a/jdk/test/javax/swing/SwingUtilities/7146377/bug7146377.java b/jdk/test/javax/swing/SwingUtilities/7146377/bug7146377.java index 5b5c2b19049..5114b77e079 100644 --- a/jdk/test/javax/swing/SwingUtilities/7146377/bug7146377.java +++ b/jdk/test/javax/swing/SwingUtilities/7146377/bug7146377.java @@ -27,8 +27,6 @@ @author Pavel Porvatov */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; import java.awt.event.InputEvent; @@ -82,9 +80,9 @@ public class bug7146377 { } }); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); - toolkit.realSync(); + robot.waitForIdle(); // On Linux platforms realSync doesn't guaranties setSize completion Thread.sleep(1000); @@ -95,7 +93,6 @@ public class bug7146377 { } }); - Robot robot = new Robot(); robot.setAutoDelay(200); @@ -117,7 +114,7 @@ public class bug7146377 { robot.mouseRelease(button); } - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { diff --git a/jdk/test/javax/swing/ToolTipManager/Test6256140.java b/jdk/test/javax/swing/ToolTipManager/Test6256140.java index 12d5df8be03..ca90d815a79 100644 --- a/jdk/test/javax/swing/ToolTipManager/Test6256140.java +++ b/jdk/test/javax/swing/ToolTipManager/Test6256140.java @@ -29,8 +29,6 @@ * @run main Test6256140 */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; import java.awt.event.KeyEvent; @@ -46,14 +44,13 @@ public class Test6256140 { Robot robot = new Robot(); robot.setAutoDelay(10); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { createAndShowGUI(); } }); - toolkit.realSync(); + robot.waitForIdle(); Point point = ft.getLocationOnScreen(); robot.mouseMove(point.x, point.y); @@ -61,7 +58,7 @@ public class Test6256140 { robot.keyPress(KeyEvent.VK_A); robot.keyRelease(KeyEvent.VK_A); - toolkit.realSync(); + robot.waitForIdle(); if (!isTooltipShowning()) { throw new RuntimeException("Tooltip is not shown"); @@ -69,7 +66,7 @@ public class Test6256140 { robot.keyPress(KeyEvent.VK_ESCAPE); robot.keyRelease(KeyEvent.VK_ESCAPE); - toolkit.realSync(); + robot.waitForIdle(); if (isTooltipShowning()) { throw new RuntimeException("Tooltip must be hidden now"); @@ -81,7 +78,7 @@ public class Test6256140 { robot.keyPress(KeyEvent.VK_ESCAPE); robot.keyRelease(KeyEvent.VK_ESCAPE); - toolkit.realSync(); + robot.waitForIdle(); if (!isTextEqual()) { throw new RuntimeException("FormattedTextField must cancel the updated value"); diff --git a/jdk/test/javax/swing/dnd/7171812/bug7171812.java b/jdk/test/javax/swing/dnd/7171812/bug7171812.java index a550d5e3cf9..8de55bd701f 100644 --- a/jdk/test/javax/swing/dnd/7171812/bug7171812.java +++ b/jdk/test/javax/swing/dnd/7171812/bug7171812.java @@ -28,8 +28,6 @@ @run main bug7171812 */ -import sun.awt.SunToolkit; - import java.awt.*; import java.awt.dnd.*; import java.awt.event.InputEvent; @@ -45,7 +43,6 @@ public class bug7171812 { * @param args the command line arguments */ public static void main(String[] args) throws Exception{ - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -53,10 +50,10 @@ public class bug7171812 { setupGUI(); } }); - toolkit.realSync(); Robot robot = new Robot(); robot.setAutoDelay(10); + robot.waitForIdle(); robot.mouseMove(scrollPane.getLocationOnScreen().x + 5, scrollPane.getLocationOnScreen().y + 5); robot.mousePress(InputEvent.BUTTON1_MASK); for(int offset = 5; offset < scrollPane.getHeight()-20; offset++) { diff --git a/jdk/test/javax/swing/plaf/basic/BasicHTML/4251579/bug4251579.java b/jdk/test/javax/swing/plaf/basic/BasicHTML/4251579/bug4251579.java index 2069995928f..8aa96aea0ff 100644 --- a/jdk/test/javax/swing/plaf/basic/BasicHTML/4251579/bug4251579.java +++ b/jdk/test/javax/swing/plaf/basic/BasicHTML/4251579/bug4251579.java @@ -32,14 +32,11 @@ import java.awt.*; import javax.swing.*; -import sun.awt.SunToolkit; - public class bug4251579 { private static JLabel htmlComponent; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); final Robot robot = new Robot(); robot.setAutoDelay(50); @@ -51,7 +48,7 @@ public class bug4251579 { } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { diff --git a/jdk/test/javax/swing/plaf/basic/BasicMenuUI/4983388/bug4983388.java b/jdk/test/javax/swing/plaf/basic/BasicMenuUI/4983388/bug4983388.java index a09a3480f6d..666f0be73b2 100644 --- a/jdk/test/javax/swing/plaf/basic/BasicMenuUI/4983388/bug4983388.java +++ b/jdk/test/javax/swing/plaf/basic/BasicMenuUI/4983388/bug4983388.java @@ -30,7 +30,6 @@ @run main bug4983388 */ -import sun.awt.*; import java.awt.*; import javax.swing.*; import javax.swing.event.MenuListener; @@ -64,7 +63,6 @@ public class bug4983388 { public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); } catch (UnsupportedLookAndFeelException | ClassNotFoundException ex) { @@ -78,9 +76,10 @@ public class bug4983388 { }); Robot robot = new Robot(); + robot.waitForIdle(); Util.hitMnemonics(robot, KeyEvent.VK_F); - - toolkit.realSync(); + robot.waitForIdle(); + robot.delay(1000); if (!bMenuSelected) { throw new RuntimeException("shortcuts on menus do not work"); diff --git a/jdk/test/javax/swing/plaf/basic/BasicTreeUI/8023474/bug8023474.java b/jdk/test/javax/swing/plaf/basic/BasicTreeUI/8023474/bug8023474.java index 6802db66945..1095aced9f9 100644 --- a/jdk/test/javax/swing/plaf/basic/BasicTreeUI/8023474/bug8023474.java +++ b/jdk/test/javax/swing/plaf/basic/BasicTreeUI/8023474/bug8023474.java @@ -29,8 +29,6 @@ * @run main bug8023474 */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.event.CellEditorListener; import javax.swing.tree.DefaultMutableTreeNode; @@ -45,7 +43,6 @@ public class bug8023474 { private static JTree tree; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -55,14 +52,14 @@ public class bug8023474 { } }); - toolkit.realSync(); + robot.waitForIdle(); Point point = getRowPointToClick(1); robot.mouseMove(point.x, point.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); Boolean result = (Boolean)tree.getCellEditor().getCellEditorValue(); if (!result) { diff --git a/jdk/test/javax/swing/plaf/synth/7158712/bug7158712.java b/jdk/test/javax/swing/plaf/synth/7158712/bug7158712.java index a0311bced03..06653628905 100644 --- a/jdk/test/javax/swing/plaf/synth/7158712/bug7158712.java +++ b/jdk/test/javax/swing/plaf/synth/7158712/bug7158712.java @@ -28,8 +28,6 @@ @author Pavel Porvatov */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.plaf.basic.BasicComboPopup; import javax.swing.plaf.synth.SynthLookAndFeel; @@ -82,7 +80,7 @@ public class bug7158712 { } }); - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); Point comboBoxLocation = Util.invokeOnEDT(new Callable() { @Override diff --git a/jdk/test/javax/swing/plaf/synth/SynthButtonUI/6276188/bug6276188.java b/jdk/test/javax/swing/plaf/synth/SynthButtonUI/6276188/bug6276188.java index 7d6d8ea616f..1031e5ef4fa 100644 --- a/jdk/test/javax/swing/plaf/synth/SynthButtonUI/6276188/bug6276188.java +++ b/jdk/test/javax/swing/plaf/synth/SynthButtonUI/6276188/bug6276188.java @@ -35,13 +35,11 @@ import java.awt.event.*; import javax.swing.*; import javax.swing.plaf.synth.*; -import sun.awt.SunToolkit; public class bug6276188 extends JFrame { private static JButton button; private static Point p; - private static final SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); public static void main(String[] args) throws Throwable { SynthLookAndFeel lookAndFeel = new SynthLookAndFeel(); @@ -67,7 +65,7 @@ public class bug6276188 extends JFrame { robot.mouseMove(p.x , p.y); robot.mousePress(InputEvent.BUTTON1_MASK); - toolkit.realSync(); + robot.waitForIdle(); robot.delay(1000); Color color = robot.getPixelColor(p.x, p.y); diff --git a/jdk/test/javax/swing/plaf/windows/WindowsRootPaneUI/WrongAltProcessing/WrongAltProcessing.java b/jdk/test/javax/swing/plaf/windows/WindowsRootPaneUI/WrongAltProcessing/WrongAltProcessing.java index ba810238284..a13a1bea798 100644 --- a/jdk/test/javax/swing/plaf/windows/WindowsRootPaneUI/WrongAltProcessing/WrongAltProcessing.java +++ b/jdk/test/javax/swing/plaf/windows/WindowsRootPaneUI/WrongAltProcessing/WrongAltProcessing.java @@ -28,8 +28,6 @@ @run main WrongAltProcessing */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; import java.awt.event.*; @@ -56,7 +54,7 @@ public class WrongAltProcessing { createWindows(); } }); - sync(); + robot.waitForIdle(); initRobot(); runScript(); SwingUtilities.invokeLater(new Runnable() { @@ -75,11 +73,6 @@ public class WrongAltProcessing { } } - public static void sync() { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - toolkit.realSync(); - } - public static void initRobot() throws AWTException { robot = new Robot(); robot.setAutoDelay(100); @@ -101,7 +94,7 @@ public class WrongAltProcessing { robot.keyPress(KeyEvent.VK_ALT); robot.keyRelease(KeyEvent.VK_ALT); clickWindowsTitle(firstFrame); - sync(); + robot.waitForIdle(); } private static void pressTab() { diff --git a/jdk/test/javax/swing/text/AbstractDocument/6968363/Test6968363.java b/jdk/test/javax/swing/text/AbstractDocument/6968363/Test6968363.java index 624a2522356..333bfeddb94 100644 --- a/jdk/test/javax/swing/text/AbstractDocument/6968363/Test6968363.java +++ b/jdk/test/javax/swing/text/AbstractDocument/6968363/Test6968363.java @@ -20,8 +20,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -import sun.awt.SunToolkit; - import java.awt.Robot; import javax.swing.JFrame; import javax.swing.JLabel; @@ -47,17 +45,22 @@ import static javax.swing.SwingUtilities.invokeAndWait; * @bug 6968363 * @summary Ensures that a custom document may not extend AbstractDocument * @author Sergey Malenkov + * @library ../../../../../lib/testlibrary/ + * @build ExtendedRobot + * @run main Test6968363 */ public class Test6968363 implements Runnable, Thread.UncaughtExceptionHandler { private JFrame frame; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) getDefaultToolkit(); Runnable task = new Test6968363(); invokeAndWait(task); - toolkit.realSync(100); - new Robot().keyPress(VK_LEFT); - toolkit.realSync(100); + ExtendedRobot robot = new ExtendedRobot(); + robot.waitForIdle(100); + robot.keyPress(VK_LEFT); + robot.waitForIdle(100); + robot.keyRelease(VK_LEFT); + robot.waitForIdle(100); invokeAndWait(task); } diff --git a/jdk/test/javax/swing/text/CSSBorder/6796710/bug6796710.java b/jdk/test/javax/swing/text/CSSBorder/6796710/bug6796710.java index dd8508b3997..46cfd90980f 100644 --- a/jdk/test/javax/swing/text/CSSBorder/6796710/bug6796710.java +++ b/jdk/test/javax/swing/text/CSSBorder/6796710/bug6796710.java @@ -34,7 +34,6 @@ import java.awt.*; import java.awt.image.BufferedImage; import javax.swing.*; -import sun.awt.SunToolkit; public class bug6796710 { // The page is inlined because we want to be sure that the JEditorPane filled synchronously @@ -95,7 +94,7 @@ public class bug6796710 { } }); - ((SunToolkit) SunToolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); // This delay should be added for MacOSX, realSync is not enough Thread.sleep(1000); @@ -109,7 +108,7 @@ public class bug6796710 { } }); - ((SunToolkit) SunToolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); // On Linux platforms realSync doesn't guaranties setSize completion Thread.sleep(1000); diff --git a/jdk/test/javax/swing/text/DefaultEditorKit/4278839/bug4278839.java b/jdk/test/javax/swing/text/DefaultEditorKit/4278839/bug4278839.java index 9dbae2be9c8..07b79d641b9 100644 --- a/jdk/test/javax/swing/text/DefaultEditorKit/4278839/bug4278839.java +++ b/jdk/test/javax/swing/text/DefaultEditorKit/4278839/bug4278839.java @@ -33,19 +33,16 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; -import sun.awt.SunToolkit; public class bug4278839 extends JFrame { private static boolean passed = true; private static JTextArea area; private static Robot robo; - private static SunToolkit toolkit; public static void main(String[] args) { try { - toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); robo = new Robot(); robo.setAutoDelay(100); @@ -56,10 +53,10 @@ public class bug4278839 extends JFrame { } }); - toolkit.realSync(); + robo.waitForIdle(); clickMouse(); - toolkit.realSync(); + robo.waitForIdle(); if ("Aqua".equals(UIManager.getLookAndFeel().getID())) { @@ -67,7 +64,7 @@ public class bug4278839 extends JFrame { } else { Util.hitKeys(robo, KeyEvent.VK_CONTROL, KeyEvent.VK_HOME); } - toolkit.realSync(); + robo.waitForIdle(); passed &= moveCaret(true) == 1; passed &= moveCaret(true) == 5; @@ -97,7 +94,7 @@ public class bug4278839 extends JFrame { private static int moveCaret(boolean right) throws Exception { Util.hitKeys(robo, getCtrlKey(), right ? KeyEvent.VK_RIGHT : KeyEvent.VK_LEFT); - toolkit.realSync(); + robo.waitForIdle(); final int[] result = new int[1]; @@ -127,6 +124,7 @@ public class bug4278839 extends JFrame { robo.mouseMove(rect.x + rect.width / 2, rect.y + rect.width / 2); robo.mousePress(InputEvent.BUTTON1_MASK); + robo.mouseRelease(InputEvent.BUTTON1_MASK); } /** diff --git a/jdk/test/javax/swing/text/JTextComponent/5074573/bug5074573.java b/jdk/test/javax/swing/text/JTextComponent/5074573/bug5074573.java index 579d471c5fa..a2067bbacf9 100644 --- a/jdk/test/javax/swing/text/JTextComponent/5074573/bug5074573.java +++ b/jdk/test/javax/swing/text/JTextComponent/5074573/bug5074573.java @@ -35,7 +35,6 @@ import java.awt.Toolkit; import java.awt.event.*; import javax.swing.*; import javax.swing.text.*; -import sun.awt.SunToolkit; public class bug5074573 { @@ -60,11 +59,11 @@ public class bug5074573 { } static boolean test(final Class textComponentClass) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); Robot robot = new Robot(); robot.setAutoWaitForIdle(true); robot.setAutoDelay(50); + SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -73,7 +72,7 @@ public class bug5074573 { } }); - toolkit.realSync(); + robot.waitForIdle(); // Remove selection from JTextField components for the Aqua Look & Feel if (textComponent instanceof JTextField && "Aqua".equals(UIManager.getLookAndFeel().getID())) { @@ -87,14 +86,14 @@ public class bug5074573 { } }); - toolkit.realSync(); + robot.waitForIdle(); } robot.keyPress(getCtrlKey()); robot.keyPress(KeyEvent.VK_BACK_SPACE); robot.keyRelease(KeyEvent.VK_BACK_SPACE); robot.keyRelease(getCtrlKey()); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @@ -104,13 +103,13 @@ public class bug5074573 { caret.setDot(0); } }); - toolkit.realSync(); + robot.waitForIdle(); robot.keyPress(getCtrlKey()); robot.keyPress(KeyEvent.VK_DELETE); robot.keyRelease(KeyEvent.VK_DELETE); robot.keyRelease(getCtrlKey()); - toolkit.realSync(); + robot.waitForIdle(); return resultString.equals(getText()); } diff --git a/jdk/test/javax/swing/text/StyledEditorKit/4506788/bug4506788.java b/jdk/test/javax/swing/text/StyledEditorKit/4506788/bug4506788.java index b5e0f9eb973..8e9186db46b 100644 --- a/jdk/test/javax/swing/text/StyledEditorKit/4506788/bug4506788.java +++ b/jdk/test/javax/swing/text/StyledEditorKit/4506788/bug4506788.java @@ -33,13 +33,11 @@ import java.lang.reflect.InvocationTargetException; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; -import sun.awt.SunToolkit; public class bug4506788 extends JApplet { private volatile boolean passed = false; private JEditorPane jep; - private SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); @Override public void init() { @@ -65,7 +63,7 @@ public class bug4506788 extends JApplet { throw new RuntimeException("Robot could not be created"); } - toolkit.realSync(); + robot.waitForIdle(); Point p; try { @@ -78,6 +76,8 @@ public class bug4506788 extends JApplet { robot.mouseMove(p.x, p.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.keyPress(KeyEvent.VK_HOME); + robot.keyRelease(KeyEvent.VK_HOME); robot.keyPress(KeyEvent.VK_RIGHT); robot.keyRelease(KeyEvent.VK_RIGHT); robot.keyPress(KeyEvent.VK_X); @@ -85,7 +85,7 @@ public class bug4506788 extends JApplet { robot.keyPress(KeyEvent.VK_RIGHT); robot.keyRelease(KeyEvent.VK_RIGHT); - toolkit.realSync(); + robot.waitForIdle(); if (!passed) { throw new RuntimeException("Test failed."); diff --git a/jdk/test/javax/swing/text/View/8014863/bug8014863.java b/jdk/test/javax/swing/text/View/8014863/bug8014863.java index 8618ec4eba7..892d5aaec5d 100644 --- a/jdk/test/javax/swing/text/View/8014863/bug8014863.java +++ b/jdk/test/javax/swing/text/View/8014863/bug8014863.java @@ -32,8 +32,6 @@ * @run main bug8014863 */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.text.GlyphView; import javax.swing.text.View; @@ -49,7 +47,6 @@ public class bug8014863 { private static JEditorPane editorPane; private static JFrame frame; private static Robot robot; - private static SunToolkit toolkit; private static String text1 = "

one two qqqq this is a test sentence qqqq pp qqqq pp " + "qqqq pp qqqq pp qqqq pp qqqq pp qqqq pp qqqq pp qqqq

"; @@ -59,14 +56,13 @@ public class bug8014863 { private static ArrayList glyphViews; public static void main(String[] args) throws Exception { - toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); robot = new Robot(); robot.setAutoDelay(50); glyphViews = new ArrayList(); createAndShowGUI(text1); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -80,10 +76,10 @@ public class bug8014863 { createAndShowGUI(text2); - toolkit.realSync(); + robot.waitForIdle(); Util.hitKeys(robot, KeyEvent.VK_HOME); - toolkit.realSync(); + robot.waitForIdle(); Util.hitKeys(robot, KeyEvent.VK_O); Util.hitKeys(robot, KeyEvent.VK_N); @@ -94,7 +90,7 @@ public class bug8014863 { Util.hitKeys(robot, KeyEvent.VK_O); Util.hitKeys(robot, KeyEvent.VK_SPACE); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { diff --git a/jdk/test/javax/swing/text/html/CSS/4530474/bug4530474.java b/jdk/test/javax/swing/text/html/CSS/4530474/bug4530474.java index 8242c14f64a..4f23b2848f2 100644 --- a/jdk/test/javax/swing/text/html/CSS/4530474/bug4530474.java +++ b/jdk/test/javax/swing/text/html/CSS/4530474/bug4530474.java @@ -34,8 +34,6 @@ import javax.swing.*; import java.io.*; -import sun.awt.SunToolkit; - public class bug4530474 { private static final Color TEST_COLOR = Color.BLUE; @@ -43,7 +41,6 @@ public class bug4530474 { public static void main(String args[]) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); final Robot robot = new Robot(); robot.setAutoDelay(50); @@ -55,7 +52,8 @@ public class bug4530474 { } }); - toolkit.realSync(); + robot.waitForIdle(); + robot.delay(500); SwingUtilities.invokeAndWait(new Runnable() { diff --git a/jdk/test/javax/swing/text/html/HTMLEditorKit/5043626/bug5043626.java b/jdk/test/javax/swing/text/html/HTMLEditorKit/5043626/bug5043626.java index 7de86792082..de4019cdf32 100644 --- a/jdk/test/javax/swing/text/html/HTMLEditorKit/5043626/bug5043626.java +++ b/jdk/test/javax/swing/text/html/HTMLEditorKit/5043626/bug5043626.java @@ -37,7 +37,6 @@ import javax.swing.*; import javax.swing.text.Document; import javax.swing.text.BadLocationException; import java.awt.event.KeyEvent; -import sun.awt.SunToolkit; public class bug5043626 { @@ -45,7 +44,6 @@ public class bug5043626 { private static Robot robot; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); robot = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { @@ -54,12 +52,12 @@ public class bug5043626 { } }); - toolkit.realSync(); + robot.waitForIdle(); Util.hitKeys(robot, KeyEvent.VK_HOME); Util.hitKeys(robot, KeyEvent.VK_1); - toolkit.realSync(); + robot.waitForIdle(); String test = getText(); @@ -70,7 +68,7 @@ public class bug5043626 { Util.hitKeys(robot, KeyEvent.VK_HOME); Util.hitKeys(robot, KeyEvent.VK_2); - toolkit.realSync(); + robot.waitForIdle(); test = getText();