author | amurillo |
Mon, 22 Aug 2016 15:27:50 -0700 | |
changeset 40529 | 7bf112d991eb |
parent 39006 | fd8c3312d043 |
permissions | -rw-r--r-- |
36744 | 1 |
/* |
2 |
* Copyright (c) 2010, 2016, 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 |
||
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
24 |
import org.jtregext.GuiTestListener; |
36744 | 25 |
import com.sun.swingset3.DemoProperties; |
26 |
import com.sun.swingset3.demos.togglebutton.DirectionPanel; |
|
27 |
import com.sun.swingset3.demos.togglebutton.LayoutControlPanel; |
|
28 |
import com.sun.swingset3.demos.togglebutton.ToggleButtonDemo; |
|
29 |
import static com.sun.swingset3.demos.togglebutton.ToggleButtonDemo.*; |
|
30 |
import java.util.function.BiFunction; |
|
31 |
import org.jemmy2ext.JemmyExt.ByClassChooser; |
|
32 |
import static org.jemmy2ext.JemmyExt.EXACT_STRING_COMPARATOR; |
|
33 |
import static org.jemmy2ext.JemmyExt.getBorderTitledJPanelOperator; |
|
34 |
import static org.jemmy2ext.JemmyExt.getLabeledContainerOperator; |
|
35 |
import static org.testng.AssertJUnit.*; |
|
36 |
import org.testng.annotations.Test; |
|
37 |
import org.netbeans.jemmy.ClassReference; |
|
38 |
import org.netbeans.jemmy.ComponentChooser; |
|
39 |
import org.netbeans.jemmy.operators.ContainerOperator; |
|
40 |
import org.netbeans.jemmy.operators.JCheckBoxOperator; |
|
41 |
import org.netbeans.jemmy.operators.JFrameOperator; |
|
42 |
import org.netbeans.jemmy.operators.JRadioButtonOperator; |
|
43 |
import org.netbeans.jemmy.operators.JTabbedPaneOperator; |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
44 |
import org.testng.annotations.Listeners; |
36744 | 45 |
|
46 |
/* |
|
47 |
* @test |
|
48 |
* @key headful |
|
49 |
* @summary Verifies SwingSet3 ToggleButtonDemo by toggling each radio button, |
|
50 |
* each checkbox and each location of the direction dial toggle. |
|
51 |
* It verifies initial selected values for all the elements and checks |
|
52 |
* that those change upon clicking. When toggling radio buttons it |
|
53 |
* verifies that other radio buttons in the same group are not longer |
|
54 |
* selected. |
|
55 |
* |
|
56 |
* @library /sanity/client/lib/jemmy/src |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
57 |
* @library /sanity/client/lib/Extensions/src |
36744 | 58 |
* @library /sanity/client/lib/SwingSet3/src |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
59 |
* @modules java.desktop |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
60 |
* java.logging |
36744 | 61 |
* @build org.jemmy2ext.JemmyExt |
62 |
* @build com.sun.swingset3.demos.togglebutton.ToggleButtonDemo |
|
63 |
* @run testng ToggleButtonDemoTest |
|
64 |
*/ |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
65 |
@Listeners(GuiTestListener.class) |
36744 | 66 |
public class ToggleButtonDemoTest { |
67 |
||
68 |
@Test |
|
69 |
public void test() throws Exception { |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
70 |
new ClassReference(ToggleButtonDemo.class.getCanonicalName()).startApplication(); |
36744 | 71 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
72 |
JFrameOperator mainFrame = new JFrameOperator(ToggleButtonDemo.class.getAnnotation(DemoProperties.class).value()); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
73 |
JTabbedPaneOperator tabPane = new JTabbedPaneOperator(mainFrame); |
36744 | 74 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
75 |
// Radio Button Toggles |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
76 |
testRadioButtons(getBorderTitledJPanelOperator(mainFrame, TEXT_RADIO_BUTTONS), 3, null); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
77 |
testRadioButtons(getBorderTitledJPanelOperator(mainFrame, IMAGE_RADIO_BUTTONS), 3, null); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
78 |
testRadioButtons(getLabeledContainerOperator(mainFrame, PAD_AMOUNT), 3, (t, i) -> DEFAULT.equals(t)); |
36744 | 79 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
80 |
// switch to the Check Boxes Tab |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
81 |
tabPane.selectPage(CHECK_BOXES); |
36744 | 82 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
83 |
// Check Box Toggles |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
84 |
ContainerOperator<?> textCheckBoxesJPanel = getBorderTitledJPanelOperator(mainFrame, TEXT_CHECKBOXES); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
85 |
testCheckBox(textCheckBoxesJPanel, CHECK1, false); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
86 |
testCheckBox(textCheckBoxesJPanel, CHECK2, false); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
87 |
testCheckBox(textCheckBoxesJPanel, CHECK3, false); |
36744 | 88 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
89 |
ContainerOperator<?> imageCheckBoxesJPanel = getBorderTitledJPanelOperator(mainFrame, IMAGE_CHECKBOXES); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
90 |
testCheckBox(imageCheckBoxesJPanel, CHECK1, false); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
91 |
testCheckBox(imageCheckBoxesJPanel, CHECK2, false); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
92 |
testCheckBox(imageCheckBoxesJPanel, CHECK3, false); |
36744 | 93 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
94 |
ContainerOperator<?> displayOptionsContainer = getLabeledContainerOperator(mainFrame, DISPLAY_OPTIONS); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
95 |
testCheckBox(displayOptionsContainer, PAINT_BORDER, false); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
96 |
testCheckBox(displayOptionsContainer, PAINT_FOCUS, true); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
97 |
testCheckBox(displayOptionsContainer, ENABLED, true); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
98 |
testCheckBox(displayOptionsContainer, CONTENT_FILLED, true); |
36744 | 99 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
100 |
// Direction Button Toggles |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
101 |
testToggleButtons(mainFrame); |
36744 | 102 |
} |
103 |
||
104 |
/** |
|
105 |
* The interface is invoked for each radio button providing its name and |
|
106 |
* index and it should return whether the radio button has to be selected. |
|
107 |
*/ |
|
108 |
private static interface SelectedRadioButton extends BiFunction<String, Integer, Boolean> { |
|
109 |
} |
|
110 |
||
111 |
/** |
|
112 |
* Tests a group of radio buttons |
|
113 |
* |
|
114 |
* @param parent container containing the buttons |
|
115 |
* @param radioButtonCount number of radio buttons |
|
116 |
* @param selectedRadioButton initial selected radio button |
|
117 |
*/ |
|
118 |
private void testRadioButtons(ContainerOperator<?> parent, int radioButtonCount, SelectedRadioButton selectedRadioButton) { |
|
119 |
JRadioButtonOperator[] jrbo = new JRadioButtonOperator[radioButtonCount]; |
|
120 |
for (int i = 0; i < radioButtonCount; i++) { |
|
121 |
jrbo[i] = new JRadioButtonOperator(parent, i); |
|
122 |
if (selectedRadioButton != null && selectedRadioButton.apply(jrbo[i].getText(), i)) { |
|
123 |
assertTrue("Radio Button " + i + " is initially selected", jrbo[i].isSelected()); |
|
124 |
} else { |
|
125 |
assertFalse("Radio Button " + i + " is initially not selected", jrbo[i].isSelected()); |
|
126 |
} |
|
127 |
} |
|
128 |
||
129 |
for (int i = 0; i < radioButtonCount; i++) { |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
130 |
jrbo[i].push(); |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
131 |
jrbo[i].waitSelected(true); |
36744 | 132 |
|
133 |
for (int j = 0; j < radioButtonCount; j++) { |
|
134 |
if (i != j) { |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
135 |
jrbo[j].waitSelected(false); |
36744 | 136 |
} |
137 |
} |
|
138 |
} |
|
139 |
} |
|
140 |
||
141 |
/** |
|
142 |
* Will change the state of the CheckBox then change back to initial state. |
|
143 |
* |
|
144 |
* @param parent |
|
145 |
* @param text |
|
146 |
* @param expectedValue |
|
147 |
* @throws Exception |
|
148 |
*/ |
|
149 |
private void testCheckBox(ContainerOperator<?> parent, String text, boolean expectedValue) { |
|
150 |
||
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
151 |
System.out.println("Testing " + text); |
36744 | 152 |
parent.setComparator(EXACT_STRING_COMPARATOR); |
153 |
JCheckBoxOperator jcbo = new JCheckBoxOperator(parent, text); |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
154 |
jcbo.waitSelected(expectedValue); |
36744 | 155 |
|
156 |
// click check box (toggle the state) |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
157 |
jcbo.push(); |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
158 |
jcbo.waitSelected(!expectedValue); |
36744 | 159 |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
160 |
jcbo.push(); |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
161 |
jcbo.waitSelected(expectedValue); |
36744 | 162 |
} |
163 |
||
164 |
||
165 |
/* |
|
166 |
* testDirectionRadioButtons(JFrameOperator) will toggle each position of |
|
167 |
* the direction radio button panels |
|
168 |
*/ |
|
169 |
private void testToggleButtons(JFrameOperator jfo) { |
|
170 |
ComponentChooser directionPanelChooser = new ByClassChooser(DirectionPanel.class); |
|
171 |
||
172 |
String text_Position = LayoutControlPanel.TEXT_POSITION; |
|
173 |
ContainerOperator<?> textPositionContainer = getLabeledContainerOperator(jfo, text_Position); |
|
174 |
ContainerOperator<?> directionPanelOperator = new ContainerOperator<>(textPositionContainer, directionPanelChooser); |
|
175 |
testRadioButtons(directionPanelOperator, 9, (t, i) -> i == 5); |
|
176 |
||
177 |
// Unfortunately, both directionPanels are in the same parent container |
|
178 |
// so we have to use indexes here. |
|
179 |
// There is no guarantee that if the UI changes, the code would be still |
|
180 |
// valid in terms of which directionPanel is checked first. However, it |
|
181 |
// does guarantee that two different directionPanels are checked. |
|
182 |
String content_Alignment = LayoutControlPanel.CONTENT_ALIGNMENT; |
|
183 |
ContainerOperator<?> contentAlignmentContainer = getLabeledContainerOperator(jfo, content_Alignment); |
|
184 |
ContainerOperator<?> directionPanelOperator2 = new ContainerOperator<>(contentAlignmentContainer, directionPanelChooser, |
|
185 |
contentAlignmentContainer.getSource() == textPositionContainer.getSource() ? 1 : 0); |
|
186 |
testRadioButtons(directionPanelOperator2, 9, (t, i) -> i == 4); |
|
187 |
||
188 |
} |
|
189 |
||
190 |
} |