6616792: five AWT focus regression tests should be fixed
authorant
Wed, 26 Mar 2008 17:38:26 +0300
changeset 425 89b44fab010f
parent 424 c090ad2f18f2
child 426 199e77044010
6616792: five AWT focus regression tests should be fixed Summary: Fixed/refactored the tests. Reviewed-by: volk
jdk/test/java/awt/Focus/ActualFocusedWindowTest/ActualFocusedWindowBlockingTest.java
jdk/test/java/awt/Focus/ActualFocusedWindowTest/ActualFocusedWindowRetaining.java
jdk/test/java/awt/Focus/FrameJumpingToMouse/FrameJumpingToMouse.java
jdk/test/java/awt/Focus/NonFocusableWindowTest/NoEventsTest.java
jdk/test/java/awt/Focus/NonFocusableWindowTest/NonfocusableOwnerTest.java
jdk/test/java/awt/Focus/NonFocusableWindowTest/Test.java
jdk/test/java/awt/Focus/TypeAhead/TestFocusFreeze.java
jdk/test/java/awt/Focus/WrongKeyTypedConsumedTest/WrongKeyTypedConsumedTest.java
--- a/jdk/test/java/awt/Focus/ActualFocusedWindowTest/ActualFocusedWindowBlockingTest.java	Wed Mar 26 16:56:40 2008 +0300
+++ b/jdk/test/java/awt/Focus/ActualFocusedWindowTest/ActualFocusedWindowBlockingTest.java	Wed Mar 26 17:38:26 2008 +0300
@@ -25,8 +25,10 @@
   @test
   @bug       6314575
   @summary   Tests that previosly focused owned window doesn't steal focus when an owner's component requests focus.
-  @author    Anton Tarasov: area=awt-focus
-  @run       applet ActualFocusedWindowBlockingTest.html
+  @author    Anton.Tarasov: area=awt.focus
+  @library   ../../regtesthelpers
+  @build     Util
+  @run       main ActualFocusedWindowBlockingTest
 */
 
 import java.awt.*;
@@ -35,9 +37,10 @@
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.lang.reflect.InvocationTargetException;
 import sun.awt.SunToolkit;
+import test.java.awt.regtesthelpers.Util;
 
 public class ActualFocusedWindowBlockingTest extends Applet {
-    Robot robot;
+    Robot robot = Util.createRobot();
     Frame owner = new Frame("Owner Frame");
     Window win = new Window(owner);
     Frame frame = new Frame("Auxiliary Frame");
@@ -52,28 +55,12 @@
     }
 
     public void init() {
-        // Create instructions for the user here, as well as set up
-        // the environment -- set the layout manager, add buttons,
-        // etc.
-        this.setLayout (new BorderLayout ());
-        Sysout.createDialogWithInstructions(new String[]
-            {"Automatic test. Simply wait until it's done."});
-
-        if ("sun.awt.motif.MToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) {
-            return;
-        }
-
         Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
                 public void eventDispatched(AWTEvent e) {
-                    Sysout.println("--> " + e);
+                    System.out.println("--> " + e);
                 }
             }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK);
 
-        try {
-            robot = new Robot();
-        } catch (AWTException e) {
-            throw new RuntimeException("Error: unable to create robot", e);
-        }
         owner.add(fButton);
         win.add(wButton);
         frame.add(aButton);
@@ -87,19 +74,18 @@
 
     public void start() {
         if ("sun.awt.motif.MToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) {
-            Sysout.println("No testing on Motif. Test passed.");
+            System.out.println("No testing on Motif. Test passed.");
             return;
         }
 
-        Sysout.println("\nTest started:\n");
+        System.out.println("\nTest started:\n");
 
         // Test 1.
 
         clickOnCheckFocus(wButton);
-
         clickOnCheckFocus(aButton);
 
-        clickOn(fButton);
+        Util.clickOnComp(fButton, robot);
         if (!testFocused(fButton)) {
             throw new TestFailedException("The owner's component [" + fButton + "] couldn't be focused by click");
         }
@@ -107,11 +93,10 @@
         // Test 2.
 
         clickOnCheckFocus(wButton);
-
         clickOnCheckFocus(aButton);
 
         fButton.requestFocus();
-        realSync();
+        Util.waitForIdle(robot);
         if (!testFocused(fButton)) {
             throw new TestFailedException("The owner's component [" + fButton + "] couldn't be focused by request");
         }
@@ -119,19 +104,16 @@
         // Test 3.
 
         clickOnCheckFocus(wButton);
-
+        clickOnCheckFocus(aButton);
+        clickOnCheckFocus(fButton);
         clickOnCheckFocus(aButton);
 
-        clickOnCheckFocus(fButton);
-
-        clickOnCheckFocus(aButton);
-
-        clickOn(owner);
+        Util.clickOnTitle(owner, robot);
         if (!testFocused(fButton)) {
             throw new TestFailedException("The owner's component [" + fButton + "] couldn't be focused as the most recent focus owner");
         }
 
-        Sysout.println("Test passed.");
+        System.out.println("Test passed.");
     }
 
     void tuneAndShowWindows(Window[] arr) {
@@ -142,33 +124,18 @@
             w.setBackground(Color.blue);
             w.setVisible(true);
             y += 200;
-            realSync();
+            Util.waitForIdle(robot);
         }
     }
 
-    void clickOn(Component c) {
-        Sysout.println("Test: clicking " + c);
-
-        Point p = c.getLocationOnScreen();
-        Dimension d = c.getSize();
-
+    void clickOnCheckFocus(Component c) {
         if (c instanceof Frame) {
-            robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + ((Frame)c).getInsets().top/2);
-            Sysout.println((p.x + (int)(d.getWidth()/2)) + " " +  (p.y + ((Frame)c).getInsets().top/2));
+            Util.clickOnTitle((Frame)c, robot);
         } else {
-            robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)(d.getHeight()/2));
+            Util.clickOnComp(c, robot);
         }
-        robot.mousePress(InputEvent.BUTTON1_MASK);
-        robot.delay(100);
-        robot.mouseRelease(InputEvent.BUTTON1_MASK);
-
-        realSync();
-    }
-
-    void clickOnCheckFocus(Component c) {
-        clickOn(c);
         if (!testFocused(c)) {
-            throw new RuntimeException("Error: [" + c + "] couldn't get focus by click.");
+            throw new TestErrorException(c + "couldn't get focus by click.");
         }
     }
 
@@ -177,157 +144,22 @@
             if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == c) {
                 return true;
             }
-            realSync();
+            Util.waitForIdle(robot);
         }
         return false;
     }
 
-    void realSync() {
-        ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
+    // Thrown when the behavior being verified is found wrong.
+    class TestFailedException extends RuntimeException {
+        TestFailedException(String msg) {
+            super("Test failed: " + msg);
+        }
     }
 
-    class TestFailedException extends RuntimeException {
-        public TestFailedException(String cause) {
-            super("Test failed. " + cause);
-            Sysout.println(cause);
+    // Thrown when an error not related to the behavior being verified is encountered.
+    class TestErrorException extends RuntimeException {
+        TestErrorException(String msg) {
+            super("Unexpected error: " + msg);
         }
     }
 }
-
-/****************************************************
- Standard Test Machinery
- DO NOT modify anything below -- it's a standard
-  chunk of code whose purpose is to make user
-  interaction uniform, and thereby make it simpler
-  to read and understand someone else's test.
- ****************************************************/
-
-/**
- This is part of the standard test machinery.
- It creates a dialog (with the instructions), and is the interface
-  for sending text messages to the user.
- To print the instructions, send an array of strings to Sysout.createDialog
-  WithInstructions method.  Put one line of instructions per array entry.
- To display a message for the tester to see, simply call Sysout.println
-  with the string to be displayed.
- This mimics System.out.println but works within the test harness as well
-  as standalone.
- */
-
-class Sysout
-{
-    static TestDialog dialog;
-
-    public static void createDialogWithInstructions( String[] instructions )
-    {
-        dialog = new TestDialog( new Frame(), "Instructions" );
-        dialog.printInstructions( instructions );
-        dialog.setLocation(500,0);
-        dialog.setVisible(true);
-        println( "Any messages for the tester will display here." );
-    }
-
-    public static void createDialog( )
-    {
-        dialog = new TestDialog( new Frame(), "Instructions" );
-        String[] defInstr = { "Instructions will appear here. ", "" } ;
-        dialog.printInstructions( defInstr );
-        dialog.setVisible(true);
-        println( "Any messages for the tester will display here." );
-    }
-
-
-    public static void printInstructions( String[] instructions )
-    {
-        dialog.printInstructions( instructions );
-    }
-
-
-    public static void println( String messageIn )
-    {
-        dialog.displayMessage( messageIn );
-    }
-
-}// Sysout  class
-
-/**
-  This is part of the standard test machinery.  It provides a place for the
-   test instructions to be displayed, and a place for interactive messages
-   to the user to be displayed.
-  To have the test instructions displayed, see Sysout.
-  To have a message to the user be displayed, see Sysout.
-  Do not call anything in this dialog directly.
-  */
-class TestDialog extends Dialog
-{
-
-    TextArea instructionsText;
-    TextArea messageText;
-    int maxStringLength = 80;
-
-    //DO NOT call this directly, go through Sysout
-    public TestDialog( Frame frame, String name )
-    {
-        super( frame, name );
-        int scrollBoth = TextArea.SCROLLBARS_BOTH;
-        instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
-        add( "North", instructionsText );
-
-        messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
-        add("Center", messageText);
-
-        pack();
-
-        setVisible(true);
-    }// TestDialog()
-
-    //DO NOT call this directly, go through Sysout
-    public void printInstructions( String[] instructions )
-    {
-        //Clear out any current instructions
-        instructionsText.setText( "" );
-
-        //Go down array of instruction strings
-
-        String printStr, remainingStr;
-        for( int i=0; i < instructions.length; i++ )
-        {
-            //chop up each into pieces maxSringLength long
-            remainingStr = instructions[ i ];
-            while( remainingStr.length() > 0 )
-            {
-                //if longer than max then chop off first max chars to print
-                if( remainingStr.length() >= maxStringLength )
-                {
-                    //Try to chop on a word boundary
-                    int posOfSpace = remainingStr.
-                        lastIndexOf( ' ', maxStringLength - 1 );
-
-                    if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
-
-                    printStr = remainingStr.substring( 0, posOfSpace + 1 );
-                    remainingStr = remainingStr.substring( posOfSpace + 1 );
-                }
-                //else just print
-                else
-                {
-                    printStr = remainingStr;
-                    remainingStr = "";
-                }
-
-                instructionsText.append( printStr + "\n" );
-
-            }// while
-
-        }// for
-
-    }//printInstructions()
-
-    //DO NOT call this directly, go through Sysout
-    public void displayMessage( String messageIn )
-    {
-        messageText.append( messageIn + "\n" );
-        System.out.println(messageIn);
-    }
-
-}// TestDialog  class
--- a/jdk/test/java/awt/Focus/ActualFocusedWindowTest/ActualFocusedWindowRetaining.java	Wed Mar 26 16:56:40 2008 +0300
+++ b/jdk/test/java/awt/Focus/ActualFocusedWindowTest/ActualFocusedWindowRetaining.java	Wed Mar 26 17:38:26 2008 +0300
@@ -23,16 +23,19 @@
 
 /*
   @test
-  @bug 4823903
-  @summary Tests actual focused window retaining.
-  @author Anton Tarasov: area=awt.focus
-  @run applet ActualFocusedWindowRetaining.html
+  @bug      4823903
+  @summary  Tests actual focused window retaining.
+  @author   Anton.Tarasov: area=awt.focus
+  @library  ../../regtesthelpers
+  @build    Util
+  @run      main ActualFocusedWindowRetaining
 */
 
 import java.awt.*;
 import java.awt.event.*;
 import java.lang.reflect.*;
 import java.applet.*;
+import test.java.awt.regtesthelpers.Util;
 
 public class ActualFocusedWindowRetaining extends Applet {
     public static Frame frame = new Frame("Other Frame");
@@ -46,7 +49,7 @@
     public static Window window1 = new TestWindow(owner, otherButton2, testButton2, 800, 200);
     public static Window window2 = new TestWindow(owner, otherButton3, testButton3, 800, 300);
     public static int step;
-    public static Robot robot;
+    public static Robot robot = Util.createRobot();
 
     public static void main(String[] args) {
         ActualFocusedWindowRetaining a = new ActualFocusedWindowRetaining();
@@ -54,53 +57,25 @@
         a.start();
     }
 
-    public void init()
-    {
-        //Create instructions for the user here, as well as set up
-        // the environment -- set the layout manager, add buttons,
-        // etc.
-        this.setLayout (new BorderLayout ());
-
-        String[] instructions =
-        {
-            "This is an AUTOMATIC test",
-            "simply wait until it is done"
-        };
-        Sysout.createDialogWithInstructions( instructions );
-    }
-
-    public void start ()
-    {
-        if (Toolkit.getDefaultToolkit().getClass()
-                .getName().equals("sun.awt.motif.MToolkit")) {
-            Sysout.println("No testing on Motif.");
-            return;
-        }
-
-        try {
-            robot = new Robot();
-        } catch (AWTException e) {
-            throw new RuntimeException("Error: unable to create robot", e);
-        }
-
+    public void start () {
         Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
                 public void eventDispatched(AWTEvent e) {
                     Object src = e.getSource();
                     Class cls = src.getClass();
 
                     if (cls == TestWindow.class) {
-                        Sysout.println(e.paramString() + " on <" + (src == window1 ? "Window 1" : "Window 2") + ">");
+                        System.out.println(e.paramString() + " on <" + (src == window1 ? "Window 1" : "Window 2") + ">");
                     } else if (cls == Frame.class) {
-                        Sysout.println(e.paramString() + " on <" + ((Frame)src).getTitle() + ">");
+                        System.out.println(e.paramString() + " on <" + ((Frame)src).getTitle() + ">");
                     } else if (cls == Button.class) {
-                        Sysout.println(e.paramString() + " on <" + ((Button)src).getLabel() + ">");
+                        System.out.println(e.paramString() + " on <" + ((Button)src).getLabel() + ">");
                     } else {
-                        Sysout.println(e.paramString() + " on <Non-testing component>");
+                        System.out.println(e.paramString() + " on <Non-testing component>");
                     }
                 }
             }, AWTEvent.WINDOW_EVENT_MASK | AWTEvent.WINDOW_FOCUS_EVENT_MASK | AWTEvent.FOCUS_EVENT_MASK);
 
-        setSize (200,200);
+        setSize (500, 200);
         setVisible(true);
         validate();
 
@@ -117,15 +92,15 @@
         owner.setSize(new Dimension(400, 100));
         owner.setVisible(true);
         owner.toFront();
-        waitTillShown(owner);
+        Util.waitTillShown(owner);
 
         window1.setVisible(true);
         window2.setVisible(true);
         window1.toFront();
         window2.toFront();
         // Wait longer...
-        waitTillShown(window1);
-        waitTillShown(window2);
+        Util.waitTillShown(window1);
+        Util.waitTillShown(window2);
 
         test();
 
@@ -134,85 +109,39 @@
     }
 
     public void test() {
-
         Button[] butArr = new Button[] {testButton3, testButton2, testButton1};
         Window[] winArr = new Window[] {window2, window1, owner};
 
         step = 1;
         for (int i = 0; i < 3; i++) {
-            clickOnCheckFocusOwner(butArr[i]);
-            clickOnCheckFocusedWindow(frame);
-            clickOn(owner);
-            if (!checkFocusedWindow(winArr[i])) {
-                stopTest("Test failed: actual focused window didn't get a focus");
-            }
-            if (!checkFocusOwner(butArr[i])) {
-                stopTest("Test failed: actual focus owner didn't get a focus");
-            }
+            clickInSeriesCheckFocus(null, butArr[i], frame);
+            clickOwnerCheckFocus(winArr[i], butArr[i]);
             step++;
         }
 
         step = 4;
-        clickOnCheckFocusOwner(testButton3);
-        clickOnCheckFocusOwner(testButton1);
-        clickOnCheckFocusedWindow(frame);
-        clickOn(owner);
-        if (!checkFocusedWindow(owner)) {
-            stopTest("Test failed: actual focused window didn't get a focus");
-        }
-        if (!checkFocusOwner(testButton1)) {
-            stopTest("Test failed: actual focus owner didn't get a focus");
-        }
+        clickInSeriesCheckFocus(testButton3, testButton1, frame);
+        clickOwnerCheckFocus(owner, testButton1);
 
         step = 5;
-        clickOnCheckFocusOwner(testButton3);
-        clickOnCheckFocusOwner(testButton2);
-        clickOnCheckFocusedWindow(frame);
-        clickOn(owner);
-        if (!checkFocusedWindow(window1)) {
-            stopTest("Test failed: actual focused window didn't get a focus");
-        }
-        if (!checkFocusOwner(testButton2)) {
-            stopTest("Test failed: actual focus owner didn't get a focus");
-        }
+        clickInSeriesCheckFocus(testButton3, testButton2, frame);
+        clickOwnerCheckFocus(window1, testButton2);
 
         step = 6;
-        clickOnCheckFocusOwner(testButton1);
-        clickOnCheckFocusOwner(testButton2);
-        clickOnCheckFocusedWindow(frame);
-        clickOn(owner);
-        if (!checkFocusedWindow(window1)) {
-            stopTest("Test failed: actual focused window didn't get a focus");
-        }
-        if (!checkFocusOwner(testButton2)) {
-            stopTest("Test failed: actual focus owner didn't get a focus");
-        }
+        clickInSeriesCheckFocus(testButton1, testButton2, frame);
+        clickOwnerCheckFocus(window1, testButton2);
 
         step = 7;
-        clickOnCheckFocusOwner(testButton1);
-        clickOnCheckFocusOwner(testButton2);
-        clickOnCheckFocusedWindow(frame);
+        clickInSeriesCheckFocus(testButton1, testButton2, frame);
         window1.setVisible(false);
-        clickOn(owner);
-        if (!checkFocusedWindow(owner)) {
-            stopTest("Test failed: actual focused window didn't get a focus");
-        }
-        if (!checkFocusOwner(testButton1)) {
-            stopTest("Test failed: actual focus owner didn't get a focus");
-        }
+        Util.waitForIdle(robot);
+        clickOwnerCheckFocus(owner, testButton1);
 
         step = 8;
         window1.setVisible(true);
-        waitTillShown(window1);
-        clickOnCheckFocusOwner(testButton2);
-        clickOnCheckFocusedWindow(frame);
-        clickOn(owner);
-        if (!checkFocusedWindow(window1)) {
-            stopTest("Test failed: actual focused window didn't get a focus");
-        }
-        if (!checkFocusOwner(testButton2)) {
-            stopTest("Test failed: actual focus owner didn't get a focus");
-        }
+        Util.waitTillShown(window1);
+        clickInSeriesCheckFocus(null, testButton2, frame);
+        clickOwnerCheckFocus(window1, testButton2);
     }
 
     boolean checkFocusOwner(Component comp) {
@@ -223,56 +152,46 @@
         return (win == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow());
     }
 
-    void waitTillShown(Component c) {
-        ((sun.awt.SunToolkit) Toolkit.getDefaultToolkit()).realSync();
+    void clickOwnerCheckFocus(Window focusedWindow, Component focusedComp) {
+        Util.clickOnTitle(owner, robot);
+        robot.delay(500);
+
+        if (!checkFocusedWindow(focusedWindow)) {
+            stopTest("Test failed: actual focused window didn't get a focus");
+        }
+        if (!checkFocusOwner(focusedComp)) {
+            stopTest("Test failed: actual focus owner didn't get a focus");
+        }
+    }
+
+    void clickInSeriesCheckFocus(Component comp1, Component comp2, Frame frame) {
+        if (comp1 != null) {
+            clickOnCheckFocusOwner(comp1);
+        }
+        if (comp2 != null) {
+            clickOnCheckFocusOwner(comp2);
+        }
+        clickOnCheckFocusedWindow(frame);
     }
 
     void clickOnCheckFocusOwner(Component c) {
-        clickOn(c);
+        Util.clickOnComp(c, robot);
+        robot.delay(500);
+
         if (!checkFocusOwner(c)) {
             stopTest("Error: can't bring a focus on Component by clicking on it");
         }
     }
 
     void clickOnCheckFocusedWindow(Frame f) {
-        clickOn(f);
+        Util.clickOnTitle(f, robot);
+        robot.delay(500);
+
         if (!checkFocusedWindow(f)) {
             stopTest("Error: can't bring a focus on Frame by clicking on it");
         }
     }
 
-    void clickOn(Component c)
-    {
-        Point p = c.getLocationOnScreen();
-        Dimension d = c.getSize();
-
-        if (c instanceof Frame) {
-            robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + ((Frame)c).getInsets().top/2);
-        } else {
-            robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)(d.getHeight()/2));
-        }
-
-        pause(100);
-        robot.mousePress(InputEvent.BUTTON1_MASK);
-        pause(100);
-        robot.mouseRelease(InputEvent.BUTTON1_MASK);
-
-        waitForIdle();
-    }
-
-    void waitForIdle() {
-        ((sun.awt.SunToolkit) Toolkit.getDefaultToolkit()).realSync();
-    }
-
-    void pause(int msec) {
-        try {
-            Thread.sleep(msec);
-        } catch (InterruptedException e) {
-            Sysout.println("pause: non-fatal exception caught:");
-            e.printStackTrace();
-        }
-    }
-
     void stopTest(String msg) {
         throw new RuntimeException(new String("Step " + step + ": " + msg));
     }
@@ -290,141 +209,3 @@
         setBackground(Color.green);
     }
 }
-
-
-/****************************************************
- Standard Test Machinery
- DO NOT modify anything below -- it's a standard
-  chunk of code whose purpose is to make user
-  interaction uniform, and thereby make it simpler
-  to read and understand someone else's test.
- ****************************************************/
-
-/**
- This is part of the standard test machinery.
- It creates a dialog (with the instructions), and is the interface
-  for sending text messages to the user.
- To print the instructions, send an array of strings to Sysout.createDialog
-  WithInstructions method.  Put one line of instructions per array entry.
- To display a message for the tester to see, simply call Sysout.println
-  with the string to be displayed.
- This mimics System.out.println but works within the test harness as well
-  as standalone.
- */
-
-class Sysout
-{
-    private static TestDialog dialog;
-
-    public static void createDialogWithInstructions( String[] instructions )
-    {
-        dialog = new TestDialog( new Frame(), "Instructions" );
-        dialog.printInstructions( instructions );
-        dialog.setVisible(true);
-        println( "Any messages for the tester will display here." );
-    }
-
-    public static void createDialog( )
-    {
-        dialog = new TestDialog( new Frame(), "Instructions" );
-        String[] defInstr = { "Instructions will appear here. ", "" } ;
-        dialog.printInstructions( defInstr );
-        dialog.setVisible(true);
-        println( "Any messages for the tester will display here." );
-    }
-
-
-    public static void printInstructions( String[] instructions )
-    {
-        dialog.printInstructions( instructions );
-    }
-
-
-    public static void println( String messageIn )
-    {
-        dialog.displayMessage( messageIn );
-    }
-
-}// Sysout  class
-
-/**
-  This is part of the standard test machinery.  It provides a place for the
-   test instructions to be displayed, and a place for interactive messages
-   to the user to be displayed.
-  To have the test instructions displayed, see Sysout.
-  To have a message to the user be displayed, see Sysout.
-  Do not call anything in this dialog directly.
-  */
-class TestDialog extends Dialog
-{
-
-    TextArea instructionsText;
-    TextArea messageText;
-    int maxStringLength = 80;
-
-    //DO NOT call this directly, go through Sysout
-    public TestDialog( Frame frame, String name )
-    {
-        super( frame, name );
-        int scrollBoth = TextArea.SCROLLBARS_BOTH;
-        instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
-        add( "North", instructionsText );
-
-        messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
-        add("Center", messageText);
-
-        pack();
-
-        setVisible(true);
-    }// TestDialog()
-
-    //DO NOT call this directly, go through Sysout
-    public void printInstructions( String[] instructions )
-    {
-        //Clear out any current instructions
-        instructionsText.setText( "" );
-
-        //Go down array of instruction strings
-
-        String printStr, remainingStr;
-        for( int i=0; i < instructions.length; i++ )
-        {
-            //chop up each into pieces maxSringLength long
-            remainingStr = instructions[ i ];
-            while( remainingStr.length() > 0 )
-            {
-                //if longer than max then chop off first max chars to print
-                if( remainingStr.length() >= maxStringLength )
-                {
-                    //Try to chop on a word boundary
-                    int posOfSpace = remainingStr.
-                        lastIndexOf( ' ', maxStringLength - 1 );
-
-                    if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
-
-                    printStr = remainingStr.substring( 0, posOfSpace + 1 );
-                    remainingStr = remainingStr.substring( posOfSpace + 1 );
-                }
-                //else just print
-                else
-                {
-                    printStr = remainingStr;
-                    remainingStr = "";
-                }
-
-                instructionsText.append( printStr + "\n" );
-
-            }// while
-
-        }// for
-
-    }//printInstructions()
-
-    //DO NOT call this directly, go through Sysout
-    public void displayMessage( String messageIn )
-    {
-        messageText.append( messageIn + "\n" );
-        System.out.println(messageIn);
-    }
-
-}// TestDialog  class
--- a/jdk/test/java/awt/Focus/FrameJumpingToMouse/FrameJumpingToMouse.java	Wed Mar 26 16:56:40 2008 +0300
+++ b/jdk/test/java/awt/Focus/FrameJumpingToMouse/FrameJumpingToMouse.java	Wed Mar 26 17:38:26 2008 +0300
@@ -22,238 +22,65 @@
  */
 
 /*
-test
-@bug 4752312
-@summary Tests that after moving non-focusable window it ungrabs mouse pointer
-@author dom@sparc.spb.su: area=awt.focus
-@run applet FrameJumpingToMouse.html
+    @test
+    @bug        4752312
+    @summary    Tests that after moving non-focusable window it ungrabs mouse pointer
+    @author     Denis Mikhalkin: area=awt.focus
+    @library    ../../regtesthelpers
+    @build      Util
+    @run        main FrameJumpingToMouse
 */
 
-// Note there is no @ in front of test above.  This is so that the
-//  harness will not mistake this file as a test file.  It should
-//  only see the html file as a test file. (the harness runs all
-//  valid test files, so it would run this test twice if this file
-//  were valid as well as the html file.)
-// Also, note the area= after Your Name in the author tag.  Here, you
-//  should put which functional area the test falls in.  See the
-//  AWT-core home page -> test areas and/or -> AWT team  for a list of
-//  areas.
-// Note also the 'FrameJumpingToMouse.html' in the run tag.  This should
-//  be changed to the name of the test.
-
-
-/**
- * FrameJumpingToMouse.java
- *
- * summary:
- */
-
 import java.applet.Applet;
-import java.awt.*;
-import java.awt.event.*;
+import java.awt.BorderLayout;
+import java.awt.Dialog;
+import java.awt.Frame;
+import java.awt.Point;
+import java.awt.Robot;
+import java.awt.TextArea;
+import java.awt.Toolkit;
+import java.awt.event.InputEvent;
 import javax.swing.JFrame;
-
-//Automated tests should run as applet tests if possible because they
-// get their environments cleaned up, including AWT threads, any
-// test created threads, and any system resources used by the test
-// such as file descriptors.  (This is normally not a problem as
-// main tests usually run in a separate VM, however on some platforms
-// such as the Mac, separate VMs are not possible and non-applet
-// tests will cause problems).  Also, you don't have to worry about
-// synchronisation stuff in Applet tests they way you do in main
-// tests...
-
+import test.java.awt.regtesthelpers.Util;
 
 public class FrameJumpingToMouse extends Applet
 {
-    //Declare things used in the test, like buttons and labels here
     JFrame frame = new JFrame("Test jumping frame");
-    Robot robot = null;
-    public void init()
-    {
-        //Create instructions for the user here, as well as set up
-        // the environment -- set the layout manager, add buttons,
-        // etc.
+    Robot robot = Util.createRobot();
 
-        this.setLayout (new BorderLayout ());
+    public static void main(String[] args) {
+        FrameJumpingToMouse test = new FrameJumpingToMouse();
+        test.init();
+        test.start();
+    }
 
+    public void init() {
         frame.setFocusableWindowState(false);
         frame.setBounds(100, 100, 100, 100);
-    }//End  init()
-
-    public void start ()
-    {
-        //Get things going.  Request focus, set size, et cetera
-        setSize (200,200);
-        setVisible(true);
-        validate();
-
-        try {
-            robot = new Robot();
-        } catch (Exception e) {
-            throw new RuntimeException("Can't create robot");
-        }
-
-        frame.setVisible(true);
-
-        robot.delay(1000);
-
-        Point frameLoc = frame.getLocationOnScreen();
-        robot.mouseMove(frameLoc.x+frame.getWidth()/4, frameLoc.y+frame.getInsets().top/2);
-        robot.mousePress(InputEvent.BUTTON1_MASK);
-        robot.mouseMove(frameLoc.x+100, frameLoc.y+50);
-        robot.mouseRelease(InputEvent.BUTTON1_MASK);
-
-        Toolkit.getDefaultToolkit().sync();
-        robot.waitForIdle();
-        frameLoc = frame.getLocation();
-
-        robot.mouseMove(frameLoc.x+frame.getWidth()/2, frameLoc.y+frame.getHeight()/2);
-
-        Toolkit.getDefaultToolkit().sync();
-        robot.waitForIdle();
-
-        if (!(frame.getLocation().equals(frameLoc))) {
-            throw new RuntimeException("Frame is moving to mouse with grab");
-        }
-    }// start()
-
-}// class FrameJumpingToMouse
-
-
-/****************************************************
- Standard Test Machinery
- DO NOT modify anything below -- it's a standard
-  chunk of code whose purpose is to make user
-  interaction uniform, and thereby make it simpler
-  to read and understand someone else's test.
- ****************************************************/
-
-/**
- This is part of the standard test machinery.
- It creates a dialog (with the instructions), and is the interface
-  for sending text messages to the user.
- To print the instructions, send an array of strings to Sysout.createDialog
-  WithInstructions method.  Put one line of instructions per array entry.
- To display a message for the tester to see, simply call Sysout.println
-  with the string to be displayed.
- This mimics System.out.println but works within the test harness as well
-  as standalone.
- */
-
-class Sysout
-{
-    private static TestDialog dialog;
-
-    public static void createDialogWithInstructions( String[] instructions )
-    {
-        dialog = new TestDialog( new Frame(), "Instructions" );
-        dialog.printInstructions( instructions );
-        dialog.setVisible(true);
-        println( "Any messages for the tester will display here." );
-    }
-
-    public static void createDialog( )
-    {
-        dialog = new TestDialog( new Frame(), "Instructions" );
-        String[] defInstr = { "Instructions will appear here. ", "" } ;
-        dialog.printInstructions( defInstr );
-        dialog.setVisible(true);
-        println( "Any messages for the tester will display here." );
     }
 
-
-    public static void printInstructions( String[] instructions )
-    {
-        dialog.printInstructions( instructions );
-    }
-
-
-    public static void println( String messageIn )
-    {
-        dialog.displayMessage( messageIn );
-    }
-
-}// Sysout  class
+    public void start() {
+        frame.setVisible(true);
+        Util.waitTillShown(frame);
 
-/**
-  This is part of the standard test machinery.  It provides a place for the
-   test instructions to be displayed, and a place for interactive messages
-   to the user to be displayed.
-  To have the test instructions displayed, see Sysout.
-  To have a message to the user be displayed, see Sysout.
-  Do not call anything in this dialog directly.
-  */
-class TestDialog extends Dialog
-{
-
-    TextArea instructionsText;
-    TextArea messageText;
-    int maxStringLength = 80;
-
-    //DO NOT call this directly, go through Sysout
-    public TestDialog( Frame frame, String name )
-    {
-        super( frame, name );
-        int scrollBoth = TextArea.SCROLLBARS_BOTH;
-        instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
-        add( "North", instructionsText );
-
-        messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
-        add("Center", messageText);
-
-        pack();
-
-        show();
-    }// TestDialog()
+        Point loc = frame.getLocationOnScreen();
+        robot.mouseMove(loc.x + frame.getWidth() / 4, loc.y + frame.getInsets().top / 2);
+        robot.delay(50);
+        robot.mousePress(InputEvent.BUTTON1_MASK);
+        robot.delay(50);
+        robot.mouseMove(loc.x + 100, loc.y + 50);
+        robot.delay(50);
+        robot.mouseRelease(InputEvent.BUTTON1_MASK);
 
-    //DO NOT call this directly, go through Sysout
-    public void printInstructions( String[] instructions )
-    {
-        //Clear out any current instructions
-        instructionsText.setText( "" );
-
-        //Go down array of instruction strings
+        Util.waitForIdle(robot);
 
-        String printStr, remainingStr;
-        for( int i=0; i < instructions.length; i++ )
-        {
-            //chop up each into pieces maxSringLength long
-            remainingStr = instructions[ i ];
-            while( remainingStr.length() > 0 )
-            {
-                //if longer than max then chop off first max chars to print
-                if( remainingStr.length() >= maxStringLength )
-                {
-                    //Try to chop on a word boundary
-                    int posOfSpace = remainingStr.
-                        lastIndexOf( ' ', maxStringLength - 1 );
-
-                    if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+        loc = frame.getLocation();
+        robot.mouseMove(loc.x + frame.getWidth() / 2, loc.y + frame.getHeight() / 2);
+        Util.waitForIdle(robot);
 
-                    printStr = remainingStr.substring( 0, posOfSpace + 1 );
-                    remainingStr = remainingStr.substring( posOfSpace + 1 );
-                }
-                //else just print
-                else
-                {
-                    printStr = remainingStr;
-                    remainingStr = "";
-                }
-
-                instructionsText.append( printStr + "\n" );
-
-            }// while
-
-        }// for
-
-    }//printInstructions()
-
-    //DO NOT call this directly, go through Sysout
-    public void displayMessage( String messageIn )
-    {
-        messageText.append( messageIn + "\n" );
-        System.out.println(messageIn);
+        if (!(frame.getLocation().equals(loc))) {
+            throw new RuntimeException("Test failed: frame is moving to mouse with grab!");
+        }
+        System.out.println("Test passed.");
     }
-
-}// TestDialog  class
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Focus/NonFocusableWindowTest/NoEventsTest.java	Wed Mar 26 17:38:26 2008 +0300
@@ -0,0 +1,420 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+  @test
+  @bug 4452384
+  @summary Tests that non-focusable windows doesn't generate any focus events when accessed.
+  @author Denis.Mikhalkin: area=awt.focus
+  @run main NoEventsTest
+*/
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+
+public class NoEventsTest extends Frame {
+    public static final int DEF_WIDTH = 400,
+        DEF_HEIGHT = 300,
+        DEF_TOP = 1,
+        DEF_LEFT = 100,
+        DEF_ROW = 0,
+        DEF_COL = 0;
+    static boolean automatic = true;
+    static Window[] windows;
+    static Frame main_frame, jumpingFrame;
+    static Button focus_button;
+    static Robot robot;
+    static void pause(int timeout) {
+        Toolkit.getDefaultToolkit().sync();
+        robot.waitForIdle();
+        robot.delay(100);
+    }
+    static GlobalListener listener;
+    public static void main(String[] args) {
+
+        listener = new GlobalListener();
+        Toolkit.getDefaultToolkit().addAWTEventListener(listener,
+                                                        AWTEvent.FOCUS_EVENT_MASK |
+                                                        AWTEvent.WINDOW_EVENT_MASK);
+        try{
+            robot = new Robot();
+        } catch(Exception e) {}
+        // Create several pairs - focusable Frame with focusable component(button) and non-focusable:
+        // window, resizable frame, non-resizable frame, dialog, non-resiable dialog
+        main_frame = new Frame("focusable frame");
+        focus_button = new Button("button to focus");
+        main_frame.add(focus_button);
+        main_frame.pack();
+        main_frame.setVisible(true);
+        main_frame.setLocation(10, 600);
+        main_frame.addWindowListener(new WindowAdapter() {
+                public void windowClosing(WindowEvent e) {
+                    listener.report();
+                    System.exit(0);
+                }
+            });
+
+        jumpingFrame = new Frame("Jumping frame");
+        jumpingFrame.setBounds(DEF_LEFT, DEF_TOP, DEF_WIDTH, DEF_HEIGHT);
+
+        windows = new Window[7];
+        windows[0] = new TestWindow(0, 0, false, main_frame);
+        //windows[1] = new TestWindow(2, 1, true, main_frame);
+        windows[2] = new NoEventsTest(1, 0, false, true);
+        windows[3] = new NoEventsTest(2, 0, false, false);
+        //windows[4] = new Test(3, 0, true, true);
+        windows[5] = new TestDialog(0, 1, false, true, main_frame);
+        windows[6] = new TestDialog(1, 1, false, false, main_frame);
+        if (!automatic) {
+            int windowInd;
+            for (windowInd = 0; windowInd < windows.length; windowInd++) {
+                if (windows[windowInd] != null) {
+                    windows[windowInd].setVisible(true);
+                }
+            }
+        }
+        // Run the test
+        // 1. Click on all controls, check for no focus events for non-focusable, right focus events for focusable
+        // 2. Perform some action with control, check if it works
+        if (automatic) {
+            int windowInd;
+            for (windowInd = 0; windowInd < windows.length; windowInd++) {
+                if (windows[windowInd] != null) {
+                    windows[windowInd].setVisible(true);
+                    focus_button.requestFocus();
+                    pause(1000);
+
+                    // Verify that click on non-focusable window causes no focus lost on active window
+                    performFocusClick(windows[windowInd]);
+                    focus_button.requestFocus();
+                    pause(500);
+                    performActionClick(windows[windowInd]);
+
+                    // Verify that toFront, toBack doesn't cause non-focusable window to become active
+                    jumpingFrame.setVisible(true);
+                    pause(1000);
+                      jumpingFrame.toBack();
+                      pause(500);
+                      jumpingFrame.toFront();
+                      pause(500);
+                      windows[windowInd].toBack();
+                      pause(500);
+                      windows[windowInd].toFront();
+                      pause(500);
+
+                    // Verify that iconifiyng/deiconfiying and
+                    // zooming/unzooming doesn't cause non-focusable
+                    // window to become active
+                    if (windows[windowInd] instanceof Frame) {
+                        Frame toTest = (Frame)windows[windowInd];
+                        // Deiconification currently doesn't work!
+//                        toTest.setExtendedState(Frame.ICONIFIED);
+//                        pause(500);
+//                        toTest.setExtendedState(Frame.NORMAL);
+                        pause(500);
+                        toTest.setExtendedState(Frame.MAXIMIZED_BOTH);
+                        pause(500);
+                        toTest.setExtendedState(Frame.NORMAL);
+                    }
+
+                    windows[windowInd].dispose();
+                    jumpingFrame.dispose();
+                }
+            }
+            pause(1000);
+            System.err.println("Test finished.");
+            if (!listener.report()) {
+                throw new RuntimeException("Test Failed. See error stream output for details");
+            }
+        }
+    }
+    static void performFocusClick(Window parent) {
+        if (parent == null) {
+            return;
+        }
+        for (int compInd = 0; compInd < parent.getComponentCount(); compInd++) {
+            Component child = parent.getComponent(compInd);
+            if (child instanceof TestPanel) {
+                TestPanel pan = (TestPanel)child;
+                pan.performFocusClicks(robot);
+                pause(100);
+            }
+        }
+    }
+    static void performActionClick(Window parent) {
+        if (parent == null) {
+            return;
+        }
+        for (int compInd = 0; compInd < parent.getComponentCount(); compInd++) {
+            Component child = parent.getComponent(compInd);
+            if (child instanceof TestPanel) {
+                TestPanel pan = (TestPanel)child;
+                pan.performActionClicks(robot);
+                pause(100);
+            }
+        }
+    }
+    public NoEventsTest(int row, int col, boolean focusable, boolean resizable) {
+        super("Frame" + row + "" + col);
+        TestPanel panel = new TestPanel(row, col);
+        if (NoEventsTest.automatic) {
+            row = NoEventsTest.DEF_ROW;
+            col = NoEventsTest.DEF_COL;
+        }
+        setName(getTitle());
+        add("Center", panel);
+        Label l = new Label(getClass().getSuperclass().getName() + ", " + (focusable?"focusable":"non-focusable") +
+                            ", " + (resizable?"resizable":"non-resizable"));
+        l.setBackground(Color.green);
+        add("North", l);
+        setBounds(NoEventsTest.DEF_LEFT + DEF_WIDTH*col, DEF_TOP + DEF_HEIGHT*row, DEF_WIDTH, DEF_HEIGHT);
+        if (!focusable) {
+            setFocusableWindowState(false);
+        }
+        if (!resizable) {
+            setResizable(false);
+        }
+//        setVisible(true);
+    }
+}
+class TestWindow extends Window {
+    public TestWindow(int row, int col, boolean focusable, Frame owner) {
+        super(owner);
+        setName("Window" + row + "" + col);
+        TestPanel panel = new TestPanel(row, col);
+        if (NoEventsTest.automatic) {
+            row = NoEventsTest.DEF_ROW;
+            col = NoEventsTest.DEF_COL;
+        }
+
+        add("Center", panel);
+        Label l = new Label(getClass().getSuperclass().getName() + ", " + (focusable?"focusable":"non-focusable") +
+                            ", " + (false?"resizable":"non-resizable"));
+        l.setBackground(Color.green);
+        add("North", l);
+
+        setBounds(NoEventsTest.DEF_LEFT + NoEventsTest.DEF_WIDTH*col, NoEventsTest.DEF_TOP + NoEventsTest.DEF_HEIGHT*row, NoEventsTest.DEF_WIDTH, NoEventsTest.DEF_HEIGHT);
+        if (!focusable) {
+            setFocusableWindowState(false);
+        }
+//        setVisible(true);
+    }
+}
+class TestDialog extends Dialog {
+    public TestDialog(int row, int col, boolean focusable, boolean resizable, Frame owner) {
+        super(owner);
+        setName("Dialog" + row + "" + col);
+        TestPanel panel = new TestPanel(row, col);
+        if (NoEventsTest.automatic) {
+            row = NoEventsTest.DEF_ROW;
+            col = NoEventsTest.DEF_COL;
+        }
+
+        add("Center", panel);
+        Label l = new Label(getClass().getSuperclass().getName() + ", " + (focusable?"focusable":"non-focusable") +
+                            ", " + (resizable?"resizable":"non-resizable"));
+        l.setBackground(Color.green);
+        add("North", l);
+
+        setBounds(NoEventsTest.DEF_LEFT + NoEventsTest.DEF_WIDTH*col, NoEventsTest.DEF_TOP + NoEventsTest.DEF_HEIGHT*row, NoEventsTest.DEF_WIDTH, NoEventsTest.DEF_HEIGHT);
+        if (!focusable) {
+            setFocusableWindowState(false);
+        }
+        if (!resizable) {
+            setResizable(false);
+        }
+//        setVisible(true);
+    }
+}
+
+class TestPanel extends Panel {
+
+    void clickComponent(Component comp, Robot robot) {
+        if (comp instanceof Choice) {
+            return;
+        }
+        Point compLoc = comp.getLocationOnScreen();
+        Dimension size = comp.getSize();
+        robot.mouseMove(compLoc.x + size.width/2, compLoc.y + size.height/2);
+        robot.mousePress(InputEvent.BUTTON1_MASK);
+        robot.mouseRelease(InputEvent.BUTTON1_MASK);
+    }
+    void performFocusClicks(Robot robot) {
+        for (int childInd = 0; childInd < getComponentCount(); childInd++) {
+            performFocusClick(getComponent(childInd), robot);
+        }
+    }
+    void performFocusClick(Component comp, Robot robot) {
+        clickComponent(comp, robot);
+    }
+
+    void performActionClicks(Robot robot) {
+        for (int childInd = 0; childInd < getComponentCount(); childInd++) {
+            performActionClick(getComponent(childInd), robot);
+        }
+    }
+    void performActionClick(Component comp, Robot robot) {
+    }
+
+    public TestPanel(int row, int col) {
+        setLayout(new FlowLayout());
+        Button b;
+        add(b = new Button("press"+ row + "" + col));
+        b.setName(b.getLabel());
+//         b.addMouseListener(new MouseAdapter() {
+//                 public void mousePressed(MouseEvent e) {
+//                     System.err.println(e);
+//                 }
+//             });
+        TextField t;
+        add(t = new TextField("text" + row + "" + col));
+        t.setName(t.getText());
+
+        java.awt.List list = new java.awt.List();
+        add(list);
+        list.setName("list");
+        list.add("one");
+        list.add("two");
+        list.add("three");
+        list.setMultipleMode(true);
+        list.setName("list" + row + "" + col);
+
+        Checkbox check = new Checkbox("checker");
+        add(check);
+        check.setName("check" + row + "" + col);
+
+        Choice choice = new Choice();
+        choice.add("one");
+        choice.add("two");
+        choice.add("three");
+        add(choice);
+        choice.setName("choice" + row + "" + col);
+
+        Canvas can = new Canvas() {
+                public Dimension getPreferredSize() {
+                    return new Dimension(10, 10);
+                }
+            };
+        can.setBackground(Color.blue);
+        add(can);
+        can.setName("canvas" + row + "" + col);
+
+        TextArea ta = new TextArea("text\ntttt\naaaa\nwwwww\nqqqqqq\neeeeee\nrrrrrr\nyyyyyy\nuuuuu", 3, 5);
+        add(ta);
+        ta.setName("textarea" + row + "" + col);
+
+        Scrollbar bar = new Scrollbar(Scrollbar.HORIZONTAL);
+        add(bar);
+        bar.setName("scrollbar" + row + "" + col);
+
+        CheckboxGroup group = new CheckboxGroup();
+        Checkbox ch1 = new Checkbox("one", group, true);
+        Checkbox ch2 = new Checkbox("two", group, false);
+        add(ch1);
+        add(ch2);
+        ch1.setName("checkbox1 " + row + "" + col);
+        ch2.setName("checkbox2 " + row + "" + col);
+
+
+        ScrollPane pane = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
+        add(pane);
+        Button bigButton = new Button("abc") {
+                public Dimension getPreferredSize() {
+                    return new Dimension(100, 100);
+                }
+            };
+        pane.add(bigButton);
+        bigButton.setName("bigbutton" + row + "" + col);
+    }
+}
+
+class GlobalListener implements AWTEventListener {
+    java.util.List errors = new java.util.LinkedList();
+    public boolean report() {
+        if (errors.size() != 0) {
+            System.err.println("Test FAILED");
+        } else {
+            System.err.println("Test PASSED");
+            return true;
+        }
+        ListIterator iter = errors.listIterator();
+        while (iter.hasNext()) {
+            System.err.println(iter.next());
+        }
+        return false;
+    }
+    public GlobalListener() {
+    }
+    Window getWindowParent(Component comp) {
+        while (comp != null && !(comp instanceof Window)) {
+            comp = comp.getParent();
+        }
+        return (Window)comp;
+    }
+    void reportError(AWTEvent e, String message) {
+        String error = "ERROR: " + message + " : " + e;
+        errors.add(error);
+        System.err.println(error);
+    }
+    public void eventDispatched(AWTEvent e) {
+        Component comp = (Component)e.getSource();
+        Window parent = getWindowParent(comp);
+        if (!(e instanceof WindowEvent || e instanceof FocusEvent)) {
+            System.err.println("Strange event " + e);
+        }
+
+        // Skip WINDOW_OPENED
+        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
+            System.err.println(e);
+        }
+        switch (e.getID()) {
+          case WindowEvent.WINDOW_OPENED:
+          case WindowEvent.WINDOW_CLOSING:
+          case WindowEvent.WINDOW_CLOSED:
+          case WindowEvent.WINDOW_ICONIFIED:
+          case WindowEvent.WINDOW_DEICONIFIED:
+          case WindowEvent.WINDOW_STATE_CHANGED:
+            return;
+          case WindowEvent.WINDOW_LOST_FOCUS: {
+              WindowEvent we = (WindowEvent)e;
+              if (we.getOppositeWindow() != null && !we.getOppositeWindow().getFocusableWindowState()) {
+                  reportError(e, "frame lost focus because of non-focusable window");
+              }
+              break;
+          }
+        }
+        // Check that Window owner is focusable
+        if (!parent.getFocusableWindowState()) {
+            reportError(e, "focus event for component in non-focusable window " + parent.getName());
+        }
+        if (!comp.isFocusable()) {
+            reportError(e, "focus event for non-focusable component");
+        }
+//         if (e instanceof WindowEvent || e instanceof FocusEvent) {
+// //             System.err.println(e);
+//         }
+    }
+}
+
+
--- a/jdk/test/java/awt/Focus/NonFocusableWindowTest/NonfocusableOwnerTest.java	Wed Mar 26 16:56:40 2008 +0300
+++ b/jdk/test/java/awt/Focus/NonFocusableWindowTest/NonfocusableOwnerTest.java	Wed Mar 26 17:38:26 2008 +0300
@@ -25,8 +25,10 @@
   @test
   @bug       6182359
   @summary   Tests that Window having non-focusable owner can't be a focus owner.
-  @author    Anton Tarasov: area=awt.focus
-  @run       applet NonfocusableOwnerTest.html
+  @author    Anton.Tarasov: area=awt.focus
+  @library   ../../regtesthelpers
+  @build     Util
+  @run       main NonfocusableOwnerTest
 */
 
 import java.awt.*;
@@ -34,319 +36,124 @@
 import java.applet.Applet;
 import java.lang.reflect.*;
 import java.io.*;
+import test.java.awt.regtesthelpers.Util;
 
 public class NonfocusableOwnerTest extends Applet {
-    Robot robot;
+    Robot robot = Util.createRobot();
     Frame frame;
     Dialog dialog;
     Window window1;
     Window window2;
     Button button = new Button("button");
-//    PrintStream Sysout = System.out;
 
     public static void main(String[] args) {
         NonfocusableOwnerTest test = new NonfocusableOwnerTest();
-        test.init();
         test.start();
     }
 
-    public void init() {
-        try {
-            robot = new Robot();
-        } catch (AWTException e) {
-            throw new RuntimeException("Error: unable to create robot", e);
-        }
-        // Create instructions for the user here, as well as set up
-        // the environment -- set the layout manager, add buttons,
-        // etc.
-        this.setLayout (new BorderLayout ());
-    }
-
     public void start() {
         Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
                 public void eventDispatched(AWTEvent e) {
-                    Sysout.println(e.toString());
+                    System.out.println(e.toString());
                 }
             }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK | WindowEvent.WINDOW_EVENT_MASK);
 
         frame = new Frame("Frame");
         frame.setName("Frame-owner");
+        frame.setBounds(100, 0, 100, 100);
         dialog = new Dialog(frame, "Dialog");
         dialog.setName("Dialog-owner");
+        dialog.setBounds(100, 0, 100, 100);
 
         window1 = new Window(frame);
         window1.setName("1st child");
+        window1.setBounds(100, 300, 100, 100);
         window2 = new Window(window1);
         window2.setName("2nd child");
+        window2.setBounds(100, 500, 100, 100);
 
         test1(frame, window1);
         test2(frame, window1, window2);
         test3(frame, window1, window2);
 
         window1 = new Window(dialog);
+        window1.setBounds(100, 300, 100, 100);
         window1.setName("1st child");
         window2 = new Window(window1);
         window2.setName("2nd child");
+        window2.setBounds(100, 500, 100, 100);
 
         test1(dialog, window1);
         test2(dialog, window1, window2);
         test3(dialog, window1, window2);
 
-        Sysout.println("Test passed.");
+        System.out.println("Test passed.");
     }
 
     void test1(Window owner, Window child) {
-        Sysout.println("* * * STAGE 1 * * *\nowner=" + owner);
+        System.out.println("* * * STAGE 1 * * *\nWindow owner: " + owner);
 
         owner.setFocusableWindowState(false);
-        owner.setSize(100, 100);
         owner.setVisible(true);
 
         child.add(button);
-        child.setBounds(0, 300, 100, 100);
         child.setVisible(true);
 
-        waitTillShown(child);
+        Util.waitTillShown(child);
 
-        clickOn(button);
+        Util.clickOnComp(button, robot);
         if (button == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
             throw new RuntimeException("Test Failed.");
         }
+        child.dispose();
         owner.dispose();
-        child.dispose();
     }
 
     void test2(Window owner, Window child1, Window child2) {
-        Sysout.println("* * * STAGE 2 * * *\nowner=" + owner);
+        System.out.println("* * * STAGE 2 * * *\nWindow nowner: " + owner);
 
         owner.setFocusableWindowState(false);
-        owner.setSize(100, 100);
         owner.setVisible(true);
 
         child1.setFocusableWindowState(true);
-        child1.setBounds(0, 300, 100, 100);
         child1.setVisible(true);
 
         child2.add(button);
-        child2.setBounds(0, 500, 100, 100);
         child2.setVisible(true);
 
-        clickOn(button);
+        Util.waitTillShown(child2);
+
+        Util.clickOnComp(button, robot);
         if (button == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
             throw new RuntimeException("Test failed.");
         }
-        owner.dispose();
+        child2.dispose();
         child1.dispose();
-        child2.dispose();
+        owner.dispose();
     }
 
     void test3(Window owner, Window child1, Window child2) {
-        Sysout.println("* * * STAGE 3 * * *\nowner=" + owner);
+        System.out.println("* * * STAGE 3 * * *\nWidow owner: " + owner);
 
         owner.setFocusableWindowState(true);
-        owner.setSize(100, 100);
         owner.setVisible(true);
 
         child1.setFocusableWindowState(false);
-        child1.setBounds(0, 300, 100, 100);
         child1.setVisible(true);
 
         child2.setFocusableWindowState(true);
         child2.add(button);
-        child2.setBounds(0, 500, 100, 100);
         child2.setVisible(true);
 
-        clickOn(button);
+        Util.waitTillShown(child2);
 
+        Util.clickOnComp(button, robot);
         System.err.println("focus owner: " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
         if (button != KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
             throw new RuntimeException("Test failed.");
         }
-        owner.dispose();
         child1.dispose();
         child2.dispose();
-    }
-
-    void clickOn(Component c) {
-        Point p = c.getLocationOnScreen();
-        Dimension d = c.getSize();
-
-        Sysout.println("Clicking " + c);
-
-        if (c instanceof Frame) {
-            robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + ((Frame)c).getInsets().top/2);
-        } else {
-            robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)(d.getHeight()/2));
-        }
-        robot.mousePress(InputEvent.BUTTON1_MASK);
-        robot.mouseRelease(InputEvent.BUTTON1_MASK);
-        waitForIdle();
-    }
-
-    void waitTillShown(Component c) {
-        while (true) {
-            try {
-                Thread.sleep(100);
-                c.getLocationOnScreen();
-                break;
-            } catch (InterruptedException e) {
-                throw new RuntimeException(e);
-            } catch (IllegalComponentStateException e) {}
-        }
-    }
-    void waitForIdle() {
-        try {
-            Toolkit.getDefaultToolkit().sync();
-            sun.awt.SunToolkit.flushPendingEvents();
-            EventQueue.invokeAndWait( new Runnable() {
-                    public void run() {} // Dummy implementation
-                });
-        } catch(InterruptedException ie) {
-            Sysout.println("waitForIdle, non-fatal exception caught:");
-            ie.printStackTrace();
-        } catch(InvocationTargetException ite) {
-            Sysout.println("waitForIdle, non-fatal exception caught:");
-            ite.printStackTrace();
-        }
-
-        // wait longer...
-        robot.delay(200);
+        owner.dispose();
     }
 }
-
-/****************************************************
- Standard Test Machinery
- DO NOT modify anything below -- it's a standard
-  chunk of code whose purpose is to make user
-  interaction uniform, and thereby make it simpler
-  to read and understand someone else's test.
- ****************************************************/
-
-/**
- This is part of the standard test machinery.
- It creates a dialog (with the instructions), and is the interface
-  for sending text messages to the user.
- To print the instructions, send an array of strings to Sysout.createDialog
-  WithInstructions method.  Put one line of instructions per array entry.
- To display a message for the tester to see, simply call Sysout.println
-  with the string to be displayed.
- This mimics System.out.println but works within the test harness as well
-  as standalone.
- */
-
-class Sysout
-{
-    static TestDialog dialog;
-
-    public static void createDialogWithInstructions( String[] instructions )
-    {
-        dialog = new TestDialog( new Frame(), "Instructions" );
-        dialog.printInstructions( instructions );
-        dialog.setVisible(true);
-        println( "Any messages for the tester will display here." );
-    }
-
-    public static void createDialog( )
-    {
-        dialog = new TestDialog( new Frame(), "Instructions" );
-        String[] defInstr = { "Instructions will appear here. ", "" } ;
-        dialog.printInstructions( defInstr );
-        dialog.setVisible(true);
-        println( "Any messages for the tester will display here." );
-    }
-
-
-    public static void printInstructions( String[] instructions )
-    {
-        dialog.printInstructions( instructions );
-    }
-
-
-    public static void println( String messageIn )
-    {
-        System.err.println(messageIn);
-    }
-
-}// Sysout  class
-
-/**
-  This is part of the standard test machinery.  It provides a place for the
-   test instructions to be displayed, and a place for interactive messages
-   to the user to be displayed.
-  To have the test instructions displayed, see Sysout.
-  To have a message to the user be displayed, see Sysout.
-  Do not call anything in this dialog directly.
-  */
-class TestDialog extends Dialog
-{
-
-    TextArea instructionsText;
-    TextArea messageText;
-    int maxStringLength = 80;
-
-    //DO NOT call this directly, go through Sysout
-    public TestDialog( Frame frame, String name )
-    {
-        super( frame, name );
-        int scrollBoth = TextArea.SCROLLBARS_BOTH;
-        instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
-        add( "North", instructionsText );
-
-        messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
-        add("Center", messageText);
-
-        pack();
-
-        setVisible(true);
-    }// TestDialog()
-
-    //DO NOT call this directly, go through Sysout
-    public void printInstructions( String[] instructions )
-    {
-        //Clear out any current instructions
-        instructionsText.setText( "" );
-
-        //Go down array of instruction strings
-
-        String printStr, remainingStr;
-        for( int i=0; i < instructions.length; i++ )
-        {
-            //chop up each into pieces maxSringLength long
-            remainingStr = instructions[ i ];
-            while( remainingStr.length() > 0 )
-            {
-                //if longer than max then chop off first max chars to print
-                if( remainingStr.length() >= maxStringLength )
-                {
-                    //Try to chop on a word boundary
-                    int posOfSpace = remainingStr.
-                        lastIndexOf( ' ', maxStringLength - 1 );
-
-                    if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
-
-                    printStr = remainingStr.substring( 0, posOfSpace + 1 );
-                    remainingStr = remainingStr.substring( posOfSpace + 1 );
-                }
-                //else just print
-                else
-                {
-                    printStr = remainingStr;
-                    remainingStr = "";
-                }
-
-                instructionsText.append( printStr + "\n" );
-
-            }// while
-
-        }// for
-
-    }//printInstructions()
-
-    //DO NOT call this directly, go through Sysout
-    public void displayMessage( String messageIn )
-    {
-        messageText.append( messageIn + "\n" );
-        System.out.println(messageIn);
-    }
-
-}// TestDialog  class
--- a/jdk/test/java/awt/Focus/NonFocusableWindowTest/Test.java	Wed Mar 26 16:56:40 2008 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,417 +0,0 @@
-/*
- * Copyright 2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-/*
-  @test
-  @bug 4452384
-  @summary Tests that non-focusable windows doesn't generate any focus events when accessed.
-  @author dom: area=awt.focus
-  @run main Test
-*/
-
-import java.awt.*;
-import java.awt.event.*;
-import java.util.*;
-
-public class Test extends Frame {
-    public static final int DEF_WIDTH = 400,
-        DEF_HEIGHT = 300,
-        DEF_TOP = 1,
-        DEF_LEFT = 100,
-        DEF_ROW = 0,
-        DEF_COL = 0;
-    static boolean automatic = true;
-    static Window[] windows;
-    static Frame main_frame, jumpingFrame;
-    static Button focus_button;
-    static Robot robot;
-    static void pause(int timeout) {
-        Toolkit.getDefaultToolkit().sync();
-        robot.waitForIdle();
-        robot.delay(100);
-    }
-    static GlobalListener listener;
-    public static void main(String[] args) {
-
-        listener = new GlobalListener();
-        Toolkit.getDefaultToolkit().addAWTEventListener(listener,
-                                                        AWTEvent.FOCUS_EVENT_MASK |
-                                                        AWTEvent.WINDOW_EVENT_MASK);
-        try{
-            robot = new Robot();
-        } catch(Exception e) {}
-        // Create several pairs - focusable Frame with focusable component(button) and non-focusable:
-        // window, resizable frame, non-resizable frame, dialog, non-resiable dialog
-        main_frame = new Frame("focusable frame");
-        focus_button = new Button("button to focus");
-        main_frame.add(focus_button);
-        main_frame.pack();
-        main_frame.setVisible(true);
-        main_frame.setLocation(10, 600);
-        main_frame.addWindowListener(new WindowAdapter() {
-                public void windowClosing(WindowEvent e) {
-                    listener.report();
-                    System.exit(0);
-                }
-            });
-
-        jumpingFrame = new Frame("Jumping frame");
-        jumpingFrame.setBounds(DEF_LEFT, DEF_TOP, DEF_WIDTH, DEF_HEIGHT);
-
-        windows = new Window[7];
-        windows[0] = new TestWindow(0, 0, false, main_frame);
-        //windows[1] = new TestWindow(2, 1, true, main_frame);
-        windows[2] = new Test(1, 0, false, true);
-        windows[3] = new Test(2, 0, false, false);
-        //windows[4] = new Test(3, 0, true, true);
-        windows[5] = new TestDialog(0, 1, false, true, main_frame);
-        windows[6] = new TestDialog(1, 1, false, false, main_frame);
-        if (!automatic) {
-            int windowInd;
-            for (windowInd = 0; windowInd < windows.length; windowInd++) {
-                if (windows[windowInd] != null) {
-                    windows[windowInd].setVisible(true);
-                }
-            }
-        }
-        // Run the test
-        // 1. Click on all controls, check for no focus events for non-focusable, right focus events for focusable
-        // 2. Perform some action with control, check if it works
-        if (automatic) {
-            int windowInd;
-            for (windowInd = 0; windowInd < windows.length; windowInd++) {
-                if (windows[windowInd] != null) {
-                    windows[windowInd].setVisible(true);
-                    focus_button.requestFocus();
-                    pause(1000);
-
-                    // Verify that click on non-focusable window causes no focus lost on active window
-                    performFocusClick(windows[windowInd]);
-                    focus_button.requestFocus();
-                    pause(500);
-                    performActionClick(windows[windowInd]);
-
-                    // Verify that toFront, toBack doesn't cause non-focusable window to become active
-                    jumpingFrame.setVisible(true);
-                    pause(1000);
-                      jumpingFrame.toBack();
-                      pause(500);
-                      jumpingFrame.toFront();
-                      pause(500);
-                      windows[windowInd].toBack();
-                      pause(500);
-                      windows[windowInd].toFront();
-                      pause(500);
-
-                    // Verify that iconifiyng/deiconfiying and
-                    // zooming/unzooming doesn't cause non-focusable
-                    // window to become active
-                    if (windows[windowInd] instanceof Frame) {
-                        Frame toTest = (Frame)windows[windowInd];
-                        // Deiconification currently doesn't work!
-//                        toTest.setExtendedState(Frame.ICONIFIED);
-//                        pause(500);
-//                        toTest.setExtendedState(Frame.NORMAL);
-                        pause(500);
-                        toTest.setExtendedState(Frame.MAXIMIZED_BOTH);
-                        pause(500);
-                        toTest.setExtendedState(Frame.NORMAL);
-                    }
-
-                    windows[windowInd].dispose();
-                    jumpingFrame.dispose();
-                }
-            }
-            pause(1000);
-            System.err.println("Test finished.");
-            if (!listener.report()) {
-                throw new RuntimeException("Test Failed. See error stream output for details");
-            }
-        }
-    }
-    static void performFocusClick(Window parent) {
-        if (parent == null) {
-            return;
-        }
-        for (int compInd = 0; compInd < parent.getComponentCount(); compInd++) {
-            Component child = parent.getComponent(compInd);
-            if (child instanceof TestPanel) {
-                TestPanel pan = (TestPanel)child;
-                pan.performFocusClicks(robot);
-                pause(100);
-            }
-        }
-    }
-    static void performActionClick(Window parent) {
-        if (parent == null) {
-            return;
-        }
-        for (int compInd = 0; compInd < parent.getComponentCount(); compInd++) {
-            Component child = parent.getComponent(compInd);
-            if (child instanceof TestPanel) {
-                TestPanel pan = (TestPanel)child;
-                pan.performActionClicks(robot);
-                pause(100);
-            }
-        }
-    }
-    public Test(int row, int col, boolean focusable, boolean resizable) {
-        super("Frame" + row + "" + col);
-        TestPanel panel = new TestPanel(row, col);
-        if (Test.automatic) {
-            row = Test.DEF_ROW;
-            col = Test.DEF_COL;
-        }
-        setName(getTitle());
-        add("Center", panel);
-        Label l = new Label(getClass().getSuperclass().getName() + ", " + (focusable?"focusable":"non-focusable") +
-                            ", " + (resizable?"resizable":"non-resizable"));
-        l.setBackground(Color.green);
-        add("North", l);
-        setBounds(Test.DEF_LEFT + DEF_WIDTH*col, DEF_TOP + DEF_HEIGHT*row, DEF_WIDTH, DEF_HEIGHT);
-        if (!focusable) {
-            setFocusableWindowState(false);
-        }
-        if (!resizable) {
-            setResizable(false);
-        }
-//        setVisible(true);
-    }
-}
-class TestWindow extends Window {
-    public TestWindow(int row, int col, boolean focusable, Frame owner) {
-        super(owner);
-        setName("Window" + row + "" + col);
-        TestPanel panel = new TestPanel(row, col);
-        if (Test.automatic) {
-            row = Test.DEF_ROW;
-            col = Test.DEF_COL;
-        }
-
-        add("Center", panel);
-        Label l = new Label(getClass().getSuperclass().getName() + ", " + (focusable?"focusable":"non-focusable") +
-                            ", " + (false?"resizable":"non-resizable"));
-        l.setBackground(Color.green);
-        add("North", l);
-
-        setBounds(Test.DEF_LEFT + Test.DEF_WIDTH*col, Test.DEF_TOP + Test.DEF_HEIGHT*row, Test.DEF_WIDTH, Test.DEF_HEIGHT);
-        if (!focusable) {
-            setFocusableWindowState(false);
-        }
-//        setVisible(true);
-    }
-}
-class TestDialog extends Dialog {
-    public TestDialog(int row, int col, boolean focusable, boolean resizable, Frame owner) {
-        super(owner);
-        setName("Dialog" + row + "" + col);
-        TestPanel panel = new TestPanel(row, col);
-        if (Test.automatic) {
-            row = Test.DEF_ROW;
-            col = Test.DEF_COL;
-        }
-
-        add("Center", panel);
-        Label l = new Label(getClass().getSuperclass().getName() + ", " + (focusable?"focusable":"non-focusable") +
-                            ", " + (resizable?"resizable":"non-resizable"));
-        l.setBackground(Color.green);
-        add("North", l);
-
-        setBounds(Test.DEF_LEFT + Test.DEF_WIDTH*col, Test.DEF_TOP + Test.DEF_HEIGHT*row, Test.DEF_WIDTH, Test.DEF_HEIGHT);
-        if (!focusable) {
-            setFocusableWindowState(false);
-        }
-        if (!resizable) {
-            setResizable(false);
-        }
-//        setVisible(true);
-    }
-}
-
-class TestPanel extends Panel {
-
-    void clickComponent(Component comp, Robot robot) {
-        if (comp instanceof Choice) {
-            return;
-        }
-        Point compLoc = comp.getLocationOnScreen();
-        Dimension size = comp.getSize();
-        robot.mouseMove(compLoc.x + size.width/2, compLoc.y + size.height/2);
-        robot.mousePress(InputEvent.BUTTON1_MASK);
-        robot.mouseRelease(InputEvent.BUTTON1_MASK);
-    }
-    void performFocusClicks(Robot robot) {
-        for (int childInd = 0; childInd < getComponentCount(); childInd++) {
-            performFocusClick(getComponent(childInd), robot);
-        }
-    }
-    void performFocusClick(Component comp, Robot robot) {
-        clickComponent(comp, robot);
-    }
-
-    void performActionClicks(Robot robot) {
-        for (int childInd = 0; childInd < getComponentCount(); childInd++) {
-            performActionClick(getComponent(childInd), robot);
-        }
-    }
-    void performActionClick(Component comp, Robot robot) {
-    }
-
-    public TestPanel(int row, int col) {
-        setLayout(new FlowLayout());
-        Button b;
-        add(b = new Button("press"+ row + "" + col));
-        b.setName(b.getLabel());
-//         b.addMouseListener(new MouseAdapter() {
-//                 public void mousePressed(MouseEvent e) {
-//                     System.err.println(e);
-//                 }
-//             });
-        TextField t;
-        add(t = new TextField("text" + row + "" + col));
-        t.setName(t.getText());
-
-        java.awt.List list = new java.awt.List();
-        add(list);
-        list.setName("list");
-        list.add("one");
-        list.add("two");
-        list.add("three");
-        list.setMultipleMode(true);
-        list.setName("list" + row + "" + col);
-
-        Checkbox check = new Checkbox("checker");
-        add(check);
-        check.setName("check" + row + "" + col);
-
-        Choice choice = new Choice();
-        choice.add("one");
-        choice.add("two");
-        choice.add("three");
-        add(choice);
-        choice.setName("choice" + row + "" + col);
-
-        Canvas can = new Canvas() {
-                public Dimension getPreferredSize() {
-                    return new Dimension(10, 10);
-                }
-            };
-        can.setBackground(Color.blue);
-        add(can);
-        can.setName("canvas" + row + "" + col);
-
-        TextArea ta = new TextArea("text\ntttt\naaaa\nwwwww\nqqqqqq\neeeeee\nrrrrrr\nyyyyyy\nuuuuu", 3, 5);
-        add(ta);
-        ta.setName("textarea" + row + "" + col);
-
-        Scrollbar bar = new Scrollbar(Scrollbar.HORIZONTAL);
-        add(bar);
-        bar.setName("scrollbar" + row + "" + col);
-
-        CheckboxGroup group = new CheckboxGroup();
-        Checkbox ch1 = new Checkbox("one", group, true);
-        Checkbox ch2 = new Checkbox("two", group, false);
-        add(ch1);
-        add(ch2);
-        ch1.setName("checkbox1 " + row + "" + col);
-        ch2.setName("checkbox2 " + row + "" + col);
-
-
-        ScrollPane pane = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
-        add(pane);
-        Button bigButton = new Button("abc") {
-                public Dimension getPreferredSize() {
-                    return new Dimension(100, 100);
-                }
-            };
-        pane.add(bigButton);
-        bigButton.setName("bigbutton" + row + "" + col);
-    }
-}
-
-class GlobalListener implements AWTEventListener {
-    java.util.List errors = new java.util.LinkedList();
-    public boolean report() {
-        if (errors.size() != 0) {
-            System.err.println("Test FAILED");
-        } else {
-            System.err.println("Test PASSED");
-            return true;
-        }
-        ListIterator iter = errors.listIterator();
-        while (iter.hasNext()) {
-            System.err.println(iter.next());
-        }
-        return false;
-    }
-    public GlobalListener() {
-    }
-    Window getWindowParent(Component comp) {
-        while (comp != null && !(comp instanceof Window)) {
-            comp = comp.getParent();
-        }
-        return (Window)comp;
-    }
-    void reportError(AWTEvent e, String message) {
-        String error = "ERROR: " + message + " : " + e;
-        errors.add(error);
-        System.err.println(error);
-    }
-    public void eventDispatched(AWTEvent e) {
-        Component comp = (Component)e.getSource();
-        Window parent = getWindowParent(comp);
-        if (!(e instanceof WindowEvent || e instanceof FocusEvent)) {
-            System.err.println("Strange event " + e);
-        }
-
-        // Skip WINDOW_OPENED
-        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
-            System.err.println(e);
-        }
-        switch (e.getID()) {
-          case WindowEvent.WINDOW_OPENED:
-          case WindowEvent.WINDOW_CLOSING:
-          case WindowEvent.WINDOW_CLOSED:
-          case WindowEvent.WINDOW_ICONIFIED:
-          case WindowEvent.WINDOW_DEICONIFIED:
-          case WindowEvent.WINDOW_STATE_CHANGED:
-            return;
-          case WindowEvent.WINDOW_LOST_FOCUS: {
-              WindowEvent we = (WindowEvent)e;
-              if (we.getOppositeWindow() != null && !we.getOppositeWindow().getFocusableWindowState()) {
-                  reportError(e, "frame lost focus because of non-focusable window");
-              }
-              break;
-          }
-        }
-        // Check that Window owner is focusable
-        if (!parent.getFocusableWindowState()) {
-            reportError(e, "focus event for component in non-focusable window " + parent.getName());
-        }
-        if (!comp.isFocusable()) {
-            reportError(e, "focus event for non-focusable component");
-        }
-//         if (e instanceof WindowEvent || e instanceof FocusEvent) {
-// //             System.err.println(e);
-//         }
-    }
-}
--- a/jdk/test/java/awt/Focus/TypeAhead/TestFocusFreeze.java	Wed Mar 26 16:56:40 2008 +0300
+++ b/jdk/test/java/awt/Focus/TypeAhead/TestFocusFreeze.java	Wed Mar 26 17:38:26 2008 +0300
@@ -22,467 +22,118 @@
  */
 
 /*
-@test
-@bug 6183877 6216005 6225560
-@summary Tests that keyboard input doesn't freeze due to type-ahead problems
-@author Denis Mikhalkin: area=awt.focus
-@run main/timeout=300 TestFocusFreeze
+   @test
+   @bug        6183877 6216005 6225560
+   @library    ../../regtesthelpers
+   @build      Util
+   @summary    Tests that keyboard input doesn't freeze due to type-ahead problems
+   @author     Denis.Mikhalkin, Anton.Tarasov: area=awt.focus
+   @run        main TestFocusFreeze
 */
 
-// Note the area= after Your Name in the author tag.  Here, you
-//  should put which functional area the test falls in.  See the
-//  AWT-core home page -> test areas and/or -> AWT team  for a list of
-//  areas.
-
-
-/**
- * TestFocusFreeze.java
- *
- * summary:  XXX A brief summary of what this tests
- */
-
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
-import java.util.concurrent.atomic.*;
-import sun.awt.SunToolkit;
-
-public class TestFocusFreeze
-{
-
-    //*** test-writer defined static variables go here ***
-
-
-    private static void init()
-    {
-        //*** Create instructions for the user here ***
-
-        FocusTest.test();
-
-    }//End  init()
-
-
+import java.awt.Component;
+import java.awt.DefaultKeyboardFocusManager;
+import java.awt.KeyboardFocusManager;
+import java.awt.Robot;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JFrame;
+import test.java.awt.regtesthelpers.Util;
 
-    /*****************************************************
-     * Standard Test Machinery Section
-     * DO NOT modify anything in this section -- it's a
-     * standard chunk of code which has all of the
-     * synchronisation necessary for the test harness.
-     * By keeping it the same in all tests, it is easier
-     * to read and understand someone else's test, as
-     * well as insuring that all tests behave correctly
-     * with the test harness.
-     * There is a section following this for test-
-     * classes
-     ******************************************************/
-    private static boolean theTestPassed = false;
-    private static boolean testGeneratedInterrupt = false;
-    private static String failureMessage = "";
-
-    private static Thread mainThread = null;
-
-    private static int sleepTime = 300000;
+public class TestFocusFreeze {
+    private static JFrame frame;
+    private static JDialog dialog;
+    private static JButton dlgButton;
+    private static JButton frameButton;
+    private static AtomicBoolean lock = new AtomicBoolean(false);
+    private static Robot robot = Util.createRobot();
 
-    // Not sure about what happens if multiple of this test are
-    //  instantiated in the same VM.  Being static (and using
-    //  static vars), it aint gonna work.  Not worrying about
-    //  it for now.
-    public static void main( String args[] ) throws InterruptedException
-    {
-        mainThread = Thread.currentThread();
-        try
-        {
-            init();
-        }
-        catch( TestPassedException e )
-        {
-            //The test passed, so just return from main and harness will
-            // interepret this return as a pass
-            return;
-        }
-        //At this point, neither test pass nor test fail has been
-        // called -- either would have thrown an exception and ended the
-        // test, so we know we have multiple threads.
+    public static void main(String[] args) {
+        boolean all_passed = true;
+        KeyboardFocusManager testKFM = new TestKFM(robot);
+        KeyboardFocusManager defKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager();
 
-        //Test involves other threads, so sleep and wait for them to
-        // called pass() or fail()
-        try
-        {
-            Thread.sleep( sleepTime );
-            //Timed out, so fail the test
-            throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
-        }
-        catch (InterruptedException e)
-        {
-            //The test harness may have interrupted the test.  If so, rethrow the exception
-            // so that the harness gets it and deals with it.
-            if( ! testGeneratedInterrupt ) throw e;
-
-            //reset flag in case hit this code more than once for some reason (just safety)
-            testGeneratedInterrupt = false;
-
-            if ( theTestPassed == false )
-            {
-                throw new RuntimeException( failureMessage );
+        for (int i = 0; i < 10; i++) {
+            test(testKFM, defKFM);
+            Util.waitForIdle(robot);
+            System.out.println("Iter " + i + ": " + (lock.get() ? "passed." : "failed!"));
+            if (!lock.get()) {
+                all_passed = false;
             }
         }
-
-    }//main
-
-    public static synchronized void setTimeoutTo( int seconds )
-    {
-        sleepTime = seconds * 1000;
-    }
-
-    public static synchronized void pass()
-    {
-        Sysout.println( "The test passed." );
-        Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
-        //first check if this is executing in main thread
-        if ( mainThread == Thread.currentThread() )
-        {
-            //Still in the main thread, so set the flag just for kicks,
-            // and throw a test passed exception which will be caught
-            // and end the test.
-            theTestPassed = true;
-            throw new TestPassedException();
+        if (!all_passed) {
+            throw new RuntimeException("Test failed: not all iterations passed!");
         }
-        theTestPassed = true;
-        testGeneratedInterrupt = true;
-        mainThread.interrupt();
-    }//pass()
-
-    public static synchronized void fail()
-    {
-        //test writer didn't specify why test failed, so give generic
-        fail( "it just plain failed! :-)" );
+        System.out.println("Test passed.");
     }
 
-    public static synchronized void fail( String whyFailed )
-    {
-        Sysout.println( "The test failed: " + whyFailed );
-        Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
-        //check if this called from main thread
-        if ( mainThread == Thread.currentThread() )
-        {
-            //If main thread, fail now 'cause not sleeping
-            throw new RuntimeException( whyFailed );
-        }
-        theTestPassed = false;
-        testGeneratedInterrupt = true;
-        failureMessage = whyFailed;
-        mainThread.interrupt();
-    }//fail()
-
-}// class TestFocusFreeze
-
-//This exception is used to exit from any level of call nesting
-// when it's determined that the test has passed, and immediately
-// end the test.
-class TestPassedException extends RuntimeException
-{
-}
-
-//*********** End Standard Test Machinery Section **********
-
-
-//************ Begin classes defined for the test ****************
-
-// if want to make listeners, here is the recommended place for them, then instantiate
-//  them in init()
-
-/* Example of a class which may be written as part of a test
-class NewClass implements anInterface
- {
-   static int newVar = 0;
-
-   public void eventDispatched(AWTEvent e)
-    {
-      //Counting events to see if we get enough
-      eventCount++;
-
-      if( eventCount == 20 )
-       {
-         //got enough events, so pass
-
-         TestFocusFreeze.pass();
-       }
-      else if( tries == 20 )
-       {
-         //tried too many times without getting enough events so fail
-
-         TestFocusFreeze.fail();
-       }
-
-    }// eventDispatched()
+    public static void test(final KeyboardFocusManager testKFM, final KeyboardFocusManager defKFM) {
+        frame = new JFrame("Frame");
+        dialog = new JDialog(frame, "Dialog", true);
+        dlgButton = new JButton("Dialog_Button");
+        frameButton = new JButton("Frame_Button");
 
- }// NewClass class
-
-*/
-
-
-//************** End classes defined for the test *******************
-
-
-
-
-/****************************************************
- Standard Test Machinery
- DO NOT modify anything below -- it's a standard
-  chunk of code whose purpose is to make user
-  interaction uniform, and thereby make it simpler
-  to read and understand someone else's test.
- ****************************************************/
+        lock.set(false);
 
-/**
- This is part of the standard test machinery.
- It creates a dialog (with the instructions), and is the interface
-  for sending text messages to the user.
- To print the instructions, send an array of strings to Sysout.createDialog
-  WithInstructions method.  Put one line of instructions per array entry.
- To display a message for the tester to see, simply call Sysout.println
-  with the string to be displayed.
- This mimics System.out.println but works within the test harness as well
-  as standalone.
- */
-
-class Sysout
-{
-    private static TestDialog dialog;
-
-    public static void createDialogWithInstructions( String[] instructions )
-    {
-        dialog = new TestDialog( new Frame(), "Instructions" );
-        dialog.printInstructions( instructions );
-        dialog.setVisible(true);
-        println( "Any messages for the tester will display here." );
-    }
-
-    public static void createDialog( )
-    {
-        dialog = new TestDialog( new Frame(), "Instructions" );
-        String[] defInstr = { "Instructions will appear here. ", "" } ;
-        dialog.printInstructions( defInstr );
-        dialog.setVisible(true);
-        println( "Any messages for the tester will display here." );
-    }
-
-
-    public static void printInstructions( String[] instructions )
-    {
-        dialog.printInstructions( instructions );
-    }
-
+        dialog.add(dlgButton);
+        dialog.setLocation(200, 0);
+        dialog.pack();
+        frame.add(frameButton);
+        frame.pack();
 
-    public static void println( String messageIn )
-    {
-        System.out.println(messageIn);
-    }
-
-}// Sysout  class
-
-/**
-  This is part of the standard test machinery.  It provides a place for the
-   test instructions to be displayed, and a place for interactive messages
-   to the user to be displayed.
-  To have the test instructions displayed, see Sysout.
-  To have a message to the user be displayed, see Sysout.
-  Do not call anything in this dialog directly.
-  */
-class TestDialog extends Dialog
-{
-
-    TextArea instructionsText;
-    TextArea messageText;
-    int maxStringLength = 80;
-
-    //DO NOT call this directly, go through Sysout
-    public TestDialog( Frame frame, String name )
-    {
-        super( frame, name );
-        int scrollBoth = TextArea.SCROLLBARS_BOTH;
-        instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
-        add( "North", instructionsText );
-
-        messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
-        add("Center", messageText);
-
-        pack();
-
-        setVisible(true);
-    }// TestDialog()
-
-    //DO NOT call this directly, go through Sysout
-    public void printInstructions( String[] instructions )
-    {
-        //Clear out any current instructions
-        instructionsText.setText( "" );
-
-        //Go down array of instruction strings
-
-        String printStr, remainingStr;
-        for( int i=0; i < instructions.length; i++ )
-        {
-            //chop up each into pieces maxSringLength long
-            remainingStr = instructions[ i ];
-            while( remainingStr.length() > 0 )
-            {
-                //if longer than max then chop off first max chars to print
-                if( remainingStr.length() >= maxStringLength )
-                {
-                    //Try to chop on a word boundary
-                    int posOfSpace = remainingStr.
-                        lastIndexOf( ' ', maxStringLength - 1 );
+        dlgButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                dialog.dispose();
+                frame.dispose();
+                synchronized (lock) {
+                    lock.set(true);
+                    lock.notifyAll();
+                }
+            }
+        });
 
-                    if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
-
-                    printStr = remainingStr.substring( 0, posOfSpace + 1 );
-                    remainingStr = remainingStr.substring( posOfSpace + 1 );
-                }
-                //else just print
-                else
-                {
-                    printStr = remainingStr;
-                    remainingStr = "";
-                }
-
-                instructionsText.append( printStr + "\n" );
-
-            }// while
-
-        }// for
-
-    }//printInstructions()
-
-    //DO NOT call this directly, go through Sysout
-    public void displayMessage( String messageIn )
-    {
-        messageText.append( messageIn + "\n" );
-        System.out.println(messageIn);
-    }
-
-}// TestDialog  class
-
-
-class FocusTest extends JFrame implements ActionListener {
-
-    private JDialog pageDialog = null;
-
-    private AtomicBoolean passed = new AtomicBoolean();
-    private static volatile boolean all_passed = true;
-    private static volatile long pressTime;
-    private static Object testLock = new Object();
-    private static Object resultLock = new Object();
-
-    public FocusTest() {
-        final GraphicsConfiguration gc =
-            GraphicsEnvironment.getLocalGraphicsEnvironment().
-            getDefaultScreenDevice().getDefaultConfiguration();
-
-        pageDialog = new JDialog(this, "JDialog", true, gc);
-        Container c = pageDialog.getContentPane();
-        c.setLayout(new BorderLayout());
-        JButton btnApprove =new JButton("Exit Button");
-        btnApprove.addActionListener(this);
-        c.add("South", btnApprove);
-        pageDialog.pack();
-
-        JButton bb = new JButton("Action");
-        bb.addActionListener(new ActionListener() {
-                final JDialog pageDialog = FocusTest.this.pageDialog;
+        frameButton.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent e) {
-                    synchronized(testLock) {
-                        testLock.notify();
-                    }
-                    pageDialog.setVisible(true);
+                    // Right before the dialog will be shown, there will be called
+                    // enqueuKeyEvents() method. We are to catch it.
+                    KeyboardFocusManager.setCurrentKeyboardFocusManager(testKFM);
+                    dialog.setVisible(true);
+                    KeyboardFocusManager.setCurrentKeyboardFocusManager(defKFM);
                 }
             });
 
-        add(bb);
-        pack();
-        setVisible(true);
-
-        ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
-
-        bb.requestFocus();
-
-        ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
-
-        if (!bb.isFocusOwner()) {
-            System.err.println("Couldn't make bb focused");
-            all_passed = false;
+        Runnable showAction = new Runnable() {
+            public void run() {
+                frame.setVisible(true);
+            }
+        };
+        if (!Util.trackFocusGained(frameButton, showAction, 2000, false)) {
+            System.out.println("Test error: wrong initial focus!");
             return;
         }
 
-        new Thread() {
-            public void run() {
-                try {
-                    Robot r = new Robot();
-                    synchronized (testLock) {
-                        testLock.wait();
-                    }
-                    r.keyPress(KeyEvent.VK_SPACE);
-                    r.delay(50);
-                    r.keyRelease(KeyEvent.VK_SPACE);
-                    synchronized(passed) {
-                        passed.wait(1000);
-                    }
-                    pageDialog.dispose();
-                    FocusTest.this.dispose();
-                    if (!passed.get()) {
-                        all_passed = false;
-                    }
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-                synchronized (resultLock) {
-                    resultLock.notifyAll();
-                }
-            }
-        }.start();
+        robot.keyPress(KeyEvent.VK_SPACE);
+        robot.delay(50);
+        robot.keyRelease(KeyEvent.VK_SPACE);
 
-        try {
-            Robot r = new Robot();
-            r.keyPress(KeyEvent.VK_SPACE);
-            r.delay(50);
-            r.keyRelease(KeyEvent.VK_SPACE);
-        } catch (Exception e) {
-            e.printStackTrace();
-            all_passed = false;
-            return;
-        }
-
-        try {
-            synchronized (resultLock) {
-                resultLock.wait();
-            }
-        } catch (InterruptedException ie) {
-            ie.printStackTrace();
-        }
-    }
-
-    public void actionPerformed(ActionEvent ae) {
-        System.err.println("Action performed");
-        passed.set(true);
-        synchronized(passed) {
-            passed.notify();
-        }
-    }
-
-    public static void test() {
-        FocusTest test = null;
-        for (int i = 0; i < 10; i++) {
-            test = new FocusTest();
-            try {
-                Thread.sleep(500);
-            } catch (InterruptedException e) {
-                break;
-            }
-        }
-        if (!all_passed) {
-            TestFocusFreeze.fail("Not all passed");
-        } else {
-            TestFocusFreeze.pass();
-        }
+        Util.waitForCondition(lock, 2000);
+        Util.waitForIdle(robot);
     }
 }
+
+class TestKFM extends DefaultKeyboardFocusManager {
+    Robot robot;
+    public TestKFM(Robot robot) {
+        this.robot = robot;
+    }
+    protected synchronized void enqueueKeyEvents(long after, Component untilFocused) {
+        super.enqueueKeyEvents(after, untilFocused);
+        robot.keyPress(KeyEvent.VK_SPACE);
+        robot.delay(50);
+        robot.keyRelease(KeyEvent.VK_SPACE);
+    }
+}
--- a/jdk/test/java/awt/Focus/WrongKeyTypedConsumedTest/WrongKeyTypedConsumedTest.java	Wed Mar 26 16:56:40 2008 +0300
+++ b/jdk/test/java/awt/Focus/WrongKeyTypedConsumedTest/WrongKeyTypedConsumedTest.java	Wed Mar 26 17:38:26 2008 +0300
@@ -22,21 +22,16 @@
  */
 
 /*
-  test
-  @bug 4782886
-  @summary FocusManager consumes wrong KEYTYPED-Events
-  @author son: area=awt.focus
-  @run applet WrongKeyTypedConsumedTest.html
+  @test
+  @bug      4782886
+  @summary  FocusManager consumes wrong KEY_TYPED events
+  @author   Oleg.Sukhodolsky: area=awt.focus
+  @library  ../../regtesthelpers
+  @build    Util
+  @run      main WrongKeyTypedConsumedTest
 */
 
-/**
- * WrongKeyTypedConsumedTest.java
- *
- * summary: FocusManager consumes wrong KEYTYPED-Events
- */
-
 import java.applet.Applet;
-
 import java.awt.AWTException;
 import java.awt.AWTKeyStroke;
 import java.awt.BorderLayout;
@@ -58,29 +53,19 @@
 import javax.swing.JFrame;
 import javax.swing.JTextArea;
 
+import test.java.awt.regtesthelpers.Util;
+
 public class WrongKeyTypedConsumedTest extends Applet
 {
-    //Declare things used in the test, like buttons and labels here
-
-    public void init()
-    {
-        //Create instructions for the user here, as well as set up
-        // the environment -- set the layout manager, add buttons,
-        // etc.
+    Robot robot = Util.createRobot();
 
-        String[] instructions =
-        {
-            "This is an AUTOMATIC test",
-            "simply wait until it is done"
-        };
-        Sysout.createDialog( );
-        Sysout.printInstructions( instructions );
-
-    }//End  init()
+    public static void main(String[] args) {
+        WrongKeyTypedConsumedTest test = new WrongKeyTypedConsumedTest();
+        test.start();
+    }
 
     public void start ()
     {
-        //Get things going.  Request focus, set size, et cetera
         setSize (200,200);
         setVisible(true);
         validate();
@@ -100,194 +85,45 @@
 
         frame.pack();
         frame.setVisible(true);
-
-        try {
-            Robot robot = new Robot();
+        Util.waitForIdle(robot);
 
-            // wait for activation
-            robot.delay(2000);
-            if (!frame.isActive()) {
-                Point loc = frame.getLocationOnScreen();
-                Dimension size = frame.getSize();
-                robot.mouseMove(loc.x + size.width/2,
-                                loc.y + size.height/2);
-                frame.toFront();
-                robot.delay(1000);
-                if (!frame.isActive()) {
-                    throw new RuntimeException("Test Fialed: frame isn't active");
-                }
-            }
+        if (!frame.isActive()) {
+            throw new RuntimeException("Test Fialed: frame isn't active");
+        }
 
-            // verify if checkbox has focus
+        // verify if checkbox has focus
+        if (!checkbox.isFocusOwner()) {
+            checkbox.requestFocusInWindow();
+            Util.waitForIdle(robot);
             if (!checkbox.isFocusOwner()) {
-                checkbox.requestFocusInWindow();
-                robot.delay(1000);
-                if (!checkbox.isFocusOwner()) {
-                    throw new RuntimeException("Test Failed: checkbox doesn't have focus");
-                }
-            }
-            // press VK_DOWN
-            robot.keyPress(KeyEvent.VK_DOWN);
-            robot.delay(250);
-            robot.keyRelease(KeyEvent.VK_DOWN);
-            robot.delay(1000);
-
-            // verify if text area has focus
-            if (!textarea.isFocusOwner()) {
-                throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
-            }
-            // press '1'
-            robot.keyPress(KeyEvent.VK_1);
-            robot.delay(250);
-            robot.keyRelease(KeyEvent.VK_1);
-            robot.delay(1000);
-
-            // verify if KEY_TYPED arraived
-            if (!"1".equals(textarea.getText())) {
-                throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
+                throw new RuntimeException("Test Failed: checkbox doesn't have focus");
             }
-        } catch(AWTException e) {
-            e.printStackTrace();
-            throw new RuntimeException("Test failed because of some internal exception");
         }
-        Sysout.println("Test Passed");
-    }// start()
-
-}// class WrongKeyTypedConsumedTest
-
-/****************************************************
- Standard Test Machinery
- DO NOT modify anything below -- it's a standard
-  chunk of code whose purpose is to make user
-  interaction uniform, and thereby make it simpler
-  to read and understand someone else's test.
- ****************************************************/
 
-/**
- This is part of the standard test machinery.
- It creates a dialog (with the instructions), and is the interface
-  for sending text messages to the user.
- To print the instructions, send an array of strings to Sysout.createDialog
-  WithInstructions method.  Put one line of instructions per array entry.
- To display a message for the tester to see, simply call Sysout.println
-  with the string to be displayed.
- This mimics System.out.println but works within the test harness as well
-  as standalone.
- */
-
-class Sysout
-{
-    private static TestDialog dialog;
-
-    public static void createDialogWithInstructions( String[] instructions )
-    {
-        dialog = new TestDialog( new Frame(), "Instructions" );
-        dialog.printInstructions( instructions );
-        dialog.setVisible(true);
-        println( "Any messages for the tester will display here." );
-    }
-
-    public static void createDialog( )
-    {
-        dialog = new TestDialog( new Frame(), "Instructions" );
-        String[] defInstr = { "Instructions will appear here. ", "" } ;
-        dialog.printInstructions( defInstr );
-        dialog.setVisible(true);
-        println( "Any messages for the tester will display here." );
-    }
+        // press VK_DOWN
+        robot.keyPress(KeyEvent.VK_DOWN);
+        robot.delay(50);
+        robot.keyRelease(KeyEvent.VK_DOWN);
+        robot.delay(50);
 
-
-    public static void printInstructions( String[] instructions )
-    {
-        dialog.printInstructions( instructions );
-    }
-
-
-    public static void println( String messageIn )
-    {
-        dialog.displayMessage( messageIn );
-    }
-
-}// Sysout  class
-
-/**
-  This is part of the standard test machinery.  It provides a place for the
-   test instructions to be displayed, and a place for interactive messages
-   to the user to be displayed.
-  To have the test instructions displayed, see Sysout.
-  To have a message to the user be displayed, see Sysout.
-  Do not call anything in this dialog directly.
-  */
-class TestDialog extends Dialog
-{
-
-    TextArea instructionsText;
-    TextArea messageText;
-    int maxStringLength = 80;
-
-    //DO NOT call this directly, go through Sysout
-    public TestDialog( Frame frame, String name )
-    {
-        super( frame, name );
-        int scrollBoth = TextArea.SCROLLBARS_BOTH;
-        instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
-        add( "North", instructionsText );
-
-        messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
-        add("Center", messageText);
-
-        pack();
-
-        setVisible(true);
-    }// TestDialog()
+        Util.waitForIdle(robot);
 
-    //DO NOT call this directly, go through Sysout
-    public void printInstructions( String[] instructions )
-    {
-        //Clear out any current instructions
-        instructionsText.setText( "" );
-
-        //Go down array of instruction strings
-
-        String printStr, remainingStr;
-        for( int i=0; i < instructions.length; i++ )
-        {
-            //chop up each into pieces maxSringLength long
-            remainingStr = instructions[ i ];
-            while( remainingStr.length() > 0 )
-            {
-                //if longer than max then chop off first max chars to print
-                if( remainingStr.length() >= maxStringLength )
-                {
-                    //Try to chop on a word boundary
-                    int posOfSpace = remainingStr.
-                        lastIndexOf( ' ', maxStringLength - 1 );
-
-                    if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
+        // verify if text area has focus
+        if (!textarea.isFocusOwner()) {
+            throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
+        }
+        // press '1'
+        robot.keyPress(KeyEvent.VK_1);
+        robot.delay(50);
+        robot.keyRelease(KeyEvent.VK_1);
+        robot.delay(50);
 
-                    printStr = remainingStr.substring( 0, posOfSpace + 1 );
-                    remainingStr = remainingStr.substring( posOfSpace + 1 );
-                }
-                //else just print
-                else
-                {
-                    printStr = remainingStr;
-                    remainingStr = "";
-                }
-
-                instructionsText.append( printStr + "\n" );
+        Util.waitForIdle(robot);
 
-            }// while
-
-        }// for
-
-    }//printInstructions()
-
-    //DO NOT call this directly, go through Sysout
-    public void displayMessage( String messageIn )
-    {
-        messageText.append( messageIn + "\n" );
-        System.out.println(messageIn);
+        // verify if KEY_TYPED arrived
+        if (!"1".equals(textarea.getText())) {
+            throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
+        }
+        System.out.println("Test Passed");
     }
-
-}// TestDialog  class
+}