|
| 1 | +/* |
| 2 | + * Copyright (c) 2023, 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 | +/* |
| 25 | + * @test |
| 26 | + * @bug 8283404 |
| 27 | + * @library /java/awt/regtesthelpers |
| 28 | + * @build PassFailJFrame |
| 29 | + * @requires (os.family == "mac") |
| 30 | + * @summary Verifies if JMenu accessibility label magnifies using |
| 31 | + * screen magnifier a11y tool. |
| 32 | + * @run main/manual TestJMenuScreenMagnifier |
| 33 | + */ |
| 34 | + |
| 35 | +import java.lang.reflect.InvocationTargetException; |
| 36 | +import javax.swing.JFrame; |
| 37 | +import javax.swing.JMenu; |
| 38 | +import javax.swing.JMenuBar; |
| 39 | +import javax.swing.JMenuItem; |
| 40 | +import javax.swing.SwingUtilities; |
| 41 | + |
| 42 | +public class TestJMenuScreenMagnifier { |
| 43 | + private static JFrame frame; |
| 44 | + private static final String INSTRUCTIONS = |
| 45 | + "1) Enable Screen magnifier on theMac \n\n" + |
| 46 | + "System Preference -> Accessibility -> Zoom -> " + |
| 47 | + "Select ( Enable Hover Text) \n\n" + |
| 48 | + "2) Move the mouse over the \"File\" or \"Edit\" menu by pressing " + |
| 49 | + "\"cmd\" button.\n\n" + |
| 50 | + "3) If magnified label is visible, Press Pass else Fail."; |
| 51 | + |
| 52 | + public static void main(String[] args) throws InterruptedException, |
| 53 | + InvocationTargetException { |
| 54 | + PassFailJFrame passFailJFrame = new PassFailJFrame( |
| 55 | + "JMenu Screen Magnifier Test Instructions", INSTRUCTIONS, 5, 12, 40); |
| 56 | + try { |
| 57 | + SwingUtilities.invokeAndWait( |
| 58 | + TestJMenuScreenMagnifier::createAndShowUI); |
| 59 | + passFailJFrame.awaitAndCheck(); |
| 60 | + } finally { |
| 61 | + SwingUtilities.invokeAndWait(() -> { |
| 62 | + if (frame != null) { |
| 63 | + frame.dispose(); |
| 64 | + } |
| 65 | + }); |
| 66 | + } |
| 67 | + } |
| 68 | + private static void createAndShowUI() { |
| 69 | + frame = new JFrame("JMenu A11Y Screen Magnifier Test"); |
| 70 | + |
| 71 | + JMenu file = new JMenu("File"); |
| 72 | + file.getAccessibleContext().setAccessibleName("File Menu"); |
| 73 | + |
| 74 | + JMenuItem open = new JMenuItem("Open"); |
| 75 | + open.getAccessibleContext().setAccessibleName("Open MenuItem"); |
| 76 | + |
| 77 | + JMenuItem quit = new JMenuItem("Quit"); |
| 78 | + quit.getAccessibleContext().setAccessibleName("Quit MenuItem"); |
| 79 | + |
| 80 | + file.add(open); |
| 81 | + file.add(quit); |
| 82 | + |
| 83 | + JMenu edit = new JMenu("Edit"); |
| 84 | + edit.getAccessibleContext().setAccessibleName("Edit Menu"); |
| 85 | + |
| 86 | + JMenuItem cut = new JMenuItem("Cut"); |
| 87 | + cut.getAccessibleContext().setAccessibleName("Cut MenuItem"); |
| 88 | + |
| 89 | + edit.add(cut); |
| 90 | + |
| 91 | + JMenuBar jMenuBar = new JMenuBar(); |
| 92 | + |
| 93 | + jMenuBar.add(file); |
| 94 | + jMenuBar.add(edit); |
| 95 | + |
| 96 | + |
| 97 | + PassFailJFrame.addTestWindow(frame); |
| 98 | + PassFailJFrame.positionTestWindow(frame, |
| 99 | + PassFailJFrame.Position.HORIZONTAL); |
| 100 | + frame.setJMenuBar(jMenuBar); |
| 101 | + frame.setSize(300, 100); |
| 102 | + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 103 | + frame.setVisible(true); |
| 104 | + } |
| 105 | +} |
0 commit comments