Path: blob/master/test/jdk/sanity/client/SwingSet/src/SplitPaneDemoTest.java
41153 views
/*1* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import com.sun.swingset3.demos.splitpane.SplitPaneDemo;24import static com.sun.swingset3.demos.splitpane.SplitPaneDemo.*;2526import java.awt.Component;27import java.awt.event.KeyEvent;28import javax.swing.JSplitPane;29import javax.swing.UIManager;3031import static org.jemmy2ext.JemmyExt.*;3233import org.jtregext.GuiTestListener;3435import org.netbeans.jemmy.ClassReference;36import org.netbeans.jemmy.ComponentChooser;37import org.netbeans.jemmy.operators.JButtonOperator;38import org.netbeans.jemmy.operators.JCheckBoxOperator;39import org.netbeans.jemmy.operators.JFrameOperator;40import org.netbeans.jemmy.operators.JRadioButtonOperator;41import org.netbeans.jemmy.operators.JSplitPaneOperator;42import org.netbeans.jemmy.operators.JTextFieldOperator;43import org.netbeans.jemmy.util.LookAndFeel;4445import org.testng.annotations.Listeners;46import org.testng.annotations.Test;47import static org.testng.AssertJUnit.*;4849/*50* @test51* @key headful52* @summary Verifies SwingSet3 SplitPaneDemo by performing OneClick expansion,53* changing size of the divier, moving the divider to different positions54* and changing the divider orientation.55*56* @library /sanity/client/lib/jemmy/src57* @library /sanity/client/lib/Extensions/src58* @library /sanity/client/lib/SwingSet3/src59* @modules java.desktop60* java.logging61* @build org.jemmy2ext.JemmyExt62* @build com.sun.swingset3.demos.splitpane.SplitPaneDemo63* @run testng/timeout=600 SplitPaneDemoTest64*/65@Listeners(GuiTestListener.class)66public class SplitPaneDemoTest {6768@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)69public void test(String lookAndFeel) throws Exception {70UIManager.setLookAndFeel(lookAndFeel);7172new ClassReference(SplitPaneDemo.class.getCanonicalName()).startApplication();7374JFrameOperator frame = new JFrameOperator(DEMO_TITLE);7576JSplitPaneOperator splitPane = new JSplitPaneOperator(frame);7778// OneTouch feature is not available in GTK L&F79if(!LookAndFeel.isGTK()) {80// Toggle OneTouch Expandable81checkOneTouch(frame, splitPane, true);82checkOneTouch(frame, splitPane, false);83}8485// Check changing divider size to minimum and maximum values86changeDividerSize(frame, splitPane, 50);87changeDividerSize(frame, splitPane, 6);888990// TODO Skipping this code for Motif L&F as the fix for "CODETOOLS-7902324"91// is deferred now92if(!LookAndFeel.isMotif()) {93// Check moving the divider94checkDividerMoves(frame, splitPane, false);95checkDividerMoves(frame, splitPane, true);9697// Check different minumum Day/Night sizes98changeMinimumSizes(frame, splitPane, 100);99changeMinimumSizes(frame, splitPane, 0);100}101}102103// Check for different day and night minimum size104public void changeMinimumSizes(JFrameOperator frame, JSplitPaneOperator splitPane, int amount) throws Exception {105for (String label : new String[]{FIRST_COMPONENT_MIN_SIZE, SECOND_COMPONENT_MIN_SIZE}) {106JTextFieldOperator size = new JTextFieldOperator(getLabeledContainerOperator(frame, label));107size.enterText(Integer.toString(amount));108size.pressKey(KeyEvent.VK_ENTER);109}110checkDividerMoves(frame, splitPane, false);111checkDividerMoves(frame, splitPane, true);112}113114// Check moving of divider115public void checkDividerMoves(JFrameOperator frame, JSplitPaneOperator splitPane, boolean isVertical) throws Exception {116if (isVertical) {117new JRadioButtonOperator(frame, VERTICAL_SPLIT).doClick();118} else {119new JRadioButtonOperator(frame, HORIZONTAL_SPLIT).doClick();120}121122splitPane.moveDivider(0.0);123assertEquals("Move Minimum, dividerLocation is at minimumDividerLocation",124splitPane.getMinimumDividerLocation(), splitPane.getDividerLocation());125126// use getMaximumDividerLocation() to move divider to here because using proportion 1.0 does not work127splitPane.moveDivider(1.0);128129assertEquals("Move Maximum, dividerLocation is at maximumDividerLocation",130splitPane.getMaximumDividerLocation(), splitPane.getDividerLocation());131132splitPane.moveDivider(0.5);133assertEquals("Move Middle, dividerLocation is at the artithmetic average of minimum and maximum DividerLocations",134(splitPane.getMaximumDividerLocation() + splitPane.getMinimumDividerLocation()) / 2, splitPane.getDividerLocation());135}136137private void waitDividerSize(JSplitPaneOperator splitPane, int size) {138splitPane.waitState(new ComponentChooser() {139public boolean checkComponent(Component c) {140return splitPane.getDividerSize() == size;141}142public String getDescription() {143return "Divider size to be " + size;144}145});146}147148// Check changing the size of the divider149public void changeDividerSize(JFrameOperator frame, JSplitPaneOperator splitPane, int amount) throws Exception {150JTextFieldOperator size = new JTextFieldOperator(getLabeledContainerOperator(frame, DIVIDER_SIZE));151size.enterText(Integer.toString(amount));152waitDividerSize(splitPane, amount);153}154155private void waitDividerLocation(JSplitPaneOperator splitPane, int location) {156splitPane.waitState(new ComponentChooser() {157public boolean checkComponent(Component c) {158return splitPane.getDividerLocation() == location;159}160public String getDescription() {161return "Divider location to be " + location;162}163});164}165166public void checkOneTouch(JFrameOperator frame, JSplitPaneOperator splitPane, boolean oneTouch) throws Exception {167JCheckBoxOperator checkBox = new JCheckBoxOperator(frame, ONE_TOUCH_EXPANDABLE);168JButtonOperator buttonLeft = new JButtonOperator(splitPane.getDivider(), 0);169JButtonOperator buttonRight = new JButtonOperator(splitPane.getDivider(), 1);170int initDividerLocation = splitPane.getDividerLocation();171172if (oneTouch) {173if (!checkBox.isSelected()) {174// uncheck175checkBox.doClick();176}177178int left = getUIValue(splitPane, (JSplitPane sp) -> sp.getInsets().left);179System.out.println("left = " + left);180int right = getUIValue(splitPane, (JSplitPane sp) -> sp.getInsets().right);181System.out.println("right = " + right);182183// expand full left184buttonLeft.push();185waitDividerLocation(splitPane, left);186187// expand back from full left188buttonRight.push();189waitDividerLocation(splitPane, initDividerLocation);190191// expand all the way right192buttonRight.push();193waitDividerLocation(splitPane, splitPane.getWidth() - splitPane.getDividerSize() - right);194195// Click to move back from right expansion196buttonLeft.push();197waitDividerLocation(splitPane, initDividerLocation);198}199200// Test for case where one touch expandable is disabled201if (!oneTouch) {202if (checkBox.isSelected()) {203// uncheck204checkBox.doClick();205}206splitPane.waitState(new ComponentChooser() {207public boolean checkComponent(Component c) {208return !splitPane.isOneTouchExpandable();209}210public String getDescription() {211return "Split pane not to be one touch expandable";212}213});214}215}216217}218219220