bug6796710.java revision 11111:4ef86895869c
1/*
2 * Copyright (c) 2011, 2012, 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 6796710 7124242
27 * @summary Html content in JEditorPane is overlapping on swing components while resizing the application.
28 * @library ../../../regtesthelpers
29 * @build Util
30 * @author Pavel Porvatov
31   @run main bug6796710
32 */
33
34import java.awt.*;
35import java.awt.image.BufferedImage;
36import javax.swing.*;
37
38public class bug6796710 {
39    // The page is inlined because we want to be sure that the JEditorPane filled synchronously
40    public static final String TEXT = "<html>" +
41            "<body>" +
42            "<table cellpadding=\"0\" cellspacing=\"0\" border=\"1\">" +
43            "    <tbody>" +
44            "        <tr>" +
45            "            <td>Col1</td>" +
46            "            <td>Col2</td>" +
47            "            <td>Col3</td>" +
48            "        </tr>" +
49            "        <tr>" +
50            "            <td>1. It's a regression from CR 4419748. The problem is in the CSSBorder#paintBorder, which ignores clip area while painting.</td>" +
51            "            <td>2. It's a regression from CR 4419748. The problem is in the CSSBorder#paintBorder, which ignores clip area while painting.</td>" +
52            "            <td>3. It's a regression from CR 4419748. The problem is in the CSSBorder#paintBorder, which ignores clip area while painting.</td>" +
53            "        </tr>" +
54            "    </tbody>" +
55            "</table>" +
56            "</body>" +
57            "</html>";
58
59    private static Robot robot;
60
61    private static JFrame frame;
62
63    private static JPanel pnBottom;
64
65    public static void main(String[] args) throws Exception {
66        robot = new Robot();
67
68        SwingUtilities.invokeAndWait(new Runnable() {
69            @Override
70            public void run() {
71                frame = new JFrame();
72
73                frame.setUndecorated(true);
74
75                pnBottom = new JPanel();
76                pnBottom.add(new JLabel("Some label"));
77                pnBottom.add(new JButton("A button"));
78
79                JEditorPane editorPane = new JEditorPane();
80
81                editorPane.setContentType("text/html");
82                editorPane.setText(TEXT);
83                editorPane.setEditable(false);
84
85                JPanel pnContent = new JPanel(new BorderLayout());
86
87                pnContent.add(new JScrollPane(editorPane), BorderLayout.CENTER);
88                pnContent.add(pnBottom, BorderLayout.SOUTH);
89
90                frame.setContentPane(pnContent);
91                frame.setSize(400, 600);
92                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
93                frame.setVisible(true);
94            }
95        });
96
97        robot.waitForIdle();
98
99        // This delay should be added for MacOSX, realSync is not enough
100        Thread.sleep(1000);
101
102        BufferedImage bufferedImage = getPnBottomImage();
103
104        SwingUtilities.invokeAndWait(new Runnable() {
105            @Override
106            public void run() {
107                frame.setSize(400, 150);
108            }
109        });
110
111        robot.waitForIdle();
112
113        // On Linux platforms realSync doesn't guaranties setSize completion
114        Thread.sleep(1000);
115
116        if (!Util.compareBufferedImages(bufferedImage, getPnBottomImage())) {
117            throw new RuntimeException("The test failed");
118        }
119
120        System.out.println("The test bug6796710 passed.");
121    }
122
123    private static BufferedImage getPnBottomImage() {
124        Rectangle rect = pnBottom.getBounds();
125
126        Util.convertRectToScreen(rect, pnBottom.getParent());
127
128        return robot.createScreenCapture(rect);
129    }
130}
131