Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sanity/client/SwingSet/src/ProgressBarDemoTest.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 org.jtregext.GuiTestListener;
25
import com.sun.swingset3.demos.progressbar.ProgressBarDemo;
26
import static com.sun.swingset3.demos.progressbar.ProgressBarDemo.*;
27
import java.awt.Component;
28
import javax.swing.UIManager;
29
import static org.testng.AssertJUnit.*;
30
import org.testng.annotations.Test;
31
import org.netbeans.jemmy.ClassReference;
32
import org.netbeans.jemmy.ComponentChooser;
33
import org.netbeans.jemmy.Timeouts;
34
import org.netbeans.jemmy.operators.JButtonOperator;
35
import org.netbeans.jemmy.operators.JFrameOperator;
36
import org.netbeans.jemmy.operators.JProgressBarOperator;
37
import org.testng.annotations.Listeners;
38
39
/*
40
* @test
41
* @key headful
42
* @summary Verifies SwingSet3 ProgressBarDemo page by pressing start and stop
43
* buttons and checking the progress bar and the buttons state.
44
*
45
* @library /sanity/client/lib/jemmy/src
46
* @library /sanity/client/lib/Extensions/src
47
* @library /sanity/client/lib/SwingSet3/src
48
* @modules java.desktop
49
* java.logging
50
* @build org.jemmy2ext.JemmyExt
51
* @build com.sun.swingset3.demos.progressbar.ProgressBarDemo
52
* @run testng/timeout=1200 ProgressBarDemoTest
53
*/
54
@Listeners(GuiTestListener.class)
55
public class ProgressBarDemoTest {
56
57
private final static long PROGRESS_BAR_TIMEOUT = 180000;
58
59
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)
60
public void test(String lookAndFeel) throws Exception {
61
UIManager.setLookAndFeel(lookAndFeel);
62
new ClassReference(ProgressBarDemo.class.getCanonicalName()).startApplication();
63
64
JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
65
66
JButtonOperator startButton = new JButtonOperator(frame, START_BUTTON);
67
JButtonOperator stopButton = new JButtonOperator(frame, STOP_BUTTON);
68
JProgressBarOperator jpbo = new JProgressBarOperator(frame);
69
70
// Check that progress completes and corect enable/disable of start/stop buttons
71
checkCompleteProgress(frame, startButton, stopButton, jpbo);
72
73
// Check progess bar progression and start/stop button disabled/enabled states
74
checkStartStop(frame, startButton, stopButton, jpbo);
75
}
76
77
// Check that progress completes and corect enable/disable of start/stop buttons
78
public void checkStartStop(JFrameOperator frame, JButtonOperator startButton, JButtonOperator stopButton, JProgressBarOperator progressBar) throws Exception {
79
int initialProgress = progressBar.getValue();
80
System.out.println("initialProgress = " + initialProgress);
81
int maximum = progressBar.getMaximum();
82
83
startButton.pushNoBlock();
84
85
progressBar.waitState(new ComponentChooser() {
86
87
@Override
88
public boolean checkComponent(Component comp) {
89
int value = progressBar.getValue();
90
return value < maximum;
91
}
92
93
@Override
94
public String getDescription() {
95
return "Progress < maximum (" + maximum + ")";
96
}
97
});
98
99
stopButton.waitComponentEnabled();
100
101
progressBar.waitState(new ComponentChooser() {
102
103
@Override
104
public boolean checkComponent(Component comp) {
105
int value = progressBar.getValue();
106
return value > 0;
107
}
108
109
@Override
110
public String getDescription() {
111
return "Progress > 0";
112
}
113
});
114
115
int progress = progressBar.getValue();
116
System.out.println("progress = " + progress);
117
118
//Check that progress par has progressed and Start Button Disabled
119
assertTrue("Progress Bar Progressing (progress > 0, actual value: " + progress + ")", progress > 0);
120
assertFalse("Start Button Disabled", startButton.isEnabled());
121
assertTrue("Stop Button Enabled", stopButton.isEnabled());
122
123
//Wait a liitle bit longer then Press stop get progress
124
progressBar.waitState(new ComponentChooser() {
125
126
@Override
127
public boolean checkComponent(Component comp) {
128
return progressBar.getValue() > progress;
129
}
130
131
@Override
132
public String getDescription() {
133
return "Progress > " + progress;
134
}
135
});
136
137
stopButton.pushNoBlock();
138
139
startButton.waitComponentEnabled();
140
141
int interimProgress = progressBar.getValue();
142
143
// Check that progress par has Stopped and Start Button Disabled
144
assertTrue("Progress Bar Stopped "
145
+ "(interimProgress, actual value: " + interimProgress + " "
146
+ "> progress, actual value: " + progress + ")",
147
interimProgress > progress);
148
assertTrue("Start Button Enabled", startButton.isEnabled());
149
assertFalse("Stop Button Disabled", stopButton.isEnabled());
150
}
151
152
// Check progess bar progression and start/stop button disabled/enabled states
153
public void checkCompleteProgress(JFrameOperator frame, JButtonOperator startButton, JButtonOperator stopButton, JProgressBarOperator progressBar) throws Exception {
154
Timeouts timeouts = progressBar.getTimeouts();
155
long defaultTimeout = timeouts.getTimeout("ComponentOperator.WaitStateTimeout");
156
startButton.pushNoBlock();
157
158
// Set progress bar timeout as 3 minutes as it take long time to reach maximum
159
timeouts.setTimeout("ComponentOperator.WaitStateTimeout", PROGRESS_BAR_TIMEOUT);
160
progressBar.waitValue(progressBar.getMaximum());
161
// Reset timeout to default timeout value
162
timeouts.setTimeout("ComponentOperator.WaitStateTimeout", defaultTimeout);
163
164
startButton.waitComponentEnabled();
165
166
assertEquals("Complete Progress", progressBar.getMaximum(), progressBar.getValue());
167
assertTrue("Start Button Enabled", startButton.isEnabled());
168
assertFalse("Stop Button Disabled", stopButton.isEnabled());
169
}
170
171
}
172
173