--- /dev/null 2014-07-21 10:48:32.483073271 +0400 +++ new/test/java/awt/Frame/MiscUndecorated/ActiveAWTWindowTest.java 2014-07-30 10:39:13.000000000 +0400 @@ -0,0 +1,217 @@ +/* + * Copyright (c) 1999, 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. + */ + +/* +* @test +* @summary To check proper WINDOW_EVENTS are triggered when Frame gains or losses the focus +* @author Jitender(jitender.singh@eng.sun.com) area=AWT +* @author yan +* @library ../../../../lib/testlibrary +* @build ExtendedRobot +* @run main ActiveAWTWindowTest +*/ + +import java.awt.*; +import java.awt.event.*; + +public class ActiveAWTWindowTest { + + private Frame frame, frame2; + private Button button, button2; + private TextField textField, textField2; + private int eventType, eventType1; + private ExtendedRobot robot; + private Object lock1 = new Object(); + private Object lock2 = new Object(); + private Object lock3 = new Object(); + private boolean passed = true; + private boolean focusGained = false; + private int delay = 150; + + public static void main(String[] args) { + ActiveAWTWindowTest test = new ActiveAWTWindowTest(); + test.doTest(); + } + + public ActiveAWTWindowTest() { + try{ + EventQueue.invokeAndWait( () -> { + initializeGUI(); + }); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Interrupted or unexpected Exception occured"); + } + } + + private void initializeGUI() { + frame = new Frame(); + frame.setLayout(new FlowLayout()); + + frame.setLocation(5, 20); + frame.setSize(200, 200); + frame.setUndecorated(true); + frame.addWindowFocusListener(new WindowFocusListener() { + public void windowGainedFocus(WindowEvent event) { + focusGained = true; + System.out.println("Frame Focus gained"); + synchronized (lock3) { + try { + lock3.notifyAll(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + public void windowLostFocus(WindowEvent event) { + System.out.println("Frame Focus lost"); + } + }); + frame.addWindowListener(new WindowAdapter() { + public void windowActivated(WindowEvent e) { + eventType = WindowEvent.WINDOW_ACTIVATED; + System.out.println("Undecorated Frame is activated\n"); + synchronized (lock1) { + try { + lock1.notifyAll(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + public void windowDeactivated(WindowEvent e) { + eventType = WindowEvent.WINDOW_DEACTIVATED; + System.out.println("Undecorated Frame got Deactivated\n"); + synchronized (lock2) { + try { + lock2.notifyAll(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + }); + textField = new TextField("TextField"); + button = new Button("Click me"); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + textField.setText("Focus gained"); + } + }); + + frame.setBackground(Color.green); + frame.add(button); + frame.add(textField); + frame.setVisible(true); + + frame2 = new Frame(); + frame2.setLayout(new FlowLayout()); + frame2.setLocation(5, 250); + frame2.setSize(200, 200); + frame2.setBackground(Color.green); + button2 = new Button("Click me"); + textField2 = new TextField("TextField"); + button2.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + textField2.setText("Got the focus"); + } + }); + + frame2.add(button2, BorderLayout.SOUTH); + frame2.add(textField2, BorderLayout.NORTH); + frame2.setVisible(true); + + frame.toFront(); + } + + public void doTest() { + try { + robot = new ExtendedRobot(); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Cannot create robot"); + } + + robot.waitForIdle(5*delay); + robot.mouseMove(button.getLocationOnScreen().x + button.getSize().width / 2, + button.getLocationOnScreen().y + button.getSize().height / 2); + robot.waitForIdle(delay); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.waitForIdle(delay); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + if (eventType != WindowEvent.WINDOW_ACTIVATED) { + synchronized (lock1) { + try { + lock1.wait(delay * 10); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + if (eventType != WindowEvent.WINDOW_ACTIVATED) { + passed = false; + System.err.println("WINDOW_ACTIVATED event did not occur when the " + + "undecorated frame is activated!"); + } + + eventType1 = -1; + eventType = -1; + + robot.mouseMove(button2.getLocationOnScreen().x + button2.getSize().width / 2, + button2.getLocationOnScreen().y + button2.getSize().height / 2); + robot.waitForIdle(delay); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.waitForIdle(delay); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + if (eventType != WindowEvent.WINDOW_DEACTIVATED) { + synchronized (lock2) { + try { + lock2.wait(delay * 10); + } catch (Exception e) { + } + } + } + if (eventType != WindowEvent.WINDOW_DEACTIVATED) { + passed = false; + System.err.println("FAIL: WINDOW_DEACTIVATED event did not occur for the " + + "undecorated frame when another frame gains focus!"); + } + if (frame.hasFocus()) { + passed = false; + System.err.println("FAIL: The undecorated frame has focus even when " + + "another frame is clicked!"); + } + + if (!passed) { + //captureScreenAndSave(); + System.err.println("Test failed!"); + throw new RuntimeException("Test failed."); + } else { + System.out.println("Test passed"); + } + } +} --- /dev/null 2014-07-21 10:48:32.483073271 +0400 +++ new/test/java/awt/Frame/MiscUndecorated/ActiveSwingWindowTest.java 2014-07-30 10:39:13.000000000 +0400 @@ -0,0 +1,221 @@ +/* + * Copyright (c) 1999, 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. + */ + +/* +* @test +* @summary To check proper WINDOW_EVENTS are triggered when JFrame gains or losses the focus +* @author Jitender(jitender.singh@eng.sun.com) area=AWT +* @author yan +* @library ../../../../lib/testlibrary +* @build ExtendedRobot +* @run main ActiveSwingWindowTest +*/ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.JFrame; +import javax.swing.JTextField; +import javax.swing.JButton; + + +public class ActiveSwingWindowTest { + + private JFrame frame, frame2; + private JButton button, button2; + private JTextField textField, textField2; + private int eventType, eventType1; + private ExtendedRobot robot; + private Object lock1 = new Object(); + private Object lock2 = new Object(); + private Object lock3 = new Object(); + private boolean passed = true; + private boolean focusGained = false; + private int delay = 150; + + public static void main(String[] args) { + ActiveSwingWindowTest test = new ActiveSwingWindowTest(); + test.doTest(); + } + + public ActiveSwingWindowTest() { + try{ + EventQueue.invokeAndWait( () -> { + initializeGUI(); + }); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Interrupted or unexpected Exception occured"); + } + } + + private void initializeGUI() { + frame = new JFrame(); + frame.setLayout(new FlowLayout()); + + frame.setLocation(5, 20); + frame.setSize(200, 200); + frame.setUndecorated(true); + frame.addWindowFocusListener(new WindowFocusListener() { + public void windowGainedFocus(WindowEvent event) { + focusGained = true; + System.out.println("Frame Focus gained"); + synchronized (lock3) { + try { + lock3.notifyAll(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + public void windowLostFocus(WindowEvent event) { + System.out.println("Frame Focus lost"); + } + }); + frame.addWindowListener(new WindowAdapter() { + public void windowActivated(WindowEvent e) { + eventType = WindowEvent.WINDOW_ACTIVATED; + System.out.println("Undecorated Frame is activated\n"); + synchronized (lock1) { + try { + lock1.notifyAll(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + public void windowDeactivated(WindowEvent e) { + eventType = WindowEvent.WINDOW_DEACTIVATED; + System.out.println("Undecorated Frame got Deactivated\n"); + synchronized (lock2) { + try { + lock2.notifyAll(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + }); + textField = new JTextField("TextField"); + button = new JButton("Click me"); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + textField.setText("Focus gained"); + } + }); + + frame.setBackground(Color.green); + frame.add(button); + frame.add(textField); + frame.setVisible(true); + + frame2 = new JFrame(); + frame2.setLayout(new FlowLayout()); + frame2.setLocation(5, 250); + frame2.setSize(200, 200); + frame2.setBackground(Color.green); + button2 = new JButton("Click me"); + textField2 = new JTextField("TextField"); + button2.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + textField2.setText("Got the focus"); + } + }); + + frame2.add(button2, BorderLayout.SOUTH); + frame2.add(textField2, BorderLayout.NORTH); + frame2.setVisible(true); + + frame.toFront(); + } + + public void doTest() { + try { + robot = new ExtendedRobot(); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Cannot create robot"); + } + + robot.waitForIdle(5*delay); + robot.mouseMove(button.getLocationOnScreen().x + button.getSize().width / 2, + button.getLocationOnScreen().y + button.getSize().height / 2); + robot.waitForIdle(delay); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.waitForIdle(delay); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + if (eventType != WindowEvent.WINDOW_ACTIVATED) { + synchronized (lock1) { + try { + lock1.wait(delay * 10); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + if (eventType != WindowEvent.WINDOW_ACTIVATED) { + passed = false; + System.err.println("WINDOW_ACTIVATED event did not occur when the " + + "undecorated frame is activated!"); + } + + eventType1 = -1; + eventType = -1; + + robot.mouseMove(button2.getLocationOnScreen().x + button2.getSize().width / 2, + button2.getLocationOnScreen().y + button2.getSize().height / 2); + robot.waitForIdle(delay); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.waitForIdle(delay); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + if (eventType != WindowEvent.WINDOW_DEACTIVATED) { + synchronized (lock2) { + try { + lock2.wait(delay * 10); + } catch (Exception e) { + } + } + } + if (eventType != WindowEvent.WINDOW_DEACTIVATED) { + passed = false; + System.err.println("FAIL: WINDOW_DEACTIVATED event did not occur for the " + + "undecorated frame when another frame gains focus!"); + } + if (frame.hasFocus()) { + passed = false; + System.err.println("FAIL: The undecorated frame has focus even when " + + "another frame is clicked!"); + } + + if (!passed) { + //captureScreenAndSave(); + System.err.println("Test failed!"); + throw new RuntimeException("Test failed."); + } else { + System.out.println("Test passed"); + } + } +} --- /dev/null 2014-07-21 10:48:32.483073271 +0400 +++ new/test/java/awt/Frame/MiscUndecorated/FrameCloseTest.java 2014-07-30 10:39:14.000000000 +0400 @@ -0,0 +1,214 @@ +/* + * Copyright (c) 1999, 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. + */ + +/* +* @test +* @summary To make sure Undecorated Frame triggers correct windows events while closing +* @author Jitender(jitender.singh@eng.sun.com) area=AWT* +* @author yan +* @library ../../../../lib/testlibrary +* @build ExtendedRobot +* @run main FrameCloseTest +*/ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.JFrame; +import javax.swing.JButton; + +public class FrameCloseTest { + private static int delay = 150; + + private Frame frame, frame2; + private Component button, dummyButton; + private int eventType, eventType1, eventType2; + private ExtendedRobot robot; + private Object lock1 = new Object(); + private Object lock2 = new Object(); + private Object lock3 = new Object(); + private Object lock4 = new Object(); + private boolean passed = true; + private boolean focusGained = false; + + public static void main(String[] args) { + FrameCloseTest test = new FrameCloseTest(); + test.doTest(false); + test.doTest(true); + } + + private void initializeGUI(boolean swingFrame) { + frame = swingFrame? new Frame() : new JFrame(); + frame.setLayout(new FlowLayout()); + + frame.setLocation(5, 20); + frame.setSize(200, 200); + frame.setUndecorated(true); + frame.addWindowFocusListener(new WindowFocusListener() { + public void windowGainedFocus(WindowEvent event) { + focusGained = true; + System.out.println("Frame Focus gained"); + synchronized (lock4) { + try { + lock4.notifyAll(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + public void windowLostFocus(WindowEvent event) { + System.out.println("Frame Focus lost"); + } + }); + frame.addWindowListener(new WindowAdapter() { + public void windowActivated(WindowEvent e) { + eventType = WindowEvent.WINDOW_ACTIVATED; + System.out.println("Undecorated Frame is activated"); + synchronized (lock1) { + try { + lock1.notifyAll(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + public void windowDeactivated(WindowEvent e) { + eventType1 = WindowEvent.WINDOW_DEACTIVATED; + System.out.println("Undecorated Frame got Deactivated"); + synchronized (lock2) { + try { + lock2.notifyAll(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + public void windowClosed(WindowEvent e) { + eventType2 = WindowEvent.WINDOW_CLOSED; + System.out.println("Undecorated Frame got closed"); + synchronized (lock3) { + try { + lock3.notifyAll(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + }); + dummyButton = swingFrame? new JButton("Click me") : new Button("Click me"); + + frame.setBackground(Color.green); + frame.add((button = createButton(swingFrame, "Close me"))); + frame.add(dummyButton); + frame.setVisible(true); + frame.toFront(); + } + private Component createButton(boolean swingControl, String txt) { + if(swingControl) { + JButton jbtn = new JButton(txt); + jbtn.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + frame.dispose(); + } + }); + return jbtn; + }else { + Button btn = new Button(txt); + btn.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + frame.dispose(); + } + }); + return btn; + } + } + + public void doTest(boolean swingControl) { + try { + Toolkit.getDefaultToolkit().getSystemEventQueue().invokeAndWait(new Runnable() { + public void run() { + initializeGUI(swingControl); + } + }); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Interrupted or unexpected Exception occured"); + } + try { + robot = new ExtendedRobot(); + robot.waitForIdle(1000); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Cannot create robot"); + } + + robot.mouseMove(dummyButton.getLocationOnScreen().x + dummyButton.getSize().width / 2, + dummyButton.getLocationOnScreen().y + dummyButton.getSize().height / 2); + robot.waitForIdle(delay); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.waitForIdle(delay); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.waitForIdle(delay); + + eventType1 = -1; + eventType = -1; + eventType2 = -1; + + robot.mouseMove(button.getLocationOnScreen().x + button.getSize().width / 2, + button.getLocationOnScreen().y + button.getSize().height / 2); + robot.waitForIdle(delay); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.waitForIdle(delay); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.waitForIdle(delay * 10); + + if (eventType2 != WindowEvent.WINDOW_CLOSED) { + synchronized (lock3) { + try { + lock3.wait(delay * 10); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + if (eventType2 != WindowEvent.WINDOW_CLOSED) { + passed = false; + System.err.println("WINDOW_CLOSED event did not occur when the " + + "undecorated frame is closed!"); + } + if (eventType == WindowEvent.WINDOW_ACTIVATED) { + passed = false; + System.err.println("WINDOW_ACTIVATED event occured when the " + + "undecorated frame is closed!"); + } + + if (!passed) { + System.err.println("Test failed!"); + throw new RuntimeException("Test failed"); + } else { + System.out.println("Test passed"); + } + } +} --- /dev/null 2014-07-21 10:48:32.483073271 +0400 +++ new/test/java/awt/Frame/MiscUndecorated/RepaintTest.java 2014-07-30 10:39:14.000000000 +0400 @@ -0,0 +1,302 @@ +/* + * Copyright (c) 1999, 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. + */ +/* +* @test +* @summary Make sure that on changing state of Undecorated Frame, +* all the components on it are repainted correctly +* @author Jitender(jitender.singh@eng.sun.com) area=AWT +* @author yan +* @library ../../../../lib/testlibrary +* @build ExtendedRobot +* @run main RepaintTest +*/ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.JFrame; +import javax.swing.JButton; +import javax.swing.JTextField; +import javax.swing.JPanel; +import java.io.*; +import java.awt.image.*; + +public class RepaintTest { + private static int delay = 150; + + private Frame frame; + private Container panel1, panel2; + private Component button; + private Component textField; + private ExtendedRobot robot; + private Object buttonLock = new Object(); + private boolean passed = true; + private boolean buttonClicked = false; + private int MAX_TOLERANCE_LEVEL = 10; + + public static void main(String[] args) { + RepaintTest test = new RepaintTest(); + test.doTest(false); + try { + Toolkit.getDefaultToolkit().getSystemEventQueue().invokeAndWait(new Runnable() { + public void run() { + test.frame.dispose(); + } + }); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Unexpected Exception occured"); + } + test.doTest(true); + try { + Toolkit.getDefaultToolkit().getSystemEventQueue().invokeAndWait(new Runnable() { + public void run() { + test.frame.dispose(); + } + }); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Unexpected Exception occured"); + } + } + + /** + * Do screen capture and save it as image + */ + private static void captureScreenAndSave() { + + try { + Robot robot = new Robot(); + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + Rectangle rectangle = new Rectangle(0, 0, screenSize.width, screenSize.height); + System.out.println("About to screen capture - " + rectangle); + BufferedImage image = robot.createScreenCapture(rectangle); + javax.imageio.ImageIO.write(image, "jpg", new File("ScreenImage.jpg")); + robot.delay(3000); + } catch (Throwable t) { + System.out.println("WARNING: Exception thrown while screen capture!"); + t.printStackTrace(); + } + } + + private void initializeGUI(boolean swingControl) { + frame = swingControl ? new JFrame() : new Frame(); + frame.setLayout(new BorderLayout()); + + frame.setSize(300, 300); + frame.setUndecorated(true); + + button = createButton(swingControl, (swingControl ? "Swing Button" : "AWT Button")); + textField = swingControl ? new JTextField("TextField") : new TextField("TextField"); + panel1 = swingControl ? new JPanel() : new Panel(); + panel2 = swingControl ? new JPanel() : new Panel(); + panel1.add(button); + panel2.add(textField); + frame.add(panel2, BorderLayout.SOUTH); + frame.add(panel1, BorderLayout.NORTH); + + frame.setBackground(Color.green); + frame.setVisible(true); + frame.toFront(); + } + private Component createButton(boolean swingControl, String txt) { + if(swingControl) { + JButton jbtn = new JButton(txt); + jbtn.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + buttonClicked = true; + synchronized (buttonLock) { + try { + buttonLock.notifyAll(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + }); + return jbtn; + }else { + Button btn = new Button(txt); + btn.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + buttonClicked = true; + synchronized (buttonLock) { + try { + buttonLock.notifyAll(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + }); + return btn; + } + } + + public void doTest(boolean swingControl) { + try { + Toolkit.getDefaultToolkit().getSystemEventQueue().invokeAndWait(new Runnable() { + public void run() { + initializeGUI(swingControl); + } + }); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Interrupted or unexpected Exception occured"); + } + try { + robot = new ExtendedRobot(); + robot.waitForIdle(1000); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Cannot create robot"); + } + + robot.mouseMove(button.getLocationOnScreen().x + button.getSize().width / 2, + button.getLocationOnScreen().y + button.getSize().height / 2); + robot.waitForIdle(delay); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.waitForIdle(delay); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + if (! buttonClicked) { + synchronized (buttonLock) { + try { + buttonLock.wait(delay * 10); + } catch (Exception e) { + } + } + } + if (! buttonClicked) { + passed = false; + System.err.println("ActionEvent not triggered when " + + "button is clicked!"); + throw new RuntimeException("ActionEvent not triggered"); + } + + robot.waitForIdle(delay * 5); // Need to wait until look of the button + // returns to normal undepressed + passed = paintAndRepaint(button, (swingControl? "J": "")+"Button"); + if( !paintAndRepaint(button, (swingControl? "J": "")+"TextField") ) { + passed = false; + } + if(!passed) { + throw new RuntimeException("Test failed"); + } + } + private boolean paintAndRepaint(Component comp, String prefix) { + //Capture the component & compare it's dimensions + //before iconifying & after frame comes back from + //iconified to normal state + System.out.println("paintAndRepaint "+prefix); + Point p = comp.getLocationOnScreen(); + Rectangle bRect = new Rectangle((int)p.getX(), (int)p.getY(), + comp.getWidth(), comp.getHeight()); + BufferedImage capturedImage = robot.createScreenCapture(bRect); + + try { + Toolkit.getDefaultToolkit().getSystemEventQueue().invokeAndWait(new Runnable() { + public void run() { + frame.setExtendedState(Frame.ICONIFIED); + } + }); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Exception while setting extended state ICONIFIED"); + } + robot.waitForIdle(delay * 5); + try { + Toolkit.getDefaultToolkit().getSystemEventQueue().invokeAndWait(new Runnable() { + public void run() { + frame.setExtendedState(Frame.NORMAL); + frame.toFront(); + } + }); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Exception while setting extended state NORMAL"); + } + robot.waitForIdle(delay * 5); + + if (! p.equals(comp.getLocationOnScreen())) { + passed = false; + System.err.println("FAIL: Frame or component did not get positioned in the same place"); + } + + p = comp.getLocationOnScreen(); + bRect = new Rectangle((int)p.getX(), (int)p.getY(), + comp.getWidth(), comp.getHeight()); + BufferedImage capturedImage2 = robot.createScreenCapture(bRect); + + if (! compareImages(capturedImage, capturedImage2)) { + passed = false; + try { + javax.imageio.ImageIO.write(capturedImage, "jpg", new File( + prefix+"BeforeMinimize.jpg")); + javax.imageio.ImageIO.write(capturedImage2, "jpg", new File( + prefix+"AfterMinimize.jpg")); + } catch (Exception e) { + e.printStackTrace(); + } + + System.err.println("FAIL: The frame or component did not get repainted correctly"); + } + return passed; + } + + //method for comparing two images + public boolean compareImages(BufferedImage capturedImg, BufferedImage realImg) { + int capturedPixels[], realPixels[]; + int imgWidth, imgHeight; + boolean comparison = true; + int toleranceLevel = 0; + + imgWidth = capturedImg.getWidth(null); + imgHeight = capturedImg.getHeight(null); + capturedPixels = new int[imgWidth * imgHeight]; + realPixels = new int[imgWidth * imgHeight]; + + try { + PixelGrabber pgCapturedImg = new PixelGrabber(capturedImg, 0, 0, + imgWidth, imgHeight, capturedPixels, 0, imgWidth); + pgCapturedImg.grabPixels(); + + PixelGrabber pgRealImg = new PixelGrabber(realImg, 0, 0, + imgWidth, imgHeight, realPixels, 0, imgWidth); + pgRealImg.grabPixels(); + + for(int i=0; i<(imgWidth * imgHeight); i++) { + if(capturedPixels[i] != realPixels[i]) { + toleranceLevel++; + } + } + + if (toleranceLevel > MAX_TOLERANCE_LEVEL) { + comparison = false; + } + } catch(Exception ie) { + ie.printStackTrace(); + comparison = false; + } + return comparison; + } +} --- /dev/null 2014-07-21 10:48:32.483073271 +0400 +++ new/test/java/awt/Frame/MiscUndecorated/UndecoratedInitiallyIconified.java 2014-07-30 10:39:14.000000000 +0400 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2002, 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.Frame; +import java.awt.Toolkit; +import javax.swing.JFrame; +import java.awt.EventQueue; +import java.awt.FlowLayout; +/* + * @test + * @bug 4464710 7102299 + * @summary Recurring bug is, an undecorated JFrame cannot be set iconified + * before setVisible(true) + * + * @run main UndecoratedInitiallyIconified + */ + + +public class UndecoratedInitiallyIconified { + private static JFrame frame; + public static void main(String args[]) { + if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.ICONIFIED)) { + return; + } + try{ + EventQueue.invokeAndWait( () -> { + frame = new JFrame("Test Frame"); + frame.setLayout(new FlowLayout()); + frame.setBounds(50,50,300,300); + frame.setUndecorated(true); + frame.setExtendedState(Frame.ICONIFIED); + if(frame.getExtendedState() != Frame.ICONIFIED) { + throw new RuntimeException("getExtendedState is not Frame.ICONIFIED as expected"); + } + }); + }catch(Exception ie) { + ie.printStackTrace(); + throw new RuntimeException("Interrupted or unexpected Exception occured"); + } + } +} --- old/test/java/awt/Mixing/AWT_Mixing/Util.java 2014-07-30 10:39:15.000000000 +0400 +++ /dev/null 2014-07-21 10:48:32.483073271 +0400 @@ -1,601 +0,0 @@ -/* - * 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