diff --git a/jdk/test/com/sun/awt/Translucency/WindowOpacity.java b/jdk/test/com/sun/awt/Translucency/WindowOpacity.java index 26c611c35d5..a8391503238 100644 --- a/jdk/test/com/sun/awt/Translucency/WindowOpacity.java +++ b/jdk/test/com/sun/awt/Translucency/WindowOpacity.java @@ -33,15 +33,12 @@ import java.awt.*; import java.awt.event.*; import com.sun.awt.AWTUtilities; -import sun.awt.SunToolkit; public class WindowOpacity { //*** test-writer defined static variables go here *** - private static void realSync() { - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); - } + private static Robot robot; private static void init() @@ -60,6 +57,12 @@ public class WindowOpacity System.out.println("Either the Toolkit or the native system does not support controlling the window opacity level."); pass(); } + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException ("Unexpected failure"); + } boolean passed; @@ -137,7 +140,7 @@ public class WindowOpacity f.setBounds(100, 100, 300, 200); f.setVisible(true); - realSync(); + robot.waitForIdle(); curOpacity = AWTUtilities.getWindowOpacity(f); if (curOpacity < 0.75f || curOpacity > 0.75f) { @@ -147,7 +150,7 @@ public class WindowOpacity AWTUtilities.setWindowOpacity(f, 0.5f); - realSync(); + robot.waitForIdle(); curOpacity = AWTUtilities.getWindowOpacity(f); if (curOpacity < 0.5f || curOpacity > 0.5f) { diff --git a/jdk/test/java/awt/Component/NoUpdateUponShow/NoUpdateUponShow.java b/jdk/test/java/awt/Component/NoUpdateUponShow/NoUpdateUponShow.java index 80360dfdbe5..d032f0d784b 100644 --- a/jdk/test/java/awt/Component/NoUpdateUponShow/NoUpdateUponShow.java +++ b/jdk/test/java/awt/Component/NoUpdateUponShow/NoUpdateUponShow.java @@ -36,7 +36,6 @@ */ import java.awt.*; -import sun.awt.SunToolkit; public class NoUpdateUponShow { @@ -70,7 +69,13 @@ public class NoUpdateUponShow }); f.setVisible(true); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + try { + Robot robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } if (wasUpdate) { fail(" Unexpected update. "); diff --git a/jdk/test/java/awt/Component/PaintAll/PaintAll.java b/jdk/test/java/awt/Component/PaintAll/PaintAll.java index e734cad1fdf..483f1a5bd5a 100644 --- a/jdk/test/java/awt/Component/PaintAll/PaintAll.java +++ b/jdk/test/java/awt/Component/PaintAll/PaintAll.java @@ -21,8 +21,6 @@ * questions. */ -import sun.awt.SunToolkit; - import java.awt.Button; import java.awt.Canvas; import java.awt.Checkbox; @@ -48,6 +46,8 @@ import java.awt.image.BufferedImage; @bug 6596915 @summary Test Component.paintAll() method @author sergey.bylokhov@oracle.com: area=awt.component + @library ../../../../lib/testlibrary/ + @build ExtendedRobot @run main PaintAll */ public class PaintAll { @@ -66,6 +66,7 @@ public class PaintAll { private static volatile boolean scrollPanePainted; private static volatile boolean textAreaPainted; private static volatile boolean textFieldPainted; + private static ExtendedRobot robot = null; private static final Button buttonStub = new Button() { @Override @@ -283,11 +284,15 @@ public class PaintAll { } private static void sleep() { - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); - try { - Thread.sleep(500L); - } catch (InterruptedException ignored) { + if(robot == null) { + try { + robot = new ExtendedRobot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } } + robot.waitForIdle(500); } private static void fail(final String message) { diff --git a/jdk/test/java/awt/Focus/ModalBlockedStealsFocusTest/ModalBlockedStealsFocusTest.java b/jdk/test/java/awt/Focus/ModalBlockedStealsFocusTest/ModalBlockedStealsFocusTest.java index 7c8e6574c92..f718ecbcfc1 100644 --- a/jdk/test/java/awt/Focus/ModalBlockedStealsFocusTest/ModalBlockedStealsFocusTest.java +++ b/jdk/test/java/awt/Focus/ModalBlockedStealsFocusTest/ModalBlockedStealsFocusTest.java @@ -34,11 +34,9 @@ import java.awt.event.*; import java.applet.Applet; import java.util.concurrent.atomic.AtomicBoolean; import java.lang.reflect.InvocationTargetException; -import sun.awt.SunToolkit; import test.java.awt.regtesthelpers.Util; public class ModalBlockedStealsFocusTest extends Applet { - SunToolkit toolkit = (SunToolkit)Toolkit.getDefaultToolkit(); Frame frame = new Frame("Blocked Frame"); Dialog dialog = new Dialog(frame, "Modal Dialog", Dialog.ModalityType.TOOLKIT_MODAL); AtomicBoolean lostFocus = new AtomicBoolean(false); @@ -85,7 +83,13 @@ public class ModalBlockedStealsFocusTest extends Applet { }).start(); Util.waitTillShown(dialog); - toolkit.realSync(); + try { + Robot robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } // Test 1. Show a modal blocked frame, check that it doesn't steal focus. diff --git a/jdk/test/java/awt/Focus/WindowInitialFocusTest/WindowInitialFocusTest.java b/jdk/test/java/awt/Focus/WindowInitialFocusTest/WindowInitialFocusTest.java index ee047a3b493..38c924b3a6c 100644 --- a/jdk/test/java/awt/Focus/WindowInitialFocusTest/WindowInitialFocusTest.java +++ b/jdk/test/java/awt/Focus/WindowInitialFocusTest/WindowInitialFocusTest.java @@ -33,7 +33,6 @@ import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.util.concurrent.atomic.AtomicBoolean; -import sun.awt.SunToolkit; import test.java.awt.regtesthelpers.Util; public class WindowInitialFocusTest extends Applet { @@ -41,7 +40,7 @@ public class WindowInitialFocusTest extends Applet { Window window = new Window(frame); Button button = new Button("button"); AtomicBoolean focused = new AtomicBoolean(false); - SunToolkit toolkit = (SunToolkit)Toolkit.getDefaultToolkit(); + Robot robot; public static void main(String[] args) { WindowInitialFocusTest app = new WindowInitialFocusTest(); @@ -75,12 +74,18 @@ public class WindowInitialFocusTest extends Applet { }}); frame.setVisible(true); - toolkit.realSync(); + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } + robot.waitForIdle(); // Test 1. Show the window, check that it become focused. window.setVisible(true); - toolkit.realSync(); + robot.waitForIdle(); if (!Util.waitForCondition(focused, 2000L)) { throw new TestFailedException("the window didn't get focused on its showing!"); @@ -89,13 +94,13 @@ public class WindowInitialFocusTest extends Applet { // Test 2. Show unfocusable window, check that it doesn't become focused. window.setVisible(false); - toolkit.realSync(); + robot.waitForIdle(); window.setFocusableWindowState(false); focused.set(false); window.setVisible(true); - toolkit.realSync(); + robot.waitForIdle(); if (Util.waitForCondition(focused, 2000L)) { throw new TestFailedException("the unfocusable window got focused on its showing!"); diff --git a/jdk/test/java/awt/Frame/ExceptionOnSetExtendedStateTest/ExceptionOnSetExtendedStateTest.java b/jdk/test/java/awt/Frame/ExceptionOnSetExtendedStateTest/ExceptionOnSetExtendedStateTest.java index b0f3c63b048..845138ab3bb 100644 --- a/jdk/test/java/awt/Frame/ExceptionOnSetExtendedStateTest/ExceptionOnSetExtendedStateTest.java +++ b/jdk/test/java/awt/Frame/ExceptionOnSetExtendedStateTest/ExceptionOnSetExtendedStateTest.java @@ -30,11 +30,8 @@ import java.awt.*; -import sun.awt.SunToolkit; - public class ExceptionOnSetExtendedStateTest { private static final int[] frameStates = { Frame.NORMAL, Frame.ICONIFIED, Frame.MAXIMIZED_BOTH }; - private static final SunToolkit toolkit = (SunToolkit)Toolkit.getDefaultToolkit(); private static boolean validatePlatform() { String osName = System.getProperty("os.name"); @@ -53,7 +50,13 @@ public class ExceptionOnSetExtendedStateTest { frame.setSize(200, 200); frame.setUndecorated(!decoratedFrame); frame.setVisible(true); - toolkit.realSync(); + try { + Robot robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } frame.setExtendedState(oldState); sleep(1000); diff --git a/jdk/test/java/awt/Frame/FrameSize/TestFrameSize.java b/jdk/test/java/awt/Frame/FrameSize/TestFrameSize.java index b2a978300a9..b42a70fbd11 100644 --- a/jdk/test/java/awt/Frame/FrameSize/TestFrameSize.java +++ b/jdk/test/java/awt/Frame/FrameSize/TestFrameSize.java @@ -77,7 +77,13 @@ public class TestFrameSize { mainWindow.setVisible(true); - ((sun.awt.SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + try { + Robot robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure."); + } Dimension clientSize2 = getClientSize(mainWindow); System.out.println("Client size after showing: " + clientSize2); diff --git a/jdk/test/java/awt/Frame/MaximizedByPlatform/MaximizedByPlatform.java b/jdk/test/java/awt/Frame/MaximizedByPlatform/MaximizedByPlatform.java index 070aa4deba6..224c10e7996 100644 --- a/jdk/test/java/awt/Frame/MaximizedByPlatform/MaximizedByPlatform.java +++ b/jdk/test/java/awt/Frame/MaximizedByPlatform/MaximizedByPlatform.java @@ -25,11 +25,12 @@ * @bug 8026143 * @summary [macosx] Maximized state could be inconsistent between peer and frame * @author Petr Pchelko + * @library ../../../../lib/testlibrary + * @build jdk.testlibrary.OSInfo * @run main MaximizedByPlatform */ -import sun.awt.OSInfo; -import sun.awt.SunToolkit; +import jdk.testlibrary.OSInfo; import java.awt.*; @@ -43,6 +44,13 @@ public class MaximizedByPlatform { return; } + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } availableScreenBounds = getAvailableScreenBounds(); // Test 1. The maximized state is set in setBounds @@ -51,12 +59,12 @@ public class MaximizedByPlatform { frame.setBounds(100, 100, 100, 100); frame.setVisible(true); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); frame.setBounds(availableScreenBounds.x, availableScreenBounds.y, availableScreenBounds.width, availableScreenBounds.height); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) { throw new RuntimeException("Maximized state was not set for frame in setBounds"); @@ -73,7 +81,7 @@ public class MaximizedByPlatform { availableScreenBounds.width + 100, availableScreenBounds.height); frame.setVisible(true); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) { throw new RuntimeException("Maximized state was not set for frame in setVisible"); diff --git a/jdk/test/java/awt/Frame/MaximizedToMaximized/MaximizedToMaximized.java b/jdk/test/java/awt/Frame/MaximizedToMaximized/MaximizedToMaximized.java index 83fcfa1701d..e0da056b035 100644 --- a/jdk/test/java/awt/Frame/MaximizedToMaximized/MaximizedToMaximized.java +++ b/jdk/test/java/awt/Frame/MaximizedToMaximized/MaximizedToMaximized.java @@ -28,7 +28,7 @@ import java.awt.GraphicsEnvironment; import java.awt.Insets; import java.awt.Rectangle; import java.awt.Toolkit; -import sun.awt.SunToolkit; +import java.awt.Robot; /** * @test @@ -65,7 +65,8 @@ public class MaximizedToMaximized { Rectangle frameBounds = frame.getBounds(); frame.setExtendedState(Frame.MAXIMIZED_BOTH); - ((SunToolkit) toolkit).realSync(); + Robot robot = new Robot(); + robot.waitForIdle(); Rectangle maximizedFrameBounds = frame.getBounds(); if (maximizedFrameBounds.width < frameBounds.width diff --git a/jdk/test/java/awt/Frame/SlideNotResizableTest/SlideNotResizableTest.java b/jdk/test/java/awt/Frame/SlideNotResizableTest/SlideNotResizableTest.java index 37df055ca22..b5938187185 100644 --- a/jdk/test/java/awt/Frame/SlideNotResizableTest/SlideNotResizableTest.java +++ b/jdk/test/java/awt/Frame/SlideNotResizableTest/SlideNotResizableTest.java @@ -21,8 +21,6 @@ * questions. */ -import sun.awt.SunToolkit; - import java.awt.*; import java.awt.Dimension; import java.awt.Point; @@ -62,8 +60,9 @@ public class SlideNotResizableTest { } } - private static void sync() throws InterruptedException { - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + private static void sync() throws Exception { + Robot robot = new Robot(); + robot.waitForIdle(); Thread.sleep(1000); } } diff --git a/jdk/test/java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java b/jdk/test/java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java index 1210b0dc551..35ab7dc906f 100644 --- a/jdk/test/java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java +++ b/jdk/test/java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java @@ -34,10 +34,17 @@ import java.awt.geom.*; import static java.awt.GraphicsDevice.WindowTranslucency.*; -import sun.awt.SunToolkit; public class TranslucentWindow { public static void main(String args[]) { + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); @@ -47,10 +54,10 @@ public class TranslucentWindow { // First, check it can be made fullscreen window without any effects applied gd.setFullScreenWindow(f); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); gd.setFullScreenWindow(null); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); // Second, check if it applying any effects doesn't prevent the window // from going into the fullscreen mode @@ -64,7 +71,7 @@ public class TranslucentWindow { f.setBackground(new Color(0, 0, 0, 128)); } gd.setFullScreenWindow(f); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); // Third, make sure all the effects are unset when entering the fullscreen mode if (f.getShape() != null) { diff --git a/jdk/test/java/awt/GraphicsDevice/IncorrectDisplayModeExitFullscreen.java b/jdk/test/java/awt/GraphicsDevice/IncorrectDisplayModeExitFullscreen.java index 1d42db8f47d..ad808c3ab63 100644 --- a/jdk/test/java/awt/GraphicsDevice/IncorrectDisplayModeExitFullscreen.java +++ b/jdk/test/java/awt/GraphicsDevice/IncorrectDisplayModeExitFullscreen.java @@ -27,16 +27,17 @@ import java.awt.DisplayMode; import java.awt.Frame; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; -import java.awt.Toolkit; - -import sun.awt.SunToolkit; /** * @test * @bug 8019587 * @author Sergey Bylokhov + * @library ../../../lib/testlibrary/ + * @build ExtendedRobot + * @run main IncorrectDisplayModeExitFullscreen */ public class IncorrectDisplayModeExitFullscreen { + static ExtendedRobot robot; public static void main(final String[] args) { @@ -64,6 +65,13 @@ public class IncorrectDisplayModeExitFullscreen { return; } + try { + robot = new ExtendedRobot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } + final Frame frame = new Frame(); frame.setBackground(Color.GREEN); frame.setUndecorated(true); @@ -85,10 +93,6 @@ public class IncorrectDisplayModeExitFullscreen { } } private static void sleep() { - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); - try { - Thread.sleep(1500); - } catch (InterruptedException ignored) { - } + robot.waitForIdle(1500); } } diff --git a/jdk/test/java/awt/GridBagLayout/GridBagLayoutIpadXYTest/GridBagLayoutIpadXYTest.java b/jdk/test/java/awt/GridBagLayout/GridBagLayoutIpadXYTest/GridBagLayoutIpadXYTest.java index f547ead583e..637bed4f3d5 100644 --- a/jdk/test/java/awt/GridBagLayout/GridBagLayoutIpadXYTest/GridBagLayoutIpadXYTest.java +++ b/jdk/test/java/awt/GridBagLayout/GridBagLayoutIpadXYTest/GridBagLayoutIpadXYTest.java @@ -71,7 +71,14 @@ public class GridBagLayoutIpadXYTest extends Applet frame.pack(); frame.setVisible(true); - ((sun.awt.SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + Robot robot; + try { + robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } Dimension minSize = jtf.getMinimumSize(); if ( minSize.width + customIpadx != jtf.getSize().width || diff --git a/jdk/test/java/awt/List/ListPeer/R2303044ListSelection.java b/jdk/test/java/awt/List/ListPeer/R2303044ListSelection.java index d7ef3902a03..d170fe081b9 100644 --- a/jdk/test/java/awt/List/ListPeer/R2303044ListSelection.java +++ b/jdk/test/java/awt/List/ListPeer/R2303044ListSelection.java @@ -21,12 +21,10 @@ * questions. */ -import sun.awt.SunToolkit; - import java.awt.Frame; import java.awt.HeadlessException; import java.awt.List; -import java.awt.Toolkit; +import java.awt.Robot; /** * @test @@ -57,9 +55,11 @@ public final class R2303044ListSelection { private static void sleep() { try { - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + Robot robot = new Robot(); + robot.waitForIdle(); Thread.sleep(1000); - } catch (final InterruptedException ignored) { + } catch (final Exception ignored) { + ignored.printStackTrace(); } } } diff --git a/jdk/test/java/awt/List/SingleModeDeselect/SingleModeDeselect.java b/jdk/test/java/awt/List/SingleModeDeselect/SingleModeDeselect.java index 726835f5f73..c4452cd1015 100644 --- a/jdk/test/java/awt/List/SingleModeDeselect/SingleModeDeselect.java +++ b/jdk/test/java/awt/List/SingleModeDeselect/SingleModeDeselect.java @@ -30,7 +30,6 @@ */ import java.awt.*; -import sun.awt.SunToolkit; public class SingleModeDeselect { @@ -50,7 +49,13 @@ public class SingleModeDeselect list.select(0); list.deselect(1); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + try { + Robot robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } if (list.getSelectedIndex() != 0){ throw new RuntimeException("Test failed: List.getSelectedIndex() returns "+list.getSelectedIndex()); diff --git a/jdk/test/java/awt/Paint/ExposeOnEDT.java b/jdk/test/java/awt/Paint/ExposeOnEDT.java index cf8a3a547e0..21f7dc00c29 100644 --- a/jdk/test/java/awt/Paint/ExposeOnEDT.java +++ b/jdk/test/java/awt/Paint/ExposeOnEDT.java @@ -22,18 +22,19 @@ */ -import sun.awt.SunToolkit; - import java.awt.*; /** * @test * @bug 7090424 * @author Sergey Bylokhov + * @library ../../../lib/testlibrary/ + * @build ExtendedRobot * @run main ExposeOnEDT */ public final class ExposeOnEDT { + private static ExtendedRobot robot = null; private static final Button buttonStub = new Button() { @Override public void paint(final Graphics g) { @@ -275,11 +276,15 @@ public final class ExposeOnEDT { } private static void sleep() { - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); - try { - Thread.sleep(1000L); - } catch (InterruptedException ignored) { + if(robot == null) { + try { + robot = new ExtendedRobot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } } + robot.waitForIdle(1000); } private static void fail(final String message) { diff --git a/jdk/test/java/awt/ScrollPane/ScrollPanePreferredSize/ScrollPanePreferredSize.java b/jdk/test/java/awt/ScrollPane/ScrollPanePreferredSize/ScrollPanePreferredSize.java index 0c799f14a1d..02a84e859fa 100644 --- a/jdk/test/java/awt/ScrollPane/ScrollPanePreferredSize/ScrollPanePreferredSize.java +++ b/jdk/test/java/awt/ScrollPane/ScrollPanePreferredSize/ScrollPanePreferredSize.java @@ -26,12 +26,13 @@ import java.awt.Frame; import java.awt.ScrollPane; import java.awt.Toolkit; -import sun.awt.SunToolkit; - /** * @test * @bug 7124213 * @author Sergey Bylokhov + * @library ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @run main ScrollPanePreferredSize */ public final class ScrollPanePreferredSize { @@ -54,10 +55,12 @@ public final class ScrollPanePreferredSize { } private static void sleep() { - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); try { - Thread.sleep(500L); - } catch (InterruptedException ignored) { + ExtendedRobot robot = new ExtendedRobot(); + robot.waitForIdle(500); + } catch (Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); } } } diff --git a/jdk/test/java/awt/TextArea/DisposeTest/TestDispose.java b/jdk/test/java/awt/TextArea/DisposeTest/TestDispose.java index 91c795fbfee..47c534be94f 100644 --- a/jdk/test/java/awt/TextArea/DisposeTest/TestDispose.java +++ b/jdk/test/java/awt/TextArea/DisposeTest/TestDispose.java @@ -35,14 +35,12 @@ import java.awt.FlowLayout; import java.awt.Frame; import java.awt.TextArea; -import java.awt.Toolkit; +import java.awt.Robot; import java.lang.reflect.InvocationTargetException; import javax.swing.JFrame; import javax.swing.SwingUtilities; -import sun.awt.SunToolkit; - public class TestDispose { public static Frame frame = null; @@ -51,7 +49,14 @@ public class TestDispose { public void testDispose() throws InvocationTargetException, InterruptedException { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } + SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -69,7 +74,7 @@ public class TestDispose { frame.setVisible(true); } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -77,7 +82,7 @@ public class TestDispose { frame.dispose(); } }); - toolkit.realSync(); + robot.waitForIdle(); } public static void main(String[] args) throws Exception{ diff --git a/jdk/test/java/awt/TextArea/TextAreaCaretVisibilityTest/bug7129742.java b/jdk/test/java/awt/TextArea/TextAreaCaretVisibilityTest/bug7129742.java index d3de4954591..94f1d911f89 100644 --- a/jdk/test/java/awt/TextArea/TextAreaCaretVisibilityTest/bug7129742.java +++ b/jdk/test/java/awt/TextArea/TextAreaCaretVisibilityTest/bug7129742.java @@ -34,7 +34,7 @@ import java.awt.FlowLayout; import java.awt.TextArea; -import java.awt.Toolkit; +import java.awt.Robot; import java.lang.reflect.Field; import javax.swing.JFrame; @@ -42,7 +42,6 @@ import javax.swing.JTextArea; import javax.swing.SwingUtilities; import javax.swing.text.DefaultCaret; -import sun.awt.SunToolkit; public class bug7129742 { @@ -51,7 +50,7 @@ public class bug7129742 { public static boolean fastreturn = false; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -88,7 +87,7 @@ public class bug7129742 { } } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override diff --git a/jdk/test/java/awt/TextArea/TextAreaTwicePack/TextAreaTwicePack.java b/jdk/test/java/awt/TextArea/TextAreaTwicePack/TextAreaTwicePack.java index eba92a50063..e134c386c05 100644 --- a/jdk/test/java/awt/TextArea/TextAreaTwicePack/TextAreaTwicePack.java +++ b/jdk/test/java/awt/TextArea/TextAreaTwicePack/TextAreaTwicePack.java @@ -24,9 +24,8 @@ import java.awt.Dimension; import java.awt.Frame; import java.awt.TextArea; -import java.awt.Toolkit; +import java.awt.Robot; -import sun.awt.SunToolkit; /** * @test @@ -55,10 +54,12 @@ public final class TextAreaTwicePack { } private static void sleep() { - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); try { + Robot robot = new Robot(); + robot.waitForIdle(); Thread.sleep(500L); - } catch (InterruptedException ignored) { + } catch (Exception ignored) { + ignored.printStackTrace(); } } } diff --git a/jdk/test/java/awt/TextField/DisposeTest/TestDispose.java b/jdk/test/java/awt/TextField/DisposeTest/TestDispose.java index 6ef00cd215d..a4adbc2b229 100644 --- a/jdk/test/java/awt/TextField/DisposeTest/TestDispose.java +++ b/jdk/test/java/awt/TextField/DisposeTest/TestDispose.java @@ -35,14 +35,12 @@ import java.awt.FlowLayout; import java.awt.Frame; import java.awt.TextField; -import java.awt.Toolkit; +import java.awt.Robot; import java.lang.reflect.InvocationTargetException; import javax.swing.JFrame; import javax.swing.SwingUtilities; -import sun.awt.SunToolkit; - public class TestDispose { public static Frame frame = null; @@ -51,7 +49,13 @@ public class TestDispose { public void testDispose() throws InvocationTargetException, InterruptedException { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -69,7 +73,7 @@ public class TestDispose { frame.setVisible(true); } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -77,7 +81,7 @@ public class TestDispose { frame.dispose(); } }); - toolkit.realSync(); + robot.waitForIdle(); } diff --git a/jdk/test/java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java b/jdk/test/java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java index 4d5dd7295f6..5220546fd63 100644 --- a/jdk/test/java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java +++ b/jdk/test/java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java @@ -26,12 +26,13 @@ @bug 8007220 @summary Reference to the popup leaks after the TrayIcon is removed @author Petr Pchelko + @library ../../../../lib/testlibrary/ + @build ExtendedRobot @run main/othervm -Xmx50m PopupMenuLeakTest */ import java.awt.*; import javax.swing.SwingUtilities; -import sun.awt.SunToolkit; import java.awt.image.BufferedImage; import java.lang.ref.WeakReference; @@ -42,8 +43,10 @@ public class PopupMenuLeakTest { static final AtomicReference> iconWeakReference = new AtomicReference<>(); static final AtomicReference> popupWeakReference = new AtomicReference<>(); + static ExtendedRobot robot; public static void main(String[] args) throws Exception { + robot = new ExtendedRobot(); SwingUtilities.invokeAndWait(PopupMenuLeakTest::createSystemTrayIcon); sleep(); // To make the test automatic we explicitly call addNotify on a popup to create the peer @@ -141,9 +144,6 @@ public class PopupMenuLeakTest { } private static void sleep() { - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); - try { - Thread.sleep(100); - } catch (InterruptedException ignored) { } + robot.waitForIdle(100); } } diff --git a/jdk/test/java/awt/Window/8027025/Test8027025.java b/jdk/test/java/awt/Window/8027025/Test8027025.java index 44988904419..e798354264f 100644 --- a/jdk/test/java/awt/Window/8027025/Test8027025.java +++ b/jdk/test/java/awt/Window/8027025/Test8027025.java @@ -28,8 +28,6 @@ * @run main Test8027025 */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; import java.util.concurrent.atomic.AtomicReference; @@ -49,7 +47,8 @@ public class Test8027025 { window.setVisible(true); }); - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + Robot robot = new Robot(); + robot.waitForIdle(); AtomicReference point = new AtomicReference<>(); SwingUtilities.invokeAndWait(() -> point.set(window.getLocationOnScreen())); diff --git a/jdk/test/java/awt/Window/AlwaysOnTop/AlwaysOnTopFieldTest.java b/jdk/test/java/awt/Window/AlwaysOnTop/AlwaysOnTopFieldTest.java index 965eb7f5b07..5cfaa00419c 100644 --- a/jdk/test/java/awt/Window/AlwaysOnTop/AlwaysOnTopFieldTest.java +++ b/jdk/test/java/awt/Window/AlwaysOnTop/AlwaysOnTopFieldTest.java @@ -22,9 +22,8 @@ */ import java.awt.Dialog; import java.awt.Frame; -import java.awt.Toolkit; +import java.awt.Robot; import java.awt.Window; -import sun.awt.SunToolkit; /** * @test * @bug 7081594 @@ -35,19 +34,25 @@ import sun.awt.SunToolkit; public class AlwaysOnTopFieldTest { public static void main(String[] args) { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } Window window = new Frame("Window 1"); window.setSize(200, 200); window.setAlwaysOnTop(true); window.setVisible(true); - toolkit.realSync(); + robot.waitForIdle(); Dialog dialog = new Dialog(window, "Owned dialog 1"); dialog.setSize(200, 200); dialog.setLocation(100, 100); dialog.setVisible(true); - toolkit.realSync(); + robot.waitForIdle(); try { if (!window.isAlwaysOnTop()) { @@ -64,17 +69,17 @@ public class AlwaysOnTopFieldTest { window = new Frame("Window 2"); window.setSize(200, 200); window.setVisible(true); - toolkit.realSync(); + robot.waitForIdle(); dialog = new Dialog(window, "Owned dialog 2"); dialog.setSize(200, 200); dialog.setLocation(100, 100); dialog.setVisible(true); - toolkit.realSync(); + robot.waitForIdle(); window.setAlwaysOnTop(true); - toolkit.realSync(); + robot.waitForIdle(); try { if (!window.isAlwaysOnTop()) { diff --git a/jdk/test/java/awt/Window/OwnedWindowsSerialization/OwnedWindowsSerialization.java b/jdk/test/java/awt/Window/OwnedWindowsSerialization/OwnedWindowsSerialization.java index 864c5add1df..9100c500674 100644 --- a/jdk/test/java/awt/Window/OwnedWindowsSerialization/OwnedWindowsSerialization.java +++ b/jdk/test/java/awt/Window/OwnedWindowsSerialization/OwnedWindowsSerialization.java @@ -21,8 +21,6 @@ * questions. */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; import java.io.ByteArrayInputStream; @@ -54,7 +52,8 @@ public class OwnedWindowsSerialization { subDialog = new Dialog(dialog, SUBDIALOG_LABEL); }); - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + Robot robot = new Robot(); + robot.waitForIdle(); if (!topFrame.isAlwaysOnTop() || !dialog.isAlwaysOnTop() || !subDialog.isAlwaysOnTop()) { throw new RuntimeException("TEST FAILED: AlwaysOnTop was not set properly"); diff --git a/jdk/test/java/awt/event/TextEvent/TextEventSequenceTest/TextEventSequenceTest.java b/jdk/test/java/awt/event/TextEvent/TextEventSequenceTest/TextEventSequenceTest.java index 7836b086f4e..0c06ba162eb 100644 --- a/jdk/test/java/awt/event/TextEvent/TextEventSequenceTest/TextEventSequenceTest.java +++ b/jdk/test/java/awt/event/TextEvent/TextEventSequenceTest/TextEventSequenceTest.java @@ -30,7 +30,6 @@ */ import java.awt.*; import java.awt.event.*; -import sun.awt.SunToolkit; public class TextEventSequenceTest { @@ -48,43 +47,50 @@ public class TextEventSequenceTest { } private static void test(String test) { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } createAndShowGUI(test); - toolkit.realSync(); + robot.waitForIdle(); initCounts(); t.setText("Hello "); - toolkit.realSync(); + robot.waitForIdle(); t.append("World! !"); - toolkit.realSync(); + robot.waitForIdle(); t.insert("from Roger Pham", 13); - toolkit.realSync(); + robot.waitForIdle(); t.replaceRange("Java Duke", 18, 28); - toolkit.realSync(); + robot.waitForIdle(); checkCounts(0, 4); initCounts(); t.setText(""); - toolkit.realSync(); + robot.waitForIdle(); t.setText(""); - toolkit.realSync(); + robot.waitForIdle(); t.setText(""); - toolkit.realSync(); + robot.waitForIdle(); checkCounts(1, 0); initCounts(); tf.setText("Hello There!"); - toolkit.realSync(); + robot.waitForIdle(); checkCounts(0, 1); initCounts(); tf.setText(""); - toolkit.realSync(); + robot.waitForIdle(); tf.setText(""); - toolkit.realSync(); + robot.waitForIdle(); tf.setText(""); - toolkit.realSync(); + robot.waitForIdle(); checkCounts(1, 0); f.dispose(); diff --git a/jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeCrashTest.java b/jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeCrashTest.java index 298059054d9..25e03d61646 100644 --- a/jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeCrashTest.java +++ b/jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeCrashTest.java @@ -26,26 +26,25 @@ @bug 8041490 @summary tests that the WarningWindow's surface is invalidated on dispose @author Petr Pchelko - @run main/othervm WarningWindowDisposeCrashTest + @run main/othervm/policy=policy -Djava.security.manager WarningWindowDisposeCrashTest */ -import sun.applet.AppletSecurity; -import sun.awt.SunToolkit; import java.awt.*; public class WarningWindowDisposeCrashTest { public static void main(String[] args) throws Exception { - System.setSecurityManager(new AppletSecurity() { - @Override - public void checkPackageAccess (String s){ - } - }); - Frame f = new Frame(); f.setVisible(true); - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + Robot robot; + try{ + robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Cannot create Robot"); + } Thread.sleep(1000); f.dispose(); // If the bug is present VM could crash after this call diff --git a/jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeTest.java b/jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeTest.java index 6f0149dc4d1..3f525e967d9 100644 --- a/jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeTest.java +++ b/jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeTest.java @@ -31,12 +31,11 @@ @run main WarningWindowDisposeTest */ -import sun.applet.AppletSecurity; -import sun.awt.SunToolkit; - import java.awt.*; import java.awt.Toolkit; import java.util.concurrent.atomic.AtomicBoolean; +import java.security.Permission; +import java.io.File; import test.java.awt.regtesthelpers.process.ProcessCommunicator; import test.java.awt.regtesthelpers.process.ProcessResults; @@ -57,7 +56,9 @@ public class WarningWindowDisposeTest { }, "TimeoutThread").start(); String classpath = System.getProperty("java.class.path"); - ProcessResults pres = ProcessCommunicator.executeChildProcess(TestApplication.class, classpath, new String[0]); + String policyPath = System.getProperty("test.src")+File.separatorChar+"policy"; + System.out.println("policyPath in main: "+policyPath); + ProcessResults pres = ProcessCommunicator.executeChildProcess(TestApplication.class, classpath+" -Djava.security.manager -Djava.security.policy="+policyPath, new String[0]); passed.set(true); if (pres.getStdErr() != null && pres.getStdErr().length() > 0) { System.err.println("========= Child VM System.err ========"); @@ -74,14 +75,16 @@ public class WarningWindowDisposeTest { public static class TestApplication { public static void main(String[] args) throws Exception { - System.setSecurityManager(new AppletSecurity() { - @Override - public void checkPackageAccess (String s){ - } - }); + Robot robot; + try{ + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Cannot create Robot"); + } Frame f = new Frame("Test frame"); f.setVisible(true); - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); Thread.sleep(500); f.setVisible(false); f.dispose();