|
| 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.BorderLayout; |
| 25 | +import java.awt.GridLayout; |
| 26 | + |
| 27 | +import javax.swing.JCheckBox; |
| 28 | +import javax.swing.JFrame; |
| 29 | +import javax.swing.JPanel; |
| 30 | +import javax.swing.JToggleButton; |
| 31 | + |
| 32 | +/* |
| 33 | + * @test |
| 34 | + * @bug 8348936 8345728 |
| 35 | + * @summary Verifies that VoiceOver announces the untick state of CheckBox and |
| 36 | + * ToggleButton when space key is pressed. Also verifies that CheckBox |
| 37 | + * and ToggleButton untick state is magnified with Screen Magnifier. |
| 38 | + * @requires os.family == "mac" |
| 39 | + * @library /java/awt/regtesthelpers |
| 40 | + * @build PassFailJFrame |
| 41 | + * @run main/manual TestJCheckBoxToggleAccessibility |
| 42 | + */ |
| 43 | + |
| 44 | +public class TestJCheckBoxToggleAccessibility { |
| 45 | + public static void main(String[] args) throws Exception { |
| 46 | + String INSTRUCTIONS = """ |
| 47 | + <html><body> |
| 48 | + <p><b>Testing with VoiceOver</b></p> |
| 49 | +
|
| 50 | + <ol> |
| 51 | + <li>Start the VoiceOver application |
| 52 | + (Press <kbd>Command</kbd> + <kbd>F5</kbd>) |
| 53 | + <li>Click on the <i>Frame with CheckBox and ToggleButton</i> |
| 54 | + window to move focus |
| 55 | + <li>Press <kbd>Spacebar</kbd> |
| 56 | + <li>VO should announce the checked state |
| 57 | + <li>Press <kbd>Spacebar</kbd> again |
| 58 | + <li>VO should announce the unchecked state |
| 59 | + <li>Press <kbd>Tab</kbd> to move focus to <i>ToggleButton</i> |
| 60 | + <li>Repeat steps 3 to 6 and listen the announcement |
| 61 | + <li>If announcements are incorrect, press <b>Fail</b> |
| 62 | + <li>Stop the VoiceOver application |
| 63 | + (Press <kbd>Command</kbd> + <kbd>F5</kbd> again) |
| 64 | + </ol> |
| 65 | +
|
| 66 | + <p><b>Testing with Screen Magnifier</b></p> |
| 67 | + <ol style="margin-bottom: 0"> |
| 68 | + <li>Enable Screen magnifier on the Mac: |
| 69 | + <b>System Settings</b> -> <b>Accessibility</b> -> |
| 70 | + <b>Hover Text</b> -> Enable <b>Hover Text</b><br> |
| 71 | + Default Hover Text Activation Modifier is <kbd>Command</kbd> key |
| 72 | + <li>Move focus back to the test application and perform the following tests |
| 73 | +
|
| 74 | + <ul style="margin-bottom: 0"> |
| 75 | + <li>Test <i>CheckBox</i> states with Screen Magnifier |
| 76 | + <ol style="list-style-type: lower-alpha; margin-top: 0; margin-bottom: 0"> |
| 77 | + <li>Click on <i>CheckBox</i> to select it |
| 78 | + <li>Press the <kbd>Command</kbd> key and |
| 79 | + hover mouse over <i>CheckBox</i> |
| 80 | + <li>CheckBox ticked state along with its label should be magnified |
| 81 | + <li>Keep the <kbd>Command</kbd> key pressed and |
| 82 | + click <i>CheckBox</i> to deselect it |
| 83 | + <li>CheckBox unticked state along with its label should be magnified |
| 84 | + <li>Release the <kbd>Command</kbd> key |
| 85 | + <li>If Screen Magnifier behaviour is incorrect, press <b>Fail</b> |
| 86 | + </ol> |
| 87 | + <li>Test <i>ToggleButton</i> states with Screen Magnifier |
| 88 | + <ol style="list-style-type: lower-alpha; margin-top: 0; margin-bottom: 0"> |
| 89 | + <li>Click on <i>ToggleButton</i> to select it |
| 90 | + <li>Press the <kbd>Command</kbd> key and |
| 91 | + hover mouse over <i>ToggleButton</i> |
| 92 | + <li>Ticked state along with label should be magnified |
| 93 | + <li>Keep the <kbd>Command</kbd> button pressed and |
| 94 | + click <i>ToggleButton</i> to deselect it |
| 95 | + <li>Unticked state along with its label should be magnified |
| 96 | + <li>Release the <kbd>Command</kbd> key |
| 97 | + <li>If Screen Magnifier behaviour is incorrect, press <b>Fail</b> |
| 98 | + </ol> |
| 99 | + </ul> |
| 100 | + <li>Disable <b>Hover Text</b> (optionally) in the Settings |
| 101 | + </ol> |
| 102 | +
|
| 103 | + <p>Press <b>Pass</b> if you are able to hear correct VoiceOver announcements and |
| 104 | + able to see the correct screen magnifier behaviour.</p></body></html>"""; |
| 105 | + |
| 106 | + PassFailJFrame.builder() |
| 107 | + .title("TestJCheckBoxToggleAccessibility Instruction") |
| 108 | + .instructions(INSTRUCTIONS) |
| 109 | + .columns(40) |
| 110 | + .rows(25) |
| 111 | + .testUI(TestJCheckBoxToggleAccessibility::createUI) |
| 112 | + .testTimeOut(8) |
| 113 | + .build() |
| 114 | + .awaitAndCheck(); |
| 115 | + } |
| 116 | + |
| 117 | + private static JFrame createUI() { |
| 118 | + JFrame frame = new JFrame("A Frame with CheckBox and ToggleButton"); |
| 119 | + JCheckBox cb = new JCheckBox("CheckBox", false); |
| 120 | + JToggleButton tb = new JToggleButton("ToggleButton"); |
| 121 | + |
| 122 | + JPanel p = new JPanel(new GridLayout(2, 1)); |
| 123 | + p.add(cb); |
| 124 | + p.add(tb); |
| 125 | + frame.getContentPane().add(p, BorderLayout.CENTER); |
| 126 | + frame.setSize(400, 400); |
| 127 | + return frame; |
| 128 | + } |
| 129 | +} |
0 commit comments