Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Choice/PopupPosTest/PopupPosTest.java
41152 views
1
/*
2
* Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
@test
26
@key headful
27
@bug 5044150
28
@summary Tests that pupup doesn't popdown if no space to display under
29
@requires (os.family == "linux")
30
@run main PopupPosTest
31
*/
32
33
import java.awt.*;
34
import java.awt.event.*;
35
36
public class PopupPosTest {
37
38
public static void main(final String[] args) {
39
Frame frame = new TestFrame();
40
}
41
}
42
43
class TestFrame extends Frame implements ItemListener {
44
Robot robot;
45
Toolkit tk = Toolkit.getDefaultToolkit();
46
Choice choice = new Choice();
47
boolean indexChanged = false;
48
final static int INITIAL_ITEM = 99;
49
volatile boolean stateChanged;
50
51
public TestFrame() {
52
for (int i = 0; i < 100; i++) {
53
choice.addItem("Item Item Item " + i);
54
}
55
choice.addItemListener(this);
56
57
choice.select(INITIAL_ITEM);
58
choice.setFont(new Font("Courier", Font.BOLD + Font.ITALIC, 100));
59
60
add(choice, BorderLayout.CENTER);
61
Dimension screen = tk.getScreenSize();
62
setSize(screen.width - 10, screen.height - 70);
63
setVisible(true);
64
toFront();
65
try {
66
robot = new Robot();
67
robot.setAutoDelay(50);
68
robot.waitForIdle();
69
// fix for 6175418. When we take "choice.getHeight()/2"
70
// divider 2 is not sufficiently big to hit into the
71
// small box Choice. We should use bigger divider to get
72
// smaller value choice.getHeight()/i. 4 is sufficient.
73
Point pt = choice.getLocationOnScreen();
74
// click on 1/4 of Choice's height
75
mouseMoveAndPressOnChoice(pt.x + choice.getWidth()/2,
76
pt.y + choice.getHeight()/4);
77
78
// click on center of Choice's height
79
mouseMoveAndPressOnChoice(pt.x + choice.getWidth()/2,
80
pt.y + choice.getHeight()/2);
81
82
// click on 3/4 of Choice's height
83
mouseMoveAndPressOnChoice(pt.x + choice.getWidth()/2,
84
pt.y + choice.getHeight()*3/4);
85
// testing that ItemEvent doesn't generated on a simple
86
// mouse click when the dropdown appears under mouse : 6425067
87
stateChanged = false;
88
openChoice();
89
closeChoice();
90
} catch (Throwable e) {
91
throw new RuntimeException("The test was not completed.\n\n" + e);
92
}
93
94
if (!indexChanged){
95
throw new RuntimeException("Test failed. Another item wasn't selected.");
96
}
97
98
if(stateChanged){
99
throw new RuntimeException("Test failed. ItemEvent was generated on a simple mouse click when the dropdown appears under mouse");
100
}
101
}// start()
102
103
public void itemStateChanged(ItemEvent ie) {
104
System.out.println("choice.stateChanged = "+ ie);
105
stateChanged = true;
106
}
107
108
public void mouseMoveAndPressOnChoice(int x, int y){
109
openChoice();
110
robot.mouseMove(x, y);
111
robot.mousePress(InputEvent.BUTTON1_MASK);
112
robot.delay(30);
113
robot.mouseRelease(InputEvent.BUTTON1_MASK);
114
robot.waitForIdle();
115
//should close choice after each test stage
116
closeChoice();
117
checkSelectedIndex();
118
}
119
120
public void openChoice(){
121
Point pt = choice.getLocationOnScreen();
122
robot.mouseMove(pt.x + choice.getWidth() - choice.getHeight()/4,
123
pt.y + choice.getHeight()/2);
124
robot.mousePress(InputEvent.BUTTON1_MASK);
125
robot.delay(30);
126
robot.mouseRelease(InputEvent.BUTTON1_MASK);
127
robot.waitForIdle();
128
}
129
public void closeChoice(){
130
robot.keyPress(KeyEvent.VK_ESCAPE);
131
robot.keyRelease(KeyEvent.VK_ESCAPE);
132
robot.waitForIdle();
133
}
134
135
public void checkSelectedIndex(){
136
if (choice.getSelectedIndex() != INITIAL_ITEM) {
137
System.out.println("choice.getSelectedIndex = "+ choice.getSelectedIndex());
138
indexChanged = true;
139
}
140
}
141
}// class TestFrame
142
143