|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 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 | +import java.awt.event.InputEvent; |
| 25 | +import java.awt.event.KeyEvent; |
| 26 | +import javax.swing.JFrame; |
| 27 | +import javax.swing.JMenu; |
| 28 | +import javax.swing.JMenuBar; |
| 29 | +import javax.swing.JMenuItem; |
| 30 | +import javax.swing.KeyStroke; |
| 31 | + |
| 32 | +/* |
| 33 | + * @test |
| 34 | + * @bug 8339728 |
| 35 | + * @summary Tests that JAWS announce the shortcuts for JMenuItems. |
| 36 | + * @requires os.family == "windows" |
| 37 | + * @library /java/awt/regtesthelpers |
| 38 | + * @build PassFailJFrame |
| 39 | + * @run main/manual TestJMenuItemShortcutAccessibility |
| 40 | + */ |
| 41 | + |
| 42 | +public class TestJMenuItemShortcutAccessibility { |
| 43 | + public static void main(String[] args) throws Exception { |
| 44 | + String INSTRUCTIONS = """ |
| 45 | + 1. Start the JAWS application |
| 46 | + 2. Press Alt + M to open application Menu |
| 47 | + 3. Navigate the Menu Items by using UP / DOWN arrow key |
| 48 | + 4. Press Pass if you are able to hear correct JAWS announcements |
| 49 | + (JAWS should read full shortcut text and not only the 1st |
| 50 | + character of shortcut text for each menu item) else Fail |
| 51 | + """; |
| 52 | + |
| 53 | + PassFailJFrame.builder() |
| 54 | + .title("TestJMenuItemShortcutAccessibility Instruction") |
| 55 | + .instructions(INSTRUCTIONS) |
| 56 | + .columns(35) |
| 57 | + .testUI(TestJMenuItemShortcutAccessibility::createUI) |
| 58 | + .build() |
| 59 | + .awaitAndCheck(); |
| 60 | + } |
| 61 | + |
| 62 | + private static JFrame createUI() { |
| 63 | + JFrame frame = new JFrame("A Frame with Menu"); |
| 64 | + |
| 65 | + JMenuBar menuBar = new JMenuBar(); |
| 66 | + JMenu menu = new JMenu("Menu with shortcuts"); |
| 67 | + menu.setMnemonic(KeyEvent.VK_M); |
| 68 | + menuBar.add(menu); |
| 69 | + |
| 70 | + KeyStroke keyStroke1 = KeyStroke.getKeyStroke(KeyEvent.VK_F, |
| 71 | + InputEvent.CTRL_DOWN_MASK); |
| 72 | + KeyStroke keyStroke2 = KeyStroke.getKeyStroke(KeyEvent.VK_2, |
| 73 | + InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK); |
| 74 | + KeyStroke keyStroke3 = KeyStroke.getKeyStroke(KeyEvent.VK_F1, |
| 75 | + InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK); |
| 76 | + KeyStroke keyStroke4 = KeyStroke.getKeyStroke(KeyEvent.VK_COMMA, |
| 77 | + InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK); |
| 78 | + KeyStroke keyStroke5 = KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD, |
| 79 | + InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK); |
| 80 | + KeyStroke keyStroke6 = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, |
| 81 | + InputEvent.CTRL_DOWN_MASK); |
| 82 | + KeyStroke keyStroke7 = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, |
| 83 | + InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK); |
| 84 | + |
| 85 | + JMenuItem menuItem1 = new JMenuItem("First Menu Item"); |
| 86 | + menuItem1.setAccelerator(keyStroke1); |
| 87 | + JMenuItem menuItem2 = new JMenuItem("Second Menu Item"); |
| 88 | + menuItem2.setAccelerator(keyStroke2); |
| 89 | + JMenuItem menuItem3 = new JMenuItem("Third Menu Item"); |
| 90 | + menuItem3.setAccelerator(keyStroke3); |
| 91 | + JMenuItem menuItem4 = new JMenuItem("Fourth Menu Item"); |
| 92 | + menuItem4.setAccelerator(keyStroke4); |
| 93 | + JMenuItem menuItem5 = new JMenuItem("Fifth Menu Item"); |
| 94 | + menuItem5.setAccelerator(keyStroke5); |
| 95 | + JMenuItem menuItem6 = new JMenuItem("Sixth Menu Item"); |
| 96 | + menuItem6.setAccelerator(keyStroke6); |
| 97 | + JMenuItem menuItem7 = new JMenuItem("Seventh Menu Item"); |
| 98 | + menuItem7.setAccelerator(keyStroke7); |
| 99 | + |
| 100 | + menu.add(menuItem1); |
| 101 | + menu.add(menuItem2); |
| 102 | + menu.add(menuItem3); |
| 103 | + menu.add(menuItem4); |
| 104 | + menu.add(menuItem5); |
| 105 | + menu.add(menuItem6); |
| 106 | + menu.add(menuItem7); |
| 107 | + |
| 108 | + frame.setJMenuBar(menuBar); |
| 109 | + frame.setSize(300, 200); |
| 110 | + return frame; |
| 111 | + } |
| 112 | +} |
1 commit comments
openjdk-notifier[bot] commentedon Jan 9, 2025
Review
Issues