# HG changeset patch # User yan # Date 1398767558 -14400 # Node ID f0250a79028baba8db21211a3a02aeb37fe53068 # Parent 25bf8153fbfec645b800557afe6fe78cf6e39893 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk Reviewed-by: anthony, pchelko diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/FrameBorderCounter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/FrameBorderCounter.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.MouseEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.WindowEvent; +import java.awt.event.WindowAdapter; + +public class FrameBorderCounter { + + private static Frame frame; + private static Frame background; + private static Dimension size; + private static Point location; + private static Point entered; + + public static void main(String[] args) throws Exception { + final Robot robot = new Robot(); + EventQueue.invokeAndWait(new Runnable() { + public void run() { + robot.mouseMove(0, 0); + } + }); + EventQueue.invokeAndWait(new Runnable() { + public void run() { + background = new Frame(); + background.setBounds(100, 100, 300, 300); + background.addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) { + entered = e.getLocationOnScreen(); + System.err.println("[ENTERED] : " + entered); + } + }); + background.setVisible(true); + } + }); + EventQueue.invokeAndWait(new Runnable() { + public void run() { + frame = new Frame("Frame"); + frame.setBounds(200, 200, 100, 100); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + frame.setVisible(true); + } + }); + Thread.sleep(1000); + EventQueue.invokeAndWait(new Runnable() { + public void run() { + location = frame.getLocationOnScreen(); + size = frame.getSize(); + } + }); + int out = 20; + for (int x = location.x + size.width - out; x <= location.x + size.width + out; ++x) { + robot.mouseMove(x, location.y + size.height / 2); + Thread.sleep(50); + } + System.err.println("[LOCATION] : " + location); + System.err.println("[SIZE] : " + size); + Thread.sleep(250); + int shift = entered.x - location.x - size.width - 1; + System.err.println("Done"); + System.out.println(shift); + frame.dispose(); + background.dispose(); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/GlassPaneOverlappingTestBase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/GlassPaneOverlappingTestBase.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Container; +import java.awt.Point; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.InputEvent; +import java.lang.reflect.InvocationTargetException; +import javax.swing.JFrame; +import javax.swing.SpringLayout; +import javax.swing.SwingUtilities; + +/** + * Base class for testing overlapping of Swing and AWT component put into GlassPane. + * Validates drawing and event delivery at the components intersection. + *

See {@link OverlappingTestBase} for usage + * + * @author Sergey Grinev + */ +public abstract class GlassPaneOverlappingTestBase extends SimpleOverlappingTestBase { + + /** + * If true components is additionally tested to be correctly drawn after resize. + */ + protected boolean testResize = true; + private JFrame f = null; + private volatile Point ancestorLoc; + + /** + * Setups GlassPane with lightweight component returned by {@link SimpleOverlappingTestBase#getSwingComponent() } + * Called by base class. + */ + @Override + protected void prepareControls() { + wasLWClicked = false; + + if(f != null) { + f.setVisible(false); + } + f = new JFrame("Mixing : GlassPane Overlapping test"); + f.setLayout(new SpringLayout()); + f.setSize(200, 200); + + propagateAWTControls(f); + + f.getGlassPane().setVisible(true); + Container glassPane = (Container) f.getGlassPane(); + glassPane.setLayout(null); + + testedComponent = getSwingComponent(); + if (useDefaultClickValidation) { + testedComponent.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + //System.err.println("lw mouse clicked"); + wasLWClicked = true; + } + }); + } + testedComponent.setBounds(0, 0, testedComponent.getPreferredSize().width, testedComponent.getPreferredSize().height); + glassPane.add(testedComponent); + + f.setVisible(true); + } + + public GlassPaneOverlappingTestBase() { + super(); + } + + public GlassPaneOverlappingTestBase(boolean defaultClickValidation) { + super(defaultClickValidation); + } + + /** + * Run test by {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point) } validation for current lightweight component. + *

Also resize component and repeat validation in the resized area. + *

Called by base class. + * @return true if test passed + * @see GlassPaneOverlappingTestBase#testResize + */ + @Override + protected boolean performTest() { + if (!super.performTest()) { + return false; + } + if (testResize) { + wasLWClicked = false; + try { + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + testedComponent.setBounds(0, 0, testedComponent.getPreferredSize().width, testedComponent.getPreferredSize().height + 20); + ancestorLoc = f.getLocationOnScreen(); + } + }); + } catch (InterruptedException ex) { + fail(ex.getMessage()); + } catch (InvocationTargetException ex) { + fail(ex.getMessage()); + } + Point lLoc = testedComponent.getLocationOnScreen(); + lLoc.translate(1, testedComponent.getPreferredSize().height + 1); + + /* this is a workaround for certain jtreg(?) focus issue: + tests fail starting after failing mixing tests but always pass alone. + */ + Util.waitForIdle(robot); + ancestorLoc.translate(f.getWidth()/2-15, 2); + robot.mouseMove(ancestorLoc.x, ancestorLoc.y); + Util.waitForIdle(robot); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.delay(50); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + Util.waitForIdle(robot); + + clickAndBlink(robot, lLoc); + return wasLWClicked; + } else { + return true; + } + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/HierarchyBoundsListenerMixingTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/HierarchyBoundsListenerMixingTest.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,692 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.*; +import java.awt.event.*; +import java.lang.reflect.InvocationTargetException; +import javax.swing.SwingUtilities; +import java.io.*; + +/** + * AWT Mixing test for HierarchyBoundsListener ancestors. + *

See CR6768230 for details. + */ +/* +@test +@bug 6768230 +@summary Mixing test for HierarchyBoundsListener ancestors +@build FrameBorderCounter +@run main HierarchyBoundsListenerMixingTest + */ +public class HierarchyBoundsListenerMixingTest { + + protected void prepareControls() { + dummy = new Frame(); + dummy.setSize(100, 100); + dummy.setLocation(0, 350); + dummy.setVisible(true); + + frame = new Frame("Test Frame"); + frame.setLayout(new FlowLayout()); + + panel = new Panel(); + button = new Button("Button"); + label = new Label("Label"); + list = new List(); + list.add("One"); + list.add("Two"); + list.add("Three"); + choice = new Choice(); + choice.add("Red"); + choice.add("Orange"); + choice.add("Yellow"); + checkbox = new Checkbox("Checkbox"); + scrollbar = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 255); + textfield = new TextField(15); + textarea = new TextArea(5, 15); + + components = new Component[] { + panel, button, label, list, choice, checkbox, scrollbar, textfield, textarea + }; + ancestorResized = new boolean[components.length]; + ancestorMoved = new boolean[components.length]; + + frame.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent event) { + System.err.println("User closed the window"); + System.exit(1); + } + }); + + HierarchyBoundsListener listener = new HierarchyBoundsListenerImpl(); + for (int i = 0; i < components.length; i++) { + components[i].addHierarchyBoundsListener(listener); + frame.add(components[i]); + } + frame.setSize(300, 300); + frame.setVisible(true); + } + + private int frameBorderCounter() { + String JAVA_HOME = System.getProperty("java.home"); + + try { + Process p = Runtime.getRuntime().exec(JAVA_HOME + "/bin/java FrameBorderCounter"); + try { + p.waitFor(); + } catch (InterruptedException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + if (p.exitValue() != 0) { + throw new RuntimeException("FrameBorderCounter exited with not null code!\n" + readInputStream(p.getErrorStream())); + } + return Integer.parseInt(readInputStream(p.getInputStream()).trim()); + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + private String readInputStream(InputStream is) throws IOException { + byte[] buffer = new byte[4096]; + int len = 0; + StringBuilder sb = new StringBuilder(); + try (InputStreamReader isr = new InputStreamReader(is)) { + while ((len = is.read(buffer)) > 0) { + sb.append(new String(buffer, 0, len)); + } + } + return sb.toString(); + } + + protected boolean performTest() { + int BORDER_SHIFT = frameBorderCounter(); + BORDER_SHIFT = Math.abs(BORDER_SHIFT) == 1 ? BORDER_SHIFT : BORDER_SHIFT / 2; + Robot robot = null; + try { + robot = new Robot(); + Thread.sleep(delay * 10); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + + robot.mouseMove((int) components[0].getLocationOnScreen().x + components[0].getSize().width / 2, + (int) components[0].getLocationOnScreen().y + components[0].getSize().height / 2); + robot.delay(delay); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.delay(delay); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.delay(delay); + + resetValues(); + try { + EventQueue.invokeAndWait(new Runnable() { + public void run() { + frame.setSize(new Dimension(frame.getSize().width + 10, frame.getSize().height + 10)); + frame.invalidate(); + frame.validate(); + } + }); + } catch (Exception e) { + e.printStackTrace(); + passed = false; + } + if (! resizeTriggered) { + synchronized (resizeLock) { + try { + resizeLock.wait(delay * 10); + } catch (Exception e) { + } + } + } + for (int i = 0; i < components.length; i++) { + if (! ancestorResized[i]) { + System.err.println("FAIL: Frame resized using API call. " + + "Ancestor resized event did not occur for " + components[i].getClass()); + passed = false; + } + } + if (moveCount > 0) { + System.err.println("FAIL: Ancestor moved event occured when Frame resized using API"); + passed = false; + } + robot.delay(delay * 5); + + resetValues(); + int x = (int) frame.getLocationOnScreen().x; + int y = (int) frame.getLocationOnScreen().y; + int w = frame.getSize().width; + int h = frame.getSize().height; + + robot.mouseMove(x + w + BORDER_SHIFT, y + h / 2); + robot.delay(delay); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.delay(delay); + for (int i = 0; i < 20; i++) { + robot.mouseMove(x + w + i + BORDER_SHIFT, y + h / 2); + robot.delay(50); + } + robot.delay(delay); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + if (! resizeTriggered) { + synchronized (resizeLock) { + try { + resizeLock.wait(delay * 10); + } catch (Exception e) { + } + } + } + + for (int i = 0; i < components.length; i++) { + if (! ancestorResized[i]) { + System.err.println("FAIL: Frame resized using mouse action. " + + "Ancestor resized event did not occur for " + + components[i].getClass()); + passed = false; + } + } + if (moveCount > 0) { + System.err.println("FAIL: Ancestor moved event occured when Frame resized using mouse"); + passed = false; + } + + resetValues(); + try { + EventQueue.invokeAndWait(new Runnable() { + public void run() { + frame.setLocation(frame.getLocation().x + 20, frame.getLocation().y + 20); + frame.invalidate(); + frame.validate(); + } + }); + } catch (Exception e) { + e.printStackTrace(); + passed = false; + } + if (! moveTriggered) { + synchronized (moveLock) { + try { + moveLock.wait(delay * 10); + } catch (Exception e) { + } + } + } + for (int i = 0; i < components.length; i++) { + if (! ancestorMoved[i]) { + System.err.println("FAIL: Frame moved using API call. " + + "Ancestor moved event did not occur for " + components[i].getClass()); + passed = false; + } + } + if (resizeCount > 0) { + System.err.println("FAIL: Ancestor resized event occured when Frame moved using API"); + passed = false; + } + robot.delay(delay * 10); + + resetValues(); + x = (int) frame.getLocationOnScreen().x; + y = (int) frame.getLocationOnScreen().y; + w = frame.getSize().width; + h = frame.getSize().height; + + //Click on the dummy frame so that the test frame loses focus. This is to workaround + //a bug in Linux AS. + robot.mouseMove((int) dummy.getLocationOnScreen().x + dummy.getSize().width / 2, + (int) dummy.getLocationOnScreen().y + dummy.getSize().height / 2); + robot.delay(delay); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.delay(delay); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.delay(delay); + + robot.mouseMove(x + w / 2, y + 10); + robot.delay(delay); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.delay(delay); + for (int i = 1; i <= 20; i++) { + robot.mouseMove(x + w / 2 + i, y + 10); + robot.delay(50); + } + robot.delay(delay); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + if (! moveTriggered) { + synchronized (moveLock) { + try { + moveLock.wait(delay * 10); + } catch (Exception e) { + } + } + } + + for (int i = 0; i < components.length; i++) { + if (! ancestorMoved[i]) { + System.err.println("FAIL: Frame moved using mouse action. " + + "Ancestor moved event did not occur for " + components[i].getClass()); + passed = false; + } + } + if (resizeCount > 0) { + System.err.println("FAIL: Ancestor resized event occured when Frame moved using mouse"); + passed = false; + } + + return passed; + } + + private void resetValues() { + moveTriggered = false; + resizeTriggered = false; + moveCount = 0; + resizeCount = 0; + for (int i = 0; i < ancestorResized.length; i++) { + ancestorResized[i] = false; + ancestorMoved[i] = false; + } + } + + private void keyType(int key, Robot robot) throws Exception { + robot.keyPress(key); + robot.delay(keyDelay); + robot.keyRelease(key); + robot.delay(keyDelay); + } + + class HierarchyBoundsListenerImpl implements HierarchyBoundsListener { + // checks for Ancestor_Moved events + public void ancestorMoved(HierarchyEvent ce) { + if (check) { + System.out.println("Moved " + ce.getComponent()); + } + for (int i = 0; i < components.length; i++) { + if (components[i].equals(ce.getComponent())) { + //setting this array for purpose of checking ancestor_moved. + ancestorMoved[i] = true; + moveCount++; + if (moveCount == components.length) { + moveTriggered = true; + synchronized (moveLock) { + try { + moveLock.notifyAll(); + } catch (Exception e) { + } + } + } + } + } + } + // checks for Ancestor_Moved events + public void ancestorResized(HierarchyEvent ce) { + if (check) { + System.out.println("Resized " + ce.getComponent()); + } + for (int i = 0; i < components.length; i++) { + if (components[i].equals(ce.getComponent())) { + if (! frame.equals(ce.getChanged()) || ce.getChangedParent() != null) { + System.err.println("FAIL: Invalid value of HierarchyEvent.getXXX"); + System.err.println("ce.getChanged() : " + ce.getChanged()); + System.err.println("ce.getChangedParent() : " + ce.getChangedParent()); + passed = false; + } + //setting this array for purpose of checking ancestor_resized + ancestorResized[i] = true; + resizeCount++; + if (resizeCount == components.length) { + resizeTriggered = true; + synchronized (resizeLock) { + try { + resizeLock.notifyAll(); + } catch (Exception e) { + } + } + } + } + } + } + } + + private Frame frame, dummy; + private Panel panel; + private Button button; + private Label label; + private List list; + private Choice choice; + private Checkbox checkbox; + private Scrollbar scrollbar; + private TextField textfield; + private TextArea textarea; + private Component[] components; + private boolean[] ancestorResized; + private boolean[] ancestorMoved; + + private int delay = 500; + private int keyDelay = 50; + private int moveCount = 0; + private int resizeCount = 0; + + private boolean passed = true; + private boolean moveTriggered = false; + private boolean resizeTriggered = false; + private final Object moveLock = new Object(); + private final Object resizeLock = new Object(); + + private boolean check = false; + + private void invoke() throws InterruptedException { + try { + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + prepareControls(); + } + }); + try { + Thread.sleep(1000); // wait for graphic effects on systems like Win7 + } catch (InterruptedException ex) { + } + if (!performTest()) { + fail("Test failed"); + } + } catch (InvocationTargetException ex) { + fail(ex.getMessage()); + } + } + + /***************************************************** + * Standard Test Machinery Section + * DO NOT modify anything in this section -- it's a + * standard chunk of code which has all of the + * synchronisation necessary for the test harness. + * By keeping it the same in all tests, it is easier + * to read and understand someone else's test, as + * well as insuring that all tests behave correctly + * with the test harness. + * There is a section following this for test- + * classes + ******************************************************/ + private static void init() throws InterruptedException { + //*** Create instructions for the user here *** + //System.setProperty("sun.awt.disableMixing", "true"); + + String[] instructions = { + "This is an AUTOMATIC test, simply wait until it is done.", + "The result (passed or failed) will be shown in the", + "message window below." + }; + Sysout.createDialog(); + Sysout.printInstructions(instructions); + + HierarchyBoundsListenerMixingTest instance = new HierarchyBoundsListenerMixingTest(); + + instance.invoke(); + + pass(); + }//End init() + private static boolean theTestPassed = false; + private static boolean testGeneratedInterrupt = false; + private static String failureMessage = ""; + private static Thread mainThread = null; + private static int sleepTime = 300000; + + // Not sure about what happens if multiple of this test are + // instantiated in the same VM. Being static (and using + // static vars), it aint gonna work. Not worrying about + // it for now. + public static void main(String args[]) throws InterruptedException { + mainThread = Thread.currentThread(); + try { + init(); + } catch (TestPassedException e) { + //The test passed, so just return from main and harness will + // interepret this return as a pass + return; + } + //At this point, neither test pass nor test fail has been + // called -- either would have thrown an exception and ended the + // test, so we know we have multiple threads. + + //Test involves other threads, so sleep and wait for them to + // called pass() or fail() + try { + Thread.sleep(sleepTime); + //Timed out, so fail the test + throw new RuntimeException("Timed out after " + sleepTime / 1000 + " seconds"); + } catch (InterruptedException e) { + //The test harness may have interrupted the test. If so, rethrow the exception + // so that the harness gets it and deals with it. + if (!testGeneratedInterrupt) { + throw e; + } + + //reset flag in case hit this code more than once for some reason (just safety) + testGeneratedInterrupt = false; + + if (theTestPassed == false) { + throw new RuntimeException(failureMessage); + } + } + + }//main + + public static synchronized void setTimeoutTo(int seconds) { + sleepTime = seconds * 1000; + } + + public static synchronized void pass() { + Sysout.println("The test passed."); + Sysout.println("The test is over, hit Ctl-C to stop Java VM"); + //first check if this is executing in main thread + if (mainThread == Thread.currentThread()) { + //Still in the main thread, so set the flag just for kicks, + // and throw a test passed exception which will be caught + // and end the test. + theTestPassed = true; + throw new TestPassedException(); + } + theTestPassed = true; + testGeneratedInterrupt = true; + mainThread.interrupt(); + }//pass() + + public static synchronized void fail() { + //test writer didn't specify why test failed, so give generic + fail("it just plain failed! :-)"); + } + + public static synchronized void fail(String whyFailed) { + Sysout.println("The test failed: " + whyFailed); + Sysout.println("The test is over, hit Ctl-C to stop Java VM"); + //check if this called from main thread + if (mainThread == Thread.currentThread()) { + //If main thread, fail now 'cause not sleeping + throw new RuntimeException(whyFailed); + } + theTestPassed = false; + testGeneratedInterrupt = true; + failureMessage = whyFailed; + mainThread.interrupt(); + }//fail() +}// class LWComboBox +class TestPassedException extends RuntimeException { +} + +//*********** End Standard Test Machinery Section ********** +//************ Begin classes defined for the test **************** +// if want to make listeners, here is the recommended place for them, then instantiate +// them in init() + +/* Example of a class which may be written as part of a test +class NewClass implements anInterface +{ +static int newVar = 0; + +public void eventDispatched(AWTEvent e) +{ +//Counting events to see if we get enough +eventCount++; + +if( eventCount == 20 ) +{ +//got enough events, so pass + +LWComboBox.pass(); +} +else if( tries == 20 ) +{ +//tried too many times without getting enough events so fail + +LWComboBox.fail(); +} + +}// eventDispatched() + +}// NewClass class + + */ +//************** End classes defined for the test ******************* +/**************************************************** +Standard Test Machinery +DO NOT modify anything below -- it's a standard +chunk of code whose purpose is to make user +interaction uniform, and thereby make it simpler +to read and understand someone else's test. + ****************************************************/ +/** +This is part of the standard test machinery. +It creates a dialog (with the instructions), and is the interface +for sending text messages to the user. +To print the instructions, send an array of strings to Sysout.createDialog +WithInstructions method. Put one line of instructions per array entry. +To display a message for the tester to see, simply call Sysout.println +with the string to be displayed. +This mimics System.out.println but works within the test harness as well +as standalone. + */ +class Sysout { + + private static TestDialog dialog; + + public static void createDialogWithInstructions(String[] instructions) { + dialog = new TestDialog(new Frame(), "Instructions"); + dialog.printInstructions(instructions); + dialog.setVisible(true); + println("Any messages for the tester will display here."); + } + + public static void createDialog() { + dialog = new TestDialog(new Frame(), "Instructions"); + String[] defInstr = {"Instructions will appear here. ", ""}; + dialog.printInstructions(defInstr); + dialog.setVisible(true); + println("Any messages for the tester will display here."); + } + + public static void printInstructions(String[] instructions) { + dialog.printInstructions(instructions); + } + + public static void println(String messageIn) { + dialog.displayMessage(messageIn); + System.out.println(messageIn); + } +}// Sysout class + +/** +This is part of the standard test machinery. It provides a place for the +test instructions to be displayed, and a place for interactive messages +to the user to be displayed. +To have the test instructions displayed, see Sysout. +To have a message to the user be displayed, see Sysout. +Do not call anything in this dialog directly. + */ +class TestDialog extends Dialog { + + TextArea instructionsText; + TextArea messageText; + int maxStringLength = 80; + + //DO NOT call this directly, go through Sysout + public TestDialog(Frame frame, String name) { + super(frame, name); + int scrollBoth = TextArea.SCROLLBARS_BOTH; + instructionsText = new TextArea("", 15, maxStringLength, scrollBoth); + add("North", instructionsText); + + messageText = new TextArea("", 5, maxStringLength, scrollBoth); + add("Center", messageText); + + pack(); + + setVisible(true); + }// TestDialog() + + //DO NOT call this directly, go through Sysout + public void printInstructions(String[] instructions) { + //Clear out any current instructions + instructionsText.setText(""); + + //Go down array of instruction strings + + String printStr, remainingStr; + for (int i = 0; i < instructions.length; i++) { + //chop up each into pieces maxSringLength long + remainingStr = instructions[i]; + while (remainingStr.length() > 0) { + //if longer than max then chop off first max chars to print + if (remainingStr.length() >= maxStringLength) { + //Try to chop on a word boundary + int posOfSpace = remainingStr.lastIndexOf(' ', maxStringLength - 1); + + if (posOfSpace <= 0) { + posOfSpace = maxStringLength - 1; + } + + printStr = remainingStr.substring(0, posOfSpace + 1); + remainingStr = remainingStr.substring(posOfSpace + 1); + } //else just print + else { + printStr = remainingStr; + remainingStr = ""; + } + + instructionsText.append(printStr + "\n"); + + }// while + + }// for + + }//printInstructions() + + //DO NOT call this directly, go through Sysout + public void displayMessage(String messageIn) { + messageText.append(messageIn + "\n"); + System.out.println(messageIn); + } +}// TestDialog class + diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JButtonInGlassPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JButtonInGlassPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JButton } component in GlassPane. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JButton +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JButtonInGlassPaneOverlapping + */ +public class JButtonInGlassPaneOverlapping extends GlassPaneOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JButton ch = new JButton(); + ch.setText("Swing component"); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JButtonInGlassPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JButtonOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JButtonOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JButton } component. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JButton +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JButtonOverlapping + */ +public class JButtonOverlapping extends SimpleOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JButton ch = new JButton(); + ch.setText("Swing component"); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JButtonOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JColorChooserOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JColorChooserOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JColorChooser } component. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JColorChooser +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JColorChooserOverlapping + */ +public class JColorChooserOverlapping extends SimpleOverlappingTestBase { + + public JColorChooserOverlapping() { + super(false); + } + + @Override + protected JComponent getSwingComponent() { + wasLWClicked = true; + JColorChooser ch = new JColorChooser(); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JColorChooserOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JComboBoxOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JComboBoxOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.BoxLayout; +import javax.swing.JComboBox; +import javax.swing.JFrame; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JCombobox } component. + *

This test creates combobox and test if heavyweight component is drawn correctly then dropdown is shown. + *

See base class for details. + */ +/* +@test +@summary Overlapping test for javax.swing.JScrollPane +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JComboBoxOverlapping + */ +public class JComboBoxOverlapping extends OverlappingTestBase { + + private boolean lwClicked = false; + private Point loc; + private Point loc2; + + {testEmbeddedFrame = true;} + + protected void prepareControls() { + final JFrame frame = new JFrame("Mixing : Dropdown Overlapping test"); + frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS)); + frame.setSize(200, 200); + frame.setVisible(true); + + final JComboBox cb = new JComboBox(petStrings); + cb.setPreferredSize(new Dimension(frame.getContentPane().getWidth(), 20)); + cb.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + if (e.getSource() == cb) { + lwClicked = true; + } + } + }); + + frame.add(cb); + propagateAWTControls(frame); + frame.setVisible(true); + loc = cb.getLocationOnScreen(); + loc2 = frame.getContentPane().getLocationOnScreen(); + } + + @Override + protected boolean performTest() { + // run robot + Robot robot = Util.createRobot(); + robot.setAutoDelay(ROBOT_DELAY); + + loc2.translate(75, 75); + pixelPreCheck(robot, loc2, currentAwtControl); + + loc.translate(3, 3); + clickAndBlink(robot, loc, false); + + clickAndBlink(robot, loc2, false); + + return lwClicked; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JComboBoxOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JEditorPaneInGlassPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JEditorPaneInGlassPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.Point; +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JBEditorPane } component in GlassPane. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JLabel +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JEditorPaneInGlassPaneOverlapping + */ +public class JEditorPaneInGlassPaneOverlapping extends GlassPaneOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JEditorPane ch = new JEditorPane(); + ch.setText("Swing component"); + OverlappingTestBase.shift = new Point(12, 12); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JEditorPaneInGlassPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JEditorPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JEditorPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JEditorPane } component. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JLabel +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JEditorPaneOverlapping + */ +public class JEditorPaneOverlapping extends SimpleOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JEditorPane ch = new JEditorPane(); + ch.setText("Swing component"); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JEditorPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JGlassPaneInternalFrameOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JGlassPaneInternalFrameOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Container; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.JFrame; +import javax.swing.JInternalFrame; +import javax.swing.SwingUtilities; + +/** + * AWT/Swing overlapping test with JInternalFrame being put in GlassPane. + * See JDK-6637655 and + * JDK-6985776. + *

See base class for details. + */ +/* +@test +@bug 6637655 6985776 +@summary Overlapping test for javax.swing.JScrollPane +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JGlassPaneInternalFrameOverlapping + */ +public class JGlassPaneInternalFrameOverlapping extends OverlappingTestBase { + + private boolean lwClicked = true; + private Point lLoc; + private Point lLoc2; + private JInternalFrame internalFrame; + + protected boolean performTest() { + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + lLoc = internalFrame.getContentPane().getLocationOnScreen(); + lLoc2 = lLoc.getLocation(); + lLoc2.translate(0, internalFrame.getContentPane().getHeight() + 10); + } + }); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + // run robot + Robot robot = Util.createRobot(); + robot.setAutoDelay(ROBOT_DELAY); + + clickAndBlink(robot, lLoc); + + Color c = robot.getPixelColor(lLoc2.x, lLoc2.y); + robot.mouseMove(lLoc2.x, lLoc2.y); + if (!c.equals(AWT_BACKGROUND_COLOR) && + currentAwtControl.getClass() != java.awt.Scrollbar.class && + currentAwtControl.getClass() != java.awt.Choice.class) { + fail("The HW component did not pass pixel color check and is not drawn correctly"); + } + + return lwClicked; + } + + // {debugClassName = "Choice";} + + @Override + protected void prepareControls() { + JFrame frame = new JFrame("Glass Pane children test"); + frame.setLayout(null); + + Container contentPane = frame.getContentPane(); + contentPane.setLayout(new BorderLayout()); + super.propagateAWTControls(contentPane); + + Container glassPane = (Container) frame.getRootPane().getGlassPane(); + glassPane.setVisible(true); + glassPane.setLayout(null); + + internalFrame = new JInternalFrame("Internal Frame", true); + internalFrame.setBounds(50, 0, 200, 100); + internalFrame.setVisible(true); + glassPane.add(internalFrame); + + internalFrame.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + lwClicked = true; + } + }); + + frame.setSize(300, 180); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + if (System.getProperty("os.name").toLowerCase().contains("os x")) { + System.out.println("Aqua L&F ignores setting color to component. Test passes on Mac OS X."); + return; + } + instance = new JGlassPaneInternalFrameOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JGlassPaneMoveOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JGlassPaneMoveOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Container; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.InputEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.JFrame; +import javax.swing.JInternalFrame; +import javax.swing.SwingUtilities; + +/** + * AWT/Swing overlapping test with JInternalFrame being moved in GlassPane. + * See JDK-6637655 and + * JDK-6981919. + *

See base class for details. + */ +/* +@test +@bug 6637655 6981919 +@summary Overlapping test for javax.swing.JScrollPane +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JGlassPaneMoveOverlapping + */ +public class JGlassPaneMoveOverlapping extends OverlappingTestBase { + + private boolean lwClicked = true; + private volatile Point lLoc; + private volatile Point lLoc2; + + private JInternalFrame internalFrame; + private JFrame frame = null; + private volatile Point frameLoc; + + protected boolean performTest() { + + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + lLoc = internalFrame.getContentPane().getLocationOnScreen(); + lLoc2 = lLoc.getLocation(); + lLoc2.translate(0, internalFrame.getHeight()); + frameLoc = frame.getLocationOnScreen(); + frameLoc.translate(frame.getWidth()/2, 3); + } + }); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + + // run robot + Robot robot = Util.createRobot(); + robot.setAutoDelay(ROBOT_DELAY); + + // force focus on JFrame (jtreg workaround) + robot.mouseMove(frameLoc.x, frameLoc.y); + Util.waitForIdle(robot); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.delay(50); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + Util.waitForIdle(robot); + + + //slow move + robot.mouseMove(lLoc.x + 25, lLoc.y - 5); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.delay(100); + robot.mouseMove(lLoc.x + 45, lLoc.y - 5); + robot.delay(100); + robot.mouseMove(lLoc.x + internalWidth - 75, lLoc.y - 5); + robot.delay(100); + robot.mouseMove(lLoc.x + internalWidth - 55, lLoc.y - 5); + robot.delay(100); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + Color c2 = robot.getPixelColor(lLoc.x + internalWidth + 15, lLoc.y - 5); + if (c2.equals(AWT_BACKGROUND_COLOR)) { + error("Foreground frame is not drawn properly"); + } + Color c = robot.getPixelColor(lLoc.x + internalWidth - 95, lLoc.y + 5); + robot.mouseMove(lLoc.x + internalWidth - 95, lLoc.y + 5); + System.out.println("color: " + c + " " + AWT_BACKGROUND_COLOR); + if (!c.equals(AWT_BACKGROUND_COLOR) && currentAwtControl.getClass() != java.awt.Scrollbar.class) { + error("Background AWT component is not drawn properly"); + } + + return true; + } + + // {debugClassName = "Choice";} + + private static void error(String st) { + //System.out.println(st); + fail(st); + } + + private static final int internalWidth = 200; + + @Override + protected void prepareControls() { + if(frame != null) { + frame.setVisible(false); + } + frame = new JFrame("Glass Pane children test"); + frame.setLayout(null); + + Container contentPane = frame.getContentPane(); + contentPane.setLayout(new BorderLayout()); + super.propagateAWTControls(contentPane); + + Container glassPane = (Container) frame.getRootPane().getGlassPane(); + glassPane.setVisible(true); + glassPane.setLayout(null); + + internalFrame = new JInternalFrame("Internal Frame", true); + internalFrame.setBounds(50, 0, internalWidth, 100); + internalFrame.setVisible(true); + glassPane.add(internalFrame); + + internalFrame.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + lwClicked = true; + } + }); + + frame.setSize(400, 180); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + if (System.getProperty("os.name").toLowerCase().contains("os x")) { + System.out.println("Aqua L&F ignores setting color to component. Test passes on Mac OS X."); + return; + } + instance = new JGlassPaneMoveOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JInternalFrameMoveOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JInternalFrameMoveOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.InputEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.JButton; +import javax.swing.JDesktopPane; +import javax.swing.JFrame; +import javax.swing.JInternalFrame; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JInternalFrame } component during move. + *

See CR6768230 for details and base class for test info. + */ +/* +@test +@bug 6985399 +@summary Overlapping test for javax.swing.JScrollPane +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JInternalFrameMoveOverlapping + */ +public class JInternalFrameMoveOverlapping extends OverlappingTestBase { + + private boolean lwClicked = true; + private Point locTopFrame; + private Point locTarget; + + protected boolean performTest() { + // run robot + Robot robot = Util.createRobot(); + robot.setAutoDelay(ROBOT_DELAY); + + robot.mouseMove(locTopFrame.x + 25, locTopFrame.y + 25); + robot.mousePress(InputEvent.BUTTON1_MASK); + try { + Thread.sleep(500); + } catch (InterruptedException ex) { + } + robot.mouseMove(locTopFrame.x + (locTarget.x - locTopFrame.x)/2, locTopFrame.y + (locTarget.y - locTopFrame.y)/2); + try { + Thread.sleep(500); + } catch (InterruptedException ex) { + } + robot.mouseMove(locTarget.x, locTarget.y); + try { + Thread.sleep(500); + } catch (InterruptedException ex) { + } + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + clickAndBlink(robot, locTarget); + + return lwClicked; + } + + //static {debugClassName = "Choice";} + + @Override + protected void prepareControls() { + + + JDesktopPane desktopPane = new JDesktopPane(); + + JInternalFrame bottomFrame = new JInternalFrame("bottom frame", false, false, false, false); + bottomFrame.setSize(220, 220); + super.propagateAWTControls(bottomFrame); + desktopPane.add(bottomFrame); + bottomFrame.setVisible(true); + + JInternalFrame topFrame = new JInternalFrame("top frame", false, false, false, false); + topFrame.setSize(200, 200); + topFrame.add(new JButton("LW Button") { + + { + addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + lwClicked = true; + } + }); + } + }); + desktopPane.add(topFrame); + topFrame.setVisible(true); + + JFrame frame = new JFrame("Test Window"); + frame.setSize(300, 300); + frame.setContentPane(desktopPane); + frame.setVisible(true); + + locTopFrame = topFrame.getLocationOnScreen(); + locTarget = new Point(locTopFrame.x + bottomFrame.getWidth() / 2, locTopFrame.y + bottomFrame.getHeight()/2); + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JInternalFrameMoveOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JInternalFrameOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JInternalFrameOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.JButton; +import javax.swing.JDesktopPane; +import javax.swing.JFrame; +import javax.swing.JInternalFrame; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JInternalFrame } component. + *

See base class for test info. + */ +/* +@test +@summary Overlapping test for javax.swing.JScrollPane +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JInternalFrameOverlapping + */ +public class JInternalFrameOverlapping extends OverlappingTestBase { + + private boolean lwClicked = true; + private Point lLoc; + + protected boolean performTest() { + + + // run robot + Robot robot = Util.createRobot(); + robot.setAutoDelay(ROBOT_DELAY); + + clickAndBlink(robot, lLoc); + + return lwClicked; + } + + /** + * Creating two JInternalFrames in JDesktopPanes. Put lightweight component into one frame and heavyweight into another. + */ + @Override + protected void prepareControls() { + JDesktopPane desktopPane = new JDesktopPane(); + + JFrame frame = new JFrame("Test Window"); + frame.setSize(300, 300); + frame.setContentPane(desktopPane); + frame.setVisible(true); + JInternalFrame bottomFrame = new JInternalFrame("bottom frame", false, false, false, false); + bottomFrame.setSize(220, 220); + desktopPane.add(bottomFrame); + bottomFrame.setVisible(true); + + super.propagateAWTControls(bottomFrame); + JInternalFrame topFrame = new JInternalFrame("top frame", false, false, false, false); + topFrame.setSize(200, 200); + JButton jbutton = new JButton("LW Button") {{ + addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + lwClicked = true; + } + }); + }}; + topFrame.add(jbutton); + desktopPane.add(topFrame); + topFrame.setVisible(true); + lLoc = jbutton.getLocationOnScreen(); + lLoc.translate(jbutton.getWidth()/2, jbutton.getWidth()/2); //click at middle of the button + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JInternalFrameOverlapping(); + OverlappingTestBase.doMain(args); + } + +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JLabelInGlassPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JLabelInGlassPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.Dimension; +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JLabel } component in GlassPane. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JLabel +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JLabelInGlassPaneOverlapping + */ +public class JLabelInGlassPaneOverlapping extends GlassPaneOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JLabel ch = new JLabel(); + ch.setPreferredSize(new Dimension(50, 50)); + ch.setText("Swing component"); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JLabelInGlassPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JLabelOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JLabelOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Dimension; +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JLabel } component. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JLabel +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JLabelOverlapping + */ +public class JLabelOverlapping extends SimpleOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JLabel ch = new JLabel(); + ch.setPreferredSize(new Dimension(50, 50)); + ch.setText("Swing component"); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JLabelOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JListInGlassPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JListInGlassPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JList } component in GlassPane. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JList +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JListInGlassPaneOverlapping + */ +public class JListInGlassPaneOverlapping extends GlassPaneOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JList ch = new JList(new String[] {"one", "two", "three"}); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JListInGlassPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JListOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JListOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JList } component. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JList +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JListOverlapping + */ +public class JListOverlapping extends SimpleOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JList ch = new JList(new String[] {"one", "two", "three", "four"}); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JListOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JMenuBarOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JMenuBarOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.Color; +import java.awt.GridLayout; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JSeparator; +import javax.swing.SwingUtilities; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JMenuBar } and {@link javax.swing.JSeparator} components. + *

This test creates menu bar and test if heavyweight component is drawn correctly then menu dropdown is shown. + *

See base class for test info. + */ +/* +@test +@summary Overlapping test for javax.swing.JScrollPane +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JMenuBarOverlapping + */ +public class JMenuBarOverlapping extends OverlappingTestBase { + + {testEmbeddedFrame = true;} + + private boolean lwClicked = false; + private boolean spClicked = false; + private Point loc; + private Point loc2; + private Point sepLoc; + private JFrame frame; + private JMenuBar menuBar; + JSeparator separator; + + protected void prepareControls() { + frame = new JFrame("Mixing : Dropdown Overlapping test"); + frame.setLayout(new GridLayout(0,1)); + frame.setSize(200, 200); + frame.setVisible(true); + + menuBar = new JMenuBar(); + JMenu menu = new JMenu("Test Menu"); + ActionListener menuListener = new ActionListener() { + + public void actionPerformed(ActionEvent event) { + lwClicked = true; + } + }; + + JMenuItem item; + menu.add(item = new JMenuItem("first")); + item.addActionListener(menuListener); + separator = new JSeparator(); + separator.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + spClicked = true; + } + }); + menu.add(separator); + + for (int i = 0; i < petStrings.length; i++) { + menu.add(item = new JMenuItem(petStrings[i])); + item.addActionListener(menuListener); + } + menuBar.add(menu); + frame.setJMenuBar(menuBar); + + propagateAWTControls(frame); + frame.setVisible(true); + } + + @Override + protected boolean performTest() { + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + loc = menuBar.getLocationOnScreen(); + loc2 = frame.getContentPane().getLocationOnScreen(); + } + }); + } catch (Exception e) { + } + // run robot + Robot robot = Util.createRobot(); + robot.setAutoDelay(ROBOT_DELAY); + + loc2.translate(75, 75); + pixelPreCheck(robot, loc2, currentAwtControl); + + loc.translate(3, 3); + clickAndBlink(robot, loc, false); + + clickAndBlink(robot, loc2, false); + + clickAndBlink(robot, loc, false); + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + sepLoc = separator.getLocationOnScreen(); + } + }); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + sepLoc.translate(20, 1); + clickAndBlink(robot, sepLoc, false); + + clickAndBlink(robot, loc, false); // close menu before running next step + return lwClicked && spClicked; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JMenuBarOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JPanelInGlassPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JPanelInGlassPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.Dimension; +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JPanel } component in GlassPane. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JPanel +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JPanelInGlassPaneOverlapping + */ +public class JPanelInGlassPaneOverlapping extends GlassPaneOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JPanel ch = new JPanel(); + ch.setPreferredSize(new Dimension(50, 50)); + ch.setBorder(BorderFactory.createTitledBorder("Swing Component")); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JPanelInGlassPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JPanelOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JPanelOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Dimension; +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JPanel } component. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JPanel +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JPanelOverlapping + */ +public class JPanelOverlapping extends SimpleOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JPanel ch = new JPanel(); + ch.setPreferredSize(new Dimension(50, 50)); + ch.setBorder(BorderFactory.createTitledBorder("Swing Component")); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JPanelOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JPopupMenuOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JPopupMenuOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.Color; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.lang.reflect.InvocationTargetException; +import javax.swing.JFrame; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; +import javax.swing.SpringLayout; +import javax.swing.SwingUtilities; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JPopupMenu } component. + *

This test creates menu and test if heavyweight component is drawn correctly then menu dropdown is shown. + *

See base class for test info. + */ +/* +@test +@summary Overlapping test for javax.swing.JScrollPane +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JPopupMenuOverlapping + */ +public class JPopupMenuOverlapping extends OverlappingTestBase { + + {testEmbeddedFrame = true;} + + private boolean lwClicked = false; + private Point loc; + private JPopupMenu popup; + private JFrame frame=null; + + protected void prepareControls() { + if(frame != null) { + frame.setVisible(false); + } + frame = new JFrame("Mixing : Dropdown Overlapping test"); + frame.setLayout(new SpringLayout()); + frame.setSize(200, 200); + + popup = new JPopupMenu(); + ActionListener menuListener = new ActionListener() { + + public void actionPerformed(ActionEvent event) { + lwClicked = true; + } + }; + JMenuItem item; + for (int i = 0; i < petStrings.length; i++) { + popup.add(item = new JMenuItem(petStrings[i])); + item.addActionListener(menuListener); + } + propagateAWTControls(frame); + frame.setVisible(true); + loc = frame.getContentPane().getLocationOnScreen(); + } + + @Override + protected boolean performTest() { + // run robot + Robot robot = Util.createRobot(); + robot.setAutoDelay(ROBOT_DELAY); + + loc.translate(75, 75); + + pixelPreCheck(robot, loc, currentAwtControl); + + try { + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + popup.show(frame.getContentPane(), 15, 15); + } + }); + + robot.waitForIdle(); + + clickAndBlink(robot, loc, false); + + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + popup.setVisible(false); + } + }); + } catch (InterruptedException ex) { + fail(ex.getMessage()); + } catch (InvocationTargetException ex) { + fail(ex.getMessage()); + } + + return lwClicked; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JPopupMenuOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JProgressBarInGlassPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JProgressBarInGlassPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.Dimension; +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JProgressBar } component in GlassPane. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JProgressBar +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JProgressBarInGlassPaneOverlapping + */ +public class JProgressBarInGlassPaneOverlapping extends GlassPaneOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JProgressBar ch = new JProgressBar(); + ch.setValue(50); + ch.setPreferredSize(new Dimension(50, 50)); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JProgressBarInGlassPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JProgressBarOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JProgressBarOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Dimension; +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JProgressBar } component. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JProgressBar +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JProgressBarOverlapping + */ +public class JProgressBarOverlapping extends SimpleOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JProgressBar ch = new JProgressBar(); + ch.setValue(50); + ch.setPreferredSize(new Dimension(50, 50)); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JProgressBarOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JScrollBarInGlassPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JScrollBarInGlassPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.Point; +import java.awt.Dimension; +import java.awt.event.AdjustmentEvent; +import java.awt.event.AdjustmentListener; +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JScrollBar } component in GlassPane. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JScrollBar +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JScrollBarInGlassPaneOverlapping + */ +public class JScrollBarInGlassPaneOverlapping extends GlassPaneOverlappingTestBase { + + public JScrollBarInGlassPaneOverlapping() { + super(false); + } + + @Override + protected JComponent getSwingComponent() { + JScrollBar ch = new JScrollBar(JScrollBar.VERTICAL); + ch.setPreferredSize(new Dimension(50, 50)); + ch.setValue(50); + ch.addAdjustmentListener(new AdjustmentListener() { + + public void adjustmentValueChanged(AdjustmentEvent e) { + wasLWClicked = true; + } + }); + OverlappingTestBase.shift = new Point(20, 16); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JScrollBarInGlassPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JScrollBarOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JScrollBarOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Point; +import java.awt.Dimension; +import java.awt.event.AdjustmentEvent; +import java.awt.event.AdjustmentListener; +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JScrollBar } component. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JScrollBar +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JScrollBarOverlapping + */ +public class JScrollBarOverlapping extends SimpleOverlappingTestBase { + + public JScrollBarOverlapping() { + super(false); + } + + @Override + protected JComponent getSwingComponent() { + JScrollBar ch = new JScrollBar(JScrollBar.VERTICAL); + ch.setPreferredSize(new Dimension(50, 50)); + ch.setValue(50); + ch.addAdjustmentListener(new AdjustmentListener() { + + public void adjustmentValueChanged(AdjustmentEvent e) { + wasLWClicked = true; + } + }); + OverlappingTestBase.shift = new Point(20, 16); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JScrollBarOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JScrollPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JScrollPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.AdjustmentEvent; +import java.awt.event.AdjustmentListener; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JScrollPane } component. + *

See base class for test info. + */ +/* +@test +@summary Overlapping test for javax.swing.JScrollPane +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JScrollPaneOverlapping + */ +public class JScrollPaneOverlapping extends OverlappingTestBase { + +// {testEmbeddedFrame = true;} + + private boolean horizontalClicked = false; + private boolean verticalClicked = false; + private Point hLoc; + private Point vLoc; + + private JFrame f; + private JPanel p; + private JScrollPane scrollPane; + + protected void prepareControls() { + + f = new JFrame("JScrollPane"); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.setSize(120, 120); + + p = new JPanel(new GridLayout(0, 1)); + + scrollPane = new JScrollPane(p); + scrollPane.setPreferredSize(new Dimension(300,300)); + scrollPane.setHorizontalScrollBarPolicy( + JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + scrollPane.setVerticalScrollBarPolicy( + JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + + scrollPane.getHorizontalScrollBar().setValue(1); + scrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() { + + public void adjustmentValueChanged(AdjustmentEvent e) { + horizontalClicked = true; + } + }); + + scrollPane.getVerticalScrollBar().setValue(1); + scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() { + + public void adjustmentValueChanged(AdjustmentEvent e) { + verticalClicked = true; + } + }); + + f.getContentPane().add(scrollPane); + f.setVisible(true); + propagateAWTControls(p); +// JButton b = new JButton("Space extender"); +// b.setPreferredSize(new Dimension(150,150)); +// p.add( b ); + + //b.requestFocus(); // to change the look of AWT component, especially Choice + } + + @Override + protected boolean performTest() { + // run robot + Robot robot = Util.createRobot(); + robot.setAutoDelay(ROBOT_DELAY); + + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + hLoc = scrollPane.getHorizontalScrollBar().getLocationOnScreen(); + vLoc = scrollPane.getVerticalScrollBar().getLocationOnScreen(); + } + }); + } catch (Exception e) { + } + hLoc.translate(2, 2); + vLoc.translate(2, 2); + + clickAndBlink(robot, hLoc, false); + clickAndBlink(robot, vLoc, false); + + return horizontalClicked && verticalClicked; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JScrollPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JSliderInGlassPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JSliderInGlassPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.Dimension; +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JSlider } component in GlassPane. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JSlider +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JSliderInGlassPaneOverlapping + */ +public class JSliderInGlassPaneOverlapping extends GlassPaneOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JSlider ch = new JSlider(); + ch.setPreferredSize(new Dimension(50, 50)); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JSliderInGlassPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JSliderOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JSliderOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Dimension; +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JSlider } component. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JSlider +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JSliderOverlapping + */ +public class JSliderOverlapping extends SimpleOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JSlider ch = new JSlider(); + ch.setPreferredSize(new Dimension(50, 50)); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JSliderOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JSpinnerInGlassPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JSpinnerInGlassPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.Dimension; +import javax.swing.event.ChangeEvent; +import javax.swing.*; +import javax.swing.event.ChangeListener; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JSpinner } component in GlassPane. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JSpinner +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JSpinnerInGlassPaneOverlapping + */ +public class JSpinnerInGlassPaneOverlapping extends GlassPaneOverlappingTestBase { + + {testResize = false;} + + public JSpinnerInGlassPaneOverlapping() { + super(false); + } + +// static {debugClassName = "Choice";} + @Override + protected JComponent getSwingComponent() { + JSpinner ch = new JSpinner(); + ch.setPreferredSize(new Dimension(30, 50)); + ch.addChangeListener(new ChangeListener() { + + public void stateChanged(ChangeEvent e) { + wasLWClicked = true; + } + }); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JSpinnerInGlassPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JSpinnerOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JSpinnerOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Dimension; +import javax.swing.event.ChangeEvent; +import javax.swing.*; +import javax.swing.event.ChangeListener; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JSpinner } component. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JSpinner +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JSpinnerOverlapping + */ +public class JSpinnerOverlapping extends SimpleOverlappingTestBase { + + public JSpinnerOverlapping() { + super(false); + } + +// static {debugClassName = "Choice";} + @Override + protected JComponent getSwingComponent() { + JSpinner ch = new JSpinner(); + ch.setPreferredSize(new Dimension(30, 50)); + ch.addChangeListener(new ChangeListener() { + + public void stateChanged(ChangeEvent e) { + wasLWClicked = true; + } + }); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JSpinnerOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JSplitPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JSplitPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.SwingUtilities; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JSplitPane } component. + *

This test creates puts heavyweight and lightweight components into different panels and test if splitter image and components itself are drawn correctly. + *

See base class for test info. + */ +/* +@test +@bug 6986109 +@summary Overlapping test for javax.swing.JSplitPane +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JSplitPaneOverlapping + */ +public class JSplitPaneOverlapping extends OverlappingTestBase { + + private boolean clicked = false; + private Point splitterLoc; + private JScrollPane sp1; + private JScrollPane sp2; + + protected void prepareControls() { + JFrame frame = new JFrame("SplitPane Mixing"); + JPanel p = new JPanel(new GridLayout()); + p.setPreferredSize(new Dimension(500, 500)); + propagateAWTControls(p); + sp1 = new JScrollPane(p); + + JButton button = new JButton("JButton"); + button.setBackground(Color.RED); + button.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + clicked = true; + } + }); + sp2 = new JScrollPane(button); + + JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp1, sp2); + splitPane.setOneTouchExpandable(false); + splitPane.setDividerLocation(150); + + splitPane.setPreferredSize(new Dimension(400, 200)); + + frame.getContentPane().add(splitPane); + frame.pack(); + frame.setVisible(true); + } + + private static final boolean ignoreFail = false; + + @Override + protected boolean performTest() { + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + splitterLoc = sp2.getLocationOnScreen(); + Point leftLoc = sp1.getLocationOnScreen(); + leftLoc.translate(sp1.getWidth(), 0); + splitterLoc.translate(-(splitterLoc.x - leftLoc.x) / 2, 30); + } + }); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + // run robot + Robot robot = Util.createRobot(); + robot.setAutoDelay(ROBOT_DELAY); + + robot.mouseMove(splitterLoc.x, splitterLoc.y); + Util.waitForIdle(robot); + + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseMove(splitterLoc.x - 50, splitterLoc.y); + Color c = robot.getPixelColor(splitterLoc.x - 50, splitterLoc.y); + System.out.println("Actual: "+c+", (not) expected: "+AWT_VERIFY_COLOR+" at "+(splitterLoc.x - 50)+", "+ splitterLoc.y); + if (!ignoreFail && c.equals(AWT_VERIFY_COLOR)) { + fail("The JSplitPane drag-n-drop image did not pass pixel color check and is overlapped"); + } + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + clickAndBlink(robot, splitterLoc); + + return clicked; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JSplitPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JTableInGlassPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JTableInGlassPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import javax.swing.JComponent; +import javax.swing.JTable; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JTable } component in GlassPane. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for JTable +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JTableInGlassPaneOverlapping + */ +public class JTableInGlassPaneOverlapping extends GlassPaneOverlappingTestBase { + + { + testResize = false; + } + + @Override + protected JComponent getSwingComponent() { + // Create columns names + String columnNames[] = {"Column 1", "Column 2", "Column 3"}; + + // Create some data + String dataValues[][] = { + {"12", "234", "67"}, + {"-123", "43", "853"}, + {"93", "89.2", "109"}, + {"279", "9033", "3092"}, + {"12", "234", "67"}, + {"-123", "43", "853"}, + {"93", "89.2", "109"}, + {"279", "9033", "3092"}, + {"12", "234", "67"}, + {"-123", "43", "853"}, + {"93", "89.2", "109"}, + {"279", "9033", "3092"}, + {"12", "234", "67"}, + {"-123", "43", "853"}, + {"93", "89.2", "109"}, + {"279", "9033", "3092"} + }; + + // Create a new table instance + JTable jt = new JTable(dataValues, columnNames); + jt.getModel().addTableModelListener(new TableModelListener() { + + public void tableChanged(TableModelEvent e) { + System.err.println("table changed"); + } + }); + return jt; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JTableInGlassPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JTableOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JTableOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JTable } component. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for JTable +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JTableOverlapping + */ +public class JTableOverlapping extends SimpleOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + // Create columns names + String columnNames[] = { "Column 1", "Column 2", "Column 3" }; + + // Create some data + String dataValues[][] = + { + { "12", "234", "67" }, + { "-123", "43", "853" }, + { "93", "89.2", "109" }, + { "279", "9033", "3092" }, + { "12", "234", "67" }, + { "-123", "43", "853" }, + { "93", "89.2", "109" }, + { "279", "9033", "3092" }, + { "12", "234", "67" }, + { "-123", "43", "853" }, + { "93", "89.2", "109" }, + { "279", "9033", "3092" }, + { "12", "234", "67" }, + { "-123", "43", "853" }, + { "93", "89.2", "109" }, + { "279", "9033", "3092" } + }; + + // Create a new table instance + return new JTable( dataValues, columnNames ); + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JTableOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JTextAreaInGlassPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JTextAreaInGlassPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.Dimension; +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JTextArea } component in GlassPane. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JLabel +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JTextAreaInGlassPaneOverlapping + */ +public class JTextAreaInGlassPaneOverlapping extends GlassPaneOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JTextArea ch = new JTextArea(); + ch.setPreferredSize(new Dimension(50, 50)); + ch.setText("Swing component"); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JTextAreaInGlassPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JTextAreaOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JTextAreaOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Dimension; +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JTextArea } component. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JLabel +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JTextAreaOverlapping + */ +public class JTextAreaOverlapping extends SimpleOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JTextArea ch = new JTextArea(); + ch.setPreferredSize(new Dimension(50, 50)); + ch.setText("Swing component"); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JTextAreaOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JTextFieldInGlassPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JTextFieldInGlassPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.Dimension; +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JTextField } component in GlassPane. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JLabel +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JTextFieldInGlassPaneOverlapping + */ +public class JTextFieldInGlassPaneOverlapping extends GlassPaneOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JTextField ch = new JTextField(); + ch.setPreferredSize(new Dimension(50, 50)); + ch.setText("Swing component"); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JTextFieldInGlassPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JTextFieldOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JTextFieldOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Dimension; +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JTextField } component. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JLabel +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JTextFieldOverlapping + */ +public class JTextFieldOverlapping extends SimpleOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JTextField ch = new JTextField(); + ch.setPreferredSize(new Dimension(50, 50)); + ch.setText("Swing component"); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JTextFieldOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JToggleButtonInGlassPaneOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JToggleButtonInGlassPaneOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JToggleButton } component in GlassPane. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JToggleButton +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JToggleButtonInGlassPaneOverlapping + */ +public class JToggleButtonInGlassPaneOverlapping extends GlassPaneOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JToggleButton ch = new JToggleButton(); + ch.setText("Swing component"); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JToggleButtonInGlassPaneOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/JToggleButtonOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/JToggleButtonOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.swing.*; + +/** + * AWT/Swing overlapping test for {@link javax.swing.JToggleButton } component. + *

See base class for details. + */ +/* +@test +@summary Simple Overlapping test for javax.swing.JToggleButton +@author sergey.grinev@oracle.com: area=awt.mixing +@run main JToggleButtonOverlapping + */ +public class JToggleButtonOverlapping extends SimpleOverlappingTestBase { + + @Override + protected JComponent getSwingComponent() { + JToggleButton ch = new JToggleButton(); + ch.setText("Swing component"); + return ch; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new JToggleButtonOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/MixingFrameResizing.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/MixingFrameResizing.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.InputEvent; +import javax.swing.JFrame; +import javax.swing.SpringLayout; +import javax.swing.SwingUtilities; + +/** + * AWT/Swing overlapping test. + *

This test puts heavyweight component into JFrame and verifies that it's being drawn correctly after resizing the frame. + *

See base class for test info. + */ +/* +@test +@bug 6777370 +@summary Issues when resizing the JFrame with HW components +@author sergey.grinev@oracle.com: area=awt.mixing +@run main MixingFrameResizing + */ +public class MixingFrameResizing extends OverlappingTestBase { + + {testEmbeddedFrame = true;} + + private JFrame frame = null; + private Point lLoc; + private Point lLoc2; + private Dimension size; + + protected void prepareControls() { + if(frame != null) { + frame.setVisible(false); + } + frame = new JFrame("Mixing : Frame Resizing test"); + frame.setLayout(new SpringLayout()); + frame.setSize(50, 50); + frame.setVisible(true); + propagateAWTControls(frame); + Util.waitTillShown(frame); + } + + @Override + protected boolean performTest() { + int BORDER_SHIFT = frameBorderCounter(); + BORDER_SHIFT = Math.abs(BORDER_SHIFT) == 1 ? BORDER_SHIFT : (BORDER_SHIFT / 2); + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + lLoc = frame.getLocationOnScreen(); + size = frame.getSize(); + lLoc2 = frame.getContentPane().getLocationOnScreen(); + } + }); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + Robot robot = Util.createRobot(); + robot.setAutoDelay(ROBOT_DELAY/2); + + // resize window + robot.mouseMove(lLoc.x + size.width / 2 + BORDER_SHIFT, lLoc.y + size.height + BORDER_SHIFT); + Util.waitForIdle(robot); + robot.mousePress(InputEvent.BUTTON1_MASK); + for (int i = 0; i < 10; i++) { + robot.mouseMove(lLoc.x + size.width / 2 + BORDER_SHIFT, lLoc.y + size.height + BORDER_SHIFT + 20 * i); + } + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + robot.mouseMove(lLoc.x + size.width + BORDER_SHIFT, lLoc.y + size.height + BORDER_SHIFT); + Util.waitForIdle(robot); + robot.mousePress(InputEvent.BUTTON1_MASK); + for (int i = 0; i < 10; i++) { + robot.mouseMove(lLoc.x + size.width + BORDER_SHIFT + 20 * i, lLoc.y + size.height + BORDER_SHIFT); + } + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + Util.waitForIdle(robot); + // check if component is visible on the opened space + try { + Thread.sleep(300); //some more wait for Solaris (for some reason) + }catch(Exception ex) {} + lLoc2.translate(75, 75); + Color c = robot.getPixelColor(lLoc2.x, lLoc2.y); + System.out.println("Actual: "+c+", expected: "+AWT_VERIFY_COLOR); + + if (!c.equals(AWT_VERIFY_COLOR)) { + fail("HW component is not visible after resizing"); + } + + return true; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + if (System.getProperty("os.name").toLowerCase().contains("os x")) { + System.out.println("Aqua L&F ignores setting color to component. Test passes on Mac OS X."); + return; + } + instance = new MixingFrameResizing(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/MixingPanelsResizing.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/MixingPanelsResizing.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,462 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.*; +import java.awt.event.InputEvent; +import javax.swing.*; +import java.io.*; + +/** + * AWT/Swing overlapping test for Panel and JPanel behavior during resizing. + *

See JDK-6786219 for details + */ +/* +@test +@bug 6786219 +@summary Issues when resizing the frame after mixing of heavy weight & light weight components +@author sergey.grinev@oracle.com: area=awt.mixing +@build FrameBorderCounter +@run main MixingPanelsResizing + */ +public class MixingPanelsResizing { + + static volatile boolean failed = false; + + private static JFrame frame; + private static JButton jbutton; + private static Button awtButton; + private static JButton jbutton2; + private static Button awtButton2; + private static final Color jbColor = Color.RED; + private static final Color awtColor = Color.ORANGE; + private static final Color jb2Color = Color.BLUE; + private static final Color awt2Color = Color.CYAN; + private static final int ROBOT_DELAY = 500; + + private static Point lLoc; + private static int borderShift; + + private static int frameBorderCounter() { + String JAVA_HOME = System.getProperty("java.home"); + try { + Process p = Runtime.getRuntime().exec(JAVA_HOME + "/bin/java FrameBorderCounter"); + try { + p.waitFor(); + } catch (InterruptedException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + if (p.exitValue() != 0) { + throw new RuntimeException("FrameBorderCounter exited with not null code!\n" + readInputStream(p.getErrorStream())); + } + return Integer.parseInt(readInputStream(p.getInputStream()).trim()); + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + private static String readInputStream(InputStream is) throws IOException { + byte[] buffer = new byte[4096]; + int len = 0; + StringBuilder sb = new StringBuilder(); + try (InputStreamReader isr = new InputStreamReader(is)) { + while ((len = is.read(buffer)) > 0) { + sb.append(new String(buffer, 0, len)); + } + } + return sb.toString(); + } + + private static void init() throws Exception { + //*** Create instructions for the user here *** + + borderShift = frameBorderCounter(); + borderShift = Math.abs(borderShift) == 1 ? borderShift : (borderShift / 2); + String[] instructions = { + "This is an AUTOMATIC test, simply wait until it is done.", + "The result (passed or failed) will be shown in the", + "message window below." + }; + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + Sysout.createDialog(); + Sysout.printInstructions(instructions); + + // prepare controls + + frame = new JFrame(); + + Panel awtPanel = new Panel(); + awtPanel.setBackground(Color.GREEN); + awtButton = new Button("AWTButton"); + awtPanel.add(awtButton); + awtButton.setForeground(awtColor); + awtButton.setBackground(awtColor); + jbutton = new JButton("SwingButton"); + awtPanel.add(jbutton); + jbutton.setForeground(jbColor); + jbutton.setBackground(jbColor); + + JPanel jPanel = new JPanel(); + jbutton2 = new JButton("SwingButton2"); + jPanel.add(jbutton2); + jbutton2.setForeground(jb2Color); + jbutton2.setBackground(jb2Color); + awtButton2 = new Button("AWT Button2"); + jPanel.add(awtButton2); + awtButton2.setForeground(awt2Color); + awtButton2.setBackground(awt2Color); + jPanel.setBackground(Color.YELLOW); + + frame.add(awtPanel, BorderLayout.SOUTH); + frame.add(jPanel, BorderLayout.NORTH); + + frame.pack(); + frame.setVisible(true); + } + }); + + ///////////////////////// + + final Robot robot = Util.createRobot(); + robot.setAutoDelay(ROBOT_DELAY); + + Util.waitForIdle(robot); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + lLoc = frame.getLocationOnScreen(); + lLoc.translate(frame.getWidth() + borderShift, frame.getHeight() + borderShift); + } + }); + + //grow + robot.mouseMove(lLoc.x, lLoc.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + + Runnable test = new Runnable() { + + public void run() { + Point btnLoc = jbutton.getLocationOnScreen(); + Color c = robot.getPixelColor(btnLoc.x + 5, btnLoc.y + 5); + if (!c.equals(jbColor)) { + fail("JButton was not redrawn properly on AWT Panel during move"); + } + + btnLoc = awtButton.getLocationOnScreen(); + c = robot.getPixelColor(btnLoc.x + 5, btnLoc.y + 5); + if (!c.equals(awtColor)) { + fail("AWT Button was not redrawn properly on AWT Panel during move"); + } + + btnLoc = jbutton2.getLocationOnScreen(); + c = robot.getPixelColor(btnLoc.x + 5, btnLoc.y + 5); + if (!c.equals(jb2Color)) { + fail("JButton was not redrawn properly on JPanel during move"); + } + + btnLoc = awtButton2.getLocationOnScreen(); + c = robot.getPixelColor(btnLoc.x + 5, btnLoc.y + 5); + if (!c.equals(awt2Color)) { + fail("ATW Button was not redrawn properly on JPanel during move"); + } + } + }; + + for (int i = 0; i < 30; i++) { + test.run(); + robot.mouseMove(lLoc.x + 20 * i, lLoc.y + 10 * i); + } + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + //back + System.out.println("fast back"); + robot.mousePress(InputEvent.BUTTON1_MASK); + for (int i = 5; i >= 0; i--) { + test.run(); + robot.mouseMove(lLoc.x + 120 * i, lLoc.y + 60 * i); + } + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + pass(); + }//End init() + /***************************************************** + * Standard Test Machinery Section + * DO NOT modify anything in this section -- it's a + * standard chunk of code which has all of the + * synchronisation necessary for the test harness. + * By keeping it the same in all tests, it is easier + * to read and understand someone else's test, as + * well as insuring that all tests behave correctly + * with the test harness. + * There is a section following this for test- + * classes + ******************************************************/ + private static boolean theTestPassed = false; + private static boolean testGeneratedInterrupt = false; + private static String failureMessage = ""; + private static Thread mainThread = null; + private static int sleepTime = 300000; + + // Not sure about what happens if multiple of this test are + // instantiated in the same VM. Being static (and using + // static vars), it aint gonna work. Not worrying about + // it for now. + public static void main(String args[]) throws Exception { + if (!Toolkit.getDefaultToolkit().isDynamicLayoutActive()) { + System.out.println("Dynamic layout is not active. Test passes."); + return; + } + mainThread = Thread.currentThread(); + try { + init(); + } catch (TestPassedException e) { + //The test passed, so just return from main and harness will + // interepret this return as a pass + return; + } + //At this point, neither test pass nor test fail has been + // called -- either would have thrown an exception and ended the + // test, so we know we have multiple threads. + + //Test involves other threads, so sleep and wait for them to + // called pass() or fail() + try { + Thread.sleep(sleepTime); + //Timed out, so fail the test + throw new RuntimeException("Timed out after " + sleepTime / 1000 + " seconds"); + } catch (InterruptedException e) { + //The test harness may have interrupted the test. If so, rethrow the exception + // so that the harness gets it and deals with it. + if (!testGeneratedInterrupt) { + throw e; + } + + //reset flag in case hit this code more than once for some reason (just safety) + testGeneratedInterrupt = false; + + if (theTestPassed == false) { + throw new RuntimeException(failureMessage); + } + } + + }//main + + public static synchronized void setTimeoutTo(int seconds) { + sleepTime = seconds * 1000; + } + + public static synchronized void pass() { + Sysout.println("The test passed."); + Sysout.println("The test is over, hit Ctl-C to stop Java VM"); + //first check if this is executing in main thread + if (mainThread == Thread.currentThread()) { + //Still in the main thread, so set the flag just for kicks, + // and throw a test passed exception which will be caught + // and end the test. + theTestPassed = true; + throw new TestPassedException(); + } + theTestPassed = true; + testGeneratedInterrupt = true; + mainThread.interrupt(); + }//pass() + + public static synchronized void fail() { + //test writer didn't specify why test failed, so give generic + fail("it just plain failed! :-)"); + } + + public static synchronized void fail(String whyFailed) { + Sysout.println("The test failed: " + whyFailed); + Sysout.println("The test is over, hit Ctl-C to stop Java VM"); + //check if this called from main thread + if (mainThread == Thread.currentThread()) { + //If main thread, fail now 'cause not sleeping + throw new RuntimeException(whyFailed); + } + theTestPassed = false; + testGeneratedInterrupt = true; + failureMessage = whyFailed; + mainThread.interrupt(); + }//fail() +}// class JButtonInGlassPane +class TestPassedException extends RuntimeException { +} + +//*********** End Standard Test Machinery Section ********** +//************ Begin classes defined for the test **************** +// if want to make listeners, here is the recommended place for them, then instantiate +// them in init() + +/* Example of a class which may be written as part of a test +class NewClass implements anInterface +{ +static int newVar = 0; + +public void eventDispatched(AWTEvent e) +{ +//Counting events to see if we get enough +eventCount++; + +if( eventCount == 20 ) +{ +//got enough events, so pass + +JButtonInGlassPane.pass(); +} +else if( tries == 20 ) +{ +//tried too many times without getting enough events so fail + +JButtonInGlassPane.fail(); +} + +}// eventDispatched() + +}// NewClass class + + */ +//************** End classes defined for the test ******************* +/**************************************************** +Standard Test Machinery +DO NOT modify anything below -- it's a standard +chunk of code whose purpose is to make user +interaction uniform, and thereby make it simpler +to read and understand someone else's test. + ****************************************************/ +/** +This is part of the standard test machinery. +It creates a dialog (with the instructions), and is the interface +for sending text messages to the user. +To print the instructions, send an array of strings to Sysout.createDialog +WithInstructions method. Put one line of instructions per array entry. +To display a message for the tester to see, simply call Sysout.println +with the string to be displayed. +This mimics System.out.println but works within the test harness as well +as standalone. + */ +class Sysout { + + private static TestDialog dialog; + + public static void createDialogWithInstructions(String[] instructions) { + dialog = new TestDialog(new Frame(), "Instructions"); + dialog.printInstructions(instructions); + dialog.setVisible(true); + println("Any messages for the tester will display here."); + } + + public static void createDialog() { + dialog = new TestDialog(new Frame(), "Instructions"); + String[] defInstr = {"Instructions will appear here. ", ""}; + dialog.printInstructions(defInstr); + dialog.setVisible(true); + println("Any messages for the tester will display here."); + } + + public static void printInstructions(String[] instructions) { + dialog.printInstructions(instructions); + } + + public static void println(String messageIn) { + dialog.displayMessage(messageIn); + System.out.println(messageIn); + } +}// Sysout class + +/** +This is part of the standard test machinery. It provides a place for the +test instructions to be displayed, and a place for interactive messages +to the user to be displayed. +To have the test instructions displayed, see Sysout. +To have a message to the user be displayed, see Sysout. +Do not call anything in this dialog directly. + */ +class TestDialog extends Dialog { + + TextArea instructionsText; + TextArea messageText; + int maxStringLength = 80; + + //DO NOT call this directly, go through Sysout + public TestDialog(Frame frame, String name) { + super(frame, name); + int scrollBoth = TextArea.SCROLLBARS_BOTH; + instructionsText = new TextArea("", 15, maxStringLength, scrollBoth); + add("North", instructionsText); + + messageText = new TextArea("", 5, maxStringLength, scrollBoth); + add("Center", messageText); + + pack(); + + setVisible(true); + }// TestDialog() + + //DO NOT call this directly, go through Sysout + public void printInstructions(String[] instructions) { + //Clear out any current instructions + instructionsText.setText(""); + + //Go down array of instruction strings + + String printStr, remainingStr; + for (int i = 0; i < instructions.length; i++) { + //chop up each into pieces maxSringLength long + remainingStr = instructions[i]; + while (remainingStr.length() > 0) { + //if longer than max then chop off first max chars to print + if (remainingStr.length() >= maxStringLength) { + //Try to chop on a word boundary + int posOfSpace = remainingStr.lastIndexOf(' ', maxStringLength - 1); + + if (posOfSpace <= 0) { + posOfSpace = maxStringLength - 1; + } + + printStr = remainingStr.substring(0, posOfSpace + 1); + remainingStr = remainingStr.substring(posOfSpace + 1); + } //else just print + else { + printStr = remainingStr; + remainingStr = ""; + } + + instructionsText.append(printStr + "\n"); + + }// while + + }// for + + }//printInstructions() + + //DO NOT call this directly, go through Sysout + public void displayMessage(String messageIn) { + messageText.append(messageIn + "\n"); + System.out.println(messageIn); + } +}// TestDialog class + diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/OpaqueOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/OpaqueOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import com.sun.awt.AWTUtilities; +import java.awt.Frame; +import java.awt.Panel; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.event.InputEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.JButton; +import javax.swing.SwingUtilities; + +/** + * AWT/Swing overlapping test for opaque Swing components. + *

This test verify if AWT components are drawn correctly under opaque components. + *

See JDK-6776743 for details + *

See base class for test info. + */ +/* +@test +@bug 6776743 +@summary Opaque overlapping test for each AWT component +@run main OpaqueOverlapping + */ +public class OpaqueOverlapping extends OverlappingTestBase { + + { + useClickValidation = false; + failMessage = "Opacity test mismatchs"; + + // CR 6994264 (Choice autohides dropdown on Solaris 10) + skipClassNames = new String[] { "Choice" }; + } + private String testSeq; + private final static String checkSeq = "010000101"; + private Point heavyLoc; + private JButton light; + private Frame frame = null; + + protected void prepareControls() { + testSeq = ""; + // Create components + if(frame != null) { + frame.setVisible(false); + } + frame = new Frame("OpaqueOverlapping mixing test"); + final Panel panel = new Panel(); + panel.setLayout(null); + + propagateAWTControls(panel); + + // Overlap the buttons + currentAwtControl.setBounds(30, 30, 200, 200); + + light = new JButton(" LW Button "); + light.setBounds(10, 10, 50, 50); + + // Put the components into the frame + panel.add(light); + frame.add(panel); + frame.setBounds(50, 50, 400, 400); + frame.setVisible(true); + + currentAwtControl.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + panel.setComponentZOrder(light, 0); + frame.validate(); + testSeq = testSeq + "0"; + } + }); + light.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent e) { + panel.setComponentZOrder(currentAwtControl, 0); + frame.validate(); + testSeq = testSeq + "1"; + } + }); + } + + @Override + protected boolean performTest() { + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + heavyLoc = currentAwtControl.getLocationOnScreen(); + } + }); + } catch (Exception e) { + } + Robot robot = Util.createRobot(); + robot.setAutoDelay(ROBOT_DELAY); + + Util.waitForIdle(robot); + + // Move the mouse pointer to the position where both + // components overlap + robot.mouseMove(heavyLoc.x + 5, heavyLoc.y + 5); + + // Now perform the click at this point for 9 times + // In the middle of the process toggle the opaque + // flag value. + for (int i = 0; i < 9; ++i) { + if (i == 3) { + AWTUtilities.setComponentMixingCutoutShape(light, + new Rectangle()); + } + if (i == 6) { + AWTUtilities.setComponentMixingCutoutShape(light, + null); + } + + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + Util.waitForIdle(robot); + + if (currentAwtControl.getClass() == java.awt.Choice.class && i != 1 && i != 6 && i != 8) { + // due to the fact that Choice doesn't get mouseClicked event if its dropdown is shown + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + Util.waitForIdle(robot); + } + } + + Util.waitForIdle(robot); + + boolean result = testSeq.equals(checkSeq); + if (!result) { + System.err.println("Expected: " + checkSeq); + System.err.println("Observed: " + testSeq); + } + return result; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new OpaqueOverlapping(); + OverlappingTestBase.doMain(args); + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/OpaqueOverlappingChoice.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/OpaqueOverlappingChoice.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/** + * AWT/Swing overlapping test for opaque Choice. + * + * This test case was separated from {@link OpaqueOverlapping} due to CR 6994264 (Choice autohides dropdown on Solaris 10) + */ +/* +@test +@bug 6994264 +@summary Opaque overlapping test for Choice AWT component +@run main OpaqueOverlappingChoice + */ +public class OpaqueOverlappingChoice extends OpaqueOverlapping { + { + onlyClassName = "Choice"; + skipClassNames = null; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new OpaqueOverlappingChoice(); + OverlappingTestBase.doMain(args); + } +} + diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/OverlappingTestBase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/OverlappingTestBase.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,800 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.*; +import java.awt.event.*; +import java.awt.peer.ComponentPeer; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import javax.swing.*; +import sun.awt.*; +import java.io.*; + +/** + *

This class provides basis for AWT Mixing testing. + *

It provides all standard test machinery and should be used by + * extending and overriding next methods: + *

  • {@link OverlappingTestBase#prepareControls()} - setup UI components + *
  • {@link OverlappingTestBase#performTest()} - run particular test + * Those methods would be run in the loop for each AWT component. + *

    Current AWT component should be added to the tested UI by {@link OverlappingTestBase#propagateAWTControls(java.awt.Container) ()}. + * There AWT components are prepared to be tested as being overlayed by other (e.g. Swing) components - they are colored to + * {@link OverlappingTestBase#AWT_BACKGROUND_COLOR} and throws failure on catching mouse event. + *

    Validation of component being overlayed should be tested by {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point) } + * See each method javadoc for more details. + * + *

    Due to test machinery limitations all test should be run from their own main() by calling next coe + * + * public static void main(String args[]) throws InterruptedException { + * instance = new YourTestInstance(); + * OverlappingTestBase.doMain(args); + * } + * + * + * @author Sergey Grinev + */ +public abstract class OverlappingTestBase { + // working variables + private static volatile boolean wasHWClicked = false; + private static volatile boolean passed = true; + // constants + /** + * Default color for AWT component used for validate correct drawing of overlapping. Never use it for lightweight components. + */ + protected static final Color AWT_BACKGROUND_COLOR = new Color(21, 244, 54); + protected static Color AWT_VERIFY_COLOR = AWT_BACKGROUND_COLOR; + protected static final int ROBOT_DELAY = 500; + private static final String[] simpleAwtControls = {"Button", "Checkbox", "Label", "TextArea"}; + /** + * Generic strings array. To be used for population of List based controls. + */ + protected static final String[] petStrings = {"Bird", "Cat", "Dog", "Rabbit", "Rhynocephalia Granda", "Bear", "Tiger", "Mustang"}; + // "properties" + /** + * Tests customization. Set this variable to test only control from java.awt + *

    Usage of this variable should be marked with CR being the reason. + *

    Do not use this variable simultaneously with {@link OverlappingTestBase#skipClassNames} + */ + protected String onlyClassName = null; + /** + * For customizing tests. List classes' simple names to skip them from testings. + *

    Usage of this variable should be marked with CR being the reason. + */ + protected String[] skipClassNames = null; + /** + * Set to false to avoid event delivery validation + * @see OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point, boolean) + */ + protected boolean useClickValidation = true; + /** + * Set to false if test doesn't supposed to verify EmbeddedFrame + */ + protected boolean testEmbeddedFrame = false; + /** + * Set this variable to true if testing embedded frame is impossible (on Mac, for instance, for now). + * The testEmbeddedFrame is explicitly set to true in dozen places. + */ + protected boolean skipTestingEmbeddedFrame = false; + + public static final boolean isMac = System.getProperty("os.name").toLowerCase().contains("os x"); + private boolean isFrameBorderCalculated; + private int borderShift; + + { if (Toolkit.getDefaultToolkit().getClass().getName().matches(".*L.*Toolkit")) { + // No EmbeddedFrame in LWToolkit/LWCToolkit, yet + // And it should be programmed some other way, too, in any case + System.err.println("skipTestingEmbeddedFrame"); + skipTestingEmbeddedFrame = true; + }else { + System.err.println("do not skipTestingEmbeddedFrame"); + } + } + + protected int frameBorderCounter() { + if (!isFrameBorderCalculated) { + try { + new FrameBorderCounter(); // force compilation by jtreg + String JAVA_HOME = System.getProperty("java.home"); + Process p = Runtime.getRuntime().exec(JAVA_HOME + "/bin/java FrameBorderCounter"); + try { + p.waitFor(); + } catch (InterruptedException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + if (p.exitValue() != 0) { + throw new RuntimeException("FrameBorderCounter exited with not null code!\n" + readInputStream(p.getErrorStream())); + } + borderShift = Integer.parseInt(readInputStream(p.getInputStream()).trim()); + isFrameBorderCalculated = true; + } catch (IOException e) { + e.printStackTrace(); + System.exit(1); + } + } + return borderShift; + } + + public void getVerifyColor() { + try { + final int size = 200; + final SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + final Point[] p = new Point[1]; + SwingUtilities.invokeAndWait(new Runnable() { + public void run(){ + JFrame frame = new JFrame("set back"); + frame.getContentPane().setBackground(AWT_BACKGROUND_COLOR); + frame.setSize(size, size); + frame.setUndecorated(true); + frame.setVisible(true); + frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + p[0] = frame.getLocation(); + } + }); + Robot robot = new Robot(); + toolkit.realSync(); + Thread.sleep(ROBOT_DELAY); + AWT_VERIFY_COLOR = robot.getPixelColor(p[0].x+size/2, p[0].y+size/2); + System.out.println("Color will be compared with " + AWT_VERIFY_COLOR + " instead of " + AWT_BACKGROUND_COLOR); + } catch (Exception e) { + System.err.println("Cannot get verify color: "+e.getMessage()); + } + } + + private String readInputStream(InputStream is) throws IOException { + byte[] buffer = new byte[4096]; + int len = 0; + StringBuilder sb = new StringBuilder(); + try (InputStreamReader isr = new InputStreamReader(is)) { + while ((len = is.read(buffer)) > 0) { + sb.append(new String(buffer, 0, len)); + } + } + return sb.toString(); + } + + private void setupControl(final Component control) { + if (useClickValidation) { + control.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + System.err.println("ERROR: " + control.getClass() + " received mouse click."); + wasHWClicked = true; + } + }); + } + control.setBackground(AWT_BACKGROUND_COLOR); + control.setForeground(AWT_BACKGROUND_COLOR); + control.setPreferredSize(new Dimension(150, 150)); + control.setFocusable(false); + } + + private void addAwtControl(java.util.List container, final Component control) { + String simpleName = control.getClass().getSimpleName(); + if (onlyClassName != null && !simpleName.equals(onlyClassName)) { + return; + } + if (skipClassNames != null) { + for (String skipMe : skipClassNames) { + if (simpleName.equals(skipMe)) { + return; + } + } + } + setupControl(control); + container.add(control); + } + + private void addSimpleAwtControl(java.util.List container, String className) { + try { + Class definition = Class.forName("java.awt." + className); + Constructor constructor = definition.getConstructor(new Class[]{String.class}); + java.awt.Component component = (java.awt.Component) constructor.newInstance(new Object[]{"AWT Component " + className}); + addAwtControl(container, component); + } catch (Exception ex) { + System.err.println(ex.getMessage()); + fail("Setup error, this jdk doesn't have awt conrol " + className); + } + } + + /** + * Adds current AWT control to container + *

    N.B.: if testEmbeddedFrame == true this method will also add EmbeddedFrame over Canvas + * and it should be called after Frame.setVisible(true) call + * @param container container to hold AWT component + */ + protected final void propagateAWTControls(Container container) { + if (currentAwtControl != null) { + container.add(currentAwtControl); + } else { // embedded frame + try { + + //create embedder + Canvas embedder = new Canvas(); + embedder.setBackground(Color.RED); + embedder.setPreferredSize(new Dimension(150, 150)); + container.add(embedder); + container.setVisible(true); // create peer + + long frameWindow = 0; + String getWindowMethodName = "getHWnd"; + if (Toolkit.getDefaultToolkit().getClass().getName().contains("XToolkit")) { + getWindowMethodName = "getWindow"; + } + ComponentPeer peer = embedder.getPeer(); +// System.err.println("Peer: " + peer); + Method getWindowMethod = peer.getClass().getMethod(getWindowMethodName); + frameWindow = (Long) getWindowMethod.invoke(peer); +// System.err.println("frame peer ID: " + frameWindow); + + String eframeClassName = "sun.awt.windows.WEmbeddedFrame"; + if (Toolkit.getDefaultToolkit().getClass().getName().contains("XToolkit")) { + eframeClassName = "sun.awt.X11.XEmbeddedFrame"; + } + Class eframeClass = Class.forName(eframeClassName); + Constructor eframeCtor = eframeClass.getConstructor(long.class); + EmbeddedFrame eframe = (EmbeddedFrame) eframeCtor.newInstance(frameWindow); + setupControl(eframe); + eframe.setSize(new Dimension(150, 150)); + eframe.setVisible(true); +// System.err.println(eframe.getSize()); + } catch (Exception ex) { + ex.printStackTrace(); + fail("Failed to instantiate EmbeddedFrame: " + ex.getMessage()); + } + } + } + private static final Font hugeFont = new Font("Arial", Font.BOLD, 70); + + private java.util.List getAWTControls() { + java.util.List components = new ArrayList(); + + for (String clazz : simpleAwtControls) { + addSimpleAwtControl(components, clazz); + } + + TextField tf = new TextField(); + tf.setFont(hugeFont); + addAwtControl(components, tf); + + // more complex controls + Choice c = new Choice(); + for (int i = 0; i < petStrings.length; i++) { + c.add(petStrings[i]); + } + addAwtControl(components, c); + c.setPreferredSize(null); + c.setFont(hugeFont); // to make control bigger as setPrefferedSize don't do his job here + + List l = new List(petStrings.length); + for (int i = 0; i < petStrings.length; i++) { + l.add(petStrings[i]); + } + addAwtControl(components, l); + + Canvas canvas = new Canvas(); + canvas.setSize(100, 200); + addAwtControl(components, canvas); + + Scrollbar sb = new Scrollbar(Scrollbar.VERTICAL, 500, 1, 0, 500); + addAwtControl(components, sb); + + Scrollbar sb2 = new Scrollbar(Scrollbar.HORIZONTAL, 500, 1, 0, 500); + addAwtControl(components, sb2); + + return components; + } + /** + * Default shift for {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point) } + */ + protected static Point shift = new Point(16, 16); + + /** + * Verifies point using specified AWT Robot. Supposes defaultShift == true for {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point, boolean) }. + * This method is used to verify controls by providing just their plain screen coordinates. + * @param robot AWT Robot. Usually created by {@link Util#createRobot() } + * @param lLoc point to verify + * @see OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point, boolean) + */ + protected void clickAndBlink(Robot robot, Point lLoc) { + clickAndBlink(robot, lLoc, true); + } + /** + * Default failure message for color check + * @see OverlappingTestBase#performTest() + */ + protected String failMessageColorCheck = "The LW component did not pass pixel color check and is overlapped"; + /** + * Default failure message event check + * @see OverlappingTestBase#performTest() + */ + protected String failMessage = "The LW component did not received the click."; + + private static boolean isValidForPixelCheck(Component component) { + if ((component instanceof java.awt.Scrollbar) || isMac && (component instanceof java.awt.Button)) { + return false; + } + return true; + } + + /** + * Preliminary validation - should be run before overlapping happens to ensure test is correct. + * @param robot AWT Robot. Usually created by {@link Util#createRobot() } + * @param lLoc point to validate to be of {@link OverlappingTestBase#AWT_BACKGROUND_COLOR} + * @param component tested component, should be pointed out as not all components are valid for pixel check. + */ + protected void pixelPreCheck(Robot robot, Point lLoc, Component component) { + if (isValidForPixelCheck(component)) { + int tries = 10; + Color c = null; + while (tries-- > 0) { + c = robot.getPixelColor(lLoc.x, lLoc.y); + System.out.println("Precheck. color: "+c+" compare with "+AWT_VERIFY_COLOR); + if (c.equals(AWT_VERIFY_COLOR)) { + return; + } + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + } + System.err.println(lLoc + ": " + c); + fail("Dropdown test setup failure, colored part of AWT component is not located at click area"); + } + } + + /** + * Verifies point using specified AWT Robot. + *

    Firstly, verifies point by color pixel check + *

    Secondly, verifies event delivery by mouse click + * @param robot AWT Robot. Usually created by {@link Util#createRobot() } + * @param lLoc point to verify + * @param defaultShift if true verified position will be shifted by {@link OverlappingTestBase#shift }. + */ + protected void clickAndBlink(Robot robot, Point lLoc, boolean defaultShift) { + Point loc = lLoc.getLocation(); + //check color + Util.waitForIdle(robot); + try{ + Thread.sleep(500); + }catch(Exception exx){ + exx.printStackTrace(); + } + + if (defaultShift) { + loc.translate(shift.x, shift.y); + } + if (!(System.getProperty("os.name").toLowerCase().contains("os x"))) { + Color c = robot.getPixelColor(loc.x, loc.y); + System.out.println("C&B. color: "+c+" compare with "+AWT_VERIFY_COLOR); + if (c.equals(AWT_VERIFY_COLOR)) { + fail(failMessageColorCheck); + passed = false; + } + + // perform click + Util.waitForIdle(robot); + } + + robot.mouseMove(loc.x, loc.y); + + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + Util.waitForIdle(robot); + } + + /** + * This method should be overriden with code which setups UI for testing. + * Code in this method will be called only from AWT thread so Swing operations can be called directly. + * + * @see {@link OverlappingTestBase#propagateAWTControls(java.awt.Container) } for instructions about adding tested AWT control to UI + */ + protected abstract void prepareControls(); + + /** + * This method should be overriden with test execution. It will not be called from AWT thread so all Swing operations should be treated accordingly. + * @return true if test passed. Otherwise fail with default fail message. + * @see {@link OverlappingTestBase#failMessage} default fail message + */ + protected abstract boolean performTest(); + /** + * This method can be overriden with cleanup routines. It will be called from AWT thread so all Swing operations should be treated accordingly. + */ + protected void cleanup() { + // intentionally do nothing + } + /** + * Currect tested AWT Control. Usually shouldn't be accessed directly. + * + * @see {@link OverlappingTestBase#propagateAWTControls(java.awt.Container) } for instructions about adding tested AWT control to UI + */ + protected Component currentAwtControl; + + private void testComponent(Component component) throws InterruptedException, InvocationTargetException { + currentAwtControl = component; + System.out.println("Testing " + currentAwtControl.getClass().getSimpleName()); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + prepareControls(); + } + }); + if (component != null) { + Util.waitTillShown(component); + } + Util.waitForIdle(null); + try { + Thread.sleep(500); // wait for graphic effects on systems like Win7 + } catch (InterruptedException ex) { + } + if (!instance.performTest()) { + fail(failMessage); + passed = false; + } + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + cleanup(); + } + }); + } + + private void testEmbeddedFrame() throws InvocationTargetException, InterruptedException { + System.out.println("Testing EmbeddedFrame"); + currentAwtControl = null; + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + prepareControls(); + } + }); + Util.waitForIdle(null); + try { + Thread.sleep(500); // wait for graphic effects on systems like Win7 + } catch (InterruptedException ex) { + } + if (!instance.performTest()) { + fail(failMessage); + passed = false; + } + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + cleanup(); + } + }); + } + + private void testAwtControls() throws InterruptedException { + try { + for (Component component : getAWTControls()) { + testComponent(component); + } + if (testEmbeddedFrame && !skipTestingEmbeddedFrame) { + testEmbeddedFrame(); + } + } catch (InvocationTargetException ex) { + ex.printStackTrace(); + fail(ex.getMessage()); + } + } + /** + * Used by standard test machinery. See usage at {@link OverlappingTestBase } + */ + protected static OverlappingTestBase instance; + + protected OverlappingTestBase() { + getVerifyColor(); + } + + /***************************************************** + * Standard Test Machinery Section + * DO NOT modify anything in this section -- it's a + * standard chunk of code which has all of the + * synchronisation necessary for the test harness. + * By keeping it the same in all tests, it is easier + * to read and understand someone else's test, as + * well as insuring that all tests behave correctly + * with the test harness. + * There is a section following this for test- + * classes + ******************************************************/ + private static void init() throws InterruptedException { + //*** Create instructions for the user here *** + //System.setProperty("sun.awt.disableMixing", "true"); + + String[] instructions = { + "This is an AUTOMATIC test, simply wait until it is done.", + "The result (passed or failed) will be shown in the", + "message window below." + }; + Sysout.createDialog(); + Sysout.printInstructions(instructions); + + instance.testAwtControls(); + + if (wasHWClicked) { + fail("HW component received the click."); + passed = false; + } + if (passed) { + pass(); + } + }//End init() + private static boolean theTestPassed = false; + private static boolean testGeneratedInterrupt = false; + private static String failureMessage = ""; + private static Thread mainThread = null; + private static int sleepTime = 300000; + + // Not sure about what happens if multiple of this test are + // instantiated in the same VM. Being static (and using + // static vars), it aint gonna work. Not worrying about + // it for now. + /** + * Starting point for test runs. See usage at {@link OverlappingTestBase } + * @param args regular main args, not used. + * @throws InterruptedException + */ + public static void doMain(String args[]) throws InterruptedException { + mainThread = Thread.currentThread(); + try { + init(); + } catch (TestPassedException e) { + //The test passed, so just return from main and harness will + // interepret this return as a pass + return; + } + //At this point, neither test pass nor test fail has been + // called -- either would have thrown an exception and ended the + // test, so we know we have multiple threads. + + //Test involves other threads, so sleep and wait for them to + // called pass() or fail() + try { + Thread.sleep(sleepTime); + //Timed out, so fail the test + throw new RuntimeException("Timed out after " + sleepTime / 1000 + " seconds"); + } catch (InterruptedException e) { + //The test harness may have interrupted the test. If so, rethrow the exception + // so that the harness gets it and deals with it. + if (!testGeneratedInterrupt) { + throw e; + } + + //reset flag in case hit this code more than once for some reason (just safety) + testGeneratedInterrupt = false; + + if (theTestPassed == false) { + throw new RuntimeException(failureMessage); + } + } + + }//main + + /** + * Test will fail if not passed after this timeout. Default timeout is 300 seconds. + * @param seconds timeout in seconds + */ + public static synchronized void setTimeoutTo(int seconds) { + sleepTime = seconds * 1000; + } + + /** + * Set test as passed. Usually shoudn't be called directly. + */ + public static synchronized void pass() { + Sysout.println("The test passed."); + Sysout.println("The test is over, hit Ctl-C to stop Java VM"); + //first check if this is executing in main thread + if (mainThread == Thread.currentThread()) { + //Still in the main thread, so set the flag just for kicks, + // and throw a test passed exception which will be caught + // and end the test. + theTestPassed = true; + throw new TestPassedException(); + } + theTestPassed = true; + testGeneratedInterrupt = true; + mainThread.interrupt(); + }//pass() + + /** + * Fail test generic message. + */ + public static synchronized void fail() { + //test writer didn't specify why test failed, so give generic + fail("it just plain failed! :-)"); + } + + /** + * Fail test providing specific reason. + * @param whyFailed reason + */ + public static synchronized void fail(String whyFailed) { + Sysout.println("The test failed: " + whyFailed); + Sysout.println("The test is over, hit Ctl-C to stop Java VM"); + //check if this called from main thread + if (mainThread == Thread.currentThread()) { + //If main thread, fail now 'cause not sleeping + throw new RuntimeException(whyFailed); + } + theTestPassed = false; + testGeneratedInterrupt = true; + failureMessage = whyFailed; + mainThread.interrupt(); + }//fail() +}// class LWComboBox +class TestPassedException extends RuntimeException { +} + +//*********** End Standard Test Machinery Section ********** +//************ Begin classes defined for the test **************** +// if want to make listeners, here is the recommended place for them, then instantiate +// them in init() + +/* Example of a class which may be written as part of a test +class NewClass implements anInterface +{ +static int newVar = 0; + +public void eventDispatched(AWTEvent e) +{ +//Counting events to see if we get enough +eventCount++; + +if( eventCount == 20 ) +{ +//got enough events, so pass + +LWComboBox.pass(); +} +else if( tries == 20 ) +{ +//tried too many times without getting enough events so fail + +LWComboBox.fail(); +} + +}// eventDispatched() + +}// NewClass class + + */ +//************** End classes defined for the test ******************* +/**************************************************** +Standard Test Machinery +DO NOT modify anything below -- it's a standard +chunk of code whose purpose is to make user +interaction uniform, and thereby make it simpler +to read and understand someone else's test. + ****************************************************/ +/** +This is part of the standard test machinery. +It creates a dialog (with the instructions), and is the interface +for sending text messages to the user. +To print the instructions, send an array of strings to Sysout.createDialog +WithInstructions method. Put one line of instructions per array entry. +To display a message for the tester to see, simply call Sysout.println +with the string to be displayed. +This mimics System.out.println but works within the test harness as well +as standalone. + */ +class Sysout { + private static TestDialog dialog; + + public static void createDialogWithInstructions(String[] instructions) { + dialog = new TestDialog(new Frame(), "Instructions"); + dialog.printInstructions(instructions); + //dialog.setVisible(true); + println("Any messages for the tester will display here."); + } + + public static void createDialog() { + dialog = new TestDialog(new Frame(), "Instructions"); + String[] defInstr = {"Instructions will appear here. ", ""}; + dialog.printInstructions(defInstr); + //dialog.setVisible(true); + println("Any messages for the tester will display here."); + } + + public static void printInstructions(String[] instructions) { + dialog.printInstructions(instructions); + } + + public static void println(String messageIn) { + dialog.displayMessage(messageIn); + System.out.println(messageIn); + } +}// Sysout class + +/** +This is part of the standard test machinery. It provides a place for the +test instructions to be displayed, and a place for interactive messages +to the user to be displayed. +To have the test instructions displayed, see Sysout. +To have a message to the user be displayed, see Sysout. +Do not call anything in this dialog directly. + */ +class TestDialog extends Dialog { + TextArea instructionsText; + TextArea messageText; + int maxStringLength = 80; + + //DO NOT call this directly, go through Sysout + public TestDialog(Frame frame, String name) { + super(frame, name); + int scrollBoth = TextArea.SCROLLBARS_BOTH; + instructionsText = new TextArea("", 15, maxStringLength, scrollBoth); + add("North", instructionsText); + + messageText = new TextArea("", 5, maxStringLength, scrollBoth); + add("Center", messageText); + + pack(); + + //setVisible(true); + }// TestDialog() + + //DO NOT call this directly, go through Sysout + public void printInstructions(String[] instructions) { + //Clear out any current instructions + instructionsText.setText(""); + + //Go down array of instruction strings + + String printStr, remainingStr; + for (int i = 0; i < instructions.length; i++) { + //chop up each into pieces maxSringLength long + remainingStr = instructions[i]; + while (remainingStr.length() > 0) { + //if longer than max then chop off first max chars to print + if (remainingStr.length() >= maxStringLength) { + //Try to chop on a word boundary + int posOfSpace = remainingStr.lastIndexOf(' ', maxStringLength - 1); + + if (posOfSpace <= 0) { + posOfSpace = maxStringLength - 1; + } + + printStr = remainingStr.substring(0, posOfSpace + 1); + remainingStr = remainingStr.substring(posOfSpace + 1); + } //else just print + else { + printStr = remainingStr; + remainingStr = ""; + } + + instructionsText.append(printStr + "\n"); + + }// while + + }// for + + }//printInstructions() + + //DO NOT call this directly, go through Sysout + public void displayMessage(String messageIn) { + messageText.append(messageIn + "\n"); + System.out.println(messageIn); + } +}// TestDialog class + diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/SimpleOverlappingTestBase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/SimpleOverlappingTestBase.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +/** + * Base class for testing overlapping of Swing and AWT component put into one frame. + * Validates drawing and event delivery at the components intersection. + *

    See base class for usage + * + * @author Sergey Grinev +*/ +public abstract class SimpleOverlappingTestBase extends OverlappingTestBase { + + { + testEmbeddedFrame = true; + } + + /** + * Event delivery validation. If set to true (default) tested lightweight component will be provided + * with mouse listener which should be called in order for test to pass. + */ + protected final boolean useDefaultClickValidation; + + /** + * Constructor which sets {@link SimpleOverlappingTestBase#useDefaultClickValidation } + * @param defaultClickValidation + */ + protected SimpleOverlappingTestBase(boolean defaultClickValidation) { + super(); + this.useDefaultClickValidation = defaultClickValidation; + } + + public SimpleOverlappingTestBase() { + this(true); + } + + //overridables + /** + * Successors override this method providing swing component for testing + * @return swing component to test + */ + protected abstract JComponent getSwingComponent(); + + /** + * For tests debugging. Please, ignore. + */ + protected static final boolean debug = false; + + /** + * Should be set to true if test isn't using {@link SimpleOverlappingTestBase#useDefaultClickValidation } + */ + protected volatile boolean wasLWClicked = false; + + /** + * Current tested lightweight component + * @see SimpleOverlappingTestBase#getSwingComponent() + */ + protected JComponent testedComponent; + + /** + * Setups simple frame with lightweight component returned by {@link SimpleOverlappingTestBase#getSwingComponent() } + * Called by base class. + */ + protected void prepareControls() { + wasLWClicked = false; + + final JFrame f = new JFrame("Mixing : Simple Overlapping test"); + f.setLayout(new SpringLayout()); + f.setSize(200, 200); + + testedComponent = getSwingComponent(); + + if (useDefaultClickValidation) { + testedComponent.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + wasLWClicked = true; + f.setVisible(false); + } + }); + } + + if (!debug) { + f.add(testedComponent); + } else { + System.err.println("Warning: DEBUG MODE"); + } + + propagateAWTControls(f); + + f.setVisible(true); + } + + /** + * AWT Robot instance. Shouldn't be used in most cases. + */ + protected Robot robot; + + /** + * Run test by {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point) } validation for current lightweight component. + *

    Called by base class. + * @return true if test passed + */ + protected boolean performTest() { + testedComponent.requestFocus(); + + // run robot + robot = Util.createRobot(); + robot.setAutoDelay(20); + + // get coord + Point lLoc = !debug ? testedComponent.getLocationOnScreen() : new Point(70, 30); + Util.waitForIdle(null); + /* this is a workaround for certain jtreg(?) focus issue: + tests fail starting after failing mixing tests but always pass alone. + */ + JFrame ancestor = (JFrame)(testedComponent.getTopLevelAncestor()); + if( ancestor != null ) { + Point ancestorLoc = ancestor.getLocationOnScreen(); + ancestorLoc.translate(ancestor.getWidth()/2-15, 2); + robot.mouseMove(ancestorLoc.x, ancestorLoc.y); + Util.waitForIdle(robot); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.delay(50); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + Util.waitForIdle(robot); + } + + clickAndBlink(robot, lLoc); + Util.waitForIdle(null); + + return wasLWClicked; + } + +} + diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/Util.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/Util.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,601 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Component; +import java.awt.Frame; +import java.awt.Dialog; +import java.awt.Window; +import java.awt.Button; +import java.awt.Point; +import java.awt.Dimension; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.Toolkit; +import java.awt.IllegalComponentStateException; +import java.awt.AWTException; +import java.awt.AWTEvent; + +import java.awt.event.InputEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.event.ActionEvent; +import java.awt.event.FocusEvent; +import java.awt.event.WindowListener; +import java.awt.event.WindowFocusListener; +import java.awt.event.FocusListener; +import java.awt.event.ActionListener; + +import java.awt.peer.FramePeer; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import java.security.PrivilegedAction; +import java.security.AccessController; + +import java.util.concurrent.atomic.AtomicBoolean; + +/** + *

    This class contains utilities useful for regression testing. + *

    When using jtreg you would include this class into the build + * list via something like: + *

    +     &library ../../../../share/lib/AWT_Mixing/src/regtesthelpers/
    +     &build Util
    +     &run main YourTest
    +   
    + * Note that if you are about to create a test based on + * Applet-template, then put those lines into html-file, not in java-file. + *

    And put an + * import regtesthelpers.Util; + * into the java source of test. +*/ +public final class Util { + private Util() {} // this is a helper class with static methods :) + + /* + * @throws RuntimeException when creation failed + */ + public static Robot createRobot() { + try { + return new Robot(); + } catch (AWTException e) { + throw new RuntimeException("Error: unable to create robot", e); + } + } + + public static Frame createEmbeddedFrame(final Frame embedder) + throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, + InstantiationException, InvocationTargetException + { + Toolkit tk = Toolkit.getDefaultToolkit(); + FramePeer frame_peer = (FramePeer) embedder.getPeer(); + System.out.println("frame's peer = " + frame_peer); + if ("sun.awt.windows.WToolkit".equals(tk.getClass().getName())) { + Class comp_peer_class = + Class.forName("sun.awt.windows.WComponentPeer"); + System.out.println("comp peer class = " + comp_peer_class); + Field hwnd_field = comp_peer_class.getDeclaredField("hwnd"); + hwnd_field.setAccessible(true); + System.out.println("hwnd_field =" + hwnd_field); + long hwnd = hwnd_field.getLong(frame_peer); + System.out.println("hwnd = " + hwnd); + + Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame"); + Constructor constructor = clazz.getConstructor (new Class [] {Long.TYPE}); + return (Frame) constructor.newInstance (new Object[] {hwnd}); + } else if ("sun.awt.X11.XToolkit".equals(tk.getClass().getName())) { + Class x_base_window_class = Class.forName("sun.awt.X11.XBaseWindow"); + System.out.println("x_base_window_class = " + x_base_window_class); + Method get_window = x_base_window_class.getMethod("getWindow", new Class[0]); + System.out.println("get_window = " + get_window); + long window = (Long) get_window.invoke(frame_peer, new Object[0]); + System.out.println("window = " + window); + Class clazz = Class.forName("sun.awt.X11.XEmbeddedFrame"); + Constructor constructor = clazz.getConstructor (new Class [] {Long.TYPE, Boolean.TYPE}); + return (Frame) constructor.newInstance (new Object[] {window, true}); + } + + throw new RuntimeException("Unexpected toolkit - " + tk); + } + + /** + * Makes the window visible and waits until it's shown. + */ + public static void showWindowWait(Window win) { + win.setVisible(true); + waitTillShown(win); + } + + /** + * Moves mouse pointer in the center of given {@code comp} component + * using {@code robot} parameter. + */ + public static void pointOnComp(final Component comp, final Robot robot) { + Rectangle bounds = new Rectangle(comp.getLocationOnScreen(), comp.getSize()); + robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2); + } + + /** + * Moves mouse pointer in the center of a given {@code comp} component + * and performs a left mouse button click using the {@code robot} parameter + * with the {@code delay} delay between press and release. + */ + public static void clickOnComp(final Component comp, final Robot robot, int delay) { + pointOnComp(comp, robot); + robot.delay(delay); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.delay(delay); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + + /** + * Moves mouse pointer in the center of a given {@code comp} component + * and performs a left mouse button click using the {@code robot} parameter + * with the default delay between press and release. + */ + public static void clickOnComp(final Component comp, final Robot robot) { + clickOnComp(comp, robot, 50); + } + + /* + * Clicks on a title of Frame/Dialog. + * WARNING: it may fail on some platforms when the window is not wide enough. + */ + public static void clickOnTitle(final Window decoratedWindow, final Robot robot) { + Point p = decoratedWindow.getLocationOnScreen(); + Dimension d = decoratedWindow.getSize(); + + if (decoratedWindow instanceof Frame || decoratedWindow instanceof Dialog) { + robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)decoratedWindow.getInsets().top/2); + robot.delay(50); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.delay(50); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + } + + public static void waitForIdle(final Robot robot) { + // we do not use robot for now, use SunToolkit.realSync() instead + ((sun.awt.SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + } + + public static Field getField(final Class klass, final String fieldName) { + return AccessController.doPrivileged(new PrivilegedAction() { + public Field run() { + try { + Field field = klass.getDeclaredField(fieldName); + assert (field != null); + field.setAccessible(true); + return field; + } catch (SecurityException se) { + throw new RuntimeException("Error: unexpected exception caught!", se); + } catch (NoSuchFieldException nsfe) { + throw new RuntimeException("Error: unexpected exception caught!", nsfe); + } + } + }); + } + + /* + * Waits for a notification and for a boolean condition to become true. + * The method returns when the above conditions are fullfilled or when the timeout + * occurs. + * + * @param condition the object to be notified and the booelan condition to wait for + * @param timeout the maximum time to wait in milliseconds + * @param catchExceptions if {@code true} the method catches InterruptedException + * @return the final boolean value of the {@code condition} + * @throws InterruptedException if the awaiting proccess has been interrupted + */ + public static boolean waitForConditionEx(final AtomicBoolean condition, long timeout) + throws InterruptedException + { + synchronized (condition) { + long startTime = System.currentTimeMillis(); + while (!condition.get()) { + condition.wait(timeout); + if (System.currentTimeMillis() - startTime >= timeout ) { + break; + } + } + } + return condition.get(); + } + + /* + * The same as {@code waitForConditionEx(AtomicBoolean, long)} except that it + * doesn't throw InterruptedException. + */ + public static boolean waitForCondition(final AtomicBoolean condition, long timeout) { + try { + return waitForConditionEx(condition, timeout); + } catch (InterruptedException e) { + throw new RuntimeException("Error: unexpected exception caught!", e); + } + } + + /* + * The same as {@code waitForConditionEx(AtomicBoolean, long)} but without a timeout. + */ + public static void waitForConditionEx(final AtomicBoolean condition) + throws InterruptedException + { + synchronized (condition) { + while (!condition.get()) { + condition.wait(); + } + } + } + + /* + * The same as {@code waitForConditionEx(AtomicBoolean)} except that it + * doesn't throw InterruptedException. + */ + public static void waitForCondition(final AtomicBoolean condition) { + try { + waitForConditionEx(condition); + } catch (InterruptedException e) { + throw new RuntimeException("Error: unexpected exception caught!", e); + } + } + + public static void waitTillShownEx(final Component comp) throws InterruptedException { + while (true) { + try { + Thread.sleep(100); + comp.getLocationOnScreen(); + break; + } catch (IllegalComponentStateException e) {} + } + } + public static void waitTillShown(final Component comp) { + try { + waitTillShownEx(comp); + } catch (InterruptedException e) { + throw new RuntimeException("Error: unexpected exception caught!", e); + } + } + + /** + * Drags from one point to another with the specified mouse button pressed. + * + * @param robot a robot to use for moving the mouse, etc. + * @param startPoint a start point of the drag + * @param endPoint an end point of the drag + * @param button one of {@code InputEvent.BUTTON1_MASK}, + * {@code InputEvent.BUTTON2_MASK}, {@code InputEvent.BUTTON3_MASK} + * + * @throws IllegalArgumentException if {@code button} is not one of + * {@code InputEvent.BUTTON1_MASK}, {@code InputEvent.BUTTON2_MASK}, + * {@code InputEvent.BUTTON3_MASK} + */ + public static void drag(Robot robot, Point startPoint, Point endPoint, int button) { + if (!(button == InputEvent.BUTTON1_MASK || button == InputEvent.BUTTON2_MASK + || button == InputEvent.BUTTON3_MASK)) + { + throw new IllegalArgumentException("invalid mouse button"); + } + + robot.mouseMove(startPoint.x, startPoint.y); + robot.mousePress(button); + try { + mouseMove(robot, startPoint, endPoint); + } finally { + robot.mouseRelease(button); + } + } + + /** + * Moves the mouse pointer from one point to another. + * Uses Bresenham's algorithm. + * + * @param robot a robot to use for moving the mouse + * @param startPoint a start point of the drag + * @param endPoint an end point of the drag + */ + public static void mouseMove(Robot robot, Point startPoint, Point endPoint) { + int dx = endPoint.x - startPoint.x; + int dy = endPoint.y - startPoint.y; + + int ax = Math.abs(dx) * 2; + int ay = Math.abs(dy) * 2; + + int sx = signWOZero(dx); + int sy = signWOZero(dy); + + int x = startPoint.x; + int y = startPoint.y; + + int d = 0; + + if (ax > ay) { + d = ay - ax/2; + while (true){ + robot.mouseMove(x, y); + robot.delay(50); + + if (x == endPoint.x){ + return; + } + if (d >= 0){ + y = y + sy; + d = d - ax; + } + x = x + sx; + d = d + ay; + } + } else { + d = ax - ay/2; + while (true){ + robot.mouseMove(x, y); + robot.delay(50); + + if (y == endPoint.y){ + return; + } + if (d >= 0){ + x = x + sx; + d = d - ay; + } + y = y + sy; + d = d + ax; + } + } + } + + private static int signWOZero(int i){ + return (i > 0)? 1: -1; + } + + private static int sign(int n) { + return n < 0 ? -1 : n == 0 ? 0 : 1; + } + + /** Returns {@code WindowListener} instance that diposes {@code Window} on + * "window closing" event. + * + * @return the {@code WindowListener} instance that could be set + * on a {@code Window}. After that + * the {@code Window} is disposed when "window closed" + * event is sent to the {@code Window} + */ + public static WindowListener getClosingWindowAdapter() { + return new WindowAdapter () { + public void windowClosing(WindowEvent e) { + e.getWindow().dispose(); + } + }; + } + + /* + * The values directly map to the ones of + * sun.awt.X11.XWM & sun.awt.motif.MToolkit classes. + */ + public final static int + UNDETERMINED_WM = 1, + NO_WM = 2, + OTHER_WM = 3, + OPENLOOK_WM = 4, + MOTIF_WM = 5, + CDE_WM = 6, + ENLIGHTEN_WM = 7, + KDE2_WM = 8, + SAWFISH_WM = 9, + ICE_WM = 10, + METACITY_WM = 11, + COMPIZ_WM = 12, + LG3D_WM = 13; + + /* + * Returns -1 in case of not X Window or any problems. + */ + public static int getWMID() { + Class clazz = null; + try { + if ("sun.awt.X11.XToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) { + clazz = Class.forName("sun.awt.X11.XWM"); + } else if ("sun.awt.motif.MToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) { + clazz = Class.forName("sun.awt.motif.MToolkit"); + } + } catch (ClassNotFoundException cnfe) { + cnfe.printStackTrace(); + } + if (clazz == null) { + return -1; + } + + try { + final Class _clazz = clazz; + Method m_getWMID = (Method)AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + try { + Method method = _clazz.getDeclaredMethod("getWMID", new Class[] {}); + if (method != null) { + method.setAccessible(true); + } + return method; + } catch (NoSuchMethodException e) { + assert false; + } catch (SecurityException e) { + assert false; + } + return null; + } + }); + return ((Integer)m_getWMID.invoke(null, new Object[] {})).intValue(); + } catch (IllegalAccessException iae) { + iae.printStackTrace(); + } catch (InvocationTargetException ite) { + ite.printStackTrace(); + } + return -1; + } + + + //////////////////////////// + // Some stuff to test focus. + //////////////////////////// + + private static WindowGainedFocusListener wgfListener = new WindowGainedFocusListener(); + private static FocusGainedListener fgListener = new FocusGainedListener(); + private static ActionPerformedListener apListener = new ActionPerformedListener(); + + private abstract static class EventListener { + AtomicBoolean notifier = new AtomicBoolean(false); + Component comp; + boolean printEvent; + + public void listen(Component comp, boolean printEvent) { + this.comp = comp; + this.printEvent = printEvent; + notifier.set(false); + setListener(comp); + } + + public AtomicBoolean getNotifier() { + return notifier; + } + + abstract void setListener(Component comp); + + void printAndNotify(AWTEvent e) { + if (printEvent) { + System.err.println(e); + } + synchronized (notifier) { + notifier.set(true); + notifier.notifyAll(); + } + } + } + + private static class WindowGainedFocusListener extends EventListener implements WindowFocusListener { + + void setListener(Component comp) { + ((Window)comp).addWindowFocusListener(this); + } + + public void windowGainedFocus(WindowEvent e) { + + ((Window)comp).removeWindowFocusListener(this); + printAndNotify(e); + } + + public void windowLostFocus(WindowEvent e) {} + } + + private static class FocusGainedListener extends EventListener implements FocusListener { + + void setListener(Component comp) { + comp.addFocusListener(this); + } + + public void focusGained(FocusEvent e) { + comp.removeFocusListener(this); + printAndNotify(e); + } + + public void focusLost(FocusEvent e) {} + } + + private static class ActionPerformedListener extends EventListener implements ActionListener { + + void setListener(Component comp) { + ((Button)comp).addActionListener(this); + } + + public void actionPerformed(ActionEvent e) { + ((Button)comp).removeActionListener(this); + printAndNotify(e); + } + } + + private static boolean trackEvent(int eventID, Component comp, Runnable action, int time, boolean printEvent) { + EventListener listener = null; + + switch (eventID) { + case WindowEvent.WINDOW_GAINED_FOCUS: + listener = wgfListener; + break; + case FocusEvent.FOCUS_GAINED: + listener = fgListener; + break; + case ActionEvent.ACTION_PERFORMED: + listener = apListener; + break; + } + + listener.listen(comp, printEvent); + action.run(); + return Util.waitForCondition(listener.getNotifier(), time); + } + + /* + * Tracks WINDOW_GAINED_FOCUS event for a window caused by an action. + * @param window the window to track the event for + * @param action the action to perform + * @param time the max time to wait for the event + * @param printEvent should the event received be printed or doesn't + * @return true if the event has been received, otherwise false + */ + public static boolean trackWindowGainedFocus(Window window, Runnable action, int time, boolean printEvent) { + return trackEvent(WindowEvent.WINDOW_GAINED_FOCUS, window, action, time, printEvent); + } + + /* + * Tracks FOCUS_GAINED event for a component caused by an action. + * @see #trackWindowGainedFocus + */ + public static boolean trackFocusGained(Component comp, Runnable action, int time, boolean printEvent) { + return trackEvent(FocusEvent.FOCUS_GAINED, comp, action, time, printEvent); + } + + /* + * Tracks ACTION_PERFORMED event for a button caused by an action. + * @see #trackWindowGainedFocus + */ + public static boolean trackActionPerformed(Button button, Runnable action, int time, boolean printEvent) { + return trackEvent(ActionEvent.ACTION_PERFORMED, button, action, time, printEvent); + } + + /* + * Requests focus on the component provided and waits for the result. + * @return true if the component has been focused, false otherwise. + */ + public static boolean focusComponent(Component comp, int time) { + return focusComponent(comp, time, false); + } + public static boolean focusComponent(final Component comp, int time, boolean printEvent) { + return trackFocusGained(comp, + new Runnable() { + public void run() { + comp.requestFocus(); + } + }, + time, printEvent); + + } +} diff -r 25bf8153fbfe -r f0250a79028b jdk/test/java/awt/Mixing/AWT_Mixing/ViewportOverlapping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Mixing/AWT_Mixing/ViewportOverlapping.java Tue Apr 29 14:32:38 2014 +0400 @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.InputEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; + +/** + * AWT/Swing overlapping test for viewport + *

    This test verify if AWT components are drawn correctly being partially shown through viewport + *

    See CR6778882 for details + *

    See base class for test info. + */ +/* +@test +@bug 6778882 +@summary Viewport overlapping test for each AWT component +@author sergey.grinev@oracle.com: area=awt.mixing +@run main ViewportOverlapping + */ +public class ViewportOverlapping extends OverlappingTestBase { + + private volatile int frameClicked; + private Point hLoc; + private Point vLoc; + private Point testLoc; + private Point resizeLoc; + + private JFrame f; + private JPanel p; + private JButton b; + private JScrollPane scrollPane; + + protected void prepareControls() { + p = new JPanel(new GridLayout(0, 1)); + propagateAWTControls(p); + b = new JButton("Space extender"); + p.add(b); + p.setPreferredSize(new Dimension(500, 500)); + scrollPane = new JScrollPane(p); + + f = new JFrame(); + f.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + frameClicked++; + } + }); + f.getContentPane().add(scrollPane, BorderLayout.CENTER); + ((JComponent) f.getContentPane()).setBorder( + BorderFactory.createEmptyBorder(50, 50, 50, 50)); + f.setSize(400, 400); + f.setLocationRelativeTo(null); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.setVisible(true); + } + + @Override + protected boolean performTest() { + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + // prepare test data + frameClicked = 0; + + b.requestFocus(); + + scrollPane.getHorizontalScrollBar().setUnitIncrement(40); + scrollPane.getVerticalScrollBar().setUnitIncrement(40); + + hLoc = scrollPane.getHorizontalScrollBar().getLocationOnScreen(); + hLoc.translate(scrollPane.getHorizontalScrollBar().getWidth() - 3, 3); + vLoc = scrollPane.getVerticalScrollBar().getLocationOnScreen(); + vLoc.translate(3, scrollPane.getVerticalScrollBar().getHeight() - 3); + + testLoc = p.getLocationOnScreen(); + testLoc.translate(-3, -3); + + resizeLoc = f.getLocationOnScreen(); + resizeLoc.translate(f.getWidth() - 1, f.getHeight() - 1); + } + }); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + // run robot + Robot robot = Util.createRobot(); + robot.setAutoDelay(ROBOT_DELAY); + + robot.mouseMove(hLoc.x, hLoc.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + Util.waitForIdle(robot); + + robot.mouseMove(vLoc.x, vLoc.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + Util.waitForIdle(robot); + + clickAndBlink(robot, testLoc, false); + robot.mouseMove(resizeLoc.x, resizeLoc.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseMove(resizeLoc.x + 5, resizeLoc.y + 5); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + Util.waitForIdle(robot); + + clickAndBlink(robot, testLoc, false); + return frameClicked == 2; + } + + // this strange plumbing stuff is required due to "Standard Test Machinery" in base class + public static void main(String args[]) throws InterruptedException { + instance = new ViewportOverlapping(); + OverlappingTestBase.doMain(args); + } +}