|
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 |
|
24 import com.sun.swingset3.demos.splitpane.SplitPaneDemo; |
|
25 import static com.sun.swingset3.demos.splitpane.SplitPaneDemo.*; |
|
26 import java.awt.event.KeyEvent; |
|
27 import javax.swing.JSplitPane; |
|
28 import static org.testng.AssertJUnit.*; |
|
29 import org.testng.annotations.Test; |
|
30 import org.netbeans.jemmy.ClassReference; |
|
31 import org.netbeans.jemmy.operators.JButtonOperator; |
|
32 import org.netbeans.jemmy.operators.JCheckBoxOperator; |
|
33 import org.netbeans.jemmy.operators.JFrameOperator; |
|
34 import org.netbeans.jemmy.operators.JRadioButtonOperator; |
|
35 import org.netbeans.jemmy.operators.JSplitPaneOperator; |
|
36 import org.netbeans.jemmy.operators.JTextFieldOperator; |
|
37 import static org.jemmy2ext.JemmyExt.*; |
|
38 |
|
39 /* |
|
40 * @test |
|
41 * @key headful |
|
42 * @summary Verifies SwingSet3 SplitPaneDemo by performing OneClick expansion, |
|
43 * changing size of the divier, moving the divider to different positions |
|
44 * and changing the divider orientation. |
|
45 * |
|
46 * @library /sanity/client/lib/jemmy/src |
|
47 * @library /sanity/client/lib/Jemmy2Ext/src |
|
48 * @library /sanity/client/lib/SwingSet3/src |
|
49 * @build org.jemmy2ext.JemmyExt |
|
50 * @build com.sun.swingset3.demos.splitpane.SplitPaneDemo |
|
51 * @run testng SplitPaneDemoTest |
|
52 */ |
|
53 public class SplitPaneDemoTest { |
|
54 |
|
55 @Test |
|
56 public void test() throws Exception { |
|
57 captureDebugInfoOnFail(() -> { |
|
58 new ClassReference(SplitPaneDemo.class.getCanonicalName()).startApplication(); |
|
59 |
|
60 JFrameOperator frame = new JFrameOperator(DEMO_TITLE); |
|
61 |
|
62 JSplitPaneOperator splitPane = new JSplitPaneOperator(frame); |
|
63 |
|
64 // Toggle OneTouch Expandable |
|
65 checkOneTouch(frame, splitPane, true); |
|
66 checkOneTouch(frame, splitPane, false); |
|
67 |
|
68 // Check changing divider size to minimum and maximum values |
|
69 changeDividerSize(frame, splitPane, 50); |
|
70 changeDividerSize(frame, splitPane, 6); |
|
71 |
|
72 // Check moving the divider |
|
73 checkDividerMoves(frame, splitPane, false); |
|
74 checkDividerMoves(frame, splitPane, true); |
|
75 |
|
76 // Check different minumum Day/Night sizes |
|
77 changeMinimumSizes(frame, splitPane, 100); |
|
78 changeMinimumSizes(frame, splitPane, 0); |
|
79 }); |
|
80 } |
|
81 |
|
82 // Check for different day and night minimum size |
|
83 public void changeMinimumSizes(JFrameOperator frame, JSplitPaneOperator splitPane, int amount) throws Exception { |
|
84 for (String label : new String[]{FIRST_COMPONENT_MIN_SIZE, SECOND_COMPONENT_MIN_SIZE}) { |
|
85 JTextFieldOperator size = new JTextFieldOperator(getLabeledContainerOperator(frame, label)); |
|
86 size.enterText(Integer.toString(amount)); |
|
87 size.pressKey(KeyEvent.VK_ENTER); |
|
88 } |
|
89 checkDividerMoves(frame, splitPane, false); |
|
90 checkDividerMoves(frame, splitPane, true); |
|
91 } |
|
92 |
|
93 // Check moving of divider |
|
94 public void checkDividerMoves(JFrameOperator frame, JSplitPaneOperator splitPane, boolean isVertical) throws Exception { |
|
95 if (isVertical) { |
|
96 new JRadioButtonOperator(frame, VERTICAL_SPLIT).doClick(); |
|
97 } else { |
|
98 new JRadioButtonOperator(frame, HORIZONTAL_SPLIT).doClick(); |
|
99 } |
|
100 |
|
101 splitPane.moveDivider(0.0); |
|
102 assertEquals("Move Minimum, dividerLocation is at minimumDividerLocation", |
|
103 splitPane.getMinimumDividerLocation(), splitPane.getDividerLocation()); |
|
104 |
|
105 // use getMaximumDividerLocation() to move divider to here because using proportion 1.0 does not work |
|
106 splitPane.moveDivider(1.0); |
|
107 |
|
108 assertEquals("Move Maximum, dividerLocation is at maximumDividerLocation", |
|
109 splitPane.getMaximumDividerLocation(), splitPane.getDividerLocation()); |
|
110 |
|
111 splitPane.moveDivider(0.5); |
|
112 assertEquals("Move Middle, dividerLocation is at the artithmetic average of minimum and maximum DividerLocations", |
|
113 (splitPane.getMaximumDividerLocation() + splitPane.getMinimumDividerLocation()) / 2, splitPane.getDividerLocation()); |
|
114 } |
|
115 |
|
116 // Check changing the size of the divider |
|
117 public void changeDividerSize(JFrameOperator frame, JSplitPaneOperator splitPane, int amount) throws Exception { |
|
118 JTextFieldOperator size = new JTextFieldOperator(getLabeledContainerOperator(frame, DIVIDER_SIZE)); |
|
119 size.clearText(); |
|
120 size.typeText(Integer.toString(amount)); |
|
121 size.pressKey(KeyEvent.VK_ENTER); |
|
122 |
|
123 assertEquals("Change Divider Size", amount, splitPane.getDividerSize()); |
|
124 } |
|
125 |
|
126 public void checkOneTouch(JFrameOperator frame, JSplitPaneOperator splitPane, boolean oneTouch) throws Exception { |
|
127 JCheckBoxOperator checkBox = new JCheckBoxOperator(frame, ONE_TOUCH_EXPANDABLE); |
|
128 JButtonOperator buttonLeft = new JButtonOperator(splitPane.getDivider(), 0); |
|
129 JButtonOperator buttonRight = new JButtonOperator(splitPane.getDivider(), 1); |
|
130 int initDividerLocation = splitPane.getDividerLocation(); |
|
131 |
|
132 if (oneTouch) { |
|
133 if (!checkBox.isSelected()) { |
|
134 // uncheck |
|
135 checkBox.doClick(); |
|
136 } |
|
137 |
|
138 int left = getUIValue(splitPane, (JSplitPane sp) -> sp.getInsets().left); |
|
139 System.out.println("left = " + left); |
|
140 int right = getUIValue(splitPane, (JSplitPane sp) -> sp.getInsets().right); |
|
141 System.out.println("right = " + right); |
|
142 |
|
143 // expand full left |
|
144 buttonLeft.push(); |
|
145 assertEquals("Expandable Left", left, splitPane.getDividerLocation()); |
|
146 |
|
147 // expand back from full left |
|
148 buttonRight.push(); |
|
149 assertEquals("Expandable Back to Original from Left", |
|
150 initDividerLocation, splitPane.getDividerLocation()); |
|
151 |
|
152 // expand all the way right |
|
153 buttonRight.push(); |
|
154 assertEquals("Expandable Right", |
|
155 splitPane.getWidth() - splitPane.getDividerSize() - right, |
|
156 splitPane.getDividerLocation()); |
|
157 |
|
158 // Click to move back from right expansion |
|
159 buttonLeft.push(); |
|
160 assertEquals("Expandable Back to Original from Right", |
|
161 initDividerLocation, splitPane.getDividerLocation()); |
|
162 } |
|
163 |
|
164 // Test for case where one touch expandable is disabled |
|
165 if (!oneTouch) { |
|
166 if (checkBox.isSelected()) { |
|
167 // uncheck |
|
168 checkBox.doClick(); |
|
169 } |
|
170 assertFalse("One Touch Expandable Off", splitPane.isOneTouchExpandable()); |
|
171 } |
|
172 } |
|
173 |
|
174 } |