Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
4b0fe58c
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4b0fe58c
编写于
3月 26, 2008
作者:
A
ant
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6616792: five AWT focus regression tests should be fixed
Summary: Fixed/refactored the tests. Reviewed-by: volk
上级
6ae611c9
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
309 addition
and
1572 deletion
+309
-1572
test/java/awt/Focus/ActualFocusedWindowTest/ActualFocusedWindowBlockingTest.java
...ualFocusedWindowTest/ActualFocusedWindowBlockingTest.java
+28
-196
test/java/awt/Focus/ActualFocusedWindowTest/ActualFocusedWindowRetaining.java
...ActualFocusedWindowTest/ActualFocusedWindowRetaining.java
+56
-275
test/java/awt/Focus/FrameJumpingToMouse/FrameJumpingToMouse.java
...va/awt/Focus/FrameJumpingToMouse/FrameJumpingToMouse.java
+40
-213
test/java/awt/Focus/NonFocusableWindowTest/NoEventsTest.java
test/java/awt/Focus/NonFocusableWindowTest/NoEventsTest.java
+21
-18
test/java/awt/Focus/NonFocusableWindowTest/NonfocusableOwnerTest.java
...t/Focus/NonFocusableWindowTest/NonfocusableOwnerTest.java
+28
-221
test/java/awt/Focus/TypeAhead/TestFocusFreeze.java
test/java/awt/Focus/TypeAhead/TestFocusFreeze.java
+91
-440
test/java/awt/Focus/WrongKeyTypedConsumedTest/WrongKeyTypedConsumedTest.java
.../WrongKeyTypedConsumedTest/WrongKeyTypedConsumedTest.java
+45
-209
未找到文件。
test/java/awt/Focus/ActualFocusedWindowTest/ActualFocusedWindowBlockingTest.java
浏览文件 @
4b0fe58c
...
...
@@ -25,8 +25,10 @@
@test
@bug 6314575
@summary Tests that previosly focused owned window doesn't steal focus when an owner's component requests focus.
@author Anton Tarasov: area=awt-focus
@run applet ActualFocusedWindowBlockingTest.html
@author Anton.Tarasov: area=awt.focus
@library ../../regtesthelpers
@build Util
@run main ActualFocusedWindowBlockingTest
*/
import
java.awt.*
;
...
...
@@ -35,9 +37,10 @@ import java.applet.Applet;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.lang.reflect.InvocationTargetException
;
import
sun.awt.SunToolkit
;
import
test.java.awt.regtesthelpers.Util
;
public
class
ActualFocusedWindowBlockingTest
extends
Applet
{
Robot
robot
;
Robot
robot
=
Util
.
createRobot
()
;
Frame
owner
=
new
Frame
(
"Owner Frame"
);
Window
win
=
new
Window
(
owner
);
Frame
frame
=
new
Frame
(
"Auxiliary Frame"
);
...
...
@@ -52,28 +55,12 @@ public class ActualFocusedWindowBlockingTest extends Applet {
}
public
void
init
()
{
// Create instructions for the user here, as well as set up
// the environment -- set the layout manager, add buttons,
// etc.
this
.
setLayout
(
new
BorderLayout
());
Sysout
.
createDialogWithInstructions
(
new
String
[]
{
"Automatic test. Simply wait until it's done."
});
if
(
"sun.awt.motif.MToolkit"
.
equals
(
Toolkit
.
getDefaultToolkit
().
getClass
().
getName
()))
{
return
;
}
Toolkit
.
getDefaultToolkit
().
addAWTEventListener
(
new
AWTEventListener
()
{
public
void
eventDispatched
(
AWTEvent
e
)
{
Sysout
.
println
(
"--> "
+
e
);
Sys
tem
.
out
.
println
(
"--> "
+
e
);
}
},
FocusEvent
.
FOCUS_EVENT_MASK
|
WindowEvent
.
WINDOW_FOCUS_EVENT_MASK
);
try
{
robot
=
new
Robot
();
}
catch
(
AWTException
e
)
{
throw
new
RuntimeException
(
"Error: unable to create robot"
,
e
);
}
owner
.
add
(
fButton
);
win
.
add
(
wButton
);
frame
.
add
(
aButton
);
...
...
@@ -87,19 +74,18 @@ public class ActualFocusedWindowBlockingTest extends Applet {
public
void
start
()
{
if
(
"sun.awt.motif.MToolkit"
.
equals
(
Toolkit
.
getDefaultToolkit
().
getClass
().
getName
()))
{
Sysout
.
println
(
"No testing on Motif. Test passed."
);
Sys
tem
.
out
.
println
(
"No testing on Motif. Test passed."
);
return
;
}
Sysout
.
println
(
"\nTest started:\n"
);
Sys
tem
.
out
.
println
(
"\nTest started:\n"
);
// Test 1.
clickOnCheckFocus
(
wButton
);
clickOnCheckFocus
(
aButton
);
clickOn
(
fButton
);
Util
.
clickOnComp
(
fButton
,
robot
);
if
(!
testFocused
(
fButton
))
{
throw
new
TestFailedException
(
"The owner's component ["
+
fButton
+
"] couldn't be focused by click"
);
}
...
...
@@ -107,11 +93,10 @@ public class ActualFocusedWindowBlockingTest extends Applet {
// Test 2.
clickOnCheckFocus
(
wButton
);
clickOnCheckFocus
(
aButton
);
fButton
.
requestFocus
();
realSync
(
);
Util
.
waitForIdle
(
robot
);
if
(!
testFocused
(
fButton
))
{
throw
new
TestFailedException
(
"The owner's component ["
+
fButton
+
"] couldn't be focused by request"
);
}
...
...
@@ -119,19 +104,16 @@ public class ActualFocusedWindowBlockingTest extends Applet {
// Test 3.
clickOnCheckFocus
(
wButton
);
clickOnCheckFocus
(
aButton
);
clickOnCheckFocus
(
fButton
);
clickOnCheckFocus
(
aButton
);
clickOn
(
owner
);
Util
.
clickOnTitle
(
owner
,
robot
);
if
(!
testFocused
(
fButton
))
{
throw
new
TestFailedException
(
"The owner's component ["
+
fButton
+
"] couldn't be focused as the most recent focus owner"
);
}
Sysout
.
println
(
"Test passed."
);
Sys
tem
.
out
.
println
(
"Test passed."
);
}
void
tuneAndShowWindows
(
Window
[]
arr
)
{
...
...
@@ -142,33 +124,18 @@ public class ActualFocusedWindowBlockingTest extends Applet {
w
.
setBackground
(
Color
.
blue
);
w
.
setVisible
(
true
);
y
+=
200
;
realSync
(
);
Util
.
waitForIdle
(
robot
);
}
}
void
clickOn
(
Component
c
)
{
Sysout
.
println
(
"Test: clicking "
+
c
);
Point
p
=
c
.
getLocationOnScreen
();
Dimension
d
=
c
.
getSize
();
void
clickOnCheckFocus
(
Component
c
)
{
if
(
c
instanceof
Frame
)
{
robot
.
mouseMove
(
p
.
x
+
(
int
)(
d
.
getWidth
()/
2
),
p
.
y
+
((
Frame
)
c
).
getInsets
().
top
/
2
);
Sysout
.
println
((
p
.
x
+
(
int
)(
d
.
getWidth
()/
2
))
+
" "
+
(
p
.
y
+
((
Frame
)
c
).
getInsets
().
top
/
2
));
Util
.
clickOnTitle
((
Frame
)
c
,
robot
);
}
else
{
robot
.
mouseMove
(
p
.
x
+
(
int
)(
d
.
getWidth
()/
2
),
p
.
y
+
(
int
)(
d
.
getHeight
()/
2
)
);
Util
.
clickOnComp
(
c
,
robot
);
}
robot
.
mousePress
(
InputEvent
.
BUTTON1_MASK
);
robot
.
delay
(
100
);
robot
.
mouseRelease
(
InputEvent
.
BUTTON1_MASK
);
realSync
();
}
void
clickOnCheckFocus
(
Component
c
)
{
clickOn
(
c
);
if
(!
testFocused
(
c
))
{
throw
new
RuntimeException
(
"Error: ["
+
c
+
"]
couldn't get focus by click."
);
throw
new
TestErrorException
(
c
+
"
couldn't get focus by click."
);
}
}
...
...
@@ -177,157 +144,22 @@ public class ActualFocusedWindowBlockingTest extends Applet {
if
(
KeyboardFocusManager
.
getCurrentKeyboardFocusManager
().
getFocusOwner
()
==
c
)
{
return
true
;
}
realSync
(
);
Util
.
waitForIdle
(
robot
);
}
return
false
;
}
void
realSync
()
{
((
SunToolkit
)
Toolkit
.
getDefaultToolkit
()).
realSync
();
}
// Thrown when the behavior being verified is found wrong.
class
TestFailedException
extends
RuntimeException
{
public
TestFailedException
(
String
cause
)
{
super
(
"Test failed. "
+
cause
);
Sysout
.
println
(
cause
);
TestFailedException
(
String
msg
)
{
super
(
"Test failed: "
+
msg
);
}
}
}
/****************************************************
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
{
static
TestDialog
dialog
;
public
static
void
createDialogWithInstructions
(
String
[]
instructions
)
{
dialog
=
new
TestDialog
(
new
Frame
(),
"Instructions"
);
dialog
.
printInstructions
(
instructions
);
dialog
.
setLocation
(
500
,
0
);
dialog
.
setVisible
(
true
);
println
(
"Any messages for the tester will display here."
);
// Thrown when an error not related to the behavior being verified is encountered.
class
TestErrorException
extends
RuntimeException
{
TestErrorException
(
String
msg
)
{
super
(
"Unexpected error: "
+
msg
);
}
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
);
}
}
// 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
}
test/java/awt/Focus/ActualFocusedWindowTest/ActualFocusedWindowRetaining.java
浏览文件 @
4b0fe58c
...
...
@@ -25,14 +25,17 @@
@test
@bug 4823903
@summary Tests actual focused window retaining.
@author Anton Tarasov: area=awt.focus
@run applet ActualFocusedWindowRetaining.html
@author Anton.Tarasov: area=awt.focus
@library ../../regtesthelpers
@build Util
@run main ActualFocusedWindowRetaining
*/
import
java.awt.*
;
import
java.awt.event.*
;
import
java.lang.reflect.*
;
import
java.applet.*
;
import
test.java.awt.regtesthelpers.Util
;
public
class
ActualFocusedWindowRetaining
extends
Applet
{
public
static
Frame
frame
=
new
Frame
(
"Other Frame"
);
...
...
@@ -46,7 +49,7 @@ public class ActualFocusedWindowRetaining extends Applet {
public
static
Window
window1
=
new
TestWindow
(
owner
,
otherButton2
,
testButton2
,
800
,
200
);
public
static
Window
window2
=
new
TestWindow
(
owner
,
otherButton3
,
testButton3
,
800
,
300
);
public
static
int
step
;
public
static
Robot
robot
;
public
static
Robot
robot
=
Util
.
createRobot
()
;
public
static
void
main
(
String
[]
args
)
{
ActualFocusedWindowRetaining
a
=
new
ActualFocusedWindowRetaining
();
...
...
@@ -54,53 +57,25 @@ public class ActualFocusedWindowRetaining extends Applet {
a
.
start
();
}
public
void
init
()
{
//Create instructions for the user here, as well as set up
// the environment -- set the layout manager, add buttons,
// etc.
this
.
setLayout
(
new
BorderLayout
());
String
[]
instructions
=
{
"This is an AUTOMATIC test"
,
"simply wait until it is done"
};
Sysout
.
createDialogWithInstructions
(
instructions
);
}
public
void
start
()
{
if
(
Toolkit
.
getDefaultToolkit
().
getClass
()
.
getName
().
equals
(
"sun.awt.motif.MToolkit"
))
{
Sysout
.
println
(
"No testing on Motif."
);
return
;
}
try
{
robot
=
new
Robot
();
}
catch
(
AWTException
e
)
{
throw
new
RuntimeException
(
"Error: unable to create robot"
,
e
);
}
public
void
start
()
{
Toolkit
.
getDefaultToolkit
().
addAWTEventListener
(
new
AWTEventListener
()
{
public
void
eventDispatched
(
AWTEvent
e
)
{
Object
src
=
e
.
getSource
();
Class
cls
=
src
.
getClass
();
if
(
cls
==
TestWindow
.
class
)
{
Sysout
.
println
(
e
.
paramString
()
+
" on <"
+
(
src
==
window1
?
"Window 1"
:
"Window 2"
)
+
">"
);
Sys
tem
.
out
.
println
(
e
.
paramString
()
+
" on <"
+
(
src
==
window1
?
"Window 1"
:
"Window 2"
)
+
">"
);
}
else
if
(
cls
==
Frame
.
class
)
{
Sysout
.
println
(
e
.
paramString
()
+
" on <"
+
((
Frame
)
src
).
getTitle
()
+
">"
);
Sys
tem
.
out
.
println
(
e
.
paramString
()
+
" on <"
+
((
Frame
)
src
).
getTitle
()
+
">"
);
}
else
if
(
cls
==
Button
.
class
)
{
Sysout
.
println
(
e
.
paramString
()
+
" on <"
+
((
Button
)
src
).
getLabel
()
+
">"
);
Sys
tem
.
out
.
println
(
e
.
paramString
()
+
" on <"
+
((
Button
)
src
).
getLabel
()
+
">"
);
}
else
{
Sysout
.
println
(
e
.
paramString
()
+
" on <Non-testing component>"
);
Sys
tem
.
out
.
println
(
e
.
paramString
()
+
" on <Non-testing component>"
);
}
}
},
AWTEvent
.
WINDOW_EVENT_MASK
|
AWTEvent
.
WINDOW_FOCUS_EVENT_MASK
|
AWTEvent
.
FOCUS_EVENT_MASK
);
setSize
(
200
,
200
);
setSize
(
500
,
200
);
setVisible
(
true
);
validate
();
...
...
@@ -117,15 +92,15 @@ public class ActualFocusedWindowRetaining extends Applet {
owner
.
setSize
(
new
Dimension
(
400
,
100
));
owner
.
setVisible
(
true
);
owner
.
toFront
();
waitTillShown
(
owner
);
Util
.
waitTillShown
(
owner
);
window1
.
setVisible
(
true
);
window2
.
setVisible
(
true
);
window1
.
toFront
();
window2
.
toFront
();
// Wait longer...
waitTillShown
(
window1
);
waitTillShown
(
window2
);
Util
.
waitTillShown
(
window1
);
Util
.
waitTillShown
(
window2
);
test
();
...
...
@@ -134,85 +109,39 @@ public class ActualFocusedWindowRetaining extends Applet {
}
public
void
test
()
{
Button
[]
butArr
=
new
Button
[]
{
testButton3
,
testButton2
,
testButton1
};
Window
[]
winArr
=
new
Window
[]
{
window2
,
window1
,
owner
};
step
=
1
;
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
clickOnCheckFocusOwner
(
butArr
[
i
]);
clickOnCheckFocusedWindow
(
frame
);
clickOn
(
owner
);
if
(!
checkFocusedWindow
(
winArr
[
i
]))
{
stopTest
(
"Test failed: actual focused window didn't get a focus"
);
}
if
(!
checkFocusOwner
(
butArr
[
i
]))
{
stopTest
(
"Test failed: actual focus owner didn't get a focus"
);
}
clickInSeriesCheckFocus
(
null
,
butArr
[
i
],
frame
);
clickOwnerCheckFocus
(
winArr
[
i
],
butArr
[
i
]);
step
++;
}
step
=
4
;
clickOnCheckFocusOwner
(
testButton3
);
clickOnCheckFocusOwner
(
testButton1
);
clickOnCheckFocusedWindow
(
frame
);
clickOn
(
owner
);
if
(!
checkFocusedWindow
(
owner
))
{
stopTest
(
"Test failed: actual focused window didn't get a focus"
);
}
if
(!
checkFocusOwner
(
testButton1
))
{
stopTest
(
"Test failed: actual focus owner didn't get a focus"
);
}
clickInSeriesCheckFocus
(
testButton3
,
testButton1
,
frame
);
clickOwnerCheckFocus
(
owner
,
testButton1
);
step
=
5
;
clickOnCheckFocusOwner
(
testButton3
);
clickOnCheckFocusOwner
(
testButton2
);
clickOnCheckFocusedWindow
(
frame
);
clickOn
(
owner
);
if
(!
checkFocusedWindow
(
window1
))
{
stopTest
(
"Test failed: actual focused window didn't get a focus"
);
}
if
(!
checkFocusOwner
(
testButton2
))
{
stopTest
(
"Test failed: actual focus owner didn't get a focus"
);
}
clickInSeriesCheckFocus
(
testButton3
,
testButton2
,
frame
);
clickOwnerCheckFocus
(
window1
,
testButton2
);
step
=
6
;
clickOnCheckFocusOwner
(
testButton1
);
clickOnCheckFocusOwner
(
testButton2
);
clickOnCheckFocusedWindow
(
frame
);
clickOn
(
owner
);
if
(!
checkFocusedWindow
(
window1
))
{
stopTest
(
"Test failed: actual focused window didn't get a focus"
);
}
if
(!
checkFocusOwner
(
testButton2
))
{
stopTest
(
"Test failed: actual focus owner didn't get a focus"
);
}
clickInSeriesCheckFocus
(
testButton1
,
testButton2
,
frame
);
clickOwnerCheckFocus
(
window1
,
testButton2
);
step
=
7
;
clickOnCheckFocusOwner
(
testButton1
);
clickOnCheckFocusOwner
(
testButton2
);
clickOnCheckFocusedWindow
(
frame
);
clickInSeriesCheckFocus
(
testButton1
,
testButton2
,
frame
);
window1
.
setVisible
(
false
);
clickOn
(
owner
);
if
(!
checkFocusedWindow
(
owner
))
{
stopTest
(
"Test failed: actual focused window didn't get a focus"
);
}
if
(!
checkFocusOwner
(
testButton1
))
{
stopTest
(
"Test failed: actual focus owner didn't get a focus"
);
}
Util
.
waitForIdle
(
robot
);
clickOwnerCheckFocus
(
owner
,
testButton1
);
step
=
8
;
window1
.
setVisible
(
true
);
waitTillShown
(
window1
);
clickOnCheckFocusOwner
(
testButton2
);
clickOnCheckFocusedWindow
(
frame
);
clickOn
(
owner
);
if
(!
checkFocusedWindow
(
window1
))
{
stopTest
(
"Test failed: actual focused window didn't get a focus"
);
}
if
(!
checkFocusOwner
(
testButton2
))
{
stopTest
(
"Test failed: actual focus owner didn't get a focus"
);
}
Util
.
waitTillShown
(
window1
);
clickInSeriesCheckFocus
(
null
,
testButton2
,
frame
);
clickOwnerCheckFocus
(
window1
,
testButton2
);
}
boolean
checkFocusOwner
(
Component
comp
)
{
...
...
@@ -223,53 +152,43 @@ public class ActualFocusedWindowRetaining extends Applet {
return
(
win
==
KeyboardFocusManager
.
getCurrentKeyboardFocusManager
().
getFocusedWindow
());
}
void
waitTillShown
(
Component
c
)
{
((
sun
.
awt
.
SunToolkit
)
Toolkit
.
getDefaultToolkit
()).
realSync
(
);
}
void
clickOwnerCheckFocus
(
Window
focusedWindow
,
Component
focusedComp
)
{
Util
.
clickOnTitle
(
owner
,
robot
);
robot
.
delay
(
500
);
void
clickOnCheckFocusOwner
(
Component
c
)
{
clickOn
(
c
);
if
(!
checkFocusOwner
(
c
))
{
stopTest
(
"Error: can't bring a focus on Component by clicking on it"
);
if
(!
checkFocusedWindow
(
focusedWindow
))
{
stopTest
(
"Test failed: actual focused window didn't get a focus"
);
}
if
(!
checkFocusOwner
(
focusedComp
))
{
stopTest
(
"Test failed: actual focus owner didn't get a focus"
);
}
}
void
clickOnCheckFocusedWindow
(
Frame
f
)
{
clickOn
(
f
);
if
(!
checkFocusedWindow
(
f
))
{
stopTest
(
"Error: can't bring a focus on Frame by clicking on it"
);
void
clickInSeriesCheckFocus
(
Component
comp1
,
Component
comp2
,
Frame
frame
)
{
if
(
comp1
!=
null
)
{
clickOnCheckFocusOwner
(
comp1
);
}
if
(
comp2
!=
null
)
{
clickOnCheckFocusOwner
(
comp2
);
}
void
clickOn
(
Component
c
)
{
Point
p
=
c
.
getLocationOnScreen
();
Dimension
d
=
c
.
getSize
();
if
(
c
instanceof
Frame
)
{
robot
.
mouseMove
(
p
.
x
+
(
int
)(
d
.
getWidth
()/
2
),
p
.
y
+
((
Frame
)
c
).
getInsets
().
top
/
2
);
}
else
{
robot
.
mouseMove
(
p
.
x
+
(
int
)(
d
.
getWidth
()/
2
),
p
.
y
+
(
int
)(
d
.
getHeight
()/
2
));
clickOnCheckFocusedWindow
(
frame
);
}
pause
(
100
);
robot
.
mousePress
(
InputEvent
.
BUTTON1_MASK
);
pause
(
100
);
robot
.
mouseRelease
(
InputEvent
.
BUTTON1_MASK
);
void
clickOnCheckFocusOwner
(
Component
c
)
{
Util
.
clickOnComp
(
c
,
robot
);
robot
.
delay
(
500
);
waitForIdle
();
if
(!
checkFocusOwner
(
c
))
{
stopTest
(
"Error: can't bring a focus on Component by clicking on it"
);
}
void
waitForIdle
()
{
((
sun
.
awt
.
SunToolkit
)
Toolkit
.
getDefaultToolkit
()).
realSync
();
}
void
pause
(
int
msec
)
{
try
{
Thread
.
sleep
(
msec
);
}
catch
(
InterruptedException
e
)
{
Sysout
.
println
(
"pause: non-fatal exception caught:"
);
e
.
printStackTrace
(
);
void
clickOnCheckFocusedWindow
(
Frame
f
)
{
Util
.
clickOnTitle
(
f
,
robot
);
robot
.
delay
(
500
);
if
(!
checkFocusedWindow
(
f
))
{
stopTest
(
"Error: can't bring a focus on Frame by clicking on it"
);
}
}
...
...
@@ -290,141 +209,3 @@ class TestWindow extends Window {
setBackground
(
Color
.
green
);
}
}
/****************************************************
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
);
}
}
// 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
test/java/awt/Focus/FrameJumpingToMouse/FrameJumpingToMouse.java
浏览文件 @
4b0fe58c
...
...
@@ -22,238 +22,65 @@
*/
/*
test
@bug 4752312
@summary Tests that after moving non-focusable window it ungrabs mouse pointer
@author dom@sparc.spb.su: area=awt.focus
@run applet FrameJumpingToMouse.html
@test
@bug 4752312
@summary Tests that after moving non-focusable window it ungrabs mouse pointer
@author Denis Mikhalkin: area=awt.focus
@library ../../regtesthelpers
@build Util
@run main FrameJumpingToMouse
*/
// Note there is no @ in front of test above. This is so that the
// harness will not mistake this file as a test file. It should
// only see the html file as a test file. (the harness runs all
// valid test files, so it would run this test twice if this file
// were valid as well as the html file.)
// Also, note the area= after Your Name in the author tag. Here, you
// should put which functional area the test falls in. See the
// AWT-core home page -> test areas and/or -> AWT team for a list of
// areas.
// Note also the 'FrameJumpingToMouse.html' in the run tag. This should
// be changed to the name of the test.
/**
* FrameJumpingToMouse.java
*
* summary:
*/
import
java.applet.Applet
;
import
java.awt.*
;
import
java.awt.event.*
;
import
java.awt.BorderLayout
;
import
java.awt.Dialog
;
import
java.awt.Frame
;
import
java.awt.Point
;
import
java.awt.Robot
;
import
java.awt.TextArea
;
import
java.awt.Toolkit
;
import
java.awt.event.InputEvent
;
import
javax.swing.JFrame
;
//Automated tests should run as applet tests if possible because they
// get their environments cleaned up, including AWT threads, any
// test created threads, and any system resources used by the test
// such as file descriptors. (This is normally not a problem as
// main tests usually run in a separate VM, however on some platforms
// such as the Mac, separate VMs are not possible and non-applet
// tests will cause problems). Also, you don't have to worry about
// synchronisation stuff in Applet tests they way you do in main
// tests...
import
test.java.awt.regtesthelpers.Util
;
public
class
FrameJumpingToMouse
extends
Applet
{
//Declare things used in the test, like buttons and labels here
JFrame
frame
=
new
JFrame
(
"Test jumping frame"
);
Robot
robot
=
null
;
public
void
init
()
{
//Create instructions for the user here, as well as set up
// the environment -- set the layout manager, add buttons,
// etc.
Robot
robot
=
Util
.
createRobot
();
this
.
setLayout
(
new
BorderLayout
());
public
static
void
main
(
String
[]
args
)
{
FrameJumpingToMouse
test
=
new
FrameJumpingToMouse
();
test
.
init
();
test
.
start
();
}
public
void
init
()
{
frame
.
setFocusableWindowState
(
false
);
frame
.
setBounds
(
100
,
100
,
100
,
100
);
}
//End init()
public
void
start
()
{
//Get things going. Request focus, set size, et cetera
setSize
(
200
,
200
);
setVisible
(
true
);
validate
();
try
{
robot
=
new
Robot
();
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"Can't create robot"
);
}
public
void
start
()
{
frame
.
setVisible
(
true
);
Util
.
waitTillShown
(
frame
);
robot
.
delay
(
1000
);
Point
frameLoc
=
frame
.
getLocationOnScreen
();
robot
.
mouseMove
(
frameLoc
.
x
+
frame
.
getWidth
()/
4
,
frameLoc
.
y
+
frame
.
getInsets
().
top
/
2
);
Point
loc
=
frame
.
getLocationOnScreen
();
robot
.
mouseMove
(
loc
.
x
+
frame
.
getWidth
()
/
4
,
loc
.
y
+
frame
.
getInsets
().
top
/
2
);
robot
.
delay
(
50
);
robot
.
mousePress
(
InputEvent
.
BUTTON1_MASK
);
robot
.
mouseMove
(
frameLoc
.
x
+
100
,
frameLoc
.
y
+
50
);
robot
.
delay
(
50
);
robot
.
mouseMove
(
loc
.
x
+
100
,
loc
.
y
+
50
);
robot
.
delay
(
50
);
robot
.
mouseRelease
(
InputEvent
.
BUTTON1_MASK
);
Toolkit
.
getDefaultToolkit
().
sync
();
robot
.
waitForIdle
();
frameLoc
=
frame
.
getLocation
();
robot
.
mouseMove
(
frameLoc
.
x
+
frame
.
getWidth
()/
2
,
frameLoc
.
y
+
frame
.
getHeight
()/
2
);
Toolkit
.
getDefaultToolkit
().
sync
();
robot
.
waitForIdle
();
Util
.
waitForIdle
(
robot
);
if
(!(
frame
.
getLocation
().
equals
(
frameLoc
)))
{
throw
new
RuntimeException
(
"Frame is moving to mouse with grab"
);
}
}
// start()
}
// class FrameJumpingToMouse
/****************************************************
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.
****************************************************/
loc
=
frame
.
getLocation
();
robot
.
mouseMove
(
loc
.
x
+
frame
.
getWidth
()
/
2
,
loc
.
y
+
frame
.
getHeight
()
/
2
);
Util
.
waitForIdle
(
robot
);
/**
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."
);
if
(!(
frame
.
getLocation
().
equals
(
loc
)))
{
throw
new
RuntimeException
(
"Test failed: frame is moving to mouse with grab!"
);
}
public
static
void
printInstructions
(
String
[]
instructions
)
{
dialog
.
printInstructions
(
instructions
);
System
.
out
.
println
(
"Test passed."
);
}
public
static
void
println
(
String
messageIn
)
{
dialog
.
displayMessage
(
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
();
show
();
}
// 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
}
test/java/awt/Focus/NonFocusableWindowTest/Test.java
→
test/java/awt/Focus/NonFocusableWindowTest/
NoEvents
Test.java
浏览文件 @
4b0fe58c
...
...
@@ -20,19 +20,20 @@
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
@test
@bug 4452384
@summary Tests that non-focusable windows doesn't generate any focus events when accessed.
@author
dom
: area=awt.focus
@run main Test
@author
Denis.Mikhalkin
: area=awt.focus
@run main
NoEvents
Test
*/
import
java.awt.*
;
import
java.awt.event.*
;
import
java.util.*
;
public
class
Test
extends
Frame
{
public
class
NoEvents
Test
extends
Frame
{
public
static
final
int
DEF_WIDTH
=
400
,
DEF_HEIGHT
=
300
,
DEF_TOP
=
1
,
...
...
@@ -80,8 +81,8 @@ public class Test extends Frame {
windows
=
new
Window
[
7
];
windows
[
0
]
=
new
TestWindow
(
0
,
0
,
false
,
main_frame
);
//windows[1] = new TestWindow(2, 1, true, main_frame);
windows
[
2
]
=
new
Test
(
1
,
0
,
false
,
true
);
windows
[
3
]
=
new
Test
(
2
,
0
,
false
,
false
);
windows
[
2
]
=
new
NoEvents
Test
(
1
,
0
,
false
,
true
);
windows
[
3
]
=
new
NoEvents
Test
(
2
,
0
,
false
,
false
);
//windows[4] = new Test(3, 0, true, true);
windows
[
5
]
=
new
TestDialog
(
0
,
1
,
false
,
true
,
main_frame
);
windows
[
6
]
=
new
TestDialog
(
1
,
1
,
false
,
false
,
main_frame
);
...
...
@@ -174,12 +175,12 @@ public class Test extends Frame {
}
}
}
public
Test
(
int
row
,
int
col
,
boolean
focusable
,
boolean
resizable
)
{
public
NoEvents
Test
(
int
row
,
int
col
,
boolean
focusable
,
boolean
resizable
)
{
super
(
"Frame"
+
row
+
""
+
col
);
TestPanel
panel
=
new
TestPanel
(
row
,
col
);
if
(
Test
.
automatic
)
{
row
=
Test
.
DEF_ROW
;
col
=
Test
.
DEF_COL
;
if
(
NoEvents
Test
.
automatic
)
{
row
=
NoEvents
Test
.
DEF_ROW
;
col
=
NoEvents
Test
.
DEF_COL
;
}
setName
(
getTitle
());
add
(
"Center"
,
panel
);
...
...
@@ -187,7 +188,7 @@ public class Test extends Frame {
", "
+
(
resizable
?
"resizable"
:
"non-resizable"
));
l
.
setBackground
(
Color
.
green
);
add
(
"North"
,
l
);
setBounds
(
Test
.
DEF_LEFT
+
DEF_WIDTH
*
col
,
DEF_TOP
+
DEF_HEIGHT
*
row
,
DEF_WIDTH
,
DEF_HEIGHT
);
setBounds
(
NoEvents
Test
.
DEF_LEFT
+
DEF_WIDTH
*
col
,
DEF_TOP
+
DEF_HEIGHT
*
row
,
DEF_WIDTH
,
DEF_HEIGHT
);
if
(!
focusable
)
{
setFocusableWindowState
(
false
);
}
...
...
@@ -202,9 +203,9 @@ class TestWindow extends Window {
super
(
owner
);
setName
(
"Window"
+
row
+
""
+
col
);
TestPanel
panel
=
new
TestPanel
(
row
,
col
);
if
(
Test
.
automatic
)
{
row
=
Test
.
DEF_ROW
;
col
=
Test
.
DEF_COL
;
if
(
NoEvents
Test
.
automatic
)
{
row
=
NoEvents
Test
.
DEF_ROW
;
col
=
NoEvents
Test
.
DEF_COL
;
}
add
(
"Center"
,
panel
);
...
...
@@ -213,7 +214,7 @@ class TestWindow extends Window {
l
.
setBackground
(
Color
.
green
);
add
(
"North"
,
l
);
setBounds
(
Test
.
DEF_LEFT
+
Test
.
DEF_WIDTH
*
col
,
Test
.
DEF_TOP
+
Test
.
DEF_HEIGHT
*
row
,
Test
.
DEF_WIDTH
,
Test
.
DEF_HEIGHT
);
setBounds
(
NoEventsTest
.
DEF_LEFT
+
NoEventsTest
.
DEF_WIDTH
*
col
,
NoEventsTest
.
DEF_TOP
+
NoEventsTest
.
DEF_HEIGHT
*
row
,
NoEventsTest
.
DEF_WIDTH
,
NoEvents
Test
.
DEF_HEIGHT
);
if
(!
focusable
)
{
setFocusableWindowState
(
false
);
}
...
...
@@ -225,9 +226,9 @@ class TestDialog extends Dialog {
super
(
owner
);
setName
(
"Dialog"
+
row
+
""
+
col
);
TestPanel
panel
=
new
TestPanel
(
row
,
col
);
if
(
Test
.
automatic
)
{
row
=
Test
.
DEF_ROW
;
col
=
Test
.
DEF_COL
;
if
(
NoEvents
Test
.
automatic
)
{
row
=
NoEvents
Test
.
DEF_ROW
;
col
=
NoEvents
Test
.
DEF_COL
;
}
add
(
"Center"
,
panel
);
...
...
@@ -236,7 +237,7 @@ class TestDialog extends Dialog {
l
.
setBackground
(
Color
.
green
);
add
(
"North"
,
l
);
setBounds
(
Test
.
DEF_LEFT
+
Test
.
DEF_WIDTH
*
col
,
Test
.
DEF_TOP
+
Test
.
DEF_HEIGHT
*
row
,
Test
.
DEF_WIDTH
,
Test
.
DEF_HEIGHT
);
setBounds
(
NoEventsTest
.
DEF_LEFT
+
NoEventsTest
.
DEF_WIDTH
*
col
,
NoEventsTest
.
DEF_TOP
+
NoEventsTest
.
DEF_HEIGHT
*
row
,
NoEventsTest
.
DEF_WIDTH
,
NoEvents
Test
.
DEF_HEIGHT
);
if
(!
focusable
)
{
setFocusableWindowState
(
false
);
}
...
...
@@ -415,3 +416,5 @@ class GlobalListener implements AWTEventListener {
// }
}
}
test/java/awt/Focus/NonFocusableWindowTest/NonfocusableOwnerTest.java
浏览文件 @
4b0fe58c
...
...
@@ -25,8 +25,10 @@
@test
@bug 6182359
@summary Tests that Window having non-focusable owner can't be a focus owner.
@author Anton Tarasov: area=awt.focus
@run applet NonfocusableOwnerTest.html
@author Anton.Tarasov: area=awt.focus
@library ../../regtesthelpers
@build Util
@run main NonfocusableOwnerTest
*/
import
java.awt.*
;
...
...
@@ -34,319 +36,124 @@ import java.awt.event.*;
import
java.applet.Applet
;
import
java.lang.reflect.*
;
import
java.io.*
;
import
test.java.awt.regtesthelpers.Util
;
public
class
NonfocusableOwnerTest
extends
Applet
{
Robot
robot
;
Robot
robot
=
Util
.
createRobot
()
;
Frame
frame
;
Dialog
dialog
;
Window
window1
;
Window
window2
;
Button
button
=
new
Button
(
"button"
);
// PrintStream Sysout = System.out;
public
static
void
main
(
String
[]
args
)
{
NonfocusableOwnerTest
test
=
new
NonfocusableOwnerTest
();
test
.
init
();
test
.
start
();
}
public
void
init
()
{
try
{
robot
=
new
Robot
();
}
catch
(
AWTException
e
)
{
throw
new
RuntimeException
(
"Error: unable to create robot"
,
e
);
}
// Create instructions for the user here, as well as set up
// the environment -- set the layout manager, add buttons,
// etc.
this
.
setLayout
(
new
BorderLayout
());
}
public
void
start
()
{
Toolkit
.
getDefaultToolkit
().
addAWTEventListener
(
new
AWTEventListener
()
{
public
void
eventDispatched
(
AWTEvent
e
)
{
Sysout
.
println
(
e
.
toString
());
Sys
tem
.
out
.
println
(
e
.
toString
());
}
},
FocusEvent
.
FOCUS_EVENT_MASK
|
WindowEvent
.
WINDOW_FOCUS_EVENT_MASK
|
WindowEvent
.
WINDOW_EVENT_MASK
);
frame
=
new
Frame
(
"Frame"
);
frame
.
setName
(
"Frame-owner"
);
frame
.
setBounds
(
100
,
0
,
100
,
100
);
dialog
=
new
Dialog
(
frame
,
"Dialog"
);
dialog
.
setName
(
"Dialog-owner"
);
dialog
.
setBounds
(
100
,
0
,
100
,
100
);
window1
=
new
Window
(
frame
);
window1
.
setName
(
"1st child"
);
window1
.
setBounds
(
100
,
300
,
100
,
100
);
window2
=
new
Window
(
window1
);
window2
.
setName
(
"2nd child"
);
window2
.
setBounds
(
100
,
500
,
100
,
100
);
test1
(
frame
,
window1
);
test2
(
frame
,
window1
,
window2
);
test3
(
frame
,
window1
,
window2
);
window1
=
new
Window
(
dialog
);
window1
.
setBounds
(
100
,
300
,
100
,
100
);
window1
.
setName
(
"1st child"
);
window2
=
new
Window
(
window1
);
window2
.
setName
(
"2nd child"
);
window2
.
setBounds
(
100
,
500
,
100
,
100
);
test1
(
dialog
,
window1
);
test2
(
dialog
,
window1
,
window2
);
test3
(
dialog
,
window1
,
window2
);
Sysout
.
println
(
"Test passed."
);
Sys
tem
.
out
.
println
(
"Test passed."
);
}
void
test1
(
Window
owner
,
Window
child
)
{
Sys
out
.
println
(
"* * * STAGE 1 * * *\nowner=
"
+
owner
);
Sys
tem
.
out
.
println
(
"* * * STAGE 1 * * *\nWindow owner:
"
+
owner
);
owner
.
setFocusableWindowState
(
false
);
owner
.
setSize
(
100
,
100
);
owner
.
setVisible
(
true
);
child
.
add
(
button
);
child
.
setBounds
(
0
,
300
,
100
,
100
);
child
.
setVisible
(
true
);
waitTillShown
(
child
);
Util
.
waitTillShown
(
child
);
clickOn
(
button
);
Util
.
clickOnComp
(
button
,
robot
);
if
(
button
==
KeyboardFocusManager
.
getCurrentKeyboardFocusManager
().
getFocusOwner
())
{
throw
new
RuntimeException
(
"Test Failed."
);
}
owner
.
dispose
();
child
.
dispose
();
owner
.
dispose
();
}
void
test2
(
Window
owner
,
Window
child1
,
Window
child2
)
{
Sys
out
.
println
(
"* * * STAGE 2 * * *\nowner=
"
+
owner
);
Sys
tem
.
out
.
println
(
"* * * STAGE 2 * * *\nWindow nowner:
"
+
owner
);
owner
.
setFocusableWindowState
(
false
);
owner
.
setSize
(
100
,
100
);
owner
.
setVisible
(
true
);
child1
.
setFocusableWindowState
(
true
);
child1
.
setBounds
(
0
,
300
,
100
,
100
);
child1
.
setVisible
(
true
);
child2
.
add
(
button
);
child2
.
setBounds
(
0
,
500
,
100
,
100
);
child2
.
setVisible
(
true
);
clickOn
(
button
);
Util
.
waitTillShown
(
child2
);
Util
.
clickOnComp
(
button
,
robot
);
if
(
button
==
KeyboardFocusManager
.
getCurrentKeyboardFocusManager
().
getFocusOwner
())
{
throw
new
RuntimeException
(
"Test failed."
);
}
owner
.
dispose
();
child1
.
dispose
();
child2
.
dispose
();
child1
.
dispose
();
owner
.
dispose
();
}
void
test3
(
Window
owner
,
Window
child1
,
Window
child2
)
{
Sys
out
.
println
(
"* * * STAGE 3 * * *\nowner=
"
+
owner
);
Sys
tem
.
out
.
println
(
"* * * STAGE 3 * * *\nWidow owner:
"
+
owner
);
owner
.
setFocusableWindowState
(
true
);
owner
.
setSize
(
100
,
100
);
owner
.
setVisible
(
true
);
child1
.
setFocusableWindowState
(
false
);
child1
.
setBounds
(
0
,
300
,
100
,
100
);
child1
.
setVisible
(
true
);
child2
.
setFocusableWindowState
(
true
);
child2
.
add
(
button
);
child2
.
setBounds
(
0
,
500
,
100
,
100
);
child2
.
setVisible
(
true
);
clickOn
(
button
);
Util
.
waitTillShown
(
child2
);
Util
.
clickOnComp
(
button
,
robot
);
System
.
err
.
println
(
"focus owner: "
+
KeyboardFocusManager
.
getCurrentKeyboardFocusManager
().
getFocusOwner
());
if
(
button
!=
KeyboardFocusManager
.
getCurrentKeyboardFocusManager
().
getFocusOwner
())
{
throw
new
RuntimeException
(
"Test failed."
);
}
owner
.
dispose
();
child1
.
dispose
();
child2
.
dispose
();
}
void
clickOn
(
Component
c
)
{
Point
p
=
c
.
getLocationOnScreen
();
Dimension
d
=
c
.
getSize
();
Sysout
.
println
(
"Clicking "
+
c
);
if
(
c
instanceof
Frame
)
{
robot
.
mouseMove
(
p
.
x
+
(
int
)(
d
.
getWidth
()/
2
),
p
.
y
+
((
Frame
)
c
).
getInsets
().
top
/
2
);
}
else
{
robot
.
mouseMove
(
p
.
x
+
(
int
)(
d
.
getWidth
()/
2
),
p
.
y
+
(
int
)(
d
.
getHeight
()/
2
));
}
robot
.
mousePress
(
InputEvent
.
BUTTON1_MASK
);
robot
.
mouseRelease
(
InputEvent
.
BUTTON1_MASK
);
waitForIdle
();
}
void
waitTillShown
(
Component
c
)
{
while
(
true
)
{
try
{
Thread
.
sleep
(
100
);
c
.
getLocationOnScreen
();
break
;
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
IllegalComponentStateException
e
)
{}
}
}
void
waitForIdle
()
{
try
{
Toolkit
.
getDefaultToolkit
().
sync
();
sun
.
awt
.
SunToolkit
.
flushPendingEvents
();
EventQueue
.
invokeAndWait
(
new
Runnable
()
{
public
void
run
()
{}
// Dummy implementation
});
}
catch
(
InterruptedException
ie
)
{
Sysout
.
println
(
"waitForIdle, non-fatal exception caught:"
);
ie
.
printStackTrace
();
}
catch
(
InvocationTargetException
ite
)
{
Sysout
.
println
(
"waitForIdle, non-fatal exception caught:"
);
ite
.
printStackTrace
();
}
// wait longer...
robot
.
delay
(
200
);
owner
.
dispose
();
}
}
/****************************************************
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
{
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
)
{
System
.
err
.
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
test/java/awt/Focus/TypeAhead/TestFocusFreeze.java
浏览文件 @
4b0fe58c
...
...
@@ -22,467 +22,118 @@
*/
/*
@test
@bug 6183877 6216005 6225560
@summary Tests that keyboard input doesn't freeze due to type-ahead problems
@author Denis Mikhalkin: area=awt.focus
@run main/timeout=300 TestFocusFreeze
@test
@bug 6183877 6216005 6225560
@library ../../regtesthelpers
@build Util
@summary Tests that keyboard input doesn't freeze due to type-ahead problems
@author Denis.Mikhalkin, Anton.Tarasov: area=awt.focus
@run main TestFocusFreeze
*/
// Note the area= after Your Name in the author tag. Here, you
// should put which functional area the test falls in. See the
// AWT-core home page -> test areas and/or -> AWT team for a list of
// areas.
import
java.awt.Component
;
import
java.awt.DefaultKeyboardFocusManager
;
import
java.awt.KeyboardFocusManager
;
import
java.awt.Robot
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
import
java.awt.event.KeyEvent
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
javax.swing.JButton
;
import
javax.swing.JDialog
;
import
javax.swing.JFrame
;
import
test.java.awt.regtesthelpers.Util
;
public
class
TestFocusFreeze
{
private
static
JFrame
frame
;
private
static
JDialog
dialog
;
private
static
JButton
dlgButton
;
private
static
JButton
frameButton
;
private
static
AtomicBoolean
lock
=
new
AtomicBoolean
(
false
);
private
static
Robot
robot
=
Util
.
createRobot
();
public
static
void
main
(
String
[]
args
)
{
boolean
all_passed
=
true
;
KeyboardFocusManager
testKFM
=
new
TestKFM
(
robot
);
KeyboardFocusManager
defKFM
=
KeyboardFocusManager
.
getCurrentKeyboardFocusManager
();
/**
* TestFocusFreeze.java
*
* summary: XXX A brief summary of what this tests
*/
import
java.awt.*
;
import
java.awt.event.*
;
import
javax.swing.*
;
import
java.util.concurrent.atomic.*
;
import
sun.awt.SunToolkit
;
public
class
TestFocusFreeze
{
//*** test-writer defined static variables go here ***
private
static
void
init
()
{
//*** Create instructions for the user here ***
FocusTest
.
test
();
}
//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
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 TestFocusFreeze
//This exception is used to exit from any level of call nesting
// when it's determined that the test has passed, and immediately
// end the test.
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
TestFocusFreeze.pass();
}
else if( tries == 20 )
{
//tried too many times without getting enough events so fail
TestFocusFreeze.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
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
test
(
testKFM
,
defKFM
);
Util
.
waitForIdle
(
robot
);
System
.
out
.
println
(
"Iter "
+
i
+
": "
+
(
lock
.
get
()
?
"passed."
:
"failed!"
));
if
(!
lock
.
get
())
{
all_passed
=
false
;
}
public
static
void
println
(
String
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
=
""
;
if
(!
all_passed
)
{
throw
new
RuntimeException
(
"Test failed: not all iterations passed!"
);
}
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
);
System
.
out
.
println
(
"Test passed."
);
}
}
// TestDialog class
public
static
void
test
(
final
KeyboardFocusManager
testKFM
,
final
KeyboardFocusManager
defKFM
)
{
frame
=
new
JFrame
(
"Frame"
);
dialog
=
new
JDialog
(
frame
,
"Dialog"
,
true
);
dlgButton
=
new
JButton
(
"Dialog_Button"
);
frameButton
=
new
JButton
(
"Frame_Button"
);
lock
.
set
(
false
);
class
FocusTest
extends
JFrame
implements
ActionListener
{
dialog
.
add
(
dlgButton
);
dialog
.
setLocation
(
200
,
0
);
dialog
.
pack
();
frame
.
add
(
frameButton
);
frame
.
pack
();
private
JDialog
pageDialog
=
null
;
private
AtomicBoolean
passed
=
new
AtomicBoolean
();
private
static
volatile
boolean
all_passed
=
true
;
private
static
volatile
long
pressTime
;
private
static
Object
testLock
=
new
Object
();
private
static
Object
resultLock
=
new
Object
();
public
FocusTest
()
{
final
GraphicsConfiguration
gc
=
GraphicsEnvironment
.
getLocalGraphicsEnvironment
().
getDefaultScreenDevice
().
getDefaultConfiguration
();
pageDialog
=
new
JDialog
(
this
,
"JDialog"
,
true
,
gc
);
Container
c
=
pageDialog
.
getContentPane
();
c
.
setLayout
(
new
BorderLayout
());
JButton
btnApprove
=
new
JButton
(
"Exit Button"
);
btnApprove
.
addActionListener
(
this
);
c
.
add
(
"South"
,
btnApprove
);
pageDialog
.
pack
();
JButton
bb
=
new
JButton
(
"Action"
);
bb
.
addActionListener
(
new
ActionListener
()
{
final
JDialog
pageDialog
=
FocusTest
.
this
.
pageDialog
;
dlgButton
.
addActionListener
(
new
ActionListener
()
{
public
void
actionPerformed
(
ActionEvent
e
)
{
synchronized
(
testLock
)
{
testLock
.
notify
();
dialog
.
dispose
();
frame
.
dispose
();
synchronized
(
lock
)
{
lock
.
set
(
true
);
lock
.
notifyAll
();
}
pageDialog
.
setVisible
(
true
);
}
});
add
(
bb
);
pack
();
setVisible
(
true
);
((
SunToolkit
)
Toolkit
.
getDefaultToolkit
()).
realSync
();
bb
.
requestFocus
();
((
SunToolkit
)
Toolkit
.
getDefaultToolkit
()).
realSync
();
if
(!
bb
.
isFocusOwner
())
{
System
.
err
.
println
(
"Couldn't make bb focused"
);
all_passed
=
false
;
return
;
frameButton
.
addActionListener
(
new
ActionListener
()
{
public
void
actionPerformed
(
ActionEvent
e
)
{
// Right before the dialog will be shown, there will be called
// enqueuKeyEvents() method. We are to catch it.
KeyboardFocusManager
.
setCurrentKeyboardFocusManager
(
testKFM
);
dialog
.
setVisible
(
true
);
KeyboardFocusManager
.
setCurrentKeyboardFocusManager
(
defKFM
);
}
});
new
Thread
()
{
Runnable
showAction
=
new
Runnable
()
{
public
void
run
()
{
try
{
Robot
r
=
new
Robot
();
synchronized
(
testLock
)
{
testLock
.
wait
();
}
r
.
keyPress
(
KeyEvent
.
VK_SPACE
);
r
.
delay
(
50
);
r
.
keyRelease
(
KeyEvent
.
VK_SPACE
);
synchronized
(
passed
)
{
passed
.
wait
(
1000
);
}
pageDialog
.
dispose
();
FocusTest
.
this
.
dispose
();
if
(!
passed
.
get
())
{
all_passed
=
false
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
synchronized
(
resultLock
)
{
resultLock
.
notifyAll
();
}
frame
.
setVisible
(
true
);
}
}.
start
();
try
{
Robot
r
=
new
Robot
();
r
.
keyPress
(
KeyEvent
.
VK_SPACE
);
r
.
delay
(
50
);
r
.
keyRelease
(
KeyEvent
.
VK_SPACE
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
all_passed
=
false
;
};
if
(!
Util
.
trackFocusGained
(
frameButton
,
showAction
,
2000
,
false
))
{
System
.
out
.
println
(
"Test error: wrong initial focus!"
);
return
;
}
try
{
synchronized
(
resultLock
)
{
resultLock
.
wait
();
}
}
catch
(
InterruptedException
ie
)
{
ie
.
printStackTrace
();
}
}
robot
.
keyPress
(
KeyEvent
.
VK_SPACE
);
robot
.
delay
(
50
);
robot
.
keyRelease
(
KeyEvent
.
VK_SPACE
);
public
void
actionPerformed
(
ActionEvent
ae
)
{
System
.
err
.
println
(
"Action performed"
);
passed
.
set
(
true
);
synchronized
(
passed
)
{
passed
.
notify
();
}
Util
.
waitForCondition
(
lock
,
2000
);
Util
.
waitForIdle
(
robot
);
}
}
public
static
void
test
()
{
FocusTest
test
=
null
;
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
test
=
new
FocusTest
();
try
{
Thread
.
sleep
(
500
);
}
catch
(
InterruptedException
e
)
{
break
;
}
}
if
(!
all_passed
)
{
TestFocusFreeze
.
fail
(
"Not all passed"
);
}
else
{
TestFocusFreeze
.
pass
();
class
TestKFM
extends
DefaultKeyboardFocusManager
{
Robot
robot
;
public
TestKFM
(
Robot
robot
)
{
this
.
robot
=
robot
;
}
protected
synchronized
void
enqueueKeyEvents
(
long
after
,
Component
untilFocused
)
{
super
.
enqueueKeyEvents
(
after
,
untilFocused
);
robot
.
keyPress
(
KeyEvent
.
VK_SPACE
);
robot
.
delay
(
50
);
robot
.
keyRelease
(
KeyEvent
.
VK_SPACE
);
}
}
test/java/awt/Focus/WrongKeyTypedConsumedTest/WrongKeyTypedConsumedTest.java
浏览文件 @
4b0fe58c
...
...
@@ -22,21 +22,16 @@
*/
/*
test
@
test
@bug 4782886
@summary FocusManager consumes wrong KEYTYPED-Events
@author son: area=awt.focus
@run applet WrongKeyTypedConsumedTest.html
@summary FocusManager consumes wrong KEY_TYPED events
@author Oleg.Sukhodolsky: area=awt.focus
@library ../../regtesthelpers
@build Util
@run main WrongKeyTypedConsumedTest
*/
/**
* WrongKeyTypedConsumedTest.java
*
* summary: FocusManager consumes wrong KEYTYPED-Events
*/
import
java.applet.Applet
;
import
java.awt.AWTException
;
import
java.awt.AWTKeyStroke
;
import
java.awt.BorderLayout
;
...
...
@@ -58,29 +53,19 @@ import javax.swing.JCheckBox;
import
javax.swing.JFrame
;
import
javax.swing.JTextArea
;
import
test.java.awt.regtesthelpers.Util
;
public
class
WrongKeyTypedConsumedTest
extends
Applet
{
//Declare things used in the test, like buttons and labels here
public
void
init
()
{
//Create instructions for the user here, as well as set up
// the environment -- set the layout manager, add buttons,
// etc.
String
[]
instructions
=
{
"This is an AUTOMATIC test"
,
"simply wait until it is done"
};
Sysout
.
createDialog
(
);
Sysout
.
printInstructions
(
instructions
);
Robot
robot
=
Util
.
createRobot
();
}
//End init()
public
static
void
main
(
String
[]
args
)
{
WrongKeyTypedConsumedTest
test
=
new
WrongKeyTypedConsumedTest
();
test
.
start
();
}
public
void
start
()
{
//Get things going. Request focus, set size, et cetera
setSize
(
200
,
200
);
setVisible
(
true
);
validate
();
...
...
@@ -100,37 +85,28 @@ public class WrongKeyTypedConsumedTest extends Applet
frame
.
pack
();
frame
.
setVisible
(
true
);
Util
.
waitForIdle
(
robot
);
try
{
Robot
robot
=
new
Robot
();
// wait for activation
robot
.
delay
(
2000
);
if
(!
frame
.
isActive
())
{
Point
loc
=
frame
.
getLocationOnScreen
();
Dimension
size
=
frame
.
getSize
();
robot
.
mouseMove
(
loc
.
x
+
size
.
width
/
2
,
loc
.
y
+
size
.
height
/
2
);
frame
.
toFront
();
robot
.
delay
(
1000
);
if
(!
frame
.
isActive
())
{
throw
new
RuntimeException
(
"Test Fialed: frame isn't active"
);
}
}
// verify if checkbox has focus
if
(!
checkbox
.
isFocusOwner
())
{
checkbox
.
requestFocusInWindow
();
robot
.
delay
(
1000
);
Util
.
waitForIdle
(
robot
);
if
(!
checkbox
.
isFocusOwner
())
{
throw
new
RuntimeException
(
"Test Failed: checkbox doesn't have focus"
);
}
}
// press VK_DOWN
robot
.
keyPress
(
KeyEvent
.
VK_DOWN
);
robot
.
delay
(
2
50
);
robot
.
delay
(
50
);
robot
.
keyRelease
(
KeyEvent
.
VK_DOWN
);
robot
.
delay
(
1000
);
robot
.
delay
(
50
);
Util
.
waitForIdle
(
robot
);
// verify if text area has focus
if
(!
textarea
.
isFocusOwner
())
{
...
...
@@ -138,156 +114,16 @@ public class WrongKeyTypedConsumedTest extends Applet
}
// press '1'
robot
.
keyPress
(
KeyEvent
.
VK_1
);
robot
.
delay
(
2
50
);
robot
.
delay
(
50
);
robot
.
keyRelease
(
KeyEvent
.
VK_1
);
robot
.
delay
(
100
0
);
robot
.
delay
(
5
0
);
// verify if KEY_TYPED arraived
Util
.
waitForIdle
(
robot
);
// verify if KEY_TYPED arrived
if
(!
"1"
.
equals
(
textarea
.
getText
()))
{
throw
new
RuntimeException
(
"Test Failed: text area text is \""
+
textarea
.
getText
()
+
"\", not \"1\""
);
}
}
catch
(
AWTException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
"Test failed because of some internal exception"
);
}
Sysout
.
println
(
"Test Passed"
);
}
// start()
}
// class WrongKeyTypedConsumedTest
/****************************************************
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."
);
System
.
out
.
println
(
"Test Passed"
);
}
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
);
}
}
// 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
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录