1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/*
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.sun.swingset3.demos.splitpane.SplitPaneDemo;
import static com.sun.swingset3.demos.splitpane.SplitPaneDemo.*;
import java.awt.Component;
import java.awt.event.KeyEvent;
import javax.swing.JSplitPane;
import static org.jemmy2ext.JemmyExt.*;
import org.jtregext.GuiTestListener;
import org.netbeans.jemmy.ClassReference;
import org.netbeans.jemmy.ComponentChooser;
import org.netbeans.jemmy.operators.JButtonOperator;
import org.netbeans.jemmy.operators.JCheckBoxOperator;
import org.netbeans.jemmy.operators.JFrameOperator;
import org.netbeans.jemmy.operators.JRadioButtonOperator;
import org.netbeans.jemmy.operators.JSplitPaneOperator;
import org.netbeans.jemmy.operators.JTextFieldOperator;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import static org.testng.AssertJUnit.*;
/*
* @test
* @key headful
* @summary Verifies SwingSet3 SplitPaneDemo by performing OneClick expansion,
* changing size of the divier, moving the divider to different positions
* and changing the divider orientation.
*
* @library /sanity/client/lib/jemmy/src
* @library /sanity/client/lib/Extensions/src
* @library /sanity/client/lib/SwingSet3/src
* @modules java.desktop
* java.logging
* @build org.jemmy2ext.JemmyExt
* @build com.sun.swingset3.demos.splitpane.SplitPaneDemo
* @run testng SplitPaneDemoTest
*/
@Listeners(GuiTestListener.class)
public class SplitPaneDemoTest {
@Test
public void test() throws Exception {
new ClassReference(SplitPaneDemo.class.getCanonicalName()).startApplication();
JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
JSplitPaneOperator splitPane = new JSplitPaneOperator(frame);
// Toggle OneTouch Expandable
checkOneTouch(frame, splitPane, true);
checkOneTouch(frame, splitPane, false);
// Check changing divider size to minimum and maximum values
changeDividerSize(frame, splitPane, 50);
changeDividerSize(frame, splitPane, 6);
// Check moving the divider
checkDividerMoves(frame, splitPane, false);
checkDividerMoves(frame, splitPane, true);
// Check different minumum Day/Night sizes
changeMinimumSizes(frame, splitPane, 100);
changeMinimumSizes(frame, splitPane, 0);
}
// Check for different day and night minimum size
public void changeMinimumSizes(JFrameOperator frame, JSplitPaneOperator splitPane, int amount) throws Exception {
for (String label : new String[]{FIRST_COMPONENT_MIN_SIZE, SECOND_COMPONENT_MIN_SIZE}) {
JTextFieldOperator size = new JTextFieldOperator(getLabeledContainerOperator(frame, label));
size.enterText(Integer.toString(amount));
size.pressKey(KeyEvent.VK_ENTER);
}
checkDividerMoves(frame, splitPane, false);
checkDividerMoves(frame, splitPane, true);
}
// Check moving of divider
public void checkDividerMoves(JFrameOperator frame, JSplitPaneOperator splitPane, boolean isVertical) throws Exception {
if (isVertical) {
new JRadioButtonOperator(frame, VERTICAL_SPLIT).doClick();
} else {
new JRadioButtonOperator(frame, HORIZONTAL_SPLIT).doClick();
}
splitPane.moveDivider(0.0);
assertEquals("Move Minimum, dividerLocation is at minimumDividerLocation",
splitPane.getMinimumDividerLocation(), splitPane.getDividerLocation());
// use getMaximumDividerLocation() to move divider to here because using proportion 1.0 does not work
splitPane.moveDivider(1.0);
assertEquals("Move Maximum, dividerLocation is at maximumDividerLocation",
splitPane.getMaximumDividerLocation(), splitPane.getDividerLocation());
splitPane.moveDivider(0.5);
assertEquals("Move Middle, dividerLocation is at the artithmetic average of minimum and maximum DividerLocations",
(splitPane.getMaximumDividerLocation() + splitPane.getMinimumDividerLocation()) / 2, splitPane.getDividerLocation());
}
private void waitDividerSize(JSplitPaneOperator splitPane, int size) {
splitPane.waitState(new ComponentChooser() {
public boolean checkComponent(Component c) {
return splitPane.getDividerSize() == size;
}
public String getDescription() {
return "Divider size to be " + size;
}
});
}
// Check changing the size of the divider
public void changeDividerSize(JFrameOperator frame, JSplitPaneOperator splitPane, int amount) throws Exception {
JTextFieldOperator size = new JTextFieldOperator(getLabeledContainerOperator(frame, DIVIDER_SIZE));
size.enterText(Integer.toString(amount));
waitDividerSize(splitPane, amount);
}
private void waitDividerLocation(JSplitPaneOperator splitPane, int location) {
splitPane.waitState(new ComponentChooser() {
public boolean checkComponent(Component c) {
return splitPane.getDividerLocation() == location;
}
public String getDescription() {
return "Divider location to be " + location;
}
});
}
public void checkOneTouch(JFrameOperator frame, JSplitPaneOperator splitPane, boolean oneTouch) throws Exception {
JCheckBoxOperator checkBox = new JCheckBoxOperator(frame, ONE_TOUCH_EXPANDABLE);
JButtonOperator buttonLeft = new JButtonOperator(splitPane.getDivider(), 0);
JButtonOperator buttonRight = new JButtonOperator(splitPane.getDivider(), 1);
int initDividerLocation = splitPane.getDividerLocation();
if (oneTouch) {
if (!checkBox.isSelected()) {
// uncheck
checkBox.doClick();
}
int left = getUIValue(splitPane, (JSplitPane sp) -> sp.getInsets().left);
System.out.println("left = " + left);
int right = getUIValue(splitPane, (JSplitPane sp) -> sp.getInsets().right);
System.out.println("right = " + right);
// expand full left
buttonLeft.push();
waitDividerLocation(splitPane, left);
// expand back from full left
buttonRight.push();
waitDividerLocation(splitPane, initDividerLocation);
// expand all the way right
buttonRight.push();
waitDividerLocation(splitPane, splitPane.getWidth() - splitPane.getDividerSize() - right);
// Click to move back from right expansion
buttonLeft.push();
waitDividerLocation(splitPane, initDividerLocation);
}
// Test for case where one touch expandable is disabled
if (!oneTouch) {
if (checkBox.isSelected()) {
// uncheck
checkBox.doClick();
}
splitPane.waitState(new ComponentChooser() {
public boolean checkComponent(Component c) {
return !splitPane.isOneTouchExpandable();
}
public String getDescription() {
return "Split pane not to be one touch expandable";
}
});
}
}
}
|