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