Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JPopupMenu/6544309/bug6544309.java
38854 views
/*1* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/* @test23@bug 654430924@summary Checks that 'Select Input Method' popup menu allows to select25items with keyboard.26@author Mikhail Lapshin27@library ../../../../lib/testlibrary28@build ExtendedRobot29@run main bug654430930*/3132import javax.swing.*;33import java.awt.event.*;34import java.awt.*;3536public class bug6544309 {37private JDialog dialog;38private boolean passed;39private static ExtendedRobot robot;4041public static void main(String[] args) throws Exception {42robot = new ExtendedRobot();43final bug6544309 test = new bug6544309();44try {45SwingUtilities.invokeAndWait(new Runnable() {46public void run() {47test.setupUI();48}49});50test.test();51System.out.println("Test passed");52} finally {53if (test.dialog != null) {54test.dialog.dispose();55}56}57}5859private void setupUI() {60dialog = new JDialog();61dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);62dialog.setSize(200, 100);63dialog.setLocationRelativeTo(null);64dialog.setVisible(true);6566JPopupMenu popup = new JPopupMenu();67popup.add(new JMenuItem("one"));68JMenuItem two = new JMenuItem("two");69two.addActionListener(new ActionListener() {70public void actionPerformed(ActionEvent e) {71passed = true;72}73});74popup.add(two);75popup.add(new JMenuItem("three"));76popup.show(dialog, 50, 50);77}7879private void test() throws Exception {80testImpl();81checkResult();82}838485private void testImpl() throws Exception {86robot.waitForIdle();87System.out.println("Pressing DOWN ARROW");88robot.type(KeyEvent.VK_DOWN);89robot.waitForIdle();90System.out.println("Pressing DOWN ARROW");91robot.type(KeyEvent.VK_DOWN);92robot.waitForIdle();93System.out.println("Pressing SPACE");94robot.type(KeyEvent.VK_SPACE);95}9697private void checkResult() {98robot.waitForIdle();99if (!passed) {100throw new RuntimeException("If a JDialog is invoker for JPopupMenu, " +101"the menu cannot be handled by keyboard.");102}103}104}105106107