test/java/awt/List/EmptyListEventTest/EmptyListEventTest.java

Print this page




  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6366126
  27  * @summary List throws ArrayIndexOutOfBoundsException when pressing ENTER after removing all the items, Win32
  28  * @author Dmitry Cherepanov area=awt.list
  29  * @run main EmptyListEventTest
  30  */
  31 import java.awt.*;
  32 import java.awt.event.*;
  33 import javax.swing.JFrame;
  34 import javax.swing.JPanel;
  35 import javax.swing.SwingUtilities;
  36 import sun.awt.SunToolkit;
  37 
  38 public class EmptyListEventTest {
  39 
  40     private static List list;
  41 
  42     public static void main(String[] args) throws Exception {
  43 
  44         SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
  45         Robot robot = new Robot();
  46         robot.setAutoDelay(50);
  47 
  48         SwingUtilities.invokeAndWait(new Runnable() {
  49 
  50             @Override
  51             public void run() {
  52                 createAndShowGUI();
  53             }
  54         });
  55 
  56         toolkit.realSync();
  57 
  58         // press mouse -> ItemEvent
  59         Point point = getClickPoint();
  60         robot.mouseMove(point.x, point.y);
  61         robot.mousePress(InputEvent.BUTTON1_MASK);
  62         robot.mouseRelease(InputEvent.BUTTON1_MASK);
  63 
  64         toolkit.realSync();
  65 
  66         SwingUtilities.invokeAndWait(new Runnable() {
  67 
  68             @Override
  69             public void run() {
  70                 list.requestFocusInWindow();
  71             }
  72         });
  73 
  74         toolkit.realSync();
  75 
  76         if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != list) {
  77             throw new RuntimeException("Test failed - list isn't focus owner.");
  78         }
  79 
  80         // press key ENTER -> ActionEvent
  81         robot.keyPress(KeyEvent.VK_ENTER);
  82         robot.keyRelease(KeyEvent.VK_ENTER);
  83         toolkit.realSync();
  84 
  85         // press key SPACE -> ItemEvent
  86         robot.keyPress(KeyEvent.VK_SPACE);
  87         robot.keyRelease(KeyEvent.VK_SPACE);
  88         toolkit.realSync();
  89 
  90         // mouse double click -> ActionEvent
  91         robot.setAutoDelay(10);
  92         robot.mousePress(InputEvent.BUTTON1_MASK);
  93         robot.mouseRelease(InputEvent.BUTTON1_MASK);
  94         robot.mousePress(InputEvent.BUTTON1_MASK);
  95         robot.mouseRelease(InputEvent.BUTTON1_MASK);
  96         toolkit.realSync();
  97     }
  98 
  99     private static Point getClickPoint() throws Exception {
 100         final Point[] result = new Point[1];
 101 
 102         SwingUtilities.invokeAndWait(new Runnable() {
 103 
 104             @Override
 105             public void run() {
 106                 Point point = list.getLocationOnScreen();
 107                 point.translate(list.getWidth() / 2, list.getHeight() / 2);
 108                 result[0] = point;
 109 
 110             }
 111         });
 112 
 113         return result[0];
 114 
 115 
 116     }




  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6366126
  27  * @summary List throws ArrayIndexOutOfBoundsException when pressing ENTER after removing all the items, Win32
  28  * @author Dmitry Cherepanov area=awt.list
  29  * @run main EmptyListEventTest
  30  */
  31 import java.awt.*;
  32 import java.awt.event.*;
  33 import javax.swing.JFrame;
  34 import javax.swing.JPanel;
  35 import javax.swing.SwingUtilities;

  36 
  37 public class EmptyListEventTest {
  38 
  39     private static List list;
  40 
  41     public static void main(String[] args) throws Exception {
  42 

  43         Robot robot = new Robot();
  44         robot.setAutoDelay(50);
  45 
  46         SwingUtilities.invokeAndWait(new Runnable() {
  47 
  48             @Override
  49             public void run() {
  50                 createAndShowGUI();
  51             }
  52         });
  53 
  54         robot.waitForIdle();
  55 
  56         // press mouse -> ItemEvent
  57         Point point = getClickPoint();
  58         robot.mouseMove(point.x, point.y);
  59         robot.mousePress(InputEvent.BUTTON1_MASK);
  60         robot.mouseRelease(InputEvent.BUTTON1_MASK);
  61 
  62         robot.waitForIdle();
  63 
  64         SwingUtilities.invokeAndWait(new Runnable() {
  65 
  66             @Override
  67             public void run() {
  68                 list.requestFocusInWindow();
  69             }
  70         });
  71 
  72         robot.waitForIdle();
  73 
  74         if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != list) {
  75             throw new RuntimeException("Test failed - list isn't focus owner.");
  76         }
  77 
  78         // press key ENTER -> ActionEvent
  79         robot.keyPress(KeyEvent.VK_ENTER);
  80         robot.keyRelease(KeyEvent.VK_ENTER);
  81         robot.waitForIdle();
  82 
  83         // press key SPACE -> ItemEvent
  84         robot.keyPress(KeyEvent.VK_SPACE);
  85         robot.keyRelease(KeyEvent.VK_SPACE);
  86         robot.waitForIdle();
  87 
  88         // mouse double click -> ActionEvent
  89         robot.setAutoDelay(10);
  90         robot.mousePress(InputEvent.BUTTON1_MASK);
  91         robot.mouseRelease(InputEvent.BUTTON1_MASK);
  92         robot.mousePress(InputEvent.BUTTON1_MASK);
  93         robot.mouseRelease(InputEvent.BUTTON1_MASK);
  94         robot.waitForIdle();
  95     }
  96 
  97     private static Point getClickPoint() throws Exception {
  98         final Point[] result = new Point[1];
  99 
 100         SwingUtilities.invokeAndWait(new Runnable() {
 101 
 102             @Override
 103             public void run() {
 104                 Point point = list.getLocationOnScreen();
 105                 point.translate(list.getWidth() / 2, list.getHeight() / 2);
 106                 result[0] = point;
 107 
 108             }
 109         });
 110 
 111         return result[0];
 112 
 113 
 114     }