Path: blob/master/test/jdk/java/awt/Mixing/AWT_Mixing/OpaqueOverlapping.java
41152 views
/*1* Copyright (c) 2014, 2017, 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*/222324import java.awt.Frame;25import java.awt.Panel;26import java.awt.Point;27import java.awt.Rectangle;28import java.awt.Robot;29import java.awt.event.InputEvent;30import java.awt.event.MouseAdapter;31import java.awt.event.MouseEvent;32import javax.swing.JButton;33import javax.swing.SwingUtilities;34import test.java.awt.regtesthelpers.Util;3536/**37* AWT/Swing overlapping test for opaque Swing components.38* <p>This test verify if AWT components are drawn correctly under opaque components.39* <p>See <a href="https://bugs.openjdk.java.net/browse/JDK-6776743">JDK-6776743</a> for details40* <p>See base class for test info.41*/42/*43* @test44* @key headful45* @bug 6776743 817340946* @summary Opaque overlapping test for each AWT component47* @library /java/awt/patchlib ../../regtesthelpers48* @modules java.desktop/java.awt.peer49* java.desktop/sun.awt50* @build java.desktop/java.awt.Helper51* @build Util52* @run main OpaqueOverlapping53*/54public class OpaqueOverlapping extends OverlappingTestBase {5556{57useClickValidation = false;58failMessage = "Opacity test mismatchs";5960// CR 6994264 (Choice autohides dropdown on Solaris 10)61skipClassNames = new String[] { "Choice" };62}63private String testSeq;64private final static String checkSeq = "010000101";65private Point heavyLoc;66private JButton light;67private Frame frame = null;6869protected void prepareControls() {70testSeq = "";71// Create components72if(frame != null) {73frame.setVisible(false);74}75frame = new Frame("OpaqueOverlapping mixing test");76final Panel panel = new Panel();77panel.setLayout(null);7879propagateAWTControls(panel);8081// Overlap the buttons82currentAwtControl.setBounds(30, 30, 200, 200);8384light = new JButton(" LW Button ");85light.setBounds(10, 10, 50, 50);8687// Put the components into the frame88panel.add(light);89frame.add(panel);90frame.setBounds(50, 50, 400, 400);91frame.setVisible(true);9293currentAwtControl.addMouseListener(new MouseAdapter() {94@Override95public void mouseClicked(MouseEvent e) {96panel.setComponentZOrder(light, 0);97frame.validate();98testSeq = testSeq + "0";99}100});101light.addActionListener(new java.awt.event.ActionListener() {102public void actionPerformed(java.awt.event.ActionEvent e) {103panel.setComponentZOrder(currentAwtControl, 0);104frame.validate();105testSeq = testSeq + "1";106}107});108}109110@Override111protected boolean performTest() {112try {113SwingUtilities.invokeAndWait(new Runnable() {114public void run() {115heavyLoc = currentAwtControl.getLocationOnScreen();116}117});118} catch (Exception e) {119}120Robot robot = Util.createRobot();121robot.setAutoDelay(ROBOT_DELAY);122123Util.waitForIdle(robot);124125// Move the mouse pointer to the position where both126// components overlap127robot.mouseMove(heavyLoc.x + 5, heavyLoc.y + 5);128129// Now perform the click at this point for 9 times130// In the middle of the process toggle the opaque131// flag value.132for (int i = 0; i < 9; ++i) {133if (i == 3) {134light.setMixingCutoutShape(new Rectangle());135}136if (i == 6) {137light.setMixingCutoutShape(null);138}139140robot.mousePress(InputEvent.BUTTON1_MASK);141robot.mouseRelease(InputEvent.BUTTON1_MASK);142Util.waitForIdle(robot);143144if (currentAwtControl.getClass() == java.awt.Choice.class && i != 1 && i != 6 && i != 8) {145// due to the fact that Choice doesn't get mouseClicked event if its dropdown is shown146robot.mousePress(InputEvent.BUTTON1_MASK);147robot.mouseRelease(InputEvent.BUTTON1_MASK);148Util.waitForIdle(robot);149}150}151152Util.waitForIdle(robot);153154boolean result = testSeq.equals(checkSeq);155if (!result) {156System.err.println("Expected: " + checkSeq);157System.err.println("Observed: " + testSeq);158}159return result;160}161162// this strange plumbing stuff is required due to "Standard Test Machinery" in base class163public static void main(String args[]) throws InterruptedException {164instance = new OpaqueOverlapping();165OverlappingTestBase.doMain(args);166}167}168169170