3 @bug 6378278
4 @summary Apparent missing key events causing Bugster to break
5 @author oleg.sukhodolsky: area=awt.focus
6 @run main InputVerifierTest
7 */
8
9 /**
10 * InputVerifierTest.java
11 *
12 * summary: Apparent missing key events causing Bugster to break
13 */
14
15 import java.awt.AWTException;
16 import java.awt.BorderLayout;
17 import java.awt.Component;
18 import java.awt.Dialog;
19 import java.awt.Frame;
20 import java.awt.Point;
21 import java.awt.Robot;
22 import java.awt.TextArea;
23 import java.awt.Toolkit;
24
25 import java.awt.event.InputEvent;
26 import java.awt.event.KeyEvent;
27
28 import javax.swing.InputVerifier;
29 import javax.swing.JComponent;
30 import javax.swing.JFrame;
31 import javax.swing.JTextField;
32
33 public class InputVerifierTest
34 {
35
36 //*** test-writer defined static variables go here ***
37 static volatile boolean ivWasCalled = false;
38
39 private static void init()
40 {
41 //*** Create instructions for the user here ***
42 String[] instructions =
43 {
56 ivWasCalled = true;
57 return true;
58 }
59 });
60 JTextField t2 = new JTextField();
61
62 frame.getContentPane().add(t1, BorderLayout.NORTH);
63 frame.getContentPane().add(t2, BorderLayout.SOUTH);
64 frame.setSize(200, 200);
65 frame.setVisible(true);
66
67 Robot r = null;
68 try {
69 r = new Robot();
70 } catch (AWTException e) {
71 e.printStackTrace();
72 InputVerifierTest.fail(e.toString());
73 }
74
75 try {
76 sun.awt.SunToolkit tk = (sun.awt.SunToolkit) Toolkit.getDefaultToolkit();
77 tk.realSync();
78
79 mouseClickOnComp(r, t1);
80 tk.realSync();
81
82 if (!t1.isFocusOwner()) {
83 throw new RuntimeException("t1 is not a focus owner");
84 }
85 ivWasCalled = false;
86 r.keyPress(KeyEvent.VK_TAB);
87 r.delay(10);
88 r.keyRelease(KeyEvent.VK_TAB);
89 tk.realSync();
90
91 if (!t2.isFocusOwner()) {
92 throw new RuntimeException("t2 is not a focus owner");
93 }
94 if (!ivWasCalled) {
95 throw new RuntimeException("InputVerifier was not called after tabbing");
96 }
97
98 mouseClickOnComp(r, t1);
99 tk.realSync();
100
101 if (!t1.isFocusOwner()) {
102 throw new RuntimeException("t1 is not a focus owner");
103 }
104
105 ivWasCalled = false;
106 mouseClickOnComp(r, t2);
107 tk.realSync();
108 if (!t2.isFocusOwner()) {
109 throw new RuntimeException("t2 is not a focus owner");
110 }
111 if (!ivWasCalled) {
112 throw new RuntimeException("InputVErifier was not called after mouse press");
113 }
114 } catch (Exception e) {
115 e.printStackTrace();
116 InputVerifierTest.fail(e.toString());
117 }
118
119 InputVerifierTest.pass();
120
121 }//End init()
122
123 static void mouseClickOnComp(Robot r, Component comp) {
124 Point loc = comp.getLocationOnScreen();
125 loc.x += comp.getWidth() / 2;
126 loc.y += comp.getHeight() / 2;
127 r.mouseMove(loc.x, loc.y);
|
3 @bug 6378278
4 @summary Apparent missing key events causing Bugster to break
5 @author oleg.sukhodolsky: area=awt.focus
6 @run main InputVerifierTest
7 */
8
9 /**
10 * InputVerifierTest.java
11 *
12 * summary: Apparent missing key events causing Bugster to break
13 */
14
15 import java.awt.AWTException;
16 import java.awt.BorderLayout;
17 import java.awt.Component;
18 import java.awt.Dialog;
19 import java.awt.Frame;
20 import java.awt.Point;
21 import java.awt.Robot;
22 import java.awt.TextArea;
23
24 import java.awt.event.InputEvent;
25 import java.awt.event.KeyEvent;
26
27 import javax.swing.InputVerifier;
28 import javax.swing.JComponent;
29 import javax.swing.JFrame;
30 import javax.swing.JTextField;
31
32 public class InputVerifierTest
33 {
34
35 //*** test-writer defined static variables go here ***
36 static volatile boolean ivWasCalled = false;
37
38 private static void init()
39 {
40 //*** Create instructions for the user here ***
41 String[] instructions =
42 {
55 ivWasCalled = true;
56 return true;
57 }
58 });
59 JTextField t2 = new JTextField();
60
61 frame.getContentPane().add(t1, BorderLayout.NORTH);
62 frame.getContentPane().add(t2, BorderLayout.SOUTH);
63 frame.setSize(200, 200);
64 frame.setVisible(true);
65
66 Robot r = null;
67 try {
68 r = new Robot();
69 } catch (AWTException e) {
70 e.printStackTrace();
71 InputVerifierTest.fail(e.toString());
72 }
73
74 try {
75 r.waitForIdle();
76
77 mouseClickOnComp(r, t1);
78 r.waitForIdle();
79
80 if (!t1.isFocusOwner()) {
81 throw new RuntimeException("t1 is not a focus owner");
82 }
83 ivWasCalled = false;
84 r.keyPress(KeyEvent.VK_TAB);
85 r.delay(10);
86 r.keyRelease(KeyEvent.VK_TAB);
87 r.waitForIdle();
88
89 if (!t2.isFocusOwner()) {
90 throw new RuntimeException("t2 is not a focus owner");
91 }
92 if (!ivWasCalled) {
93 throw new RuntimeException("InputVerifier was not called after tabbing");
94 }
95
96 mouseClickOnComp(r, t1);
97 r.waitForIdle();
98
99 if (!t1.isFocusOwner()) {
100 throw new RuntimeException("t1 is not a focus owner");
101 }
102
103 ivWasCalled = false;
104 mouseClickOnComp(r, t2);
105 r.waitForIdle();
106 if (!t2.isFocusOwner()) {
107 throw new RuntimeException("t2 is not a focus owner");
108 }
109 if (!ivWasCalled) {
110 throw new RuntimeException("InputVErifier was not called after mouse press");
111 }
112 } catch (Exception e) {
113 e.printStackTrace();
114 InputVerifierTest.fail(e.toString());
115 }
116
117 InputVerifierTest.pass();
118
119 }//End init()
120
121 static void mouseClickOnComp(Robot r, Component comp) {
122 Point loc = comp.getLocationOnScreen();
123 loc.x += comp.getWidth() / 2;
124 loc.y += comp.getHeight() / 2;
125 r.mouseMove(loc.x, loc.y);
|