--- /dev/null 2015-10-20 12:08:27.000000000 +0300 +++ new/test/java/awt/Focus/Cause/FocusCauseTest.java 2015-10-20 12:08:26.778484200 +0300 @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + @test + @bug 8080395 + @summary + @author Semyon Sadetsky + @run main AutoRequestFocusSetVisibleTest +*/ + + +import java.awt.*; +import java.awt.event.FocusEvent.Cause; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.util.Arrays; + +public class FocusCauseTest { + + private static Cause[] causes1 = {Cause.ACTIVATION, + Cause.UNKNOWN, Cause.UNKNOWN, Cause.TRAVERSAL_FORWARD, + Cause.TRAVERSAL_FORWARD, Cause.TRAVERSAL_BACKWARD, + Cause.TRAVERSAL_BACKWARD, Cause.TRAVERSAL_UP, + Cause.TRAVERSAL_DOWN}; + private static Cause[] causes2 = new Cause[9]; + private static int cnt; + + public static void main(String[] args) throws Exception { + Frame frame = new Frame(); + TextField comp1 = new TextField(); + comp1.addFocusListener(new FocusListener() { + @Override + public void focusGained(FocusEvent e) { + causes2[cnt++] = e.getCause(); + } + + @Override + public void focusLost(FocusEvent e) { + causes2[cnt++] = e.getCause(); + } + }); + TextField comp2 = new TextField(); + comp2.addFocusListener(new FocusListener() { + @Override + public void focusGained(FocusEvent e) { + causes2[cnt++] = e.getCause(); + } + + @Override + public void focusLost(FocusEvent e) { + causes2[cnt++] = e.getCause(); + } + }); + frame.add(comp1, BorderLayout.NORTH); + frame.add(comp2, BorderLayout.SOUTH); + frame.setVisible(true); + + Robot robot = new Robot(); + robot.delay(200); + robot.waitForIdle(); + comp2.requestFocus(); + robot.waitForIdle(); + comp2.transferFocus(); + robot.waitForIdle(); + comp1.transferFocusBackward(); + robot.waitForIdle(); + comp2.transferFocusUpCycle(); + robot.waitForIdle(); + frame.transferFocusDownCycle(); + robot.waitForIdle(); + frame.dispose(); + if (!Arrays.equals(causes1, causes2)) { + throw new RuntimeException("wrong cause " + causes2); + } + System.out.println("ok"); + } +}