< prev index next >

test/jdk/java/awt/KeyboardFocusmanager/ConsumeNextMnemonicKeyTypedTest/ConsumeNextMnemonicKeyTypedTest.java

Print this page
rev 51542 : 8210039: move OSInfo to top level testlibrary
Reviewed-by: duke


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  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       6346690
  27   @summary   Tests that key_typed is consumed after mnemonic key_pressed is handled for a menu item.
  28   @author    anton.tarasov@sun.com: area=awt-focus
  29   @library   ../../../../lib/testlibrary
  30   @build jdk.testlibrary.OSInfo
  31   @run       applet ConsumeNextMnemonicKeyTypedTest.html
  32 */
  33 


  34 import java.awt.*;
  35 import javax.swing.*;
  36 import java.awt.event.*;
  37 import java.applet.Applet;
  38 
  39 
  40 public class ConsumeNextMnemonicKeyTypedTest extends Applet {
  41     Robot robot;
  42     JFrame frame = new JFrame("Test Frame");
  43     JTextField text = new JTextField();
  44     JMenuBar bar = new JMenuBar();
  45     JMenu menu = new JMenu("Menu");
  46     JMenuItem item = new JMenuItem("item");
  47 
  48     public static void main(String[] args) {
  49         ConsumeNextMnemonicKeyTypedTest app = new ConsumeNextMnemonicKeyTypedTest();
  50         app.init();
  51         app.start();
  52     }
  53 


  99                 System.out.println("Test: text field couldn't be focused!");
 100                 return;
 101             }
 102         }
 103 
 104         robot.keyPress(KeyEvent.VK_A);
 105         robot.delay(100);
 106         robot.keyRelease(KeyEvent.VK_A);
 107 
 108         robot.waitForIdle();
 109 
 110         String charA = text.getText();
 111         System.err.println("Test: character typed with VK_A: " + charA);
 112 
 113         robot.keyPress(KeyEvent.VK_BACK_SPACE);
 114         robot.delay(100);
 115         robot.keyRelease(KeyEvent.VK_BACK_SPACE);
 116 
 117         robot.waitForIdle();
 118 
 119         if (jdk.testlibrary.OSInfo.getOSType() == jdk.testlibrary.OSInfo.OSType.MACOSX) {
 120             robot.keyPress(KeyEvent.VK_CONTROL);
 121         }
 122         robot.keyPress(KeyEvent.VK_ALT);
 123         robot.keyPress(KeyEvent.VK_F);
 124         robot.delay(100);
 125         robot.keyRelease(KeyEvent.VK_F);
 126         robot.keyRelease(KeyEvent.VK_ALT);
 127         if (jdk.testlibrary.OSInfo.getOSType() == jdk.testlibrary.OSInfo.OSType.MACOSX) {
 128             robot.keyRelease(KeyEvent.VK_CONTROL);
 129         }
 130 
 131         robot.waitForIdle();
 132 
 133         String string = text.getText();
 134 
 135         robot.keyPress(KeyEvent.VK_I);
 136         robot.delay(100);
 137         robot.keyRelease(KeyEvent.VK_I);
 138 
 139         robot.waitForIdle();
 140 
 141         System.out.println("Test: character typed after mnemonic key press: " + text.getText());
 142 
 143         if (!text.getText().equals(string)) {
 144             throw new RuntimeException("Test failed!");
 145         }
 146 
 147         robot.keyPress(KeyEvent.VK_A);


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  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       6346690
  27   @summary   Tests that key_typed is consumed after mnemonic key_pressed is handled for a menu item.
  28   @author    anton.tarasov@sun.com: area=awt-focus
  29   @library   /test/lib
  30   @build     jdk.test.lib.Platform
  31   @run       applet ConsumeNextMnemonicKeyTypedTest.html
  32 */
  33 
  34 import jdk.test.lib.Platform;
  35 
  36 import java.awt.*;
  37 import javax.swing.*;
  38 import java.awt.event.*;
  39 import java.applet.Applet;
  40 
  41 
  42 public class ConsumeNextMnemonicKeyTypedTest extends Applet {
  43     Robot robot;
  44     JFrame frame = new JFrame("Test Frame");
  45     JTextField text = new JTextField();
  46     JMenuBar bar = new JMenuBar();
  47     JMenu menu = new JMenu("Menu");
  48     JMenuItem item = new JMenuItem("item");
  49 
  50     public static void main(String[] args) {
  51         ConsumeNextMnemonicKeyTypedTest app = new ConsumeNextMnemonicKeyTypedTest();
  52         app.init();
  53         app.start();
  54     }
  55 


 101                 System.out.println("Test: text field couldn't be focused!");
 102                 return;
 103             }
 104         }
 105 
 106         robot.keyPress(KeyEvent.VK_A);
 107         robot.delay(100);
 108         robot.keyRelease(KeyEvent.VK_A);
 109 
 110         robot.waitForIdle();
 111 
 112         String charA = text.getText();
 113         System.err.println("Test: character typed with VK_A: " + charA);
 114 
 115         robot.keyPress(KeyEvent.VK_BACK_SPACE);
 116         robot.delay(100);
 117         robot.keyRelease(KeyEvent.VK_BACK_SPACE);
 118 
 119         robot.waitForIdle();
 120 
 121         if (Platform.isOSX()) {
 122             robot.keyPress(KeyEvent.VK_CONTROL);
 123         }
 124         robot.keyPress(KeyEvent.VK_ALT);
 125         robot.keyPress(KeyEvent.VK_F);
 126         robot.delay(100);
 127         robot.keyRelease(KeyEvent.VK_F);
 128         robot.keyRelease(KeyEvent.VK_ALT);
 129         if (Platform.isOSX()) {
 130             robot.keyRelease(KeyEvent.VK_CONTROL);
 131         }
 132 
 133         robot.waitForIdle();
 134 
 135         String string = text.getText();
 136 
 137         robot.keyPress(KeyEvent.VK_I);
 138         robot.delay(100);
 139         robot.keyRelease(KeyEvent.VK_I);
 140 
 141         robot.waitForIdle();
 142 
 143         System.out.println("Test: character typed after mnemonic key press: " + text.getText());
 144 
 145         if (!text.getText().equals(string)) {
 146             throw new RuntimeException("Test failed!");
 147         }
 148 
 149         robot.keyPress(KeyEvent.VK_A);
< prev index next >