Path: blob/master/test/jdk/java/awt/Mixing/AWT_Mixing/JGlassPaneMoveOverlapping.java
41152 views
/*1* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.BorderLayout;24import java.awt.Color;25import java.awt.Container;26import java.awt.Point;27import java.awt.Robot;28import java.awt.event.InputEvent;29import java.awt.event.MouseAdapter;30import java.awt.event.MouseEvent;31import javax.swing.JFrame;32import javax.swing.JInternalFrame;33import javax.swing.SwingUtilities;34import test.java.awt.regtesthelpers.Util;3536/**37* AWT/Swing overlapping test with JInternalFrame being moved in GlassPane.38* See <a href="https://bugs.openjdk.java.net/browse/JDK-6637655">JDK-6637655</a> and39* <a href="https://bugs.openjdk.java.net/browse/JDK-6981919">JDK-6981919</a>.40* <p>See base class for details.41*/42/*43* @test44* @key headful45* @bug 6637655 698191946* @summary Overlapping test for javax.swing.JScrollPane47* @author [email protected]: area=awt.mixing48* @library /java/awt/patchlib ../../regtesthelpers49* @modules java.desktop/sun.awt50* java.desktop/java.awt.peer51* @build java.desktop/java.awt.Helper52* @build Util53* @run main JGlassPaneMoveOverlapping54*/55public class JGlassPaneMoveOverlapping extends OverlappingTestBase {5657private boolean lwClicked = true;58private volatile Point lLoc;59private volatile Point lLoc2;6061private JInternalFrame internalFrame;62private JFrame frame = null;63private volatile Point frameLoc;6465protected boolean performTest() {6667try {68SwingUtilities.invokeAndWait(new Runnable() {69public void run() {70lLoc = internalFrame.getContentPane().getLocationOnScreen();71lLoc2 = lLoc.getLocation();72lLoc2.translate(0, internalFrame.getHeight());73frameLoc = frame.getLocationOnScreen();74frameLoc.translate(frame.getWidth()/2, 3);75}76});77} catch (Exception e) {78e.printStackTrace();79throw new RuntimeException("Where is internal frame?");80}8182// run robot83Robot robot = Util.createRobot();84robot.setAutoDelay(ROBOT_DELAY);8586// force focus on JFrame (jtreg workaround)87robot.mouseMove(frameLoc.x, frameLoc.y);88Util.waitForIdle(robot);89robot.mousePress(InputEvent.BUTTON1_MASK);90robot.delay(50);91robot.mouseRelease(InputEvent.BUTTON1_MASK);92Util.waitForIdle(robot);939495//slow move96robot.mouseMove(lLoc.x + 25, lLoc.y - 5);97robot.mousePress(InputEvent.BUTTON1_MASK);98robot.delay(100);99robot.mouseMove(lLoc.x + 45, lLoc.y - 5);100robot.delay(100);101robot.mouseMove(lLoc.x + internalWidth - 75, lLoc.y - 5);102robot.delay(100);103robot.mouseMove(lLoc.x + internalWidth - 55, lLoc.y - 5);104robot.delay(100);105robot.mouseRelease(InputEvent.BUTTON1_MASK);106107Color c2 = robot.getPixelColor(lLoc.x + internalWidth + 15, lLoc.y - 5);108if (c2.equals(AWT_BACKGROUND_COLOR)) {109error("Foreground frame is not drawn properly");110}111Color c = robot.getPixelColor(lLoc.x + internalWidth - 95, lLoc.y + 5);112robot.mouseMove(lLoc.x + internalWidth - 95, lLoc.y + 5);113System.out.println("color: " + c + " " + AWT_BACKGROUND_COLOR);114if (!c.equals(AWT_BACKGROUND_COLOR) && currentAwtControl.getClass() != java.awt.Scrollbar.class) {115error("Background AWT component is not drawn properly");116}117118return true;119}120121// {debugClassName = "Choice";}122123private static void error(String st) {124//System.out.println(st);125fail(st);126}127128private static final int internalWidth = 200;129130@Override131protected void prepareControls() {132if(frame != null) {133frame.setVisible(false);134}135frame = new JFrame("Glass Pane children test");136frame.setLayout(null);137138Container contentPane = frame.getContentPane();139contentPane.setLayout(new BorderLayout());140super.propagateAWTControls(contentPane);141142Container glassPane = (Container) frame.getRootPane().getGlassPane();143glassPane.setVisible(true);144glassPane.setLayout(null);145146internalFrame = new JInternalFrame("Internal Frame", true);147internalFrame.setBounds(50, 0, internalWidth, 100);148internalFrame.setVisible(true);149glassPane.add(internalFrame);150151internalFrame.addMouseListener(new MouseAdapter() {152153@Override154public void mouseClicked(MouseEvent e) {155lwClicked = true;156}157});158159frame.setSize(400, 180);160frame.setLocationRelativeTo(null);161frame.setVisible(true);162}163164// this strange plumbing stuff is required due to "Standard Test Machinery" in base class165public static void main(String args[]) throws InterruptedException {166if (System.getProperty("os.name").toLowerCase().contains("os x")) {167System.out.println("Aqua L&F ignores setting color to component. Test passes on Mac OS X.");168return;169}170instance = new JGlassPaneMoveOverlapping();171OverlappingTestBase.doMain(args);172}173}174175176