author | serb |
Wed, 27 Feb 2019 18:46:55 -0800 | |
changeset 54231 | e4813eded7cb |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
14497
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
1 |
/* |
54231
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. |
14497
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
4 |
* |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
8 |
* |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
13 |
* accompanied this code). |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
14 |
* |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
18 |
* |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
21 |
* questions. |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
22 |
*/ |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
23 |
|
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
28071
diff
changeset
|
24 |
/* |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
28071
diff
changeset
|
25 |
* @test |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
28071
diff
changeset
|
26 |
* @key headful |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
28071
diff
changeset
|
27 |
* @bug 4506788 7147408 |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
28071
diff
changeset
|
28 |
* @summary Tests if cursor gets stuck after insertion a character |
54231
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
47216
diff
changeset
|
29 |
* @run main bug4506788 |
14497
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
30 |
*/ |
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
28071
diff
changeset
|
31 |
|
14497
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
32 |
import java.awt.*; |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
33 |
import java.awt.event.*; |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
34 |
import java.lang.reflect.InvocationTargetException; |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
35 |
import javax.swing.*; |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
36 |
import javax.swing.event.*; |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
37 |
import javax.swing.text.*; |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
38 |
|
54231
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
47216
diff
changeset
|
39 |
public class bug4506788 { |
14497
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
40 |
|
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
41 |
private volatile boolean passed = false; |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
42 |
private JEditorPane jep; |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
43 |
|
54231
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
47216
diff
changeset
|
44 |
public static void main(final String[] args) { |
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
47216
diff
changeset
|
45 |
bug4506788 app = new bug4506788(); |
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
47216
diff
changeset
|
46 |
app.init(); |
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
47216
diff
changeset
|
47 |
app.start(); |
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
47216
diff
changeset
|
48 |
} |
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
47216
diff
changeset
|
49 |
|
14497
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
50 |
public void init() { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
51 |
try { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
52 |
SwingUtilities.invokeAndWait(new Runnable() { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
53 |
@Override |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
54 |
public void run() { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
55 |
createAndShowGUI(); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
56 |
} |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
57 |
}); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
58 |
} catch (InterruptedException | InvocationTargetException ex) { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
59 |
ex.printStackTrace(); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
60 |
throw new RuntimeException("FAILED: SwingUtilities.invokeAndWait method failed then creating and showing GUI"); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
61 |
} |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
62 |
} |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
63 |
|
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
64 |
public void start() { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
65 |
Robot robot; |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
66 |
try { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
67 |
robot = new Robot(); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
68 |
} catch (AWTException e) { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
69 |
throw new RuntimeException("Robot could not be created"); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
70 |
} |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
71 |
|
28071
3acb75b8df45
8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
14497
diff
changeset
|
72 |
robot.waitForIdle(); |
14497
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
73 |
|
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
74 |
Point p; |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
75 |
try { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
76 |
p = getJEPLocOnScreen(); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
77 |
} catch (Exception e) { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
78 |
throw new RuntimeException("Could not get JEditorPane location on screen"); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
79 |
} |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
80 |
|
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
81 |
robot.setAutoDelay(50); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
82 |
robot.mouseMove(p.x, p.y); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
83 |
robot.mousePress(InputEvent.BUTTON1_MASK); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
84 |
robot.mouseRelease(InputEvent.BUTTON1_MASK); |
28071
3acb75b8df45
8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
14497
diff
changeset
|
85 |
robot.keyPress(KeyEvent.VK_HOME); |
3acb75b8df45
8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
14497
diff
changeset
|
86 |
robot.keyRelease(KeyEvent.VK_HOME); |
14497
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
87 |
robot.keyPress(KeyEvent.VK_RIGHT); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
88 |
robot.keyRelease(KeyEvent.VK_RIGHT); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
89 |
robot.keyPress(KeyEvent.VK_X); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
90 |
robot.keyRelease(KeyEvent.VK_X); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
91 |
robot.keyPress(KeyEvent.VK_RIGHT); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
92 |
robot.keyRelease(KeyEvent.VK_RIGHT); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
93 |
|
28071
3acb75b8df45
8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
14497
diff
changeset
|
94 |
robot.waitForIdle(); |
14497
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
95 |
|
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
96 |
if (!passed) { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
97 |
throw new RuntimeException("Test failed."); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
98 |
} |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
99 |
} |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
100 |
|
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
101 |
private Point getJEPLocOnScreen() throws Exception { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
102 |
|
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
103 |
final Point[] result = new Point[1]; |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
104 |
|
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
105 |
SwingUtilities.invokeAndWait(new Runnable() { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
106 |
@Override |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
107 |
public void run() { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
108 |
result[0] = jep.getLocationOnScreen(); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
109 |
} |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
110 |
}); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
111 |
|
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
112 |
return result[0]; |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
113 |
} |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
114 |
|
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
115 |
private void createAndShowGUI() { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
116 |
jep = new JEditorPane(); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
117 |
String text = "abc"; |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
118 |
JFrame f = new JFrame(); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
119 |
jep.setEditorKit(new StyledEditorKit()); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
120 |
jep.setText(text); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
121 |
jep.addCaretListener(new CaretListener() { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
122 |
@Override |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
123 |
public void caretUpdate(CaretEvent e) { |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
124 |
passed = (e.getDot() == 3); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
125 |
} |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
126 |
}); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
127 |
|
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
128 |
DefaultStyledDocument doc = (DefaultStyledDocument) jep.getDocument(); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
129 |
MutableAttributeSet atr = new SimpleAttributeSet(); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
130 |
StyleConstants.setBold(atr, true); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
131 |
doc.setCharacterAttributes(1, 1, atr, false); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
132 |
|
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
133 |
f.getContentPane().add(jep); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
134 |
f.setSize(100, 100); |
54231
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
47216
diff
changeset
|
135 |
f.setLocationRelativeTo(null); |
14497
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
136 |
f.setVisible(true); |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
137 |
} |
e2413038bfbc
7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff
changeset
|
138 |
} |