< prev index next >

test/sanity/client/SwingSet/src/SplitPaneDemoTest.java

Print this page




   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 org.jtregext.GuiTestListener;
  25 import com.sun.swingset3.demos.splitpane.SplitPaneDemo;
  26 import static com.sun.swingset3.demos.splitpane.SplitPaneDemo.*;


  27 import java.awt.event.KeyEvent;
  28 import javax.swing.JSplitPane;
  29 import static org.testng.AssertJUnit.*;
  30 import org.testng.annotations.Test;



  31 import org.netbeans.jemmy.ClassReference;

  32 import org.netbeans.jemmy.operators.JButtonOperator;
  33 import org.netbeans.jemmy.operators.JCheckBoxOperator;
  34 import org.netbeans.jemmy.operators.JFrameOperator;
  35 import org.netbeans.jemmy.operators.JRadioButtonOperator;
  36 import org.netbeans.jemmy.operators.JSplitPaneOperator;
  37 import org.netbeans.jemmy.operators.JTextFieldOperator;
  38 import static org.jemmy2ext.JemmyExt.*;
  39 import org.testng.annotations.Listeners;


  40 
  41 /*
  42  * @test
  43  * @key headful
  44  * @summary Verifies SwingSet3 SplitPaneDemo by performing OneClick expansion,
  45  *          changing size of the divier, moving the divider to different positions
  46  *          and changing the divider orientation.
  47  *
  48  * @library /sanity/client/lib/jemmy/src
  49  * @library /sanity/client/lib/Extensions/src
  50  * @library /sanity/client/lib/SwingSet3/src


  51  * @build org.jemmy2ext.JemmyExt
  52  * @build com.sun.swingset3.demos.splitpane.SplitPaneDemo
  53  * @run testng SplitPaneDemoTest
  54  */
  55 @Listeners(GuiTestListener.class)
  56 public class SplitPaneDemoTest {
  57 
  58     @Test
  59     public void test() throws Exception {
  60 
  61         new ClassReference(SplitPaneDemo.class.getCanonicalName()).startApplication();
  62 
  63         JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
  64 
  65         JSplitPaneOperator splitPane = new JSplitPaneOperator(frame);
  66 
  67         // Toggle OneTouch Expandable
  68         checkOneTouch(frame, splitPane, true);
  69         checkOneTouch(frame, splitPane, false);
  70 


  98             new JRadioButtonOperator(frame, VERTICAL_SPLIT).doClick();
  99         } else {
 100             new JRadioButtonOperator(frame, HORIZONTAL_SPLIT).doClick();
 101         }
 102 
 103         splitPane.moveDivider(0.0);
 104         assertEquals("Move Minimum, dividerLocation is at minimumDividerLocation",
 105                 splitPane.getMinimumDividerLocation(), splitPane.getDividerLocation());
 106 
 107         // use getMaximumDividerLocation() to move divider to here because using proportion 1.0 does not work
 108         splitPane.moveDivider(1.0);
 109 
 110         assertEquals("Move Maximum, dividerLocation is at maximumDividerLocation",
 111                 splitPane.getMaximumDividerLocation(), splitPane.getDividerLocation());
 112 
 113         splitPane.moveDivider(0.5);
 114         assertEquals("Move Middle, dividerLocation is at the artithmetic average of minimum and maximum DividerLocations",
 115                 (splitPane.getMaximumDividerLocation() + splitPane.getMinimumDividerLocation()) / 2, splitPane.getDividerLocation());
 116     }
 117 











 118     // Check changing the size of the divider
 119     public void changeDividerSize(JFrameOperator frame, JSplitPaneOperator splitPane, int amount) throws Exception {
 120         JTextFieldOperator size = new JTextFieldOperator(getLabeledContainerOperator(frame, DIVIDER_SIZE));
 121         size.clearText();
 122         size.typeText(Integer.toString(amount));
 123         size.pressKey(KeyEvent.VK_ENTER);
 124 
 125         assertEquals("Change Divider Size", amount, splitPane.getDividerSize());








 126     }
 127 
 128     public void checkOneTouch(JFrameOperator frame, JSplitPaneOperator splitPane, boolean oneTouch) throws Exception {
 129         JCheckBoxOperator checkBox = new JCheckBoxOperator(frame, ONE_TOUCH_EXPANDABLE);
 130         JButtonOperator buttonLeft = new JButtonOperator(splitPane.getDivider(), 0);
 131         JButtonOperator buttonRight = new JButtonOperator(splitPane.getDivider(), 1);
 132         int initDividerLocation = splitPane.getDividerLocation();
 133 
 134         if (oneTouch) {
 135             if (!checkBox.isSelected()) {
 136                 // uncheck
 137                 checkBox.doClick();
 138             }
 139 
 140             int left = getUIValue(splitPane, (JSplitPane sp) -> sp.getInsets().left);
 141             System.out.println("left = " + left);
 142             int right = getUIValue(splitPane, (JSplitPane sp) -> sp.getInsets().right);
 143             System.out.println("right = " + right);
 144 
 145             // expand full left
 146             buttonLeft.push();
 147             assertEquals("Expandable Left", left, splitPane.getDividerLocation());
 148 
 149             // expand back from full left
 150             buttonRight.push();
 151             assertEquals("Expandable Back to Original from Left",
 152                     initDividerLocation, splitPane.getDividerLocation());
 153 
 154             // expand all the way right
 155             buttonRight.push();
 156             assertEquals("Expandable Right",
 157                     splitPane.getWidth() - splitPane.getDividerSize() - right,
 158                     splitPane.getDividerLocation());
 159 
 160             // Click to move back from right expansion
 161             buttonLeft.push();
 162             assertEquals("Expandable Back to Original from Right",
 163                     initDividerLocation, splitPane.getDividerLocation());
 164         }
 165 
 166         // Test for case where one touch expandable is disabled
 167         if (!oneTouch) {
 168             if (checkBox.isSelected()) {
 169                 // uncheck
 170                 checkBox.doClick();
 171             }
 172             assertFalse("One Touch Expandable Off", splitPane.isOneTouchExpandable());







 173         }
 174     }
 175 
 176 }


   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 
  27 import java.awt.Component;
  28 import java.awt.event.KeyEvent;
  29 import javax.swing.JSplitPane;
  30 
  31 import static org.jemmy2ext.JemmyExt.*;
  32 
  33 import org.jtregext.GuiTestListener;
  34 
  35 import org.netbeans.jemmy.ClassReference;
  36 import org.netbeans.jemmy.ComponentChooser;
  37 import org.netbeans.jemmy.operators.JButtonOperator;
  38 import org.netbeans.jemmy.operators.JCheckBoxOperator;
  39 import org.netbeans.jemmy.operators.JFrameOperator;
  40 import org.netbeans.jemmy.operators.JRadioButtonOperator;
  41 import org.netbeans.jemmy.operators.JSplitPaneOperator;
  42 import org.netbeans.jemmy.operators.JTextFieldOperator;
  43 
  44 import org.testng.annotations.Listeners;
  45 import org.testng.annotations.Test;
  46 import static org.testng.AssertJUnit.*;
  47 
  48 /*
  49  * @test
  50  * @key headful
  51  * @summary Verifies SwingSet3 SplitPaneDemo by performing OneClick expansion,
  52  *          changing size of the divier, moving the divider to different positions
  53  *          and changing the divider orientation.
  54  *
  55  * @library /sanity/client/lib/jemmy/src
  56  * @library /sanity/client/lib/Extensions/src
  57  * @library /sanity/client/lib/SwingSet3/src
  58  * @modules java.desktop
  59  *          java.logging
  60  * @build org.jemmy2ext.JemmyExt
  61  * @build com.sun.swingset3.demos.splitpane.SplitPaneDemo
  62  * @run testng SplitPaneDemoTest
  63  */
  64 @Listeners(GuiTestListener.class)
  65 public class SplitPaneDemoTest {
  66 
  67     @Test
  68     public void test() throws Exception {
  69 
  70         new ClassReference(SplitPaneDemo.class.getCanonicalName()).startApplication();
  71 
  72         JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
  73 
  74         JSplitPaneOperator splitPane = new JSplitPaneOperator(frame);
  75 
  76         // Toggle OneTouch Expandable
  77         checkOneTouch(frame, splitPane, true);
  78         checkOneTouch(frame, splitPane, false);
  79 


 107             new JRadioButtonOperator(frame, VERTICAL_SPLIT).doClick();
 108         } else {
 109             new JRadioButtonOperator(frame, HORIZONTAL_SPLIT).doClick();
 110         }
 111 
 112         splitPane.moveDivider(0.0);
 113         assertEquals("Move Minimum, dividerLocation is at minimumDividerLocation",
 114                 splitPane.getMinimumDividerLocation(), splitPane.getDividerLocation());
 115 
 116         // use getMaximumDividerLocation() to move divider to here because using proportion 1.0 does not work
 117         splitPane.moveDivider(1.0);
 118 
 119         assertEquals("Move Maximum, dividerLocation is at maximumDividerLocation",
 120                 splitPane.getMaximumDividerLocation(), splitPane.getDividerLocation());
 121 
 122         splitPane.moveDivider(0.5);
 123         assertEquals("Move Middle, dividerLocation is at the artithmetic average of minimum and maximum DividerLocations",
 124                 (splitPane.getMaximumDividerLocation() + splitPane.getMinimumDividerLocation()) / 2, splitPane.getDividerLocation());
 125     }
 126 
 127     private void waitDividerSize(JSplitPaneOperator splitPane, int size) {
 128         splitPane.waitState(new ComponentChooser() {
 129             public boolean checkComponent(Component c) {
 130                 return splitPane.getDividerSize() == size;
 131             }
 132             public String getDescription() {
 133                 return "Divider size to be " + size;
 134             }
 135         });
 136     }
 137 
 138     // Check changing the size of the divider
 139     public void changeDividerSize(JFrameOperator frame, JSplitPaneOperator splitPane, int amount) throws Exception {
 140         JTextFieldOperator size = new JTextFieldOperator(getLabeledContainerOperator(frame, DIVIDER_SIZE));
 141         size.enterText(Integer.toString(amount));
 142         waitDividerSize(splitPane, amount);
 143     }
 144 
 145     private void waitDividerLocation(JSplitPaneOperator splitPane, int location) {
 146         splitPane.waitState(new ComponentChooser() {
 147             public boolean checkComponent(Component c) {
 148                 return splitPane.getDividerLocation() == location;
 149             }
 150             public String getDescription() {
 151                 return "Divider location to be " + location;
 152             }
 153         });
 154     }
 155 
 156     public void checkOneTouch(JFrameOperator frame, JSplitPaneOperator splitPane, boolean oneTouch) throws Exception {
 157         JCheckBoxOperator checkBox = new JCheckBoxOperator(frame, ONE_TOUCH_EXPANDABLE);
 158         JButtonOperator buttonLeft = new JButtonOperator(splitPane.getDivider(), 0);
 159         JButtonOperator buttonRight = new JButtonOperator(splitPane.getDivider(), 1);
 160         int initDividerLocation = splitPane.getDividerLocation();
 161 
 162         if (oneTouch) {
 163             if (!checkBox.isSelected()) {
 164                 // uncheck
 165                 checkBox.doClick();
 166             }
 167 
 168             int left = getUIValue(splitPane, (JSplitPane sp) -> sp.getInsets().left);
 169             System.out.println("left = " + left);
 170             int right = getUIValue(splitPane, (JSplitPane sp) -> sp.getInsets().right);
 171             System.out.println("right = " + right);
 172 
 173             // expand full left
 174             buttonLeft.push();
 175             waitDividerLocation(splitPane, left);
 176 
 177             // expand back from full left
 178             buttonRight.push();
 179             waitDividerLocation(splitPane, initDividerLocation);

 180 
 181             // expand all the way right
 182             buttonRight.push();
 183             waitDividerLocation(splitPane, splitPane.getWidth() - splitPane.getDividerSize() - right);


 184 
 185             // Click to move back from right expansion
 186             buttonLeft.push();
 187             waitDividerLocation(splitPane, initDividerLocation);

 188         }
 189 
 190         // Test for case where one touch expandable is disabled
 191         if (!oneTouch) {
 192             if (checkBox.isSelected()) {
 193                 // uncheck
 194                 checkBox.doClick();
 195             }
 196             splitPane.waitState(new ComponentChooser() {
 197                 public boolean checkComponent(Component c) {
 198                     return !splitPane.isOneTouchExpandable();
 199                 }
 200                 public String getDescription() {
 201                     return "Split pane not to be one touch expandable";
 202                 }
 203             });
 204         }
 205     }
 206 
 207 }
< prev index next >