1 /*
2  * Copyright (c) 2014, 2016, 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.BorderLayout;
25 import java.awt.Color;
26 import java.awt.Container;
27 import java.awt.Point;
28 import java.awt.Robot;
29 import java.awt.event.MouseAdapter;
30 import java.awt.event.MouseEvent;
31 import javax.swing.JFrame;
32 import javax.swing.JInternalFrame;
33 import javax.swing.SwingUtilities;
34 import test.java.awt.regtesthelpers.Util;
35 
36 /**
37  * AWT/Swing overlapping test with JInternalFrame being put in GlassPane.
38  * See <a href="https://bugs.openjdk.java.net/browse/JDK-6637655">JDK-6637655</a> and
39  * <a href="https://bugs.openjdk.java.net/browse/JDK-6985776">JDK-6985776</a>.
40  * <p>See base class for details.
41  */
42 /*
43  * @test
44  * @key headful
45  * @bug 6637655 6985776
46  * @summary Overlapping test for javax.swing.JScrollPane
47  * @author sergey.grinev@oracle.com: area=awt.mixing
48  * @library /java/awt/patchlib  ../../regtesthelpers
49  * @modules java.desktop/sun.awt
50  *          java.desktop/java.awt.peer
51  * @build java.desktop/java.awt.Helper
52  * @build Util
53  * @run main JGlassPaneInternalFrameOverlapping
54  */
55 public class JGlassPaneInternalFrameOverlapping extends OverlappingTestBase {
56 
57     private boolean lwClicked = true;
58     private Point lLoc;
59     private Point lLoc2;
60     private JInternalFrame internalFrame;
61 
performTest()62     protected boolean performTest() {
63         try {
64             SwingUtilities.invokeAndWait(new Runnable() {
65                 public void run() {
66                     lLoc = internalFrame.getContentPane().getLocationOnScreen();
67                     lLoc2 = lLoc.getLocation();
68                     lLoc2.translate(0, internalFrame.getContentPane().getHeight() + 10);
69                 }
70             });
71         } catch (Exception e) {
72             e.printStackTrace();
73             throw new RuntimeException("Where is internal frame?");
74         }
75         // run robot
76         Robot robot = Util.createRobot();
77         robot.setAutoDelay(ROBOT_DELAY);
78 
79         clickAndBlink(robot, lLoc);
80 
81         Color c = robot.getPixelColor(lLoc2.x, lLoc2.y);
82         robot.mouseMove(lLoc2.x, lLoc2.y);
83         if (!c.equals(AWT_BACKGROUND_COLOR) &&
84             currentAwtControl.getClass() != java.awt.Scrollbar.class &&
85             currentAwtControl.getClass() != java.awt.Choice.class) {
86             fail("The HW component did not pass pixel color check and is not drawn correctly");
87         }
88 
89         return lwClicked;
90     }
91 
92    // {debugClassName = "Choice";}
93 
94     @Override
prepareControls()95     protected void prepareControls() {
96         JFrame frame = new JFrame("Glass Pane children test");
97         frame.setLayout(null);
98 
99         Container contentPane = frame.getContentPane();
100         contentPane.setLayout(new BorderLayout());
101         super.propagateAWTControls(contentPane);
102 
103         Container glassPane = (Container) frame.getRootPane().getGlassPane();
104         glassPane.setVisible(true);
105         glassPane.setLayout(null);
106 
107         internalFrame = new JInternalFrame("Internal Frame", true);
108         internalFrame.setBounds(50, 0, 200, 100);
109         internalFrame.setVisible(true);
110         glassPane.add(internalFrame);
111 
112         internalFrame.addMouseListener(new MouseAdapter() {
113 
114             @Override
115             public void mouseClicked(MouseEvent e) {
116                 lwClicked = true;
117             }
118         });
119 
120         frame.setSize(300, 180);
121         frame.setLocationRelativeTo(null);
122         frame.setVisible(true);
123     }
124 
125     // this strange plumbing stuff is required due to "Standard Test Machinery" in base class
main(String args[])126     public static void main(String args[]) throws InterruptedException {
127         if (System.getProperty("os.name").toLowerCase().contains("os x")) {
128             System.out.println("Aqua L&F ignores setting color to component. Test passes on Mac OS X.");
129             return;
130         }
131         instance = new JGlassPaneInternalFrameOverlapping();
132         OverlappingTestBase.doMain(args);
133     }
134 }
135