|
| 1 | +/* |
| 2 | + * Copyright (c) 2026, 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.GridLayout; |
| 25 | +import java.lang.reflect.InvocationTargetException; |
| 26 | +import javax.swing.JLabel; |
| 27 | +import javax.swing.JPanel; |
| 28 | +import javax.swing.JSpinner; |
| 29 | +import javax.swing.SpinnerListModel; |
| 30 | + |
| 31 | +/* |
| 32 | + * @test |
| 33 | + * @bug 8286258 |
| 34 | + * @library /java/awt/regtesthelpers |
| 35 | + * @build PassFailJFrame |
| 36 | + * @requires (os.family == "mac") |
| 37 | + * @summary Checks that JSpinner with custom model announces |
| 38 | + * the value every time it is changed |
| 39 | + * @run main/manual CustomSpinnerAccessibilityTest |
| 40 | + */ |
| 41 | + |
| 42 | +public class CustomSpinnerAccessibilityTest extends JPanel { |
| 43 | + private static final String INSTRUCTIONS = """ |
| 44 | + 1. Turn on VoiceOver |
| 45 | + 2. In the window named "Test UI" click on the text editor inside the |
| 46 | + spinner component |
| 47 | + 3. Using up and down arrows change current month |
| 48 | + 4. Wait for the VoiceOver to finish speaking |
| 49 | + 5. Repeat steps 3 and 4 couple more times |
| 50 | +
|
| 51 | + If every time value of the spinner is changed VoiceOver |
| 52 | + announces the new value click "Pass". |
| 53 | + If instead the value is narrated only partially |
| 54 | + and the new value is never fully narrated press "Fail". |
| 55 | + """; |
| 56 | + |
| 57 | + public CustomSpinnerAccessibilityTest() { |
| 58 | + super(new GridLayout(0, 2)); |
| 59 | + String[] monthStrings = new java.text.DateFormatSymbols().getMonths(); |
| 60 | + int lastIndex = monthStrings.length - 1; |
| 61 | + if (monthStrings[lastIndex] == null |
| 62 | + || monthStrings[lastIndex].length() <= 0) { |
| 63 | + String[] tmp = new String[lastIndex]; |
| 64 | + System.arraycopy(monthStrings, 0, |
| 65 | + tmp, 0, lastIndex); |
| 66 | + monthStrings = tmp; |
| 67 | + } |
| 68 | + |
| 69 | + SpinnerListModel model = new SpinnerListModel(monthStrings); |
| 70 | + JLabel label = new JLabel("Month: "); |
| 71 | + add(label); |
| 72 | + JSpinner spinner = new JSpinner(model); |
| 73 | + label.setLabelFor(spinner); |
| 74 | + add(spinner); |
| 75 | + } |
| 76 | + |
| 77 | + public static void main(String[] args) throws InterruptedException, |
| 78 | + InvocationTargetException { |
| 79 | + PassFailJFrame.builder() |
| 80 | + .title("Custom Spinner Accessibility Test") |
| 81 | + .instructions(INSTRUCTIONS) |
| 82 | + .testUI(CustomSpinnerAccessibilityTest::new) |
| 83 | + .build() |
| 84 | + .awaitAndCheck(); |
| 85 | + } |
| 86 | +} |
0 commit comments