Path: blob/master/test/jdk/sanity/client/SwingSet/src/InternalFrameDemoTest.java
41153 views
/*1* Copyright (c) 2018, 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 static com.sun.swingset3.demos.internalframe.InternalFrameDemo.CLOSABLE_LABEL;24import static com.sun.swingset3.demos.internalframe.InternalFrameDemo.DEMO_TITLE;25import static com.sun.swingset3.demos.internalframe.InternalFrameDemo.FRAME0_X;26import static com.sun.swingset3.demos.internalframe.InternalFrameDemo.FRAME0_Y;27import static com.sun.swingset3.demos.internalframe.InternalFrameDemo.FRAME_GAP;28import static com.sun.swingset3.demos.internalframe.InternalFrameDemo.FRAME_HEIGHT;29import static com.sun.swingset3.demos.internalframe.InternalFrameDemo.FRAME_WIDTH;30import static com.sun.swingset3.demos.internalframe.InternalFrameDemo.ICONIFIABLE_LABEL;31import static com.sun.swingset3.demos.internalframe.InternalFrameDemo.INTERNAL_FRAME_LABEL;32import static com.sun.swingset3.demos.internalframe.InternalFrameDemo.MAXIMIZABLE_LABEL;33import static com.sun.swingset3.demos.internalframe.InternalFrameDemo.PALETTE_HEIGHT;34import static com.sun.swingset3.demos.internalframe.InternalFrameDemo.PALETTE_LABEL;35import static com.sun.swingset3.demos.internalframe.InternalFrameDemo.PALETTE_WIDTH;36import static com.sun.swingset3.demos.internalframe.InternalFrameDemo.PALETTE_X;37import static com.sun.swingset3.demos.internalframe.InternalFrameDemo.PALETTE_Y;38import static com.sun.swingset3.demos.internalframe.InternalFrameDemo.RESIZABLE_LABEL;39import static org.jemmy2ext.JemmyExt.EXACT_STRING_COMPARATOR;40import static org.testng.AssertJUnit.assertFalse;4142import java.awt.Dimension;43import java.awt.Point;4445import javax.swing.JDesktopPane;46import javax.swing.JInternalFrame;47import javax.swing.UIManager;4849import org.jemmy2ext.JemmyExt;50import org.jtregext.GuiTestListener;51import org.netbeans.jemmy.ClassReference;52import org.netbeans.jemmy.JemmyProperties;53import org.netbeans.jemmy.operators.ComponentOperator;54import org.netbeans.jemmy.operators.JButtonOperator;55import org.netbeans.jemmy.operators.JCheckBoxOperator;56import org.netbeans.jemmy.operators.JFrameOperator;57import org.netbeans.jemmy.operators.JInternalFrameOperator;58import org.netbeans.jemmy.operators.JTextFieldOperator;59import org.testng.annotations.Listeners;60import org.testng.annotations.Test;6162import com.sun.swingset3.demos.internalframe.InternalFrameDemo;6364/*65* @test66* @bug 821170367* @key headful68* @summary Verifies SwingSet3 InternalFrameDemo page by checking the different69* actions on the parent frame, internal frame and creating internal frame70* with different properties71*72* @library /sanity/client/lib/jemmy/src73* @library /sanity/client/lib/Extensions/src74* @library /sanity/client/lib/SwingSet3/src75* @modules java.desktop76* java.logging77* @build org.jemmy2ext.JemmyExt78* @build com.sun.swingset3.demos.internalframe.InternalFrameDemo79* @run testng/timeout=600 InternalFrameDemoTest80*/81@Listeners(GuiTestListener.class)82public class InternalFrameDemoTest {8384private final static int PARENT_FRAME_NEW_SIZE_DELTA = 300;85private final static int PARENT_FRAME_NEW_LOCATION_DELTA = 200;86private final static Dimension INTERNAL_FRAME_NEW_SIZE = new Dimension(400, 400);87private final static Point INTERNAL_FRAME_NEW_LOCATION = new Point(390, 120);88private final static int DELAY = 500;89private final static String INTERNAL_FRAME_NEW_NAME = "New Internal Frame";9091/**92* Testing the different actions on the parent frame, internal frame and93* creating internal frame with different properties94*95* @throws Exception96*/97@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)98public void test(String lookAndFeel) throws Exception {99UIManager.setLookAndFeel(lookAndFeel);100// initializing internal frame driver for each L&F101JemmyProperties.setCurrentDispatchingModel(102JemmyProperties.getCurrentDispatchingModel());103104new ClassReference(InternalFrameDemo.class.getCanonicalName()).startApplication();105106JFrameOperator frameOperator = new JFrameOperator(DEMO_TITLE);107frameOperator.setComparator(EXACT_STRING_COMPARATOR);108frameOperator.setVerification(true);109110// verifying internal frame primary properties111JInternalFrameOperator internalFrameOperator = new JInternalFrameOperator(112frameOperator, getInternalFrameName(INTERNAL_FRAME_LABEL, 0));113internalFrameOperator.setVerification(true);114checkInternalFramePrimaryProps(internalFrameOperator,115new Point(FRAME0_X, FRAME0_Y), new Dimension(FRAME_WIDTH, FRAME_HEIGHT));116117// Verifying the internal frame properties after doing different118// actions on parent frame119checkParentFrameAction(frameOperator, internalFrameOperator);120121// Verifying different actions on the internal frame122checkInternalFrameAction(internalFrameOperator);123124// Creating internal frames with different action properties125// and verifying their properties126checkPaletteFrameAction(frameOperator);127}128129/**130* Verifying the internal frame properties after doing different actions on131* parent frame, it should not affect internal frame.132*133* @param parentFrameOperator : parent fame operator134* @param internalFrameOperator : internal fame operator135* @throws InterruptedException136*/137private void checkParentFrameAction(JFrameOperator parentFrameOperator,138JInternalFrameOperator internalFrameOperator) throws InterruptedException {139140// Resizing the parent frame and verifying the size of the internal141// frame(it should not be resized)142Dimension orignalSize = parentFrameOperator.getSize();143Dimension newSize = new Dimension(orignalSize.width - PARENT_FRAME_NEW_SIZE_DELTA,144orignalSize.height - PARENT_FRAME_NEW_SIZE_DELTA);145parentFrameOperator.resize(newSize.width, newSize.height);146parentFrameOperator.waitComponentSize(newSize);147// TODO This is a workaround for JDK-8210638, this delay has to remove148// after fixing this bug, this is an unstable code.149TestHelpers.delayBetweenFrameStateChange();150// keeping some delay before checking the internal frame property151// as it is a negative scenario152Thread.sleep(DELAY);153internalFrameOperator.waitComponentSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT));154// Resizing parent frame back to original size155parentFrameOperator.resize(orignalSize.width, orignalSize.height);156parentFrameOperator.waitComponentSize(orignalSize);157// TODO This is a workaround for JDK-8210638, this delay has to remove158// after fixing this bug, this is an unstable code.159TestHelpers.delayBetweenFrameStateChange();160161// Iconifying the parent frame and verifying the iconified status of the internal162// frame(it should not be iconified)163parentFrameOperator.iconify();164// TODO This is a workaround for JDK-8210638, this delay has to remove165// after fixing this bug, this is an unstable code.166TestHelpers.delayBetweenFrameStateChange();167// keeping some delay before checking the internal frame property168// as it is a negative scenario169Thread.sleep(DELAY);170assertFalse("Internal Frame should not be iconified when parent frame"171+ " alone is iconified.", internalFrameOperator.isIcon());172parentFrameOperator.deiconify();173// TODO This is a workaround for JDK-8210638, this delay has to remove174// after fixing this bug, this is an unstable code.175TestHelpers.delayBetweenFrameStateChange();176177// Maximizing the parent frame and verifying the maximized status of the internal178// frame(it should not be maximized)179parentFrameOperator.maximize();180// TODO This is a workaround for JDK-8210638, this delay has to remove181// after fixing this bug, this is an unstable code.182TestHelpers.delayBetweenFrameStateChange();183// keeping some delay before checking the internal frame property184// as it is a negative scenario185Thread.sleep(DELAY);186assertFalse("Internal Frame should not be maximized when parent frame"187+ " alone is maximized.", internalFrameOperator.isMaximum());188parentFrameOperator.demaximize();189// TODO This is a workaround for JDK-8210638, this delay has to remove190// after fixing this bug, this is an unstable code.191TestHelpers.delayBetweenFrameStateChange();192193// Relocating the parent frame and verifying the location of the internal194// frame(it should not be changed the location)195Point orignalLocation = parentFrameOperator.getLocation();196Point newLocation = new Point((orignalLocation.x - PARENT_FRAME_NEW_LOCATION_DELTA),197(orignalLocation.y + PARENT_FRAME_NEW_LOCATION_DELTA));198parentFrameOperator.move(newLocation.x, newLocation.y);199parentFrameOperator.waitComponentLocation(newLocation);200// TODO This is a workaround for JDK-8210638, this delay has to remove201// after fixing this bug, this is an unstable code.202TestHelpers.delayBetweenFrameStateChange();203// keeping some delay before checking the internal frame property204// as it is a negative scenario205Thread.sleep(DELAY);206internalFrameOperator.waitComponentLocation(new Point(FRAME0_X, FRAME0_Y));207// Moving back parent frame to original location208parentFrameOperator.move(orignalLocation.x, orignalLocation.y);209parentFrameOperator.waitComponentLocation(orignalLocation);210// TODO This is a workaround for JDK-8210638, this delay has to remove211// after fixing this bug, this is an unstable code.212TestHelpers.delayBetweenFrameStateChange();213}214215/**216* Verifying different actions on the internal frame.217*218* @param internalFrameOperator : internal fame operator219* @throws InterruptedException220*/221private void checkInternalFrameAction(JInternalFrameOperator222internalFrameOperator) throws InterruptedException {223// Verifying maximize and demaximize actions224internalFrameOperator.waitStateOnQueue(comp225-> ((JInternalFrame)comp).isMaximizable());226internalFrameOperator.maximize();227internalFrameOperator.demaximize();228229// Verifying iconify and deiconify actions230internalFrameOperator.waitStateOnQueue(comp231-> ((JInternalFrame)comp).isIconifiable());232internalFrameOperator.iconify();233internalFrameOperator.deiconify();234235// Verifying resize action236internalFrameOperator.waitStateOnQueue(comp237-> ((JInternalFrame)comp).isResizable());238TestHelpers.checkChangeSize(internalFrameOperator,239INTERNAL_FRAME_NEW_SIZE);240241// Verifying move action242TestHelpers.checkChangeLocation(internalFrameOperator,243INTERNAL_FRAME_NEW_LOCATION);244245// Verifying close action246internalFrameOperator.waitStateOnQueue(comp247-> ((JInternalFrame)comp).isClosable());248internalFrameOperator.close();249}250251/**252* Creating internal frames with different action properties and verifying253* their properties254*255* @param frameOperator : parent frame operator256*/257private void checkPaletteFrameAction(JFrameOperator frameOperator) {258// Getting palette frame and checking the properties of it259JInternalFrameOperator paletteFrameOperator =260new JInternalFrameOperator(frameOperator, PALETTE_LABEL);261paletteFrameOperator.setComparator(EXACT_STRING_COMPARATOR);262checkInternalFramePrimaryProps(paletteFrameOperator,263new Point(PALETTE_X, PALETTE_Y),264new Dimension(PALETTE_WIDTH, PALETTE_HEIGHT));265266// Getting all check boxes to set/reset frame properties267JCheckBoxOperator closableOperator =268new JCheckBoxOperator(paletteFrameOperator, CLOSABLE_LABEL);269JCheckBoxOperator iconifiableOperator =270new JCheckBoxOperator(paletteFrameOperator, ICONIFIABLE_LABEL);271JCheckBoxOperator maximizableOperator =272new JCheckBoxOperator(paletteFrameOperator, MAXIMIZABLE_LABEL);273JCheckBoxOperator resizableOperator =274new JCheckBoxOperator(paletteFrameOperator, RESIZABLE_LABEL);275JCheckBoxOperator[] checkBoxes = {closableOperator, iconifiableOperator,276maximizableOperator, resizableOperator};277278// Verifying internal frame with all action properties set to false279checkFrameProps(frameOperator, paletteFrameOperator,280getInternalFrameName(INTERNAL_FRAME_LABEL, 1), 1, checkBoxes, false);281282// Verifying internal frame with all action properties set to true and setting title283JTextFieldOperator frameTitle = new JTextFieldOperator(paletteFrameOperator);284frameTitle.setText(INTERNAL_FRAME_NEW_NAME);285checkFrameProps(frameOperator, paletteFrameOperator,286getInternalFrameName(INTERNAL_FRAME_NEW_NAME), 2, checkBoxes, true);287}288289/**290* Verifying internal frame properties291*292* @param frameOperator : parent frame operator293* @param paletteFrameOperator : palette frame operator294* @param title : title of the internal frame295* @param index : index of the internal frame296* @param checkBoxes : array of check boxes297* @param checkBoxStatus : status of check box298*/299private void checkFrameProps(JFrameOperator frameOperator,300JInternalFrameOperator paletteFrameOperator,301String title, int index, JCheckBoxOperator[] checkBoxes,302boolean checkBoxStatus) {303304pushCheckBoxes(checkBoxes, checkBoxStatus);305JButtonOperator button = new JButtonOperator(paletteFrameOperator, (index -1));306button.push();307JInternalFrameOperator internalFrameOperator =308new JInternalFrameOperator(frameOperator, title);309int gap = FRAME_GAP * index;310checkInternalFramePrimaryProps(internalFrameOperator,311new Point(FRAME0_X + gap, FRAME0_Y + gap),312new Dimension(FRAME_WIDTH, FRAME_HEIGHT));313checkFrameActionProps(internalFrameOperator, checkBoxStatus);314ComponentOperator desktopOperator = new ComponentOperator(315frameOperator, new JemmyExt.ByClassChooser(JDesktopPane.class));316frameOperator.waitStateOnQueue(comp -> ((JDesktopPane)desktopOperator.317getSource()).getAllFrames().length == index + 1);318}319320/**321* Verifying internal frame primary properties like showing status, location and size322* @param internalFrameOperator323* @param location324* @param size325*/326private void checkInternalFramePrimaryProps(JInternalFrameOperator internalFrameOperator,327Point location, Dimension size) {328internalFrameOperator.waitComponentShowing(true);329internalFrameOperator.waitComponentLocation(location);330internalFrameOperator.waitComponentSize(size);331}332333/**334* Verifying internal frame action status335*336* @param internalFrameOperator : internal frame operator337* @param propertyStatus : status to check338*/339private void checkFrameActionProps(JInternalFrameOperator internalFrameOperator,340boolean propertyStatus) {341internalFrameOperator.waitStateOnQueue(comp342-> ((JInternalFrame)comp).isClosable() == propertyStatus);343internalFrameOperator.waitStateOnQueue(comp344-> ((JInternalFrame)comp).isIconifiable() == propertyStatus);345internalFrameOperator.waitStateOnQueue(comp346-> ((JInternalFrame)comp).isMaximizable() == propertyStatus);347internalFrameOperator.waitStateOnQueue(comp348-> ((JInternalFrame)comp).isResizable() == propertyStatus);349}350351/**352* To set/reset check boxes353*354* @param checkBoxes : array of check boxes355* @param select : set/reset356*/357private void pushCheckBoxes(JCheckBoxOperator []checkBoxes, boolean select){358for (JCheckBoxOperator checkBox : checkBoxes) {359checkBox.push();360checkBox.waitSelected(select);361}362}363364/**365* Gets the internal frame name366* @param frameLabel367* @return368*/369private String getInternalFrameName(String frameLabel) {370return (frameLabel+ " ");371}372373/**374* Gets the internal frame name375* @param frameLabel376* @param index377* @return378*/379private String getInternalFrameName(String frameLabel, int index) {380return getInternalFrameName(frameLabel+ " " + index);381}382383}384385386