Skip to content

Commit a04c6c1

Browse files
committed
8315609: Open source few more swing text/html tests
Reviewed-by: jdv
1 parent dab1c21 commit a04c6c1

File tree

4 files changed

+422
-0
lines changed

4 files changed

+422
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (c) 2000, 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+
/*
25+
* @test
26+
* @bug 4322891
27+
* @summary Tests if image map receives correct coordinates.
28+
* @key headful
29+
* @run main bug4322891
30+
*/
31+
32+
import java.awt.Point;
33+
import java.awt.Robot;
34+
import java.awt.event.InputEvent;
35+
import javax.swing.JFrame;
36+
import javax.swing.JEditorPane;
37+
import javax.swing.SwingUtilities;
38+
import javax.swing.event.HyperlinkEvent;
39+
import javax.swing.event.HyperlinkListener;
40+
import javax.swing.text.html.HTMLEditorKit;
41+
42+
public class bug4322891 {
43+
44+
private boolean finished = false;
45+
private static boolean passed = false;
46+
private static Robot robot;
47+
private static JFrame f;
48+
private static JEditorPane jep;
49+
private static volatile Point p;
50+
51+
public static void main(String[] args) throws Exception {
52+
robot = new Robot();
53+
robot.setAutoDelay(100);
54+
try {
55+
bug4322891 test = new bug4322891();
56+
SwingUtilities.invokeAndWait(test::init);
57+
robot.waitForIdle();
58+
robot.delay(1000);
59+
SwingUtilities.invokeAndWait(() -> {
60+
p = jep.getLocationOnScreen();
61+
});
62+
robot.mouseMove(p.x, p.y);
63+
robot.waitForIdle();
64+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
65+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
66+
robot.waitForIdle();
67+
for (int i = 1; i < 30; i++) {
68+
robot.mouseMove(p.x + i, p.y + i);
69+
robot.waitForIdle();
70+
}
71+
if (!passed) {
72+
throw new RuntimeException("Test failed.");
73+
}
74+
} finally {
75+
SwingUtilities.invokeAndWait(() -> {
76+
if (f != null) {
77+
f.dispose();
78+
}
79+
});
80+
}
81+
}
82+
83+
public void init() {
84+
String text = "<img src=\"aaa\" height=100 width=100 usemap=\"#mymap\">" +
85+
"<map name=\"mymap\">" +
86+
"<area href=\"aaa\" shape=rect coords=\"0,0,100,100\">" +
87+
"</map>";
88+
89+
f = new JFrame();
90+
jep = new JEditorPane();
91+
jep.setEditorKit(new HTMLEditorKit());
92+
jep.setEditable(false);
93+
94+
jep.setText(text);
95+
96+
jep.addHyperlinkListener(new HyperlinkListener() {
97+
public void hyperlinkUpdate(HyperlinkEvent e) {
98+
passed = true;
99+
}
100+
});
101+
f.getContentPane().add(jep);
102+
f.setSize(500,500);
103+
f.setLocationRelativeTo(null);
104+
f.setVisible(true);
105+
}
106+
107+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
/*
25+
* @test
26+
* @bug 4476002
27+
* @summary Verifies JEditorPane: <ol> list numbers do not pick up color of the list text
28+
* @key headful
29+
* @run main bug4476002
30+
*/
31+
32+
import java.awt.Color;
33+
import java.awt.Dimension;
34+
import java.awt.Point;
35+
import java.awt.Robot;
36+
import java.awt.event.WindowAdapter;
37+
import java.awt.event.WindowEvent;
38+
import javax.swing.JFrame;
39+
import javax.swing.JLabel;
40+
import javax.swing.SwingUtilities;
41+
42+
public class bug4476002 {
43+
44+
private static boolean passed = true;
45+
private static JLabel htmlComponent;
46+
47+
private static Robot robot;
48+
private static JFrame mainFrame;
49+
private static volatile Point p;
50+
private static volatile Dimension d;
51+
52+
public static void main(String[] args) throws Exception {
53+
robot = new Robot();
54+
55+
try {
56+
SwingUtilities.invokeAndWait(() -> {
57+
String htmlText =
58+
"<html><head><style>" +
59+
"OL { list-style-type: disc; color: red }" +
60+
"</style></head>" +
61+
"<body><ol><li>wwwww</li></ol></body></html>";
62+
63+
mainFrame = new JFrame("bug4476002");
64+
65+
htmlComponent = new JLabel(htmlText);
66+
mainFrame.getContentPane().add(htmlComponent);
67+
68+
mainFrame.pack();
69+
mainFrame.setLocationRelativeTo(null);
70+
mainFrame.setVisible(true);
71+
});
72+
robot.waitForIdle();
73+
robot.delay(1000);
74+
SwingUtilities.invokeAndWait(() -> {
75+
p = htmlComponent.getLocationOnScreen();
76+
d = htmlComponent.getSize();
77+
});
78+
int x0 = p.x;
79+
int y = p.y + d.height/2;
80+
81+
for (int x = x0; x < x0 + d.width; x++) {
82+
if (robot.getPixelColor(x, y).equals(Color.black)) {
83+
passed = false;
84+
break;
85+
}
86+
}
87+
if (!passed) {
88+
throw new RuntimeException("Test failed.");
89+
}
90+
} finally {
91+
SwingUtilities.invokeAndWait(() -> {
92+
if (mainFrame != null) {
93+
mainFrame.dispose();
94+
}
95+
});
96+
}
97+
}
98+
99+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
/*
25+
* @test
26+
* @bug 4412522
27+
* @summary Tests if HTML that has comments inside of tables is rendered correctly
28+
* @key headful
29+
* @run main bug4412522
30+
*/
31+
32+
import javax.swing.JEditorPane;
33+
import javax.swing.JFrame;
34+
import javax.swing.SwingUtilities;
35+
import javax.swing.text.View;
36+
import javax.swing.text.html.HTMLEditorKit;
37+
38+
import java.awt.Robot;
39+
import java.awt.Shape;
40+
41+
public class bug4412522 {
42+
43+
private static boolean passed = false;
44+
45+
private static JEditorPane jep;
46+
private static JFrame f;
47+
private static Robot robot;
48+
49+
public void init() {
50+
51+
String text =
52+
"<html><head><table border>" +
53+
"<tr><td>first cell</td><td>second cell</td></tr>" +
54+
"<tr><!-- this is a comment --><td>row heading</td></tr>" +
55+
"</table></body></html>";
56+
57+
JFrame f = new JFrame();
58+
jep = new JEditorPane();
59+
jep.setEditorKit(new HTMLEditorKit());
60+
jep.setEditable(false);
61+
62+
jep.setText(text);
63+
64+
f.getContentPane().add(jep);
65+
f.setSize(500,500);
66+
f.setLocationRelativeTo(null);
67+
f.setVisible(true);
68+
}
69+
70+
71+
public static void main(String args[]) throws Exception {
72+
robot = new Robot();
73+
robot.setAutoDelay(100);
74+
bug4412522 test = new bug4412522();
75+
try {
76+
SwingUtilities.invokeAndWait(() -> test.init());
77+
robot.waitForIdle();
78+
robot.delay(1000);
79+
Shape r = jep.getBounds();
80+
View v = jep.getUI().getRootView(jep);
81+
int tableWidth = 0;
82+
int cellsWidth = 0;
83+
84+
while (!(v instanceof javax.swing.text.html.ParagraphView)) {
85+
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+
93+
if (viewName.endsWith("CellView")) {
94+
cellsWidth = r.getBounds().x + r.getBounds().width;
95+
}
96+
97+
v = v.getView(n - 1);
98+
if (sh != null) {
99+
r = sh;
100+
}
101+
}
102+
103+
passed = ((tableWidth - cellsWidth) > 10);
104+
if (!passed) {
105+
throw new RuntimeException("Test failed.");
106+
}
107+
} finally {
108+
SwingUtilities.invokeAndWait(() -> {
109+
if (f != null) {
110+
f.dispose();
111+
}
112+
});
113+
}
114+
}
115+
}

0 commit comments

Comments
 (0)