Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sanity/client/SwingSet/src/OptionPaneDemoTest.java
41153 views
1
/*
2
* Copyright (c) 2010, 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
import com.sun.swingset3.demos.optionpane.OptionPaneDemo;
25
import static com.sun.swingset3.demos.optionpane.OptionPaneDemo.*;
26
27
import javax.swing.UIManager;
28
29
import org.jtregext.GuiTestListener;
30
31
import org.netbeans.jemmy.ClassReference;
32
import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
33
import org.netbeans.jemmy.operators.JButtonOperator;
34
import org.netbeans.jemmy.operators.JComboBoxOperator;
35
import org.netbeans.jemmy.operators.JDialogOperator;
36
import org.netbeans.jemmy.operators.JFrameOperator;
37
import org.netbeans.jemmy.operators.JLabelOperator;
38
import org.netbeans.jemmy.operators.JTextFieldOperator;
39
40
import org.testng.annotations.Listeners;
41
import org.testng.annotations.Test;
42
import static org.testng.AssertJUnit.*;
43
44
45
/*
46
* @test
47
* @key headful
48
* @summary Verifies SwingSet3 OptionPaneDemo page by opening all the dialogs
49
* and choosing different options in them.
50
*
51
* @library /sanity/client/lib/jemmy/src
52
* @library /sanity/client/lib/Extensions/src
53
* @library /sanity/client/lib/SwingSet3/src
54
* @modules java.desktop
55
* java.logging
56
* @build org.jemmy2ext.JemmyExt
57
* @build com.sun.swingset3.demos.optionpane.OptionPaneDemo
58
* @run testng/timeout=600 OptionPaneDemoTest
59
*/
60
@Listeners(GuiTestListener.class)
61
public class OptionPaneDemoTest {
62
63
public static final String SOME_TEXT_TO_TYPE = "I am some text";
64
public static final String MESSAGE = UIManager.getString("OptionPane.messageDialogTitle");
65
public static final String OK = "OK";
66
public static final String CANCEL = "Cancel";
67
public static final String INPUT = UIManager.getString("OptionPane.inputDialogTitle");
68
public static final String TEXT_TO_TYPE = "Hooray! I'm a textField";
69
public static final String NO = "No";
70
public static final String YES = "Yes";
71
public static final String SELECT_AN_OPTION = UIManager.getString("OptionPane.titleText");
72
73
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)
74
public void test(String lookAndFeel) throws Exception {
75
UIManager.setLookAndFeel(lookAndFeel);
76
77
new ClassReference(OptionPaneDemo.class.getCanonicalName()).startApplication();
78
79
JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
80
81
showInputDialog(frame);
82
showWarningDialog(frame);
83
showMessageDialog(frame);
84
showComponentDialog(frame);
85
showConfirmationDialog(frame);
86
}
87
88
private void checkMessage(String message) {
89
JDialogOperator jdo = new JDialogOperator(MESSAGE);
90
new JLabelOperator(jdo, message);
91
new JButtonOperator(jdo, OK).push();
92
jdo.waitClosed();
93
}
94
95
private void useInputDialog(JFrameOperator jfo, String textToType, String buttonToPush) {
96
new JButtonOperator(jfo, INPUT_BUTTON).pushNoBlock();
97
JDialogOperator jdo = new JDialogOperator(INPUT);
98
if (textToType != null) {
99
JTextFieldOperator jto = new JTextFieldOperator(jdo);
100
jto.typeText(textToType);
101
jto.waitText(textToType);
102
}
103
new JButtonOperator(jdo, buttonToPush).push();
104
jdo.waitClosed();
105
}
106
107
public void showInputDialog(JFrameOperator jfo) throws Exception {
108
// Cancel with text case
109
useInputDialog(jfo, SOME_TEXT_TO_TYPE, CANCEL);
110
//TODO: wait for no dialog displayed
111
112
// Cancel with *NO* text case
113
useInputDialog(jfo, null, CANCEL);
114
//TODO: wait for no dialog displayed
115
116
// Text field has *NO* input
117
useInputDialog(jfo, null, OK);
118
//TODO: wait for no dialog displayed
119
120
// Text field has input
121
{
122
final String enteredText = "Rambo";
123
124
useInputDialog(jfo, enteredText, OK);
125
checkMessage(enteredText + INPUT_RESPONSE);
126
}
127
}
128
129
public void showWarningDialog(JFrameOperator jfo) throws Exception {
130
new JButtonOperator(jfo, WARNING_BUTTON).pushNoBlock();
131
132
JDialogOperator jdo = new JDialogOperator(WARNING_TITLE);
133
134
new JButtonOperator(jdo, OK).push();
135
136
jdo.waitClosed();
137
}
138
139
public void showMessageDialog(JFrameOperator jfo) throws Exception {
140
new JButtonOperator(jfo, MESSAGE_BUTTON).pushNoBlock();
141
142
JDialogOperator jdo = new JDialogOperator(MESSAGE);
143
144
new JButtonOperator(jdo, OK).push();
145
146
jdo.waitClosed();
147
}
148
149
private void callADialogAndClose(JFrameOperator jfo, String buttonToOpenDialog,
150
String dialogTitle, String buttonToPush) {
151
new JButtonOperator(jfo, buttonToOpenDialog).pushNoBlock();
152
JDialogOperator jdo = new JDialogOperator(dialogTitle);
153
new JButtonOperator(jdo, buttonToPush).push();
154
jdo.waitClosed();
155
}
156
157
public void showComponentDialog(JFrameOperator jfo) throws Exception {
158
// Case: Cancel
159
callADialogAndClose(jfo, COMPONENT_BUTTON, COMPONENT_TITLE, COMPONENT_OP5);
160
//TODO: wait for no dialog displayed
161
162
// Case: Yes option selected
163
{
164
callADialogAndClose(jfo, COMPONENT_BUTTON, COMPONENT_TITLE, COMPONENT_OP1);
165
checkMessage(COMPONENT_R1);
166
}
167
168
// Case: No option selected
169
{
170
callADialogAndClose(jfo, COMPONENT_BUTTON, COMPONENT_TITLE, COMPONENT_OP2);
171
checkMessage(COMPONENT_R2);
172
}
173
174
// Case: Maybe option selected
175
{
176
callADialogAndClose(jfo, COMPONENT_BUTTON, COMPONENT_TITLE, COMPONENT_OP3);
177
checkMessage(COMPONENT_R3);
178
}
179
180
// Case: Probably option selected
181
{
182
callADialogAndClose(jfo, COMPONENT_BUTTON, COMPONENT_TITLE, COMPONENT_OP4);
183
checkMessage(COMPONENT_R4);
184
}
185
186
// Case TextField and ComboBox functional
187
{
188
new JButtonOperator(jfo, COMPONENT_BUTTON).push();
189
190
JDialogOperator jdo = new JDialogOperator(COMPONENT_TITLE);
191
192
JTextFieldOperator jto = new JTextFieldOperator(jdo);
193
jto.clearText();
194
jto.typeText(TEXT_TO_TYPE);
195
jto.waitText(TEXT_TO_TYPE);
196
197
JComboBoxOperator jcbo = new JComboBoxOperator(jdo);
198
jcbo.selectItem(2);
199
jcbo.waitItemSelected(2);
200
201
new JButtonOperator(jdo, COMPONENT_OP5).push();
202
jdo.waitClosed();
203
//TODO: wait for no dialog displayed
204
}
205
}
206
207
public void showConfirmationDialog(JFrameOperator jfo) throws Exception {
208
// Case: Yes option selected
209
{
210
callADialogAndClose(jfo, CONFIRM_BUTTON, SELECT_AN_OPTION, YES);
211
checkMessage(CONFIRM_YES);
212
}
213
214
// Case: No option selected
215
{
216
callADialogAndClose(jfo, CONFIRM_BUTTON, SELECT_AN_OPTION, NO);
217
checkMessage(CONFIRM_NO);
218
}
219
220
// Case: Cancel option selected
221
{
222
callADialogAndClose(jfo, CONFIRM_BUTTON, SELECT_AN_OPTION, CANCEL);
223
//TODO: wait for no dialog displayed
224
}
225
}
226
227
}
228
229