test/java/awt/Focus/8073453/AWTFocusTransitionTest.java

Print this page




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 8073453
  26  * @summary Focus doesn't move when pressing Shift + Tab keys
  27  * @author Dmitry Markov
  28  * @compile AWTFocusTransitionTest.java
  29  * @run main/othervm AWTFocusTransitionTest
  30  */
  31 import sun.awt.SunToolkit;
  32 
  33 import java.awt.*;
  34 import java.awt.event.KeyEvent;
  35 
  36 public class AWTFocusTransitionTest {
  37     private static SunToolkit toolkit;
  38     private static Robot robot;
  39 
  40     private static Frame frame;
  41     private static TextField textField;
  42     private static Button button;
  43 
  44     public static void main(String[] args) throws Exception {
  45         toolkit = (SunToolkit)Toolkit.getDefaultToolkit();
  46         robot = new Robot();
  47         robot.setAutoDelay(50);
  48 
  49         try {
  50             createAndShowGUI();
  51 
  52             toolkit.realSync();
  53 
  54             checkFocusOwner(textField);
  55 
  56             robot.keyPress(KeyEvent.VK_TAB);
  57             robot.keyRelease(KeyEvent.VK_TAB);
  58             toolkit.realSync();
  59 
  60             checkFocusOwner(button);
  61 
  62             robot.keyPress(KeyEvent.VK_SHIFT);
  63             robot.keyPress(KeyEvent.VK_TAB);
  64             robot.keyRelease(KeyEvent.VK_TAB);
  65             robot.keyRelease(KeyEvent.VK_SHIFT);
  66             toolkit.realSync();
  67 
  68             checkFocusOwner(textField);
  69 
  70             robot.keyPress(KeyEvent.VK_SHIFT);
  71             robot.keyPress(KeyEvent.VK_TAB);
  72             robot.keyRelease(KeyEvent.VK_TAB);
  73             robot.keyRelease(KeyEvent.VK_SHIFT);
  74             toolkit.realSync();
  75 
  76             checkFocusOwner(button);
  77         } finally {
  78             if (frame != null) {
  79                 frame.dispose();
  80             }
  81         }
  82         System.out.println("Test Passed!");
  83     }
  84 
  85     private static void createAndShowGUI() {
  86         frame = new Frame("AWTFocusTransitionTest");
  87         frame.setSize(300, 300);
  88         frame.setFocusTraversalPolicyProvider(true);
  89         frame.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());
  90 
  91         textField = new TextField();
  92         button = new Button();
  93 
  94         Panel panel = new Panel();




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 8073453
  26  * @summary Focus doesn't move when pressing Shift + Tab keys
  27  * @author Dmitry Markov
  28  * @compile AWTFocusTransitionTest.java
  29  * @run main/othervm AWTFocusTransitionTest
  30  */

  31 
  32 import java.awt.*;
  33 import java.awt.event.KeyEvent;
  34 
  35 public class AWTFocusTransitionTest {

  36     private static Robot robot;
  37 
  38     private static Frame frame;
  39     private static TextField textField;
  40     private static Button button;
  41 
  42     public static void main(String[] args) throws Exception {

  43         robot = new Robot();
  44         robot.setAutoDelay(50);
  45 
  46         try {
  47             createAndShowGUI();
  48 
  49             robot.waitForIdle();
  50 
  51             checkFocusOwner(textField);
  52 
  53             robot.keyPress(KeyEvent.VK_TAB);
  54             robot.keyRelease(KeyEvent.VK_TAB);
  55             robot.waitForIdle();
  56 
  57             checkFocusOwner(button);
  58 
  59             robot.keyPress(KeyEvent.VK_SHIFT);
  60             robot.keyPress(KeyEvent.VK_TAB);
  61             robot.keyRelease(KeyEvent.VK_TAB);
  62             robot.keyRelease(KeyEvent.VK_SHIFT);
  63             robot.waitForIdle();
  64 
  65             checkFocusOwner(textField);
  66 
  67             robot.keyPress(KeyEvent.VK_SHIFT);
  68             robot.keyPress(KeyEvent.VK_TAB);
  69             robot.keyRelease(KeyEvent.VK_TAB);
  70             robot.keyRelease(KeyEvent.VK_SHIFT);
  71             robot.waitForIdle();
  72 
  73             checkFocusOwner(button);
  74         } finally {
  75             if (frame != null) {
  76                 frame.dispose();
  77             }
  78         }
  79         System.out.println("Test Passed!");
  80     }
  81 
  82     private static void createAndShowGUI() {
  83         frame = new Frame("AWTFocusTransitionTest");
  84         frame.setSize(300, 300);
  85         frame.setFocusTraversalPolicyProvider(true);
  86         frame.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());
  87 
  88         textField = new TextField();
  89         button = new Button();
  90 
  91         Panel panel = new Panel();