author | mgronlun |
Sun, 22 Sep 2019 17:31:57 +0200 | |
branch | JEP-349-branch |
changeset 58259 | b6efcf2217f1 |
parent 52128 | 1e0cdaf980f3 |
permissions | -rw-r--r-- |
36744 | 1 |
/* |
49087
68b37374319c
8196338: [TEST_BUG] sanity/client/SwingSet/src/TextFieldDemoTest.java Failed with timeout
akolarkunnu
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. |
36744 | 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.*; |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
27 |
|
36744 | 28 |
import java.awt.Color; |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
29 |
import java.awt.Component; |
36744 | 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; |
|
51749
a0f0da2c2719
8210056: Enable different look and feel tests in SwingSet3 demo test TextFieldDemoTest
akolarkunnu
parents:
49087
diff
changeset
|
35 |
import javax.swing.UIManager; |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
36 |
|
36744 | 37 |
import static org.jemmy2ext.JemmyExt.*; |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
38 |
|
36744 | 39 |
import org.netbeans.jemmy.ClassReference; |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
40 |
import org.netbeans.jemmy.ComponentChooser; |
36744 | 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; |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
48 |
|
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
49 |
import org.jtregext.GuiTestListener; |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
50 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
51 |
import org.testng.annotations.Listeners; |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
52 |
import org.testng.annotations.Test; |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
53 |
import static org.testng.AssertJUnit.*; |
36744 | 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 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
62 |
* @library /sanity/client/lib/Extensions/src |
36744 | 63 |
* @library /sanity/client/lib/SwingSet3/src |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
64 |
* @modules java.desktop |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
65 |
* java.logging |
36744 | 66 |
* @build org.jemmy2ext.JemmyExt |
67 |
* @build com.sun.swingset3.demos.textfield.TextFieldDemo |
|
52128
1e0cdaf980f3
8211139: Increase timeout value in all tests under jdk/sanity/client/SwingSet/src
akolarkunnu
parents:
51749
diff
changeset
|
68 |
* @run testng/timeout=600 TextFieldDemoTest |
36744 | 69 |
*/ |
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
70 |
@Listeners(GuiTestListener.class) |
36744 | 71 |
public class TextFieldDemoTest { |
72 |
||
51749
a0f0da2c2719
8210056: Enable different look and feel tests in SwingSet3 demo test TextFieldDemoTest
akolarkunnu
parents:
49087
diff
changeset
|
73 |
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class) |
a0f0da2c2719
8210056: Enable different look and feel tests in SwingSet3 demo test TextFieldDemoTest
akolarkunnu
parents:
49087
diff
changeset
|
74 |
public void test(String lookAndFeel) throws Exception { |
a0f0da2c2719
8210056: Enable different look and feel tests in SwingSet3 demo test TextFieldDemoTest
akolarkunnu
parents:
49087
diff
changeset
|
75 |
UIManager.setLookAndFeel(lookAndFeel); |
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
76 |
new ClassReference(TextFieldDemo.class.getCanonicalName()).startApplication(); |
36744 | 77 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
78 |
JFrameOperator frame = new JFrameOperator(DEMO_TITLE); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
79 |
|
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
80 |
historyTextField(frame); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
81 |
dateTextField(frame); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
82 |
passwordField(frame); |
36744 | 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); |
|
49087
68b37374319c
8196338: [TEST_BUG] sanity/client/SwingSet/src/TextFieldDemoTest.java Failed with timeout
akolarkunnu
parents:
47216
diff
changeset
|
105 |
calendar.setTime((Date) getUIValue(jtfo, jtf -> ((JFormattedTextField)jtf).getValue())); |
36744 | 106 |
|
107 |
// Check default date Day of the Week |
|
108 |
jbo.push(); |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
109 |
dowLabel.waitText(calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.ENGLISH)); |
36744 | 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(); |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
126 |
dowLabel.waitText("Thursday"); |
36744 | 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 |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
137 |
password1.waitState(new ComponentChooser() { |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
138 |
public boolean checkComponent(Component comp) { |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
139 |
return password1.getBackground().equals(Color.green) && |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
140 |
password2.getBackground().equals(Color.green); |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
141 |
} |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
142 |
public String getDescription() { |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
143 |
return "Passwords to match"; |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
144 |
} |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
145 |
}); |
36744 | 146 |
|
147 |
// Check non-matching passwords |
|
51749
a0f0da2c2719
8210056: Enable different look and feel tests in SwingSet3 demo test TextFieldDemoTest
akolarkunnu
parents:
49087
diff
changeset
|
148 |
final Color backgroundColor = UIManager.getColor("TextField.background"); |
36744 | 149 |
password2.typeText("passwereertegrs"); |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
150 |
password1.waitState(new ComponentChooser() { |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
151 |
public boolean checkComponent(Component comp) { |
51749
a0f0da2c2719
8210056: Enable different look and feel tests in SwingSet3 demo test TextFieldDemoTest
akolarkunnu
parents:
49087
diff
changeset
|
152 |
return password1.getBackground().equals(backgroundColor) && |
a0f0da2c2719
8210056: Enable different look and feel tests in SwingSet3 demo test TextFieldDemoTest
akolarkunnu
parents:
49087
diff
changeset
|
153 |
password2.getBackground().equals(backgroundColor); |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
154 |
} |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
155 |
public String getDescription() { |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
156 |
return "Passwords not to match"; |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
157 |
} |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
158 |
}); |
36744 | 159 |
} |
160 |
||
161 |
} |