Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sanity/client/SwingSet/src/TextFieldDemoTest.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.textfield.JHistoryTextField;
25
import com.sun.swingset3.demos.textfield.TextFieldDemo;
26
import static com.sun.swingset3.demos.textfield.TextFieldDemo.*;
27
28
import java.awt.Color;
29
import java.awt.Component;
30
import java.awt.event.KeyEvent;
31
import java.util.Calendar;
32
import java.util.Date;
33
import java.util.Locale;
34
import javax.swing.JFormattedTextField;
35
import javax.swing.UIManager;
36
37
import static org.jemmy2ext.JemmyExt.*;
38
39
import org.netbeans.jemmy.ClassReference;
40
import org.netbeans.jemmy.ComponentChooser;
41
import org.netbeans.jemmy.QueueTool;
42
import org.netbeans.jemmy.operators.ContainerOperator;
43
import org.netbeans.jemmy.operators.JButtonOperator;
44
import org.netbeans.jemmy.operators.JFrameOperator;
45
import org.netbeans.jemmy.operators.JLabelOperator;
46
import org.netbeans.jemmy.operators.JPasswordFieldOperator;
47
import org.netbeans.jemmy.operators.JTextFieldOperator;
48
49
import org.jtregext.GuiTestListener;
50
51
import org.testng.annotations.Listeners;
52
import org.testng.annotations.Test;
53
import static org.testng.AssertJUnit.*;
54
55
/*
56
* @test
57
* @key headful
58
* @summary Verifies SwingSet3 TextFieldDemo by entering text in each field and
59
* checking that app reacts accordingly.
60
*
61
* @library /sanity/client/lib/jemmy/src
62
* @library /sanity/client/lib/Extensions/src
63
* @library /sanity/client/lib/SwingSet3/src
64
* @modules java.desktop
65
* java.logging
66
* @build org.jemmy2ext.JemmyExt
67
* @build com.sun.swingset3.demos.textfield.TextFieldDemo
68
* @run testng/timeout=600 TextFieldDemoTest
69
*/
70
@Listeners(GuiTestListener.class)
71
public class TextFieldDemoTest {
72
73
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)
74
public void test(String lookAndFeel) throws Exception {
75
UIManager.setLookAndFeel(lookAndFeel);
76
new ClassReference(TextFieldDemo.class.getCanonicalName()).startApplication();
77
78
JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
79
80
historyTextField(frame);
81
dateTextField(frame);
82
passwordField(frame);
83
}
84
85
private void historyTextField(JFrameOperator jfo) throws Exception {
86
JTextFieldOperator jtfo = new JTextFieldOperator(jfo, new ByClassChooser(JHistoryTextField.class));
87
jtfo.typeText("cat");
88
89
jtfo.pressKey(KeyEvent.VK_DOWN);
90
jtfo.pressKey(KeyEvent.VK_DOWN);
91
jtfo.pressKey(KeyEvent.VK_ENTER);
92
93
final String expectedValue = "category";
94
jtfo.waitText(expectedValue);
95
assertEquals("Select History Item", expectedValue, jtfo.getText());
96
}
97
98
public void dateTextField(JFrameOperator jfo) throws Exception {
99
JTextFieldOperator jtfo = new JTextFieldOperator(jfo,
100
new ByClassChooser(JFormattedTextField.class));
101
ContainerOperator<?> containerOperator = new ContainerOperator<>(jtfo.getParent());
102
JButtonOperator jbo = new JButtonOperator(containerOperator, GO);
103
JLabelOperator dowLabel = new JLabelOperator(containerOperator);
104
Calendar calendar = Calendar.getInstance(Locale.ENGLISH);
105
calendar.setTime((Date) getUIValue(jtfo, jtf -> ((JFormattedTextField)jtf).getValue()));
106
107
// Check default date Day of the Week
108
jbo.push();
109
dowLabel.waitText(calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.ENGLISH));
110
111
// Check Custom Day of the Week
112
calendar.set(2012, 9, 11); // Represents "Oct 11, 2012"
113
Date date = calendar.getTime();
114
String dateString = jtfo.getQueueTool().invokeAndWait(
115
new QueueTool.QueueAction<String>("Formatting the value using JFormattedTextField formatter") {
116
117
@Override
118
public String launch() throws Exception {
119
return ((JFormattedTextField) jtfo.getSource()).getFormatter().valueToString(date);
120
}
121
});
122
System.out.println("dateString = " + dateString);
123
jtfo.enterText(dateString);
124
125
jbo.push();
126
dowLabel.waitText("Thursday");
127
}
128
129
public void passwordField(JFrameOperator jfo) throws Exception {
130
JPasswordFieldOperator password1 = new JPasswordFieldOperator(jfo, 0);
131
JPasswordFieldOperator password2 = new JPasswordFieldOperator(jfo, 1);
132
133
password1.typeText("password");
134
password2.typeText("password");
135
136
// Check Matching Passwords
137
password1.waitState(new ComponentChooser() {
138
public boolean checkComponent(Component comp) {
139
return password1.getBackground().equals(Color.green) &&
140
password2.getBackground().equals(Color.green);
141
}
142
public String getDescription() {
143
return "Passwords to match";
144
}
145
});
146
147
// Check non-matching passwords
148
final Color backgroundColor = UIManager.getColor("TextField.background");
149
password2.typeText("passwereertegrs");
150
password1.waitState(new ComponentChooser() {
151
public boolean checkComponent(Component comp) {
152
return password1.getBackground().equals(backgroundColor) &&
153
password2.getBackground().equals(backgroundColor);
154
}
155
public String getDescription() {
156
return "Passwords not to match";
157
}
158
});
159
}
160
161
}
162
163