1 /* 2 * Copyright (c) 2018, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package org.netbeans.jemmy.operators; 27 28 import static org.netbeans.jemmy.operators.JInternalFrameOperator.CLOSE_BUTTON_TOOLTIP; 29 import static org.netbeans.jemmy.operators.JInternalFrameOperator.MAXIMIZE_BUTTON_TOOLTIP; 30 import static org.netbeans.jemmy.operators.JInternalFrameOperator.MINIMIZE_BUTTON_TOOLTIP; 31 import static org.testng.Assert.assertEquals; 32 import static org.testng.Assert.fail; 33 34 import java.awt.Dimension; 35 import java.awt.Point; 36 37 import javax.swing.JDesktopPane; 38 import javax.swing.JFrame; 39 import javax.swing.JInternalFrame; 40 import javax.swing.UIManager; 41 42 import org.netbeans.jemmy.JemmyProperties; 43 import org.netbeans.jemmy.LookAndFeelProvider; 44 import org.netbeans.jemmy.util.Platform; 45 import org.testng.annotations.AfterMethod; 46 import org.testng.annotations.BeforeMethod; 47 import org.testng.annotations.Test; 48 49 public class JInternalFrameOperatorTest { 50 51 private JFrameOperator frameOper; 52 53 private JInternalFrameOperator internalFrameOper; 54 55 private JDesktopPane desktop; 56 57 private final static String OSX_EXCEPT_MESSAGE = "Jemmy doesn't support" 58 + " getting or initializing title related operators on Mac OSx"; 59 60 @BeforeMethod 61 private void setUp(Object[] args) throws Exception { 62 UIManager.setLookAndFeel((String)args[0]); 63 JFrame frame = new JFrame(); 64 desktop = new JDesktopPane(); 65 frame.setContentPane(desktop); 66 JemmyProperties.setCurrentDispatchingModel( 67 JemmyProperties.getCurrentDispatchingModel()); 68 JInternalFrame internalFrame = new JInternalFrame( 69 "JInternalFrameOperatorTest", true, true, true, true); 70 internalFrame.setName("JInternalFrameOperatorTest"); 71 internalFrame.setSize(200, 200); 72 internalFrame.setVisible(true); 73 desktop.add(internalFrame); 74 frame.setSize(400,400); 75 frame.setLocationRelativeTo(null); 76 frame.setVisible(true); 77 frameOper = new JFrameOperator(); 78 internalFrameOper = new JInternalFrameOperator(internalFrame); 79 internalFrameOper.setVerification(true); 80 } 81 82 @AfterMethod 83 protected void tearDown() throws Exception { 84 frameOper.setVisible(false); 85 frameOper.dispose(); 86 } 87 88 @Test(dataProvider = "availableLookAndFeels", dataProviderClass = LookAndFeelProvider.class) 89 public void testConstructors(String lookAndFeel) throws Exception { 90 new JInternalFrameOperator(frameOper); 91 new JInternalFrameOperator(frameOper, "JInternalFrameOperatorTest"); 92 new JInternalFrameOperator(frameOper, 93 comp -> "JInternalFrameOperatorTest".equals(comp.getName())); 94 95 } 96 97 @Test(dataProvider = "availableLookAndFeels", dataProviderClass = LookAndFeelProvider.class) 98 public void testIconify(String lookAndFeel) throws Exception { 99 internalFrameOper.iconify(); 100 internalFrameOper.deiconify(); 101 } 102 103 @Test(dataProvider = "availableLookAndFeels", dataProviderClass = LookAndFeelProvider.class) 104 public void testMaximize(String lookAndFeel) throws Exception { 105 internalFrameOper.maximize(); 106 internalFrameOper.demaximize(); 107 } 108 109 @Test(dataProvider = "availableLookAndFeels", dataProviderClass = LookAndFeelProvider.class) 110 public void testMove(String lookAndFeel) throws Exception { 111 Point originalLocation = internalFrameOper.getLocation(); 112 internalFrameOper.move(150, 150); 113 internalFrameOper.move(originalLocation.x, originalLocation.y); 114 } 115 116 @Test(dataProvider = "availableLookAndFeels", dataProviderClass = LookAndFeelProvider.class) 117 public void testResize(String lookAndFeel) throws Exception { 118 Dimension originaSize = internalFrameOper.getSize(); 119 internalFrameOper.resize(250, 250); 120 internalFrameOper.resize(originaSize.width, originaSize.height); 121 } 122 123 @Test(dataProvider = "availableLookAndFeels", dataProviderClass = LookAndFeelProvider.class) 124 public void testActivate(String lookAndFeel) throws Exception { 125 internalFrameOper.activate(); 126 } 127 128 @Test(dataProvider = "availableLookAndFeels", dataProviderClass = LookAndFeelProvider.class) 129 public void testTitleButtons(String lookAndFeel) throws Exception { 130 if(!Platform.isOSX() && !"Motif".equals(UIManager.getLookAndFeel().getID())) { 131 // Close, Maximize, and Minimize buttons are adding along with the 132 // construction of internal frame itself 133 JInternalFrame interanlFrame1 = new JInternalFrame( 134 "JInternalFrameButtonTest1", true, true, true, true); 135 verifyTitleButtons(interanlFrame1); 136 137 // Close, Maximize, and Minimize buttons are adding after the 138 // construction of internal frame by using APIs 139 JInternalFrame interanlFrame2 = new JInternalFrame( 140 "JInternalFrameButtonTest2", false, false, false, false); 141 interanlFrame2.setClosable(true); 142 interanlFrame2.setMaximizable(true); 143 interanlFrame2.setIconifiable(true); 144 verifyTitleButtons(interanlFrame2); 145 } else if (Platform.isOSX()){ 146 JInternalFrame interanlFrame = new JInternalFrame( 147 "JInternalFrameButtonTest3", true, true, true, true); 148 interanlFrame.setSize(200, 200); 149 interanlFrame.setVisible(true); 150 desktop.add(interanlFrame); 151 JInternalFrameOperator interanlFrameOper = new JInternalFrameOperator(interanlFrame); 152 try { 153 interanlFrameOper.getMaximizeButton(); 154 fail(); 155 } catch (UnsupportedOperationException e) { 156 assertEquals(e.getMessage(), OSX_EXCEPT_MESSAGE); 157 } 158 try { 159 interanlFrameOper.getMinimizeButton(); 160 fail(); 161 } catch (UnsupportedOperationException e) { 162 assertEquals(e.getMessage(), OSX_EXCEPT_MESSAGE); 163 } 164 try { 165 interanlFrameOper.getCloseButton(); 166 fail(); 167 } catch (UnsupportedOperationException e) { 168 assertEquals(e.getMessage(), OSX_EXCEPT_MESSAGE); 169 } 170 } 171 } 172 173 private void verifyTitleButtons(JInternalFrame interanlFrame) { 174 interanlFrame.setSize(200, 200); 175 interanlFrame.setVisible(true); 176 desktop.add(interanlFrame); 177 JInternalFrameOperator interanlFrameOper = new JInternalFrameOperator(interanlFrame); 178 179 // Verify title buttons tooltip texts 180 assertEquals(interanlFrameOper.getCloseButton().getToolTipText(), 181 CLOSE_BUTTON_TOOLTIP); 182 assertEquals(interanlFrameOper.getMaximizeButton().getToolTipText(), 183 MAXIMIZE_BUTTON_TOOLTIP); 184 assertEquals(interanlFrameOper.getMinimizeButton().getToolTipText(), 185 MINIMIZE_BUTTON_TOOLTIP); 186 187 // Verify different actions using title buttons 188 interanlFrameOper.getMaximizeButton().push(); 189 interanlFrameOper.waitMaximum(true); 190 interanlFrameOper.getMaximizeButton().push(); 191 interanlFrameOper.waitMaximum(false); 192 interanlFrameOper.getMinimizeButton().push(); 193 interanlFrameOper.waitIcon(true); 194 interanlFrameOper.deiconify(); 195 interanlFrameOper.waitIcon(false); 196 interanlFrameOper.getCloseButton().push(); 197 198 desktop.remove(interanlFrame); 199 interanlFrame.dispose(); 200 } 201 202 }