Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sanity/client/SwingSet/src/ListDemoTest.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.list.ListDemo;
25
import static com.sun.swingset3.demos.list.ListDemo.DEMO_TITLE;
26
27
import java.awt.Component;
28
import javax.swing.JList;
29
import javax.swing.UIManager;
30
31
import org.netbeans.jemmy.ClassReference;
32
import org.netbeans.jemmy.ComponentChooser;
33
import org.netbeans.jemmy.operators.JCheckBoxOperator;
34
import org.netbeans.jemmy.operators.JFrameOperator;
35
import org.netbeans.jemmy.operators.JListOperator;
36
37
import static org.jemmy2ext.JemmyExt.*;
38
39
import org.jtregext.GuiTestListener;
40
41
import org.testng.annotations.Listeners;
42
import org.testng.annotations.Test;
43
import static org.testng.AssertJUnit.*;
44
45
/*
46
* @test
47
* @key headful
48
* @summary Verifies SwingSet3 ListDemo page by checking and unchecking all
49
* the checkboxes on the page and verifying the number of items in the
50
* list.
51
*
52
* @library /sanity/client/lib/jemmy/src
53
* @library /sanity/client/lib/Extensions/src
54
* @library /sanity/client/lib/SwingSet3/src
55
* @modules java.desktop
56
* java.logging
57
* @build org.jemmy2ext.JemmyExt
58
* @build com.sun.swingset3.demos.list.ListDemo
59
* @run testng/timeout=600 ListDemoTest
60
*/
61
@Listeners(GuiTestListener.class)
62
public class ListDemoTest {
63
64
private static final int CHECKBOX_COUNT = 50;
65
66
private void waitModelSize(JListOperator listOp, int size) {
67
listOp.waitState(new ComponentChooser() {
68
public boolean checkComponent(Component comp) {
69
return getUIValue(listOp, (JList list) -> list.getModel().getSize()) == size;
70
}
71
72
public String getDescription() {
73
return "Model size to be equal to " + size;
74
}
75
});
76
}
77
78
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)
79
public void test(String lookAndFeel) throws Exception {
80
UIManager.setLookAndFeel(lookAndFeel);
81
82
new ClassReference(ListDemo.class.getCanonicalName()).startApplication();
83
84
JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
85
JListOperator listOp = new JListOperator(frame);
86
87
// Check *NO* Prefix and Suffixes Marked
88
for (int i = 0; i < CHECKBOX_COUNT; i++) {
89
JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
90
checkBox.changeSelection(false);
91
}
92
waitModelSize(listOp, 0);
93
94
// Check *ALL* Prefix and Suffixes Marked
95
for (int i = 0; i < CHECKBOX_COUNT; i++) {
96
JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
97
checkBox.changeSelection(true);
98
}
99
waitModelSize(listOp, CHECKBOX_COUNT * CHECKBOX_COUNT / 4);
100
101
// Check *ALL* Prefix and *NO* Suffixes Marked
102
for (int i = 0; i < CHECKBOX_COUNT; i++) {
103
JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
104
if (i < CHECKBOX_COUNT / 2) {
105
checkBox.changeSelection(true);
106
} else {
107
checkBox.changeSelection(false);
108
}
109
}
110
waitModelSize(listOp, 0);
111
112
// Check *NO* Prefix and *ALL* Suffixes Marked
113
for (int i = 0; i < CHECKBOX_COUNT; i++) {
114
JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);
115
if (i < CHECKBOX_COUNT / 2) {
116
checkBox.changeSelection(false);
117
} else {
118
checkBox.changeSelection(true);
119
}
120
}
121
waitModelSize(listOp, 0);
122
}
123
124
private JCheckBoxOperator getJCheckBoxOperator(JFrameOperator frame, int index) {
125
126
// We map first half of indexes to the Prefixes panel and the second half
127
// to the Suffixes panel
128
String labelText;
129
int subindex;
130
if (index < CHECKBOX_COUNT / 2) {
131
labelText = "Prefixes";
132
subindex = index;
133
} else {
134
labelText = "Suffixes";
135
subindex = index - CHECKBOX_COUNT / 2;
136
}
137
138
JCheckBoxOperator result = new JCheckBoxOperator(getLabeledContainerOperator(frame, labelText), subindex);
139
result.setVerification(true);
140
return result;
141
}
142
143
}
144
145