Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sanity/client/SwingSet/src/SliderDemoTest.java
41153 views
1
/*
2
* Copyright (c) 2016, 2020, 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
import org.jtregext.GuiTestListener;
24
import com.sun.swingset3.demos.slider.SliderDemo;
25
import java.awt.Component;
26
import java.awt.event.KeyEvent;
27
import java.util.function.Predicate;
28
29
import javax.swing.UIManager;
30
31
import static org.testng.AssertJUnit.*;
32
33
import org.netbeans.jemmy.drivers.DriverManager;
34
import org.netbeans.jemmy.drivers.scrolling.KeyboardJSliderScrollDriver;
35
import org.testng.annotations.BeforeClass;
36
import org.testng.annotations.Test;
37
import org.netbeans.jemmy.ClassReference;
38
import org.netbeans.jemmy.ComponentChooser;
39
import org.netbeans.jemmy.operators.JFrameOperator;
40
import org.netbeans.jemmy.operators.JSliderOperator;
41
import org.netbeans.jemmy.accessibility.AccessibleNameChooser;
42
import org.netbeans.jemmy.util.LookAndFeel;
43
44
import static com.sun.swingset3.demos.slider.SliderDemo.*;
45
import org.testng.annotations.Listeners;
46
47
/*
48
* @test
49
* @key headful
50
* @summary Verifies SwingSet3 SliderDemo by moving the sliders through
51
* different means, checking the slider value corresponding to it,
52
* checking maximum and minimum values, checking Snap to tick is working
53
* and checking the presence of ticks and labels.
54
*
55
* @library /sanity/client/lib/jemmy/src
56
* @library /sanity/client/lib/Extensions/src
57
* @library /sanity/client/lib/SwingSet3/src
58
* @modules java.desktop
59
* java.logging
60
* @build org.jemmy2ext.JemmyExt
61
* @build com.sun.swingset3.demos.slider.SliderDemo
62
* @run testng/timeout=600 SliderDemoTest
63
*/
64
@Listeners(GuiTestListener.class)
65
public class SliderDemoTest {
66
67
private static final int PLAIN_SLIDER_MINIMUM = -10;
68
private static final int PLAIN_SLIDER_MAXIMUM = 100;
69
private static final int HORIZONTAL_MINOR_TICKS_SLIDER_MINIMUM = 0;
70
private static final int HORIZONTAL_MINOR_TICKS_SLIDER_MAXIMUM = 11;
71
private static final int VERTICAL_MINOR_TICKS_SLIDER_MINIMUM = 0;
72
private static final int VERTICAL_MINOR_TICKS_SLIDER_MAXIMUM = 100;
73
74
@BeforeClass
75
public void useKeyboardSliderDriver() {
76
DriverManager.setScrollDriver(new KeyboardJSliderScrollDriver());
77
}
78
79
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)
80
public void test(String lookAndFeel) throws Exception {
81
UIManager.setLookAndFeel(lookAndFeel);
82
new ClassReference(SliderDemo.class.getCanonicalName()).startApplication();
83
JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
84
plain(frame, HORIZONTAL_PLAIN_SLIDER);
85
majorTicks(frame, HORIZONTAL_MAJOR_TICKS_SLIDER);
86
minorTicks(frame, HORIZONTAL_MINOR_TICKS_SLIDER);
87
disabled(frame, HORIZONTAL_DISABLED_SLIDER);
88
plain(frame, VERTICAL_PLAIN_SLIDER);
89
majorTicks(frame, VERTICAL_MAJOR_TICKS_SLIDER);
90
minorTicks(frame, VERTICAL_MINOR_TICKS_SLIDER);
91
disabled(frame, VERTICAL_DISABLED_SLIDER);
92
}
93
94
private void plain(JFrameOperator jfo, String accessibleName) {
95
JSliderOperator jso = new JSliderOperator(jfo,
96
new AccessibleNameChooser(accessibleName));
97
if (accessibleName.equals(HORIZONTAL_PLAIN_SLIDER)) {
98
jso.waitHasFocus();
99
checkKeyboard(jso);
100
checkMouse(jso);
101
}
102
checkMaximum(jso, PLAIN_SLIDER_MAXIMUM);
103
checkMinimum(jso, PLAIN_SLIDER_MINIMUM);
104
checkMoveForward(jso, 10);
105
}
106
107
private void majorTicks(JFrameOperator jfo, String accessibleName) {
108
JSliderOperator jso = new JSliderOperator(jfo,
109
new AccessibleNameChooser(accessibleName));
110
checkMoveForward(jso, 40);
111
assertTrue(jso.getPaintTicks());
112
assertEquals(100, jso.getMajorTickSpacing());
113
}
114
115
private void minorTicks(JFrameOperator jfo, String accessibleName) {
116
JSliderOperator jso = new JSliderOperator(jfo,
117
new AccessibleNameChooser(accessibleName));
118
if (accessibleName.equals(HORIZONTAL_MINOR_TICKS_SLIDER)) {
119
checkMaximum(jso, HORIZONTAL_MINOR_TICKS_SLIDER_MAXIMUM);
120
checkMinimum(jso, HORIZONTAL_MINOR_TICKS_SLIDER_MINIMUM);
121
checkMoveForward(jso, 2);
122
checkSnapToTick(jso, 5, 6);
123
assertEquals(5, jso.getMajorTickSpacing());
124
assertEquals(1, jso.getMinorTickSpacing());
125
} else {
126
checkMaximum(jso, VERTICAL_MINOR_TICKS_SLIDER_MAXIMUM);
127
checkMinimum(jso, VERTICAL_MINOR_TICKS_SLIDER_MINIMUM);
128
checkMoveForward(jso, 10);
129
assertEquals(20, jso.getMajorTickSpacing());
130
assertEquals(5, jso.getMinorTickSpacing());
131
}
132
assertTrue(jso.getPaintTicks());
133
assertTrue(jso.getPaintLabels());
134
}
135
136
private void disabled(JFrameOperator jfo, String accessibleName)
137
throws InterruptedException {
138
JSliderOperator jso = new JSliderOperator(jfo,
139
new AccessibleNameChooser(accessibleName));
140
int initialvalue;
141
initialvalue = jso.getValue();
142
jso.clickMouse(jso.getCenterXForClick(), jso.getCenterYForClick(), 10);
143
Thread.sleep(500);
144
assertFalse(jso.hasFocus());
145
assertEquals(initialvalue, jso.getValue());
146
}
147
148
private void checkMaximum(JSliderOperator jso, int maxValue) {
149
jso.scrollToMaximum();
150
waitSliderValue(jso, jSlider -> jSlider.getValue() == maxValue,
151
"value == " + maxValue);
152
}
153
154
private void checkMinimum(JSliderOperator jso, int minValue) {
155
jso.scrollToMinimum();
156
waitSliderValue(jso, jSlider -> jSlider.getValue() == minValue,
157
"value == " + minValue);
158
}
159
160
private void checkKeyboard(JSliderOperator jso) {
161
boolean isMotif = LookAndFeel.isMotif();
162
checkKeyPress(jso, KeyEvent.VK_HOME,
163
jSlider -> jSlider.getValue() == jso.getMinimum(),
164
"value == " + jso.getMinimum());
165
166
{
167
int expectedValue = jso.getValue() + 1;
168
checkKeyPress(jso, KeyEvent.VK_UP,
169
jSlider -> jSlider.getValue() >= expectedValue,
170
"value >= " + expectedValue);
171
}
172
{
173
int expectedValue = jso.getValue() + 1;
174
checkKeyPress(jso, KeyEvent.VK_RIGHT,
175
jSlider -> jSlider.getValue() >= expectedValue,
176
"value >= " + expectedValue);
177
}
178
if (!isMotif) {
179
int expectedValue = jso.getValue() + 11;
180
checkKeyPress(jso, KeyEvent.VK_PAGE_UP,
181
jSlider -> jSlider.getValue() >= expectedValue,
182
"value >= " + expectedValue);
183
}
184
185
checkKeyPress(jso, KeyEvent.VK_END,
186
jSlider -> jSlider.getValue() == jso.getMaximum(),
187
"value == " + jso.getMaximum());
188
189
{
190
int expectedValue = jso.getValue() - 1;
191
checkKeyPress(jso, KeyEvent.VK_DOWN,
192
jSlider -> jSlider.getValue() <= expectedValue,
193
"value <= " + expectedValue);
194
}
195
{
196
int expectedValue = jso.getValue() - 1;
197
checkKeyPress(jso, KeyEvent.VK_LEFT,
198
jSlider -> jSlider.getValue() <= expectedValue,
199
"value <= " + expectedValue);
200
}
201
if (!isMotif) {
202
int expectedValue = jso.getValue() - 11;
203
checkKeyPress(jso, KeyEvent.VK_PAGE_DOWN,
204
jSlider -> jSlider.getValue() <= expectedValue,
205
"value <= " + expectedValue);
206
}
207
}
208
209
private void checkKeyPress(JSliderOperator jso, int keyCode,
210
Predicate<JSliderOperator> predicate,
211
String description) {
212
jso.pushKey(keyCode);
213
waitSliderValue(jso, predicate, description);
214
}
215
216
private void waitSliderValue(JSliderOperator jso,
217
Predicate<JSliderOperator> predicate, String description) {
218
jso.waitState(new ComponentChooser() {
219
public boolean checkComponent(Component comp) {
220
return predicate.test(jso);
221
}
222
223
public String getDescription() {
224
return description;
225
}
226
});
227
}
228
229
private void checkMoveForward(JSliderOperator jso, int value) {
230
jso.setValue(jso.getMinimum());
231
int finalValue = jso.getValue() + value;
232
jso.scrollToValue(finalValue);
233
waitSliderValue(jso, jSlider -> jSlider.getValue() == finalValue,
234
"value == " + finalValue);
235
}
236
237
private void checkSnapToTick(JSliderOperator jso, int expectedLower,
238
int expectedHigher) {
239
jso.pressMouse(jso.getCenterXForClick(), jso.getCenterYForClick());
240
waitSliderValue(jso, jSlider -> jSlider.getValue() == expectedLower
241
|| jSlider.getValue() == expectedHigher,
242
"value is either" + expectedLower + " or " + expectedHigher);
243
jso.releaseMouse();
244
}
245
246
private void checkMouse(JSliderOperator jso) {
247
// Check mouse dragging by pressing on the center of Slider and then
248
// dragging the mouse till the end of the track.
249
// We set the initial value of the slider as 45,
250
// which is the value of the slider at the middle.
251
jso.setValue((jso.getMaximum() + jso.getMinimum()) / 2);
252
jso.pressMouse(jso.getCenterXForClick(), jso.getCenterYForClick());
253
jso.dragMouse(jso.getWidth() + 10, jso.getHeight());
254
waitSliderValue(jso, jSlider -> jSlider.getValue() == jSlider.getMaximum(),
255
"value == " + jso.getMaximum());
256
jso.releaseMouse();
257
258
// Check mouse click by clicking on the center of the track 2 times
259
// and waiting till the slider value has changed from its previous
260
// value as a result of the clicks.
261
jso.clickMouse(jso.getCenterXForClick(), jso.getCenterYForClick(), 2);
262
waitSliderValue(jso, jSlider -> jSlider.getValue() != jSlider.getMaximum(),
263
"value != " + jso.getMaximum());
264
}
265
}
266
267