1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
/*
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, JetBrains s.r.o.. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8267388
* @summary Test implementation of NSAccessibilityTable protocol peer
* @run main/manual AccessibleJTableTest
* @requires (os.family == "windows" | os.family == "mac")
*/
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.AbstractTableModel;
public class AccessibleJTableTest extends AccessibleComponentTest {
private static final String[] columnNames = {"One", "Two", "Three"};
private static final String[][] data = {
{"One1", "Two1", "Three1"},
{"One2", "Two2", "Three2"},
{"One3", "Two3", "Three3"},
{"One4", "Two4", "Three4"},
{"One5", "Two5", "Three5"}
};
@Override
public CountDownLatch createCountDownLatch() {
return new CountDownLatch(1);
}
public void createUI() {
INSTRUCTIONS = "INSTRUCTIONS:\n"
+ "Check a11y of JTable.\n\n"
+ "Turn screen reader on, and Tab to the table.\n"
+ "On Windows press the arrow buttons to move through the table.\n\n"
+ "On MacOS, use the up and down arrow buttons to move through rows, and VoiceOver fast navigation to move through columns.\n\n"
+ "If you can hear table cells ctrl+tab further and press PASS, otherwise press FAIL.\n";
JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
JScrollPane scrollPane = new JScrollPane(table);
panel.add(scrollPane);
panel.setFocusable(false);
exceptionString = "AccessibleJTable test failed!";
super.createUI(panel, "AccessibleJTableTest");
}
public void createUIDraggable() {
INSTRUCTIONS = "INSTRUCTIONS:\n"
+ "Check that table is properly updated when column order is changed.\n\n"
+ "Turn screen reader on, and Tab to the table.\n"
+ "Using arrow keys navigate to the last cell in the first row in the table."
+ "Screen reader should announce it as \"Column 3 row 1\"\n\n"
+ "Using mouse drag the header of the last column so the last column becomes the first one."
+ "Wait for the screen reader to finish announcing new position in table.\n\n"
+ "If new position in table corresponds to the new table layout ctrl+tab further "
+ "and press PASS, otherwise press FAIL.\n";
JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
JScrollPane scrollPane = new JScrollPane(table);
panel.add(scrollPane);
panel.setFocusable(false);
exceptionString = "AccessibleJTable test failed!";
super.createUI(panel, "AccessibleJTableTest");
}
public void createUINamed() {
INSTRUCTIONS = "INSTRUCTIONS:\n"
+ "Check a11y of named JTable.\n\n"
+ "Turn screen reader on, and Tab to the table.\n"
+ "Press the ctrl+tab button to move to second table.\n\n"
+ "If you can hear second table name: \"second table\" - ctrl+tab further and press PASS, otherwise press FAIL.\n";
JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
JTable secondTable = new JTable(data, columnNames);
secondTable.setPreferredScrollableViewportSize(secondTable.getPreferredSize());
secondTable.getAccessibleContext().setAccessibleName("Second table");
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
JScrollPane scrollPane = new JScrollPane(table);
JScrollPane secondScrollPane = new JScrollPane(secondTable);
panel.add(scrollPane);
panel.add(secondScrollPane);
panel.setFocusable(false);
exceptionString = "AccessibleJTable test failed!";
super.createUI(panel, "AccessibleJTableTest");
}
public void createUIWithChangingContent() {
INSTRUCTIONS = "INSTRUCTIONS:\n"
+ "Check a11y of dynamic JTable.\n\n"
+ "Turn screen reader on, and Tab to the table.\n"
+ "Add and remove rows and columns using the appropriate buttons and try to move around the table\n\n"
+ "If you hear changes in the table - ctrl+tab further and press PASS, otherwise press FAIL.\n";
JTable table = new JTable(new TestTableModel(3, 3));
table.setPreferredScrollableViewportSize(table.getPreferredSize());
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
JScrollPane scrollPane = new JScrollPane(table);
panel.add(scrollPane);
JPanel buttonPanel = new JPanel(new GridLayout());
JButton addRow = new JButton("Add row");
addRow.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
table.setModel(new TestTableModel(table.getModel().getRowCount() + 1, table.getModel().getColumnCount()));
}
});
JButton addColumn = new JButton("Add column");
addColumn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
table.setModel(new TestTableModel(table.getModel().getRowCount(), table.getModel().getColumnCount() + 1));
}
});
JButton removeRow = new JButton("Remove row");
removeRow.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
table.setModel(new TestTableModel(table.getModel().getRowCount() - 1, table.getModel().getColumnCount()));
}
});
JButton removeColumn = new JButton("Remove column");
removeColumn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
table.setModel(new TestTableModel(table.getModel().getRowCount(), table.getModel().getColumnCount() - 1));
}
});
buttonPanel.add(addRow);
buttonPanel.add(addColumn);
buttonPanel.add(removeRow);
buttonPanel.add(removeColumn);
panel.add(buttonPanel);
panel.setFocusable(false);
exceptionString = "AccessibleJTable test failed!";
super.createUI(panel, "AccessibleJTableTest");
}
public static void main(String[] args) throws Exception {
AccessibleJTableTest test = new AccessibleJTableTest();
countDownLatch = test.createCountDownLatch();
SwingUtilities.invokeAndWait(test::createUI);
countDownLatch.await(15, TimeUnit.MINUTES);
if (!testResult) {
throw new RuntimeException(exceptionString);
}
countDownLatch = test.createCountDownLatch();
SwingUtilities.invokeAndWait(test::createUIDraggable);
countDownLatch.await(15, TimeUnit.MINUTES);
if (!testResult) {
throw new RuntimeException(exceptionString);
}
countDownLatch = test.createCountDownLatch();
SwingUtilities.invokeAndWait(test::createUINamed);
countDownLatch.await(15, TimeUnit.MINUTES);
if (!testResult) {
throw new RuntimeException(exceptionString);
}
countDownLatch = test.createCountDownLatch();
SwingUtilities.invokeAndWait(test::createUIWithChangingContent);
countDownLatch.await(15, TimeUnit.MINUTES);
if (!testResult) {
throw new RuntimeException(exceptionString);
}
}
private static class TestTableModel extends AbstractTableModel {
private final int rows;
private final int cols;
TestTableModel(final int r, final int c) {
super();
rows = r;
cols = c;
}
@Override
public int getRowCount() {
return rows >= 0 ? rows : 0;
}
@Override
public int getColumnCount() {
return cols >= 0 ? cols : 0;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
return String.valueOf((rowIndex + 1) * (columnIndex + 1));
}
}
}
|