Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Mixing/AWT_Mixing/MixingFrameResizing.java
47626 views
/*1* Copyright (c) 2014, 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.Color;24import java.awt.Dimension;25import java.awt.Point;26import java.awt.Robot;27import java.awt.event.InputEvent;28import javax.swing.JFrame;29import javax.swing.SpringLayout;30import javax.swing.SwingUtilities;31import test.java.awt.regtesthelpers.Util;3233/**34* AWT/Swing overlapping test.35* <p>This test puts heavyweight component into JFrame and verifies that it's being drawn correctly after resizing the frame.36* <p>See base class for test info.37*/38/*39@test40@bug 677737041@summary Issues when resizing the JFrame with HW components42@author [email protected]: area=awt.mixing43@library ../../regtesthelpers44@build Util45@run main MixingFrameResizing46*/47public class MixingFrameResizing extends OverlappingTestBase {4849{testEmbeddedFrame = true;}5051private JFrame frame = null;52private Point lLoc;53private Point lLoc2;54private Dimension size;5556protected void prepareControls() {57if(frame != null) {58frame.setVisible(false);59}60frame = new JFrame("Mixing : Frame Resizing test");61frame.setLayout(new SpringLayout());62frame.setSize(50, 50);63frame.setVisible(true);64propagateAWTControls(frame);65Util.waitTillShown(frame);66}6768@Override69protected boolean performTest() {70int BORDER_SHIFT = frameBorderCounter();71BORDER_SHIFT = Math.abs(BORDER_SHIFT) == 1 ? BORDER_SHIFT : (BORDER_SHIFT / 2);72try {73SwingUtilities.invokeAndWait(new Runnable() {74public void run() {75lLoc = frame.getLocationOnScreen();76size = frame.getSize();77lLoc2 = frame.getContentPane().getLocationOnScreen();78}79});80} catch (Exception e) {81e.printStackTrace();82throw new RuntimeException("Where is frame?");83}84Robot robot = Util.createRobot();85robot.setAutoDelay(ROBOT_DELAY/2);8687// resize window88robot.mouseMove(lLoc.x + size.width / 2 + BORDER_SHIFT, lLoc.y + size.height + BORDER_SHIFT);89Util.waitForIdle(robot);90robot.mousePress(InputEvent.BUTTON1_MASK);91for (int i = 0; i < 10; i++) {92robot.mouseMove(lLoc.x + size.width / 2 + BORDER_SHIFT, lLoc.y + size.height + BORDER_SHIFT + 20 * i);93}94robot.mouseRelease(InputEvent.BUTTON1_MASK);9596robot.mouseMove(lLoc.x + size.width + BORDER_SHIFT, lLoc.y + size.height + BORDER_SHIFT);97Util.waitForIdle(robot);98robot.mousePress(InputEvent.BUTTON1_MASK);99for (int i = 0; i < 10; i++) {100robot.mouseMove(lLoc.x + size.width + BORDER_SHIFT + 20 * i, lLoc.y + size.height + BORDER_SHIFT);101}102robot.mouseRelease(InputEvent.BUTTON1_MASK);103104Util.waitForIdle(robot);105// check if component is visible on the opened space106try {107Thread.sleep(300); //some more wait for Solaris (for some reason)108}catch(Exception ex) {}109lLoc2.translate(75, 75);110Color c = robot.getPixelColor(lLoc2.x, lLoc2.y);111System.out.println("Actual: "+c+", expected: "+AWT_VERIFY_COLOR);112113if (!c.equals(AWT_VERIFY_COLOR)) {114fail("HW component is not visible after resizing");115}116117return true;118}119120// this strange plumbing stuff is required due to "Standard Test Machinery" in base class121public static void main(String args[]) throws InterruptedException {122if (System.getProperty("os.name").toLowerCase().contains("os x")) {123System.out.println("Aqua L&F ignores setting color to component. Test passes on Mac OS X.");124return;125}126instance = new MixingFrameResizing();127OverlappingTestBase.doMain(args);128}129}130131132