Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
8273986: JEditorPane HTML Demo - Accessibility issues
Reviewed-by: kizune, serb
- Loading branch information
Abhishek Kumar
committed
Mar 24, 2023
1 parent
5727610
commit 9764948
Showing
4 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
test/jdk/javax/accessibility/JEditorPane/TestEditorPaneAccessibleChildCount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
9764948
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues