Skip to content

Commit 833a828

Browse files
author
Harshitha Onkar
committedSep 19, 2023
8315876: Open source several Swing CSS related tests
Reviewed-by: azvegint, dnguyen, aivanov
1 parent 7ce5bd1 commit 833a828

File tree

5 files changed

+443
-0
lines changed

5 files changed

+443
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (c) 2003, 2023, 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.Robot;
25+
import java.awt.Shape;
26+
import javax.swing.JFrame;
27+
import javax.swing.JTextPane;
28+
import javax.swing.SwingUtilities;
29+
import javax.swing.text.View;
30+
31+
/*
32+
* @test
33+
* @bug 4174871
34+
* @key headful
35+
* @summary Tests if CELLSPACING attribute in HTML table is rendered.
36+
*/
37+
38+
public class bug4174871 {
39+
private static JFrame frame;
40+
private static JTextPane pane;
41+
private static volatile boolean passed = false;
42+
43+
public static void main(String[] args) throws Exception {
44+
try {
45+
Robot robot = new Robot();
46+
47+
SwingUtilities.invokeAndWait(bug4174871::createAndShowUI);
48+
robot.waitForIdle();
49+
robot.delay(500);
50+
51+
SwingUtilities.invokeAndWait(bug4174871::testUI);
52+
53+
if (!passed) {
54+
throw new RuntimeException("Test failed!!" +
55+
" CELLSPACING attribute in HTML table is NOT rendered");
56+
}
57+
} finally {
58+
SwingUtilities.invokeAndWait(() -> {
59+
if (frame != null) {
60+
frame.dispose();
61+
}
62+
});
63+
}
64+
}
65+
66+
public static void createAndShowUI() {
67+
pane = new JTextPane();
68+
pane.setContentType("text/html");
69+
pane.setText("<html>"
70+
+ "<html><head><table border=1 cellspacing=20>"
71+
+ "<tr><td width=100>one</td><td width=100>two</td><td width=100>three</td></tr>"
72+
+ "</table></body></html>");
73+
74+
frame = new JFrame("Table CellSpacing Test");
75+
frame.getContentPane().add(pane);
76+
frame.setSize(600, 200);
77+
frame.setVisible(true);
78+
}
79+
80+
private static void testUI() {
81+
int tableWidth = 0;
82+
Shape r = pane.getBounds();
83+
View v = pane.getUI().getRootView(pane);
84+
85+
while (!(v instanceof javax.swing.text.html.ParagraphView)) {
86+
int n = v.getViewCount();
87+
Shape sh = v.getChildAllocation(n - 1, r);
88+
String viewName = v.getClass().getName();
89+
if (viewName.endsWith("TableView")) {
90+
tableWidth = r.getBounds().width;
91+
}
92+
v = v.getView(n - 1);
93+
if (sh != null) {
94+
r = sh;
95+
}
96+
}
97+
// tableWidth should be the sum of TD's widths (300)
98+
// and cellspacings (80)
99+
passed = (tableWidth >= 380);
100+
}
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright (c) 2003, 2023, 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 javax.swing.JFrame;
25+
import javax.swing.JTextPane;
26+
import javax.swing.SwingUtilities;
27+
import javax.swing.text.View;
28+
import java.awt.Robot;
29+
import java.awt.Shape;
30+
31+
/*
32+
* @test
33+
* @bug 4174874
34+
* @key headful
35+
* @summary Tests if borders in HTML table are rendered
36+
*/
37+
38+
public class bug4174874 {
39+
private static JFrame frame;
40+
private static JTextPane pane;
41+
private static volatile boolean passed = false;
42+
43+
public static void main(String[] args) throws Exception {
44+
try {
45+
Robot robot = new Robot();
46+
47+
SwingUtilities.invokeAndWait(bug4174874::createAndShowUI);
48+
robot.waitForIdle();
49+
robot.delay(500);
50+
51+
SwingUtilities.invokeAndWait(bug4174874::testUI);
52+
53+
if (!passed) {
54+
throw new RuntimeException("Test failed!!" +
55+
" Borders of HTML table not rendered correctly");
56+
}
57+
} finally {
58+
SwingUtilities.invokeAndWait(() -> {
59+
if (frame != null) {
60+
frame.dispose();
61+
}
62+
});
63+
}
64+
}
65+
66+
public static void createAndShowUI() {
67+
pane = new JTextPane();
68+
pane.setContentType("text/html");
69+
pane.setText("<html>"
70+
+ "<html><head><table border=20>"
71+
+ "<tr><td width=100>one</td><td width=100>two</td><td width=100>three</td></tr>"
72+
+ "</table></body></html>");
73+
74+
frame = new JFrame("Table Border Test");
75+
frame.getContentPane().add(pane);
76+
frame.setSize(600, 200);
77+
frame.setVisible(true);
78+
}
79+
80+
private static void testUI() {
81+
Shape r = pane.getBounds();
82+
View v = pane.getUI().getRootView(pane);
83+
int tableWidth = 0;
84+
while (!(v instanceof javax.swing.text.html.ParagraphView)) {
85+
int n = v.getViewCount();
86+
Shape sh = v.getChildAllocation(n - 1, r);
87+
String viewName = v.getClass().getName();
88+
if (viewName.endsWith("TableView")) {
89+
tableWidth = r.getBounds().width;
90+
}
91+
v = v.getView(n - 1);
92+
if (sh != null) {
93+
r = sh;
94+
}
95+
}
96+
// tableWidth should be the sum of TD's widths (300)
97+
// and border width * 2 (40)
98+
passed = tableWidth >= 340;
99+
}
100+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (c) 2003, 2023, 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.Robot;
25+
import javax.swing.JEditorPane;
26+
import javax.swing.JFrame;
27+
import javax.swing.SwingUtilities;
28+
import javax.swing.text.AttributeSet;
29+
import javax.swing.text.StyleConstants;
30+
import javax.swing.text.View;
31+
import javax.swing.text.html.HTMLEditorKit;
32+
33+
34+
/*
35+
* @test
36+
* @bug 4284162
37+
* @key headful
38+
* @summary Tests if css text-indent attribute is supported with negative values.
39+
*/
40+
41+
public class bug4284162 {
42+
private static JEditorPane jep;
43+
private static JFrame frame;
44+
private static volatile boolean passed = false;
45+
46+
public static void main(String[] args) throws Exception {
47+
try {
48+
Robot robot = new Robot();
49+
50+
SwingUtilities.invokeAndWait(bug4284162::createAndShowUI);
51+
robot.waitForIdle();
52+
robot.delay(500);
53+
54+
SwingUtilities.invokeAndWait(bug4284162::testUI);
55+
56+
if (!passed) {
57+
throw new RuntimeException("Test failed!!" +
58+
" CSS Text-indent attribute doesn't support negative values");
59+
}
60+
} finally {
61+
SwingUtilities.invokeAndWait(() -> {
62+
if (frame != null) {
63+
frame.dispose();
64+
}
65+
});
66+
}
67+
}
68+
69+
public static void createAndShowUI() {
70+
String text ="<html><head><style>body {text-indent: -24.000000pt;}</style></head>"
71+
+ "<body><p>paragraph</body></html>";
72+
73+
frame = new JFrame("CSS Text-Indent Test");
74+
jep = new JEditorPane();
75+
jep.setEditorKit(new HTMLEditorKit());
76+
jep.setEditable(false);
77+
78+
jep.setText(text);
79+
80+
frame.getContentPane().add(jep);
81+
frame.setSize(200, 200);
82+
frame.setVisible(true);
83+
}
84+
85+
private static void testUI() {
86+
View v = jep.getUI().getRootView(jep);
87+
while (!(v instanceof javax.swing.text.html.ParagraphView)) {
88+
int n = v.getViewCount();
89+
v = v.getView(n - 1);
90+
}
91+
92+
AttributeSet attrs = v.getAttributes();
93+
Object attr = attrs.getAttribute(StyleConstants.FirstLineIndent);
94+
passed = (attr.toString().startsWith("-"));
95+
}
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (c) 2003, 2023, 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.Robot;
25+
import java.awt.Shape;
26+
import javax.swing.JEditorPane;
27+
import javax.swing.JFrame;
28+
import javax.swing.JTextPane;
29+
import javax.swing.SwingUtilities;
30+
import javax.swing.text.View;
31+
32+
/*
33+
* @test
34+
* @bug 4764897
35+
* @key headful
36+
* @summary Tests if text and borders in HTML table doesn't run over right edge
37+
*/
38+
39+
public class bug4764897 {
40+
private static JEditorPane pane;
41+
private static JFrame frame;
42+
private static volatile boolean passed = false;
43+
44+
public static void main(String[] args) throws Exception {
45+
try {
46+
Robot robot = new Robot();
47+
48+
SwingUtilities.invokeAndWait(bug4764897::createAndShowUI);
49+
robot.waitForIdle();
50+
robot.delay(500);
51+
52+
SwingUtilities.invokeAndWait(bug4764897::testUI);
53+
54+
if (!passed) {
55+
throw new RuntimeException("Test failed!!" +
56+
" Text and Borders of HTML table run over the right edge");
57+
}
58+
} finally {
59+
SwingUtilities.invokeAndWait(() -> {
60+
if (frame != null) {
61+
frame.dispose();
62+
}
63+
});
64+
}
65+
}
66+
67+
public static void createAndShowUI() {
68+
pane = new JTextPane();
69+
pane.setContentType("text/html");
70+
pane.setText("<html>"
71+
+ "<html><head><table border>"
72+
+ "<tr><td width=20%>one</td><td width=20%>&nbsp;</td>"
73+
+ "<td width=20%>ThisIsAnExtraWideWord</td><td width=40%>"
74+
+ "This is text that won't get displayed correctly.</td></tr>"
75+
+ "</table></body></html>");
76+
77+
frame = new JFrame("Table Border & Text Test");
78+
frame.getContentPane().add(pane);
79+
frame.setSize(600, 200);
80+
frame.setVisible(true);
81+
}
82+
83+
private static void testUI() {
84+
Shape r = pane.getBounds();
85+
View v = pane.getUI().getRootView(pane);
86+
int tableWidth = 0;
87+
int cellsWidth = 0;
88+
while (!(v instanceof javax.swing.text.html.ParagraphView)) {
89+
int n = v.getViewCount();
90+
Shape sh = v.getChildAllocation(n - 1, r);
91+
String viewName = v.getClass().getName();
92+
if (viewName.endsWith("TableView")) {
93+
tableWidth = r.getBounds().width;
94+
}
95+
96+
if (viewName.endsWith("CellView")) {
97+
cellsWidth = r.getBounds().x + r.getBounds().width;
98+
}
99+
100+
v = v.getView(n - 1);
101+
if (sh != null) {
102+
r = sh;
103+
}
104+
}
105+
passed = cellsWidth <= tableWidth;
106+
}
107+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 1999, 2023, 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 javax.swing.JLabel;
25+
26+
/*
27+
* @test
28+
* @bug 4209280
29+
* @summary Tests that no exception is thrown on unknown HTML tag
30+
*/
31+
32+
public class bug4209280 {
33+
34+
public static void main(String[] args) throws Exception {
35+
String html = "<html><bold>Foo</bold></html>";
36+
// The following line should throw no exceptions
37+
new JLabel(html);
38+
}
39+
}

0 commit comments

Comments
 (0)
Please sign in to comment.