|
| 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.MouseAdapter; |
| 25 | +import java.awt.event.MouseEvent; |
| 26 | + |
| 27 | +import javax.swing.JFrame; |
| 28 | +import javax.swing.JMenu; |
| 29 | +import javax.swing.JMenuItem; |
| 30 | +import javax.swing.JPopupMenu; |
| 31 | + |
| 32 | +/* |
| 33 | + * @test |
| 34 | + * @bug 8341311 |
| 35 | + * @summary Verifies that VoiceOver announces correct number of child for PopupMenu on macOS |
| 36 | + * @requires os.family == "mac" |
| 37 | + * @library /java/awt/regtesthelpers |
| 38 | + * @build PassFailJFrame |
| 39 | + * @run main/manual TestPopupMenuChildCount |
| 40 | + */ |
| 41 | + |
| 42 | +public class TestPopupMenuChildCount { |
| 43 | + public static void main(String[] args) throws Exception { |
| 44 | + String INSTRUCTIONS = """ |
| 45 | + This test is applicable only on macOS. |
| 46 | +
|
| 47 | + Test UI contains an empty JFrame. On press of left/right mouse button, |
| 48 | + a PopupMenu will be visible. |
| 49 | +
|
| 50 | + Follow these steps to test the behaviour: |
| 51 | +
|
| 52 | + 1. Start the VoiceOver (Press Command + F5) application |
| 53 | + 2. Press Left/Right mouse button inside test frame window to open |
| 54 | + the PopupMenu |
| 55 | + 3. VO should announce "Menu" with number of child items of the Popupmenu |
| 56 | + 4. Press Up/Down arrow to traverse popupmenu child items |
| 57 | + 5. Press Right arrow key to open submenu |
| 58 | + 6. VO should announce "Menu" with correct number of child items |
| 59 | + for the submenu (For e.g. When Submenu-1 is open, VO should announce |
| 60 | + "Menu 4 items") |
| 61 | + 7. Repeat the process for other submenus |
| 62 | + 8. Press Pass if you are able to hear correct announcements |
| 63 | + else Fail"""; |
| 64 | + |
| 65 | + PassFailJFrame.builder() |
| 66 | + .instructions(INSTRUCTIONS) |
| 67 | + .columns(45) |
| 68 | + .testUI(TestPopupMenuChildCount::createUI) |
| 69 | + .build() |
| 70 | + .awaitAndCheck(); |
| 71 | + } |
| 72 | + |
| 73 | + private static JFrame createUI() { |
| 74 | + JFrame frame = new JFrame("Test Frame"); |
| 75 | + |
| 76 | + JPopupMenu popupmenu = new JPopupMenu(); |
| 77 | + JMenuItem mi1 = new JMenuItem("MenuItem-1"); |
| 78 | + JMenuItem mi2 = new JMenuItem("MenuItem-2"); |
| 79 | + JMenuItem mi3 = new JMenuItem("MenuItem-3"); |
| 80 | + popupmenu.add(mi1); |
| 81 | + popupmenu.add(mi2); |
| 82 | + popupmenu.add(mi3); |
| 83 | + |
| 84 | + JMenu submenu1 = new JMenu("Submenu-1"); |
| 85 | + submenu1.add("subOne"); |
| 86 | + submenu1.add("subTwo"); |
| 87 | + submenu1.add("subThree"); |
| 88 | + |
| 89 | + JMenu submenu2 = new JMenu("Submenu-2"); |
| 90 | + submenu2.add("subOne"); |
| 91 | + submenu2.add("subTwo"); |
| 92 | + |
| 93 | + JMenu submenu3 = new JMenu ("Submenu-3"); |
| 94 | + submenu3.add("subOne"); |
| 95 | + submenu1.add(submenu3); |
| 96 | + |
| 97 | + popupmenu.add(submenu1); |
| 98 | + popupmenu.add(submenu2); |
| 99 | + |
| 100 | + frame.addMouseListener(new MouseAdapter() { |
| 101 | + @Override |
| 102 | + public void mouseClicked(MouseEvent e) { |
| 103 | + popupmenu.show(e.getComponent(), e.getX(), e.getY()); |
| 104 | + } |
| 105 | + }); |
| 106 | + frame.setSize(300, 300); |
| 107 | + return frame; |
| 108 | + } |
| 109 | +} |
0 commit comments