8273986: JEditorPane HTML Demo - Accessibility issues
Reviewed-by: kizune, serb
This commit is contained in:
parent
57276101df
commit
97649489d0
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. 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
|
||||
@ -184,6 +184,9 @@ class AccessibleHTML implements Accessible {
|
||||
|
||||
rootElementInfo = new ElementInfo(root);
|
||||
rootElementInfo.validate();
|
||||
if (rootHTMLAccessibleContext != null) {
|
||||
rootHTMLAccessibleContext.setElementInfo(rootElementInfo);
|
||||
}
|
||||
} finally {
|
||||
unlock(lock);
|
||||
}
|
||||
@ -308,6 +311,10 @@ class AccessibleHTML implements Accessible {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void setElementInfo(ElementInfo elementInfo) {
|
||||
this.elementInfo = elementInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the state set of this object.
|
||||
*
|
||||
|
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Oracle and/or its affiliates. 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 8273986
|
||||
* @key headful
|
||||
* @requires (os.family == "windows")
|
||||
* @summary Verifies if accessible child count for JEditorPane HTML demo
|
||||
* returns correct child count.
|
||||
* @run main TestEditorPaneAccessibleChildCount
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.text.html.HTMLEditorKit;
|
||||
|
||||
public class TestEditorPaneAccessibleChildCount {
|
||||
private static JEditorPane jep;
|
||||
private static AccessibleContext ac;
|
||||
private static JFrame frame;
|
||||
private static int childCount1 = 0;
|
||||
private static int childCount2 = 0;
|
||||
|
||||
|
||||
public TestEditorPaneAccessibleChildCount() {
|
||||
createAndShowUI();
|
||||
}
|
||||
|
||||
public void createAndShowUI() {
|
||||
frame = new JFrame("JEditorPane A11Y Child Count Test");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
JPanel panel = new JPanel();
|
||||
jep = new JEditorPane();
|
||||
jep.setEditable(false);
|
||||
jep.setEditorKit(new HTMLEditorKit());
|
||||
URL url = TestEditorPaneAccessibleChildCount.class.
|
||||
getResource("test1.html");
|
||||
loadHtmlPage(url);
|
||||
JScrollPane jScrollPane = new JScrollPane(jep);
|
||||
jScrollPane.setPreferredSize(new Dimension(540,400));
|
||||
panel.add(jScrollPane);
|
||||
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||
frame.setSize(560, 450);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
public static void loadHtmlPage(URL url) {
|
||||
try {
|
||||
jep.setPage(url);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void addDelay(int mSec) {
|
||||
try {
|
||||
Thread.sleep(mSec);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
new TestEditorPaneAccessibleChildCount();
|
||||
});
|
||||
|
||||
addDelay(500);
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
ac = jep.getAccessibleContext();
|
||||
childCount1 = ac.getAccessibleChildrenCount();
|
||||
});
|
||||
|
||||
URL url = TestEditorPaneAccessibleChildCount.class.
|
||||
getResource("test2.html");
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
loadHtmlPage(url);
|
||||
});
|
||||
addDelay(500);
|
||||
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
childCount2 = ac.getAccessibleChildrenCount();
|
||||
if ((childCount1 != childCount2) &&
|
||||
(childCount1 != 0 && childCount2 != 0)) {
|
||||
System.out.println("passed");
|
||||
} else {
|
||||
System.out.println("Test1 html page accessible children" +
|
||||
" count is: " + childCount1);
|
||||
System.out.println("Test2 html page accessible children" +
|
||||
" count is: " + childCount2);
|
||||
throw new RuntimeException("getAccessibleChildrenCount" +
|
||||
" returned wrong child count");
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
if (frame != null) {
|
||||
frame.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
10
test/jdk/javax/accessibility/JEditorPane/test1.html
Normal file
10
test/jdk/javax/accessibility/JEditorPane/test1.html
Normal file
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
|
||||
<h1>Welcome to Java World</h1>
|
||||
<h2>Chapter 1</h2>
|
||||
<P>Introduction to Java</p>
|
||||
|
||||
</body>
|
||||
</html>
|
12
test/jdk/javax/accessibility/JEditorPane/test2.html
Normal file
12
test/jdk/javax/accessibility/JEditorPane/test2.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
|
||||
<h1>Welcome to Java World</h1>
|
||||
<h2>Chapter 1</h2>
|
||||
<P>Introduction to Java</p>
|
||||
<h2>Chapter 2</h2>
|
||||
<P>Data Types in Java</p>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user