Skip to content

Commit ad6f34f

Browse files
committed
8353320: Open source more Swing text tests
Backport-of: 74c2d8f41bbb770e959a77ae1ce468162d68beaf
1 parent 61c1590 commit ad6f34f

File tree

9 files changed

+418
-0
lines changed

9 files changed

+418
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 2005, 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+
/* @test
25+
* @bug 4463014
26+
* @summary Tests if JEditorPane updates the correct frame when using <FORM target="xxxx">
27+
* @library /java/awt/regtesthelpers
28+
* @build PassFailJFrame
29+
* @run main/manual bug4463014
30+
*/
31+
32+
import java.io.File;
33+
import javax.swing.JEditorPane;
34+
import javax.swing.JFrame;
35+
import javax.swing.text.html.HTMLEditorKit;
36+
37+
public class bug4463014 {
38+
39+
static final String INSTRUCTIONS = """
40+
The test window displays an HTML frameset with a frame
41+
on the left and another to the right.
42+
Follow the instructions displayed in the left frame to perform testing.
43+
The test PASSES only if the test behaves as per instructions.
44+
""";
45+
46+
static JFrame createUI() {
47+
JFrame frame = new JFrame("bug4463014");
48+
JEditorPane jep = new JEditorPane();
49+
jep.setEditorKit(new HTMLEditorKit());
50+
jep.setEditable(false);
51+
52+
try {
53+
File file = new File(System.getProperty("test.src", "."), "frameset.html");
54+
System.out.println(file.toURL());
55+
jep.setPage(file.toURL());
56+
} catch (Exception e) {
57+
}
58+
59+
frame.add(jep);
60+
frame.setSize(500,500);
61+
return frame;
62+
}
63+
64+
65+
public static void main(String[] args) throws Exception {
66+
PassFailJFrame.builder()
67+
.title("Test Instructions")
68+
.instructions(INSTRUCTIONS)
69+
.columns(40)
70+
.testUI(bug4463014::createUI)
71+
.build()
72+
.awaitAndCheck();
73+
}
74+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<body>
3+
Push the <span style="color:blue">Submit query</span> button
4+
<FORM ACTION="./frameresult.html" METHOD=post TARGET="main" >
5+
<input type="text" name="Selection"><BR>
6+
<INPUT type="submit">
7+
</FORM>
8+
</body>
9+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<HTML>
2+
<BODY>
3+
</BODY>
4+
</HTML>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<body>
3+
If you see this text in the <span style="color:green">RIGHT</span> frame the test <span style="color:green">PASSED</span>.
4+
<p>If you see this text in the <span style="color:red">LEFT</span> frame the test <span style="color:red">FAILED</span>.
5+
6+
</body>
7+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<HTML>
2+
<HEAD>
3+
<TITLE>
4+
Manual test for bug 4463014
5+
</TITLE>
6+
</HEAD>
7+
<FRAMESET COLS="150,*">
8+
<FRAME SRC="frame1.html">
9+
<FRAME name="main" SRC="frame2.html">
10+
</FRAMESET>
11+
</HTML>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 1999, 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+
/* @test
25+
* @bug 4102068
26+
* @summary Tests HTML editor JEditorPane change mouse icon over the link
27+
* @library /java/awt/regtesthelpers
28+
* @build PassFailJFrame
29+
* @run main/manual bug4102068
30+
*/
31+
32+
import java.awt.Cursor;
33+
import javax.swing.JFrame;
34+
import javax.swing.JTextPane;
35+
import javax.swing.text.html.HTMLEditorKit;
36+
37+
public class bug4102068 {
38+
39+
static final String INSTRUCTIONS = """
40+
The test window contains an HTML frame containing a string with one hyperlink.
41+
Move the mouse pointer over this hyperlink.
42+
If the pointer over the hyperlink became a HAND cursor then the test PASSES,
43+
otherwise the test FAILS.
44+
""";
45+
46+
static JFrame createUI() {
47+
48+
JFrame frame = new JFrame("bug4102068");
49+
JTextPane ep = new JTextPane();
50+
ep.setContentType("text/html");
51+
HTMLEditorKit ek = new HTMLEditorKit();
52+
ep.setEditorKit(ek);
53+
ep.setText("<html><body>Here is a <a href=''>HyperLink Cursor Test</a></body></html>");
54+
ek.setDefaultCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
55+
Cursor ct = ek.getDefaultCursor();
56+
ek.setLinkCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
57+
Cursor cl = ek.getLinkCursor();
58+
if (ct.getType() != Cursor.DEFAULT_CURSOR || cl.getType() != Cursor.HAND_CURSOR) {
59+
throw new RuntimeException("Error with cursor settings...");
60+
}
61+
ep.setEditable(false);
62+
63+
frame.add(ep);
64+
frame.setSize(300, 300);
65+
return frame;
66+
}
67+
68+
public static void main(String[] args) throws Exception {
69+
PassFailJFrame.builder()
70+
.title("Test Instructions")
71+
.instructions(INSTRUCTIONS)
72+
.columns(50)
73+
.testUI(bug4102068::createUI)
74+
.build()
75+
.awaitAndCheck();
76+
}
77+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 1999, 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+
/* @test
25+
* @bug 4198022
26+
* @summary Tests if HTML tags <sup>, <sub> and <nobr> are supported in JEditorPane
27+
* @library /java/awt/regtesthelpers
28+
* @build PassFailJFrame
29+
* @run main/manual bug4198022
30+
*/
31+
32+
import javax.swing.JEditorPane;
33+
import javax.swing.JFrame;
34+
import javax.swing.text.html.HTMLEditorKit;
35+
36+
public class bug4198022 {
37+
38+
static final String INSTRUCTIONS = """
39+
There are two "lines" of text in the displayed HTML window
40+
The first line/string contains <sub> and <sup> HTML elements.
41+
The word "subscript" should be subscripted (placed lower than the word "Testing"),
42+
and the word "superscript" should be superscripted (placed higher than "Testing").
43+
If instead these words are placed on the same level then the test FAILS.
44+
45+
The second line/string contains a sentence marked with <nobr> tag.
46+
It should be presented as one long line without breaks.
47+
It is OK for the line to extend past the end of the window and not be all visible.
48+
If the line is broken up so you see multiple lines the test FAILS.
49+
50+
If all behaves as expected, the test PASSES.
51+
""";
52+
53+
static JFrame createUI() {
54+
55+
JFrame frame = new JFrame("bug4198022");
56+
JEditorPane ep = new JEditorPane();
57+
HTMLEditorKit ek = new HTMLEditorKit();
58+
ep.setEditorKit(ek);
59+
ep.setText(
60+
"<html><body>Testing <sub>subscript</sub> and <sup>superscript</sup>.<br>" +
61+
"<nobr>This text is intended to be presented as a single line without " +
62+
"any word wrapping, regardless of whether it fits the viewable area of " +
63+
"the editor pane or not.</nobr></body></html>");
64+
65+
ep.setEditable(false);
66+
67+
frame.add(ep);
68+
frame.setSize(500, 300);
69+
return frame;
70+
}
71+
72+
public static void main(String[] args) throws Exception {
73+
PassFailJFrame.builder()
74+
.title("Test Instructions")
75+
.instructions(INSTRUCTIONS)
76+
.columns(60)
77+
.testUI(bug4198022::createUI)
78+
.build()
79+
.awaitAndCheck();
80+
}
81+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 1999, 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+
/* @test
25+
* @bug 4245401
26+
* @summary Tests that JTextPane with HTMLEditorKit handles the HEAD tag properly
27+
* @library /java/awt/regtesthelpers
28+
* @build PassFailJFrame
29+
* @run main/manual bug4245401
30+
*/
31+
32+
import java.io.StringReader;
33+
import javax.swing.JFrame;
34+
import javax.swing.JTextPane;
35+
import javax.swing.text.html.HTMLDocument;
36+
import javax.swing.text.html.HTMLEditorKit;
37+
38+
public class bug4245401 {
39+
40+
static final String INSTRUCTIONS = """
41+
Place the cursor before the "H" in the word "HTML"
42+
Then press <Up-arrow> and <Enter>.
43+
If an extra HEAD tag appear, the test FAILS, otherwise it PASSES.
44+
""";
45+
46+
static JFrame createUI() {
47+
48+
JFrame frame = new JFrame("bug4245401");
49+
JTextPane ep = new JTextPane();
50+
ep.setEditable(true);
51+
ep.setContentType("text/html");
52+
HTMLEditorKit kit = (HTMLEditorKit) ep.getEditorKit();
53+
ep.setEditorKit(kit);
54+
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
55+
ep.setDocument(doc);
56+
57+
try {
58+
String text = "HTML Test... Test is a test...";
59+
kit.read(new StringReader(text), doc, 0);
60+
} catch (Exception e) {
61+
throw new RuntimeException(e);
62+
}
63+
64+
frame.add(ep);
65+
frame.setSize(300, 300);
66+
return frame;
67+
}
68+
69+
public static void main(String[] args) throws Exception {
70+
PassFailJFrame.builder()
71+
.title("Test Instructions")
72+
.instructions(INSTRUCTIONS)
73+
.columns(40)
74+
.testUI(bug4245401::createUI)
75+
.build()
76+
.awaitAndCheck();
77+
}
78+
}

0 commit comments

Comments
 (0)