Path: blob/master/test/jdk/java/awt/MenuBar/SeparatorsNavigation/SeparatorsNavigation.java
41153 views
/*1* Copyright (c) 2020, 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*/2223import java.awt.Frame;24import java.awt.Menu;25import java.awt.MenuBar;26import java.awt.MenuItem;27import java.awt.Robot;28import java.awt.event.ActionEvent;29import java.awt.event.ActionListener;30import java.awt.event.KeyEvent;3132/*33* @test34* @bug 626347035* @requires (os.family != "mac")36* @key headful37* @summary Menu bugs in XAWT38* @author Vyacheslav.Baranov: area= menu39* @run main SeparatorsNavigation40*/4142/**43* SeparatorsNavigation.java44*45* summary: Creates menu bar with menu consisting of two46* separators, then tries to navigate it using keyboard.47*/4849public class SeparatorsNavigation {50static class Listener implements ActionListener {51public void actionPerformed(ActionEvent e) {52SeparatorsNavigation.pressed = true;53}54}5556static Frame f;57static MenuBar mb;58static Menu m1;59static Menu m2;60static Menu m3;61static MenuItem i31;62static Listener l = new Listener();63static boolean pressed = false;6465public static void main(String args[]) {66f = new Frame();67mb = new MenuBar();68m1 = new Menu("m1");69m2 = new Menu("m2");70m3 = new Menu("m3");71m1.add(new MenuItem("i11"));72m2.add(new MenuItem("-"));73m2.add(new MenuItem("-"));74mb.add(m1);75mb.add(m2);76mb.add(m3);77i31 = new MenuItem("i31");78m3.add(i31);79i31.addActionListener(l);80f.setMenuBar(mb);81f.setSize(400, 400);82f.setVisible(true);83try {84Robot r = new Robot();85r.delay(1000);86r.keyPress(KeyEvent.VK_F10);87r.delay(10);88r.keyRelease(KeyEvent.VK_F10);89r.delay(1000);90r.keyPress(KeyEvent.VK_DOWN);91r.delay(10);92r.keyRelease(KeyEvent.VK_DOWN);93r.delay(1000);94r.keyPress(KeyEvent.VK_RIGHT);95r.delay(10);96r.keyRelease(KeyEvent.VK_RIGHT);97r.delay(1000);98r.keyPress(KeyEvent.VK_RIGHT);99r.delay(10);100r.keyRelease(KeyEvent.VK_RIGHT);101r.delay(1000);102r.keyPress(KeyEvent.VK_ENTER);103r.delay(10);104r.keyRelease(KeyEvent.VK_ENTER);105r.delay(10000);106} catch (Exception ex) {107throw new RuntimeException("Execution interrupted by an " +108"exception " + ex.getLocalizedMessage());109} finally {110if (f != null) {111f.setVisible(false);112f.dispose();113}114}115if (!pressed) {116throw new RuntimeException("Action was not performed, " +117"considering test failed.");118}119}120}121122