Skip to content

Commit 48e5f41

Browse files
Jonathan DowlandRealCLanger
authored andcommitted
6849922: java/awt/Choice/ChoiceKeyEventReaction/ChoiceKeyEventReaction.html fails
Backport-of: 1b012e2
1 parent d754399 commit 48e5f41

File tree

3 files changed

+87
-130
lines changed

3 files changed

+87
-130
lines changed

test/jdk/ProblemList.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ java/awt/print/PrinterJob/Margins.java 8196301 windows-all,macosx-all
254254
java/awt/PrintJob/PrinterException.java 8196301 windows-all,macosx-all
255255
java/awt/Choice/PopupPosTest/PopupPosTest.java 8192930 windows-all
256256
java/awt/Choice/ChoiceMouseWheelTest/ChoiceMouseWheelTest.java 7100044 macosx-all
257-
java/awt/Choice/ChoiceKeyEventReaction/ChoiceKeyEventReaction.html 6849922 macosx-all
258257
java/awt/Component/GetScreenLocTest/GetScreenLocTest.java 4753654 generic-all
259258
java/awt/Component/SetEnabledPerformance/SetEnabledPerformance.java 8165863 macosx-all
260259
java/awt/Choice/SelectCurrentItemTest/SelectCurrentItemTest.html 8192929 windows-all,linux-all

test/jdk/java/awt/Choice/ChoiceKeyEventReaction/ChoiceKeyEventReaction.html

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 87 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,121 +22,126 @@
2222
*/
2323

2424
/*
25-
test
26-
@bug 6252982
27-
@summary PIT: Keyboard FocusTraversal not working when choice's drop-down is visible, on XToolkit
28-
@author andrei.dmitriev : area=awt.choice
29-
@run applet ChoiceKeyEventReaction.html
30-
*/
31-
32-
import java.applet.Applet;
33-
import java.awt.*;
34-
import java.awt.event.*;
35-
import test.java.awt.regtesthelpers.Util;
36-
37-
public class ChoiceKeyEventReaction extends Applet
25+
* @test
26+
* @bug 6252982
27+
* @key headful
28+
* @summary PIT: Keyboard FocusTraversal not working when choice's drop-down is visible, on XToolkit
29+
* @author andrei.dmitriev : area=awt.choice
30+
* @run main ChoiceKeyEventReaction
31+
*/
32+
33+
import java.awt.Robot;
34+
import java.awt.Choice;
35+
import java.awt.Point;
36+
import java.awt.Toolkit;
37+
import java.awt.TextField;
38+
import java.awt.FlowLayout;
39+
import java.awt.event.InputEvent;
40+
import java.awt.event.KeyEvent;
41+
import java.awt.event.ItemEvent;
42+
import java.awt.event.KeyAdapter;
43+
import java.awt.event.ItemListener;
44+
import java.awt.Frame;
45+
46+
public class ChoiceKeyEventReaction
3847
{
39-
Robot robot;
40-
Choice choice1 = new Choice();
41-
Point pt;
42-
TextField tf = new TextField("Hi");
48+
private static Robot robot;
49+
private static Choice choice1 = new Choice();
50+
private static Point pt;
51+
private static TextField tf = new TextField("Hi");
52+
private static boolean keyTypedOnTextField = false;
53+
private static boolean itemChanged = false;
54+
private static Frame frame;
55+
private static String toolkit;
56+
57+
public static void main(String[] args) {
58+
createAndShowGUI();
59+
60+
try {
61+
robot = new Robot();
62+
robot.setAutoDelay(100);
4363

44-
boolean keyTypedOnTextField = false;
45-
boolean itemChanged = false;
46-
String toolkit;
64+
moveFocusToTextField();
65+
testKeyOnChoice(InputEvent.BUTTON1_MASK, KeyEvent.VK_UP);
66+
} catch (Exception e) {
67+
throw new RuntimeException("Test failed. Exception thrown: "+e);
68+
} finally {
69+
if (frame != null) {
70+
frame.dispose();
71+
}
72+
}
73+
}
4774

48-
public void init()
49-
{
75+
private static void createAndShowGUI() {
76+
frame = new Frame();
5077
toolkit = Toolkit.getDefaultToolkit().getClass().getName();
5178
System.out.println("Current toolkit is :" +toolkit);
5279
for (int i = 1; i<20; i++){
5380
choice1.add("item-0"+i);
5481
}
55-
tf.addKeyListener(new KeyAdapter(){
56-
public void keyPressed(KeyEvent ke) {
57-
keyTypedOnTextField = true;
58-
System.out.println(ke);
59-
}
60-
});
6182

83+
tf.addKeyListener(new KeyAdapter(){
84+
public void keyPressed(KeyEvent ke) {
85+
keyTypedOnTextField = true;
86+
System.out.println(ke);
87+
}
88+
});
6289

6390
choice1.addItemListener(new ItemListener() {
64-
public void itemStateChanged(ItemEvent e) {
65-
itemChanged = true;
66-
System.out.println(e);
67-
}
68-
});
69-
91+
public void itemStateChanged(ItemEvent e) {
92+
itemChanged = true;
93+
System.out.println(e);
94+
}
95+
});
7096
choice1.setFocusable(false);
71-
add(tf);
72-
add(choice1);
73-
setLayout (new FlowLayout());
74-
}//End init()
75-
76-
public void start ()
77-
{
78-
setSize (200,200);
79-
setVisible(true);
80-
validate();
81-
try{
82-
robot = new Robot();
83-
Util.waitForIdle(robot);
84-
moveFocusToTextField();
85-
testKeyOnChoice(InputEvent.BUTTON1_MASK, KeyEvent.VK_UP);
86-
} catch (Throwable e) {
87-
throw new RuntimeException("Test failed. Exception thrown: "+e);
88-
}
89-
}// start()
9097

91-
public void testKeyOnChoice(int button, int key){
98+
frame.add(tf);
99+
frame.add(choice1);
100+
frame.setLayout (new FlowLayout());
101+
frame.setSize (200,200);
102+
frame.setVisible(true);
103+
}
104+
105+
private static void testKeyOnChoice(int button, int key) {
92106
pt = choice1.getLocationOnScreen();
93107
robot.mouseMove(pt.x + choice1.getWidth()/2, pt.y + choice1.getHeight()/2);
94-
Util.waitForIdle(robot);
108+
95109
robot.mousePress(button);
96-
robot.delay(10);
97110
robot.mouseRelease(button);
98-
Util.waitForIdle(robot);
99111

100112
robot.keyPress(key);
101113
robot.keyRelease(key);
102114

103-
Util.waitForIdle(robot);
104-
105115
System.out.println("keyTypedOnTextField = "+keyTypedOnTextField +": itemChanged = " + itemChanged);
106-
107-
if (itemChanged){
108-
throw new RuntimeException("Test failed. ItemChanged event occur on Choice.");
109-
}
110-
111-
// We may just write
112-
// if (toolkit.equals("sun.awt.windows.WToolkit") == keyTypedOnTextField) {fail;}
113-
// but must report differently in these cases so put two separate if statements for simplicity.
114-
if (toolkit.equals("sun.awt.windows.WToolkit") &&
115-
!keyTypedOnTextField)
116-
{
117-
throw new RuntimeException("Test failed. (Win32) KeyEvent wasn't addressed to TextField. ");
116+
if (itemChanged) {
117+
throw new RuntimeException("Test failed. ItemChanged event occur on Choice.");
118118
}
119119

120-
if (!toolkit.equals("sun.awt.windows.WToolkit") &&
121-
keyTypedOnTextField)
122-
{
123-
throw new RuntimeException("Test failed. (XToolkit/MToolkit). KeyEvent was addressed to TextField.");
120+
// We may just write
121+
// if (toolkit.equals("sun.awt.windows.WToolkit") == keyTypedOnTextField) {fail;}
122+
// but must report differently in these cases so put two separate if statements for simplicity.
123+
if (toolkit.equals("sun.awt.windows.WToolkit") &&
124+
!keyTypedOnTextField) {
125+
throw new RuntimeException("Test failed. (Win32) KeyEvent wasn't addressed to TextField. ");
126+
}
127+
128+
if (!toolkit.equals("sun.awt.windows.WToolkit") &&
129+
keyTypedOnTextField) {
130+
throw new RuntimeException("Test failed. (XToolkit/MToolkit). KeyEvent was addressed to TextField.");
124131
}
125132

126133
System.out.println("Test passed. Unfocusable Choice doesn't react on keys.");
134+
127135
//close opened choice
128136
robot.keyPress(KeyEvent.VK_ESCAPE);
129137
robot.keyRelease(KeyEvent.VK_ESCAPE);
130-
Util.waitForIdle(robot);
131138
}
132139

133-
public void moveFocusToTextField(){
140+
public static void moveFocusToTextField() {
134141
pt = tf.getLocationOnScreen();
135142
robot.mouseMove(pt.x + tf.getWidth()/2, pt.y + tf.getHeight()/2);
136-
Util.waitForIdle(robot);
143+
137144
robot.mousePress(InputEvent.BUTTON1_MASK);
138-
robot.delay(10);
139145
robot.mouseRelease(InputEvent.BUTTON1_MASK);
140-
Util.waitForIdle(robot);
141146
}
142-
}//:~
147+
}

0 commit comments

Comments
 (0)