changeset 9830:c904d2c4425d

8039279: Move awt tests to openjdk repository Reviewed-by: pchelko, alexsch Contributed-by: Dmitriy Ermashov <dmitriy.ermashov@oracle.com>
author yan
date Mon, 21 Apr 2014 14:35:14 +0400
parents e128f966866a
children 85b7ff7d0ba7
files test/java/awt/Frame/SetMaximizedBounds/SetMaximizedBounds.java test/java/awt/GridLayout/ChangeGridSize/ChangeGridSize.java test/java/awt/GridLayout/ComponentPreferredSize/ComponentPreferredSize.java test/java/awt/Robot/ModifierRobotKey/ModifierRobotKeyTest.java test/java/awt/Toolkit/LockingKeyStateTest/LockingKeyStateTest.java
diffstat 5 files changed, 814 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/Frame/SetMaximizedBounds/SetMaximizedBounds.java	Mon Apr 21 14:35:14 2014 +0400
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.*;
+
+/*
+ * @test
+ * @summary When Frame.setExtendedState(Frame.MAXIMIZED_BOTH)
+ *          is called for a Frame after been called setMaximizedBounds() with
+ *          certain value, Frame bounds must equal to this value.
+ *
+ * @library ../../../../lib/testlibrary
+ * @build ExtendedRobot
+ * @run main SetMaximizedBounds
+ */
+
+public class SetMaximizedBounds {
+
+    Frame frame;
+    Rectangle bound;
+    boolean supported;
+    ExtendedRobot robot;
+    static Rectangle max = new Rectangle(100,100,400,400);
+
+    public void doTest() throws Exception {
+        robot = new ExtendedRobot();
+
+        EventQueue.invokeAndWait( () -> {
+            frame = new Frame( "TestFrame ");
+            frame.setLayout(new FlowLayout());
+
+            if (Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
+                supported = true;
+                frame.setMaximizedBounds(max);
+            } else {
+                supported = false;
+            }
+
+            frame.setSize(200, 200);
+            frame.setVisible(true);
+        });
+
+        robot.waitForIdle(2000);
+        if (supported) {
+            EventQueue.invokeAndWait( () -> {
+                frame.setExtendedState(Frame.MAXIMIZED_BOTH);
+            });
+            robot.waitForIdle(2000);
+            bound = frame.getBounds();
+            if(!bound.equals(max))
+                throw new RuntimeException("The bounds of the Frame do not equal to what"
+                    + " is specified when the frame is in Frame.MAXIMIZED_BOTH state");
+        } else {
+            System.out.println("Frame.MAXIMIZED_BOTH not supported");
+        }
+
+        frame.dispose();
+    }
+
+    public static void main(String[] args) throws Exception {
+        String os = System.getProperty("os.name").toLowerCase();
+        System.out.println(os);
+        if (os.contains("windows") || os.contains("os x"))
+            new SetMaximizedBounds().doTest();
+        else
+            System.out.println("Platform "+os+" is not supported. Supported platforms are Windows and OS X.");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/GridLayout/ChangeGridSize/ChangeGridSize.java	Mon Apr 21 14:35:14 2014 +0400
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+
+/*
+ * @test
+ * @summary Have different components having different preferred sizes
+ *          added to a grid layout. Change the rows and columns of the
+ *          grid layout and check the components are re-laid out.
+ *          The strategy followed is to calculate the component location
+ *          depending on the preferred sizes and gaps and click the cornors
+ *          of the components to check if events are triggered
+ * @library ../../../../lib/testlibrary/
+ * @build ExtendedRobot
+ * @run main ChangeGridSize
+ * @run main ChangeGridSize -hg 20 -vg 20
+ */
+
+public class ChangeGridSize {
+
+    private int width = 200;
+    private int height = 200;
+    private final int hGap, vGap;
+    private final int rows = 3;
+    private final int columns = 2;
+    private final int componentCount = 6;
+
+    private Button[] buttons;
+    private Frame frame;
+
+    private ExtendedRobot robot;
+    private GridLayout layout;
+
+    private volatile boolean actionPerformed = false;
+
+    public ChangeGridSize(int hGap, int vGap) throws Exception  {
+        this.hGap = hGap;
+        this.vGap = vGap;
+        robot = new ExtendedRobot();
+        EventQueue.invokeAndWait( () -> {
+            frame = new Frame("Test frame");
+            frame.setSize(width, height);
+            layout = new GridLayout(rows + 3, columns - 1, hGap, vGap);
+            frame.setLayout(layout);
+
+            buttons = new Button[componentCount];
+            for (int i = 0; i < componentCount; i++) {
+                buttons[i] = new Button("Button" + i);
+                frame.add(buttons[i]);
+                buttons[i].addActionListener( (event) -> { actionPerformed = true; });
+            }
+            frame.setVisible(true);
+        });
+    }
+
+    public static void main(String[] args) throws Exception {
+        int hGap = 0;
+        int vGap = 0;
+        for (int i = 0; i < args.length; i++) {
+            switch (args[i]) {
+                case "-hg":
+                    hGap = Integer.parseInt(args[++i]);
+                    break;
+                case "-vg":
+                    vGap = Integer.parseInt(args[++i]);
+                    break;
+            }
+        }
+        new ChangeGridSize(hGap, vGap).doTest();
+    }
+
+    private void resizeFrame() throws Exception {
+        EventQueue.invokeAndWait(() -> {
+            Insets insets = frame.getInsets();
+            double dH = (height-insets.top-insets.bottom - vGap*(rows-1)) % rows;
+            double dW = (width-insets.left-insets.right - hGap*(columns-1)) % columns;
+            height -= dH;
+            width -= dW;
+            frame.setSize(width, height);
+            frame.revalidate();
+        });
+        robot.waitForIdle();
+    }
+
+    private void changeGridSize() throws Exception {
+        EventQueue.invokeAndWait(() -> {
+            layout.setRows(rows);
+            layout.setColumns(columns);
+
+            frame.revalidate();
+        });
+        robot.waitForIdle();
+    }
+
+    public void testBoundaries(int topLeftX, int topLeftY, int bottomRightX, int bottomRightY) throws Exception {
+
+        actionPerformed = false;
+        robot.mouseMove(topLeftX, topLeftY);
+        robot.delay(500);
+        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+        robot.delay(500);
+        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+        robot.waitForIdle(3000);
+
+        if(!actionPerformed)
+            throw new RuntimeException("Clicking on the left top of button did not trigger action event");
+
+        actionPerformed = false;
+        robot.mouseMove(bottomRightX, bottomRightY);
+        robot.delay(500);
+        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+        robot.delay(500);
+        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+        robot.waitForIdle(3000);
+
+        if(!actionPerformed)
+            throw new RuntimeException("Clicking on the bottom right of button did not trigger action event");
+    }
+
+    private void doTest() throws Exception {
+        robot.waitForIdle();
+        changeGridSize();
+        resizeFrame();
+
+        int availableWidth = width - frame.getInsets().left -
+                frame.getInsets().right;
+        int componentWidth = (availableWidth + hGap) / columns - hGap;
+        int availableHeight = height - frame.getInsets().top -
+                frame.getInsets().bottom;
+        int componentHeight = (availableHeight + vGap) / rows - vGap;
+
+        for (int i = 0; i < buttons.length; i++) {
+            if (buttons[i].getSize().width != componentWidth ||
+                    buttons[i].getSize().height != componentHeight) {
+                throw new RuntimeException(
+                        "FAIL: Button " + i + " not of proper size" +
+                        "Expected: " + componentWidth + "*" + componentHeight +
+                        "Actual: " + buttons[i].getSize().width + "*" + buttons[i].getSize().height);
+            }
+        }
+
+        // Components are visible. They should trigger events.
+        // Now you can check for the actual size shown.
+        int currentRow = 1;
+        int currentColumn = 0;
+        for (int i = 0; i < buttons.length; i++) {
+            currentColumn++;
+            if (currentColumn > columns) {
+                currentColumn = 1;
+                currentRow++;
+            }
+
+            int topPosX = frame.getLocationOnScreen().x +
+                    frame.getInsets().left +
+                    (currentColumn - 1) * (componentWidth + hGap);
+            int topPosY = frame.getLocationOnScreen().y +
+                    frame.getInsets().top +
+                    (currentRow - 1) * (componentHeight + vGap);
+
+            int bottomPosX = topPosX + componentWidth - 1;
+            int bottomPosY = topPosY + componentHeight - 1;
+            testBoundaries(topPosX, topPosY, bottomPosX, bottomPosY);
+        }
+
+        frame.dispose();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/GridLayout/ComponentPreferredSize/ComponentPreferredSize.java	Mon Apr 21 14:35:14 2014 +0400
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.*;
+import java.awt.event.InputEvent;
+
+/*
+ * @test
+ * @summary Have different components having different preferred sizes
+ *          added to a grid layout having various values of row/columns.
+ *          Check if the compnents are correctly laid out.
+ *          The strategy followed is to calculate the component location
+ *          depending on the preferred sizes and gaps and click the cornors
+ *          of the components to check if events are triggered
+ * @library ../../../../lib/testlibrary/
+ * @build ExtendedRobot
+ * @run main ComponentPreferredSize
+ * @run main ComponentPreferredSize -hg 20 -vg 20
+ */
+
+public class ComponentPreferredSize {
+
+    private int width = 200;
+    private int height = 200;
+    private final int hGap, vGap;
+    private final int rows = 3;
+    private final int columns = 2;
+    private final int componentCount = 6;
+
+    private Button[] buttons;
+    private Frame frame;
+
+    private ExtendedRobot robot;
+    private GridLayout layout;
+
+    private volatile boolean actionPerformed = false;
+
+    public ComponentPreferredSize(int hGap, int vGap) throws Exception {
+        this.hGap = hGap;
+        this.vGap = vGap;
+        robot = new ExtendedRobot();
+        EventQueue.invokeAndWait( () -> {
+            frame = new Frame("Test frame");
+            frame.setSize(width, height);
+            layout = new GridLayout(rows, columns, hGap, vGap);
+            frame.setLayout(layout);
+
+            buttons = new Button[componentCount];
+            for (int i = 0; i < componentCount; i++) {
+                buttons[i] = new Button("Button" + i);
+                buttons[i].setPreferredSize(new Dimension((int) Math.random() * 100,
+                        (int) Math.random() * 100));
+                frame.add(buttons[i]);
+                buttons[i].addActionListener((event) -> {actionPerformed = true;});
+            }
+
+            frame.setVisible(true);
+        });
+    }
+
+    public static void main(String[] args) throws Exception {
+        int hGap = 0;
+        int vGap = 0;
+        for (int i = 0; i < args.length; i++) {
+            switch (args[i]) {
+                case "-hg":
+                    hGap = Integer.parseInt(args[++i]);
+                    break;
+                case "-vg":
+                    vGap = Integer.parseInt(args[++i]);
+                    break;
+            }
+        }
+        new ComponentPreferredSize(hGap, vGap).doTest();
+    }
+
+    private void resizeFrame() throws Exception {
+        EventQueue.invokeAndWait(() -> {
+            Insets insets = frame.getInsets();
+            double dH = (height-insets.top-insets.bottom - vGap*(rows-1)) % rows;
+            double dW = (width-insets.left-insets.right - hGap*(columns-1)) % columns;
+            height -= dH;
+            width -= dW;
+            frame.setSize(width, height);
+            frame.revalidate();
+        });
+        robot.waitForIdle();
+    }
+
+    public void testBoundaries(int topLeftX, int topLeftY, int bottomRightX, int bottomRightY) throws Exception {
+
+        actionPerformed = false;
+        robot.mouseMove(topLeftX, topLeftY);
+        robot.delay(500);
+        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+        robot.delay(500);
+        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+        robot.waitForIdle(3000);
+
+        if(!actionPerformed)
+            throw new RuntimeException("Clicking on the left top of button did not trigger action event");
+
+        actionPerformed = false;
+        robot.mouseMove(bottomRightX, bottomRightY);
+        robot.delay(500);
+        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+        robot.delay(500);
+        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+        robot.waitForIdle(3000);
+
+        if(!actionPerformed)
+            throw new RuntimeException("Clicking on the bottom right of button did not trigger action event");
+    }
+
+    private void doTest() throws Exception {
+        robot.waitForIdle();
+        resizeFrame();
+
+        int availableWidth = width - frame.getInsets().left -
+                frame.getInsets().right;
+        int componentWidth = (availableWidth + hGap) / columns - hGap;
+        int availableHeight = height - frame.getInsets().top -
+                frame.getInsets().bottom;
+        int componentHeight = (availableHeight + vGap) / rows - vGap;
+
+        for (int i = 0; i < buttons.length; i++) {
+            if (buttons[i].getSize().width != componentWidth ||
+                    buttons[i].getSize().height != componentHeight) {
+                throw new RuntimeException(
+                        "FAIL: Button " + i + " not of proper size" +
+                        "Expected: " + componentWidth + "*" + componentHeight +
+                        "Actual: " + buttons[i].getSize().width + "*" + buttons[i].getSize().height);
+            }
+        }
+
+        // Components are visible. They should trigger events.
+        // Now you can check for the actual size shown.
+        int currentRow = 1;
+        int currentColumn = 0;
+        for (int i = 0; i < buttons.length; i++) {
+            currentColumn++;
+            if (currentColumn > columns) {
+                currentColumn = 1;
+                currentRow++;
+            }
+
+            int topPosX = frame.getLocationOnScreen().x +
+                    frame.getInsets().left +
+                    (currentColumn - 1) * (componentWidth + hGap);
+            int topPosY = frame.getLocationOnScreen().y +
+                    frame.getInsets().top +
+                    (currentRow - 1) * (componentHeight + vGap);
+
+            int bottomPosX = topPosX + componentWidth - 1;
+            int bottomPosY = topPosY + componentHeight - 1;
+            testBoundaries(topPosX, topPosY, bottomPosX, bottomPosY);
+        }
+
+        frame.dispose();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/Robot/ModifierRobotKey/ModifierRobotKeyTest.java	Mon Apr 21 14:35:14 2014 +0400
@@ -0,0 +1,230 @@
+/*
+ * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+import java.awt.*;
+import java.awt.event.*;
+
+import static jdk.testlibrary.Asserts.assertTrue;
+
+/*
+ * @test
+ * @summary Make sure that modifier key mask is set when robot press
+ * some key with one or more modifiers.
+ *
+ * @library ../../../../lib/testlibrary/
+ * @build ExtendedRobot
+ * @run main ModifierRobotKeyTest
+ */
+
+public class ModifierRobotKeyTest extends KeyAdapter {
+
+    private boolean focusGained = false;
+    private boolean startTest = false;
+    private ExtendedRobot robot;
+    private Frame frame;
+    private Canvas canvas;
+
+    private volatile boolean tempPress = false;
+
+    private int[] textKeys, modifierKeys, inputMasks;
+    private boolean[] modifierStatus, textStatus;
+
+    private final static int waitDelay = 5000;
+    private Object tempLock = new Object();
+    private Object keyLock = new Object();
+
+    public static void main(String[] args) throws Exception {
+        ModifierRobotKeyTest test = new ModifierRobotKeyTest();
+        test.doTest();
+    }
+
+    public ModifierRobotKeyTest() throws Exception {
+        modifierKeys =  new int[3];
+        modifierKeys[0] = KeyEvent.VK_SHIFT;
+        modifierKeys[1] = KeyEvent.VK_CONTROL;
+        modifierKeys[2] = KeyEvent.VK_ALT;
+
+        inputMasks = new int[3];
+        inputMasks[0] =  InputEvent.SHIFT_MASK;
+        inputMasks[1] =  InputEvent.CTRL_MASK;
+        inputMasks[2] =  InputEvent.ALT_MASK;
+
+        modifierStatus = new boolean[modifierKeys.length];
+
+        textKeys = new int[2];
+        textKeys[0] = KeyEvent.VK_A;
+
+        String os = System.getProperty("os.name").toLowerCase();
+
+        if (os.contains("solaris") || os.contains("sunos"))
+            textKeys[1] = KeyEvent.VK_S;
+        else if (os.contains("os x"))
+            textKeys[1] = KeyEvent.VK_K;
+        else
+            textKeys[1] = KeyEvent.VK_I;
+
+        textStatus = new boolean[textKeys.length];
+
+        EventQueue.invokeAndWait( () -> { initializeGUI(); });
+    }
+
+    public void keyPressed(KeyEvent event) {
+
+        tempPress = true;
+        synchronized (tempLock) { tempLock.notifyAll(); }
+
+        if (! startTest) {
+            return;
+        }
+        for (int x = 0; x < inputMasks.length; x++) {
+            if ((event.getModifiers() & inputMasks[x]) != 0) {
+                System.out.println("Modifier set: " + event.getKeyModifiersText(inputMasks[x]));
+                modifierStatus[x] = true;
+            }
+        }
+        for (int x = 0; x < textKeys.length; x++) {
+            if (event.getKeyCode() == textKeys[x]) {
+                System.out.println("Text set: " + event.getKeyText(textKeys[x]));
+                textStatus[x] = true;
+            }
+        }
+
+        synchronized (keyLock) { keyLock.notifyAll(); }
+    }
+
+    private void initializeGUI() {
+        frame = new Frame("Test frame");
+        canvas = new Canvas();
+        canvas.addFocusListener(new FocusAdapter() {
+            public void focusGained(FocusEvent event) { focusGained = true; }
+        });
+        canvas.addKeyListener(this);
+        frame.setLayout(new BorderLayout());
+        frame.add(canvas);
+        frame.setSize(200, 200);
+        frame.setVisible(true);
+    }
+
+    public void doTest() throws Exception {
+        robot = new ExtendedRobot();
+
+        robot.mouseMove((int) frame.getLocationOnScreen().getX() + frame.getSize().width / 2,
+                        (int) frame.getLocationOnScreen().getY() + frame.getSize().height / 2);
+        robot.click(MouseEvent.BUTTON1_MASK);
+        robot.waitForIdle();
+
+        assertTrue(focusGained, "FAIL: Canvas gained focus!");
+
+        for (int i = 0; i < modifierKeys.length; i++) {
+            for (int j = 0; j < textKeys.length; j++) {
+                tempPress = false;
+                robot.keyPress(modifierKeys[i]);
+                robot.waitForIdle();
+                if (! tempPress) {
+                    synchronized (tempLock) { tempLock.wait(waitDelay); }
+                }
+                assertTrue(tempPress, "FAIL: keyPressed triggered for i=" + i);
+
+                resetStatus();
+                startTest = true;
+                robot.keyPress(textKeys[j]);
+                robot.waitForIdle();
+                if (! modifierStatus[i] || ! textStatus[j]) {
+                    synchronized (keyLock) { keyLock.wait(waitDelay); }
+                }
+
+
+                assertTrue(modifierStatus[i] && textStatus[j],
+                        "FAIL: KeyEvent not proper!"+
+                        "Key checked: i=" + i + "; j=" + j+
+                        "ModifierStatus = " + modifierStatus[i]+
+                        "TextStatus = " + textStatus[j]);
+                startTest = false;
+                robot.keyRelease(textKeys[j]);
+                robot.waitForIdle();
+                robot.keyRelease(modifierKeys[i]);
+                robot.waitForIdle();
+            }
+        }
+
+        for (int i = 0; i < modifierKeys.length; i++) {
+            for (int j = i + 1; j < modifierKeys.length; j++) {
+                for (int k = 0; k < textKeys.length; k++) {
+                    tempPress = false;
+                    robot.keyPress(modifierKeys[i]);
+                    robot.waitForIdle();
+                    if (! tempPress) {
+                        synchronized (tempLock) { tempLock.wait(waitDelay); }
+                    }
+
+                    assertTrue(tempPress, "FAIL: MultiKeyTest: keyPressed triggered for i=" + i);
+
+                    tempPress = false;
+                    robot.keyPress(modifierKeys[j]);
+                    robot.waitForIdle();
+                    if (! tempPress) {
+                        synchronized (tempLock) { tempLock.wait(waitDelay); }
+                    }
+                    assertTrue(tempPress, "FAIL: MultiKeyTest keyPressed triggered for j=" + j);
+
+                    resetStatus();
+                    startTest = true;
+                    robot.keyPress(textKeys[k]);
+                    robot.waitForIdle();
+                    if (! modifierStatus[i] || ! modifierStatus[j] || ! textStatus[k]) {
+                        synchronized (keyLock) {
+                            keyLock.wait(waitDelay);
+                        }
+                    }
+                    assertTrue(modifierStatus[i] && modifierStatus[j] && textStatus[k],
+                            "FAIL: KeyEvent not proper!"+
+                            "Key checked: i=" + i + "; j=" + j + "; k=" + k+
+                            "Modifier1Status = " + modifierStatus[i]+
+                            "Modifier2Status = " + modifierStatus[j]+
+                            "TextStatus = " + textStatus[k]);
+
+                    startTest = false;
+                    robot.keyRelease(textKeys[k]);
+                    robot.waitForIdle();
+                    robot.keyRelease(modifierKeys[j]);
+                    robot.waitForIdle();
+                    robot.keyRelease(modifierKeys[i]);
+                    robot.waitForIdle();
+                }
+            }
+        }
+
+        frame.dispose();
+    }
+
+    private void resetStatus() {
+        for (int i = 0; i < modifierStatus.length; i++) {
+            modifierStatus[i] = false;
+        }
+        for (int i = 0; i < textStatus.length; i++) {
+            textStatus[i] = false;
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/Toolkit/LockingKeyStateTest/LockingKeyStateTest.java	Mon Apr 21 14:35:14 2014 +0400
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.*;
+import java.awt.event.KeyEvent;
+
+/*
+  @test
+  @summary verify LOCK buttons toogle
+  @author Yuri.Nesterenko, Dmitriy.Ermashov
+  @library ../../../../lib/testlibrary
+  @build ExtendedRobot
+  @run main LockingKeyStateTest
+*/
+
+public class LockingKeyStateTest {
+
+    Frame frame;
+    ExtendedRobot robot;
+
+    // Note that Kana lock you may actually toggle only if you have one.
+    static int[] lockingKeys = { KeyEvent.VK_CAPS_LOCK, KeyEvent.VK_NUM_LOCK,
+            KeyEvent.VK_SCROLL_LOCK, KeyEvent.VK_KANA_LOCK };
+    boolean[] getSupported = new boolean[lockingKeys.length];
+    boolean[] setSupported = new boolean[lockingKeys.length];
+    boolean[] state0 = new boolean[lockingKeys.length];
+
+    Toolkit toolkit = Toolkit.getDefaultToolkit();
+
+    LockingKeyStateTest() throws Exception {
+        robot = new ExtendedRobot();
+        EventQueue.invokeAndWait( this::createGui );
+    }
+
+    void toggleAllTrue(){toggleAll(true);}
+    void toggleAllFalse(){toggleAll(false);}
+    void toggleAll(boolean b) {
+        for(int i = 0; i < lockingKeys.length; i++) {
+            if(setSupported[i]) {
+                toolkit.setLockingKeyState(lockingKeys[i], b);
+            }
+        }
+    }
+
+    void checkAllTrue(){checkAll(true);}
+    void checkAllFalse(){checkAll(false);}
+    void checkAll(boolean b) {
+        for(int i = 0; i < lockingKeys.length; i++) {
+            if(getSupported[i]  && setSupported[i]) {
+                if (!(toolkit.getLockingKeyState(lockingKeys[i]) == b))
+                    throw new RuntimeException("State of "+KeyEvent.getKeyText(lockingKeys[i])+" is not "+b);
+                System.out.println("OK, state of "+KeyEvent.getKeyText(lockingKeys[i])+" is "+b);
+            }
+        }
+    }
+
+    void restoreAll() {
+        for(int i = 0; i < lockingKeys.length; i++) {
+            if(setSupported[i] && getSupported[i]) {
+                toolkit.setLockingKeyState(lockingKeys[i], state0[i]);
+            }
+        }
+    }
+
+    public void createGui() {
+        for(int i = 0; i < lockingKeys.length; i++) {
+            getSupported[i] = false;
+            setSupported[i] = false;
+            try {
+                state0[i] = toolkit.getLockingKeyState(lockingKeys[i]);
+                getSupported[i] = true;
+                toolkit.setLockingKeyState(lockingKeys[i], state0[i]);
+                setSupported[i] = true;
+            } catch (UnsupportedOperationException uoe) {
+            }
+            System.out.println(" State get/set of "+KeyEvent.getKeyText(lockingKeys[i])+" is supported? "+
+                    getSupported[i]+", "+setSupported[i]);
+        }
+        frame = new Frame("LockingKeyStateTest Title");
+        frame.setSize(200,200);
+        frame.setVisible(true);
+    }
+
+    void doTest() throws Exception{
+        robot.waitForIdle();
+        robot.mouseMove(frame.getLocationOnScreen().x + frame.getWidth() / 2,
+                frame.getLocationOnScreen().y + frame.getHeight() / 2);
+        robot.click();
+
+        EventQueue.invokeAndWait( this::toggleAllTrue );
+        robot.waitForIdle(2000);
+        EventQueue.invokeAndWait( this::checkAllTrue );
+        EventQueue.invokeAndWait( this::toggleAllFalse );
+        robot.waitForIdle(2000);
+        EventQueue.invokeAndWait( this::checkAllFalse );
+        EventQueue.invokeAndWait( this::restoreAll );
+        robot.waitForIdle();
+
+        frame.dispose();
+    }
+
+    public static void main(String argv[]) throws Exception {
+        LockingKeyStateTest af = new LockingKeyStateTest();
+        af.doTest();
+    }
+}