Path: blob/master/test/jdk/sanity/client/SwingSet/src/DialogDemoTest.java
41153 views
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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/23import org.jtregext.GuiTestListener;24import com.sun.swingset3.demos.dialog.DialogDemo;25import static com.sun.swingset3.demos.dialog.DialogDemo.*;26import java.awt.Dimension;27import java.awt.Point;28import javax.swing.JDialog;29import javax.swing.UIManager;30import static org.testng.AssertJUnit.*;31import org.testng.annotations.Test;32import static org.jemmy2ext.JemmyExt.isIconified;33import static org.jemmy2ext.JemmyExt.ByClassChooser;34import org.netbeans.jemmy.ClassReference;35import org.netbeans.jemmy.ComponentChooser;36import static org.netbeans.jemmy.WindowWaiter.countWindows;37import org.netbeans.jemmy.operators.JFrameOperator;38import org.netbeans.jemmy.operators.JDialogOperator;39import org.netbeans.jemmy.operators.JLabelOperator;40import org.netbeans.jemmy.operators.JButtonOperator;41import org.testng.annotations.Listeners;4243/*44* @test45* @key headful46* @summary Verifies SwingSet3 DialogDemo by checking that separate JDialog is47* shown, it contains predefined label and no new dialogs are opened48* when the "Show JDialog..." button is clicked.49*50* @library /sanity/client/lib/jemmy/src51* @library /sanity/client/lib/Extensions/src52* @library /sanity/client/lib/SwingSet3/src53* @modules java.desktop54* java.logging55* @build org.jemmy2ext.JemmyExt56* @build com.sun.swingset3.demos.dialog.DialogDemo57* @run testng/timeout=600 DialogDemoTest58*/59@Listeners(GuiTestListener.class)60public class DialogDemoTest {6162private final ComponentChooser jDialogClassChooser = new ByClassChooser(JDialog.class);6364@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)65public void test(String lookAndFeel) throws Exception {66UIManager.setLookAndFeel(lookAndFeel);67new ClassReference(DialogDemo.class.getCanonicalName()).startApplication();68JFrameOperator mainFrame = new JFrameOperator(DIALOG_DEMO_TITLE);69JDialogOperator dialog = new JDialogOperator(DIALOG_TITLE);70JButtonOperator showJDialogButton = new JButtonOperator(mainFrame, SHOW_BUTTON_TITLE);71initialCheckWithLabel(mainFrame, dialog);72checkShowDialogButton(dialog, showJDialogButton);73TestHelpers.checkChangeSize(dialog, new Dimension(dialog.getSize().width * 2,74dialog.getSize().height * 2));75TestHelpers.checkChangeLocation(dialog, new Point(dialog.getLocation().x + 100,76dialog.getLocation().y + 100));77}7879private void initialCheckWithLabel(JFrameOperator frame, JDialogOperator jdo) {80JLabelOperator label = new JLabelOperator(jdo);81assertFalse("JFrame is not iconified", isIconified(frame));82assertEquals("Only one JDialog is present", 1,83countWindows(jDialogClassChooser));84assertEquals(LABEL_CONTENT, label.getText());85}8687private void checkShowDialogButton(JDialogOperator jdo, JButtonOperator jbo)88throws InterruptedException {89//Check that the button does not change the number of JDialog90jbo.push();91Thread.sleep(500);92assertEquals("Only one JDialog is present", 1,93countWindows(jDialogClassChooser));94assertTrue("Check JDialog is visible", jdo.isVisible());95jdo.requestClose();96jdo.waitClosed();97//Check that the button makes the JDialog visible98//and that 1 jDialog is present.99jbo.push();100jdo.waitComponentVisible(true);101Thread.sleep(500);102assertEquals("Only one JDialog is present", 1,103countWindows(jDialogClassChooser));104}105}106107108