Path: blob/master/test/jdk/java/awt/Mixing/AWT_Mixing/MixingFrameResizing.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.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* @key headful41* @bug 6777370 822182342* @summary Issues when resizing the JFrame with HW components43* @author [email protected]: area=awt.mixing44* @library /java/awt/patchlib ../../regtesthelpers45* @modules java.desktop/sun.awt46* java.desktop/java.awt.peer47* @build java.desktop/java.awt.Helper48* @build Util49* @run main MixingFrameResizing50*/51public class MixingFrameResizing extends OverlappingTestBase {5253{testEmbeddedFrame = true;}5455private JFrame frame = null;56private Point lLoc;57private Point lLoc2;58private Dimension size;5960protected void prepareControls() {61if(frame != null) {62frame.setVisible(false);63}64frame = new JFrame("Mixing : Frame Resizing test");65frame.setLayout(new SpringLayout());66frame.setSize(50, 50);67frame.setVisible(true);68propagateAWTControls(frame);69Util.waitTillShown(frame);70}7172@Override73protected boolean performTest() {74int BORDER_SHIFT = frameBorderCounter();75BORDER_SHIFT = Math.abs(BORDER_SHIFT) == 1 ? BORDER_SHIFT : (BORDER_SHIFT / 2);76try {77SwingUtilities.invokeAndWait(new Runnable() {78public void run() {79lLoc = frame.getLocationOnScreen();80size = frame.getSize();81lLoc2 = frame.getContentPane().getLocationOnScreen();82}83});84} catch (Exception e) {85e.printStackTrace();86throw new RuntimeException("Where is frame?");87}88Robot robot = Util.createRobot();89robot.setAutoDelay(ROBOT_DELAY/2);9091// resize window92robot.mouseMove(lLoc.x + size.width / 2 + BORDER_SHIFT, lLoc.y + size.height + BORDER_SHIFT);93Util.waitForIdle(robot);94robot.mousePress(InputEvent.BUTTON1_MASK);95for (int i = 0; i < 10; i++) {96robot.mouseMove(lLoc.x + size.width / 2 + BORDER_SHIFT, lLoc.y + size.height + BORDER_SHIFT + 20 * i);97}98robot.mouseRelease(InputEvent.BUTTON1_MASK);99100robot.mouseMove(lLoc.x + size.width + BORDER_SHIFT, lLoc.y + size.height + BORDER_SHIFT);101Util.waitForIdle(robot);102robot.mousePress(InputEvent.BUTTON1_MASK);103for (int i = 0; i < 10; i++) {104robot.mouseMove(lLoc.x + size.width + BORDER_SHIFT + 20 * i, lLoc.y + size.height + BORDER_SHIFT);105}106robot.mouseRelease(InputEvent.BUTTON1_MASK);107108Util.waitForIdle(robot);109// check if component is visible on the opened space110try {111Thread.sleep(300); //some more wait for Solaris (for some reason)112}catch(Exception ex) {}113lLoc2.translate(75, 75);114Color c = robot.getPixelColor(lLoc2.x, lLoc2.y);115System.out.println("Actual: "+c+", expected: "+AWT_VERIFY_COLOR);116117if (!c.equals(AWT_VERIFY_COLOR)) {118fail("HW component is not visible after resizing");119}120121return true;122}123124// this strange plumbing stuff is required due to "Standard Test Machinery" in base class125public static void main(String args[]) throws InterruptedException {126if (System.getProperty("os.name").toLowerCase().contains("os x")) {127System.out.println("Aqua L&F ignores setting color to component. Test passes on Mac OS X.");128return;129}130instance = new MixingFrameResizing();131OverlappingTestBase.doMain(args);132}133}134135136