author | goetz |
Tue, 14 Jun 2016 10:44:59 +0200 | |
changeset 39056 | d99e63b6d962 |
parent 28087 | 622b2f420bc3 |
permissions | -rw-r--r-- |
25094
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
1 |
/* |
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
28087
diff
changeset
|
2 |
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
25094
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
4 |
* |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
8 |
* |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
13 |
* accompanied this code). |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
14 |
* |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
18 |
* |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
21 |
* questions. |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
22 |
*/ |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
23 |
|
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
24 |
import java.awt.FlowLayout; |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
25 |
import java.awt.Frame; |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
26 |
import java.awt.Panel; |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
27 |
import java.awt.Point; |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
28 |
import java.awt.Robot; |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
29 |
import java.awt.TextField; |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
30 |
import java.awt.event.InputEvent; |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
31 |
|
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
32 |
/** |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
33 |
* @test |
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
28087
diff
changeset
|
34 |
* @key headful |
25094
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
35 |
* @bug 8036110 |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
36 |
* @author Alexander Scherbatiy |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
37 |
* @summary In TextField can only select text visible or to the left |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
38 |
* @run main SelectionInvisibleTest |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
39 |
*/ |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
40 |
|
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
41 |
public class SelectionInvisibleTest { |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
42 |
|
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
43 |
private static final String TEXT = "One Two Three Four Five Six Seven Eight Nine "; |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
44 |
private static final String LAST_WORD = "Ten"; |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
45 |
|
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
46 |
public static void main(String[] args) throws Exception { |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
47 |
|
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
48 |
Frame frame = new Frame(); |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
49 |
frame.setSize(300, 200); |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
50 |
TextField textField = new TextField(TEXT + LAST_WORD, 30); |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
51 |
Panel panel = new Panel(new FlowLayout()); |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
52 |
panel.add(textField); |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
53 |
frame.add(panel); |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
54 |
frame.setVisible(true); |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
55 |
|
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
56 |
Robot robot = new Robot(); |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
57 |
robot.setAutoDelay(50); |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
58 |
|
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
25094
diff
changeset
|
59 |
robot.waitForIdle(); |
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
25094
diff
changeset
|
60 |
|
25094
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
61 |
Point point = textField.getLocationOnScreen(); |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
62 |
int x = point.x + textField.getWidth() / 2; |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
63 |
int y = point.y + textField.getHeight() / 2; |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
64 |
robot.mouseMove(x, y); |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
65 |
robot.mousePress(InputEvent.BUTTON1_MASK); |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
66 |
robot.mouseRelease(InputEvent.BUTTON1_MASK); |
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
25094
diff
changeset
|
67 |
robot.waitForIdle(); |
25094
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
68 |
|
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
69 |
robot.mousePress(InputEvent.BUTTON1_MASK); |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
70 |
int N = 10; |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
71 |
int dx = textField.getWidth() / N; |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
72 |
for (int i = 0; i < N; i++) { |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
73 |
x += dx; |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
74 |
robot.mouseMove(x, y); |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
75 |
} |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
76 |
robot.mouseRelease(InputEvent.BUTTON1_MASK); |
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
25094
diff
changeset
|
77 |
robot.waitForIdle(); |
25094
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
78 |
|
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
79 |
if (!textField.getSelectedText().endsWith(LAST_WORD)) { |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
80 |
throw new RuntimeException("Last word is not selected!"); |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
81 |
} |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
82 |
} |
e903297446da
8036110: In TextField can only select text visible or to the left of the cursor
alexsch
parents:
diff
changeset
|
83 |
} |