# HG changeset patch # User mrkam # Date 1461804437 25200 # Node ID 9774eca96b015409b46e49c13481beb42d8e35f7 # Parent 24ef455da1b0950d2f4d26d0554f75b52ae48dbb 8154381: SwingSet tests are not auto closed in jtreg Reviewed-by: alexsch diff -r 24ef455da1b0 -r 9774eca96b01 jdk/make/netbeans/client_sanity/nbproject/genfiles.properties --- a/jdk/make/netbeans/client_sanity/nbproject/genfiles.properties Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/make/netbeans/client_sanity/nbproject/genfiles.properties Wed Apr 27 17:47:17 2016 -0700 @@ -3,6 +3,6 @@ build.xml.stylesheet.CRC32=8064a381@1.75.2.48 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=55414227 +nbproject/build-impl.xml.data.CRC32=16caf60f nbproject/build-impl.xml.script.CRC32=c12f9d04 nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48 diff -r 24ef455da1b0 -r 9774eca96b01 jdk/make/netbeans/client_sanity/nbproject/project.properties --- a/jdk/make/netbeans/client_sanity/nbproject/project.properties Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/make/netbeans/client_sanity/nbproject/project.properties Wed Apr 27 17:47:17 2016 -0700 @@ -76,4 +76,4 @@ src.src.dir=..\\..\\..\\test\\sanity\\client\\SwingSet\\src src.src2.dir=..\\..\\..\\test\\sanity\\client\\lib\\SwingSet3\\src src.src3.dir=..\\..\\..\\test\\sanity\\client\\lib\\jemmy\\src -src.src4.dir=..\\..\\..\\test\\sanity\\client\\lib\\Jemmy2Ext\\src +src.src4.dir=..\\..\\..\\test\\sanity\\client\\lib\\Extensions\\src diff -r 24ef455da1b0 -r 9774eca96b01 jdk/make/netbeans/client_sanity/nbproject/project.xml --- a/jdk/make/netbeans/client_sanity/nbproject/project.xml Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/make/netbeans/client_sanity/nbproject/project.xml Wed Apr 27 17:47:17 2016 -0700 @@ -6,7 +6,7 @@ SanityTests - + diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java --- a/jdk/test/sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/test/sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java Wed Apr 27 17:47:17 2016 -0700 @@ -21,6 +21,8 @@ * questions. */ +import com.sun.swingset3.demos.button.ButtonDemo; +import org.jtregext.GuiTestListener; import java.awt.Point; import java.awt.Robot; import java.awt.event.InputEvent; @@ -32,6 +34,7 @@ import static org.jemmy2ext.JemmyExt.*; import org.testng.annotations.Test; import static com.sun.swingset3.demos.button.ButtonDemo.*; +import org.testng.annotations.Listeners; /* * @test @@ -41,31 +44,30 @@ * image is different from initial button image. * * @library /sanity/client/lib/jemmy/src - * @library /sanity/client/lib/Jemmy2Ext/src + * @library /sanity/client/lib/Extensions/src * @library /sanity/client/lib/SwingSet3/src * @build org.jemmy2ext.JemmyExt * @build com.sun.swingset3.demos.button.ButtonDemo * @run testng ButtonDemoScreenshotTest */ +@Listeners(GuiTestListener.class) public class ButtonDemoScreenshotTest { private static final int BUTTON_COUNT = 6; // TODO: Decide about "open browser" buttons (value was 8 originally) @Test public void test() throws Exception { - captureDebugInfoOnFail(() -> { - Robot rob = new Robot(); + Robot rob = new Robot(); - new ClassReference(com.sun.swingset3.demos.button.ButtonDemo.class.getCanonicalName()).startApplication(); + new ClassReference(ButtonDemo.class.getCanonicalName()).startApplication(); - JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE); - waitImageIsStill(rob, mainFrame); + JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE); + waitImageIsStill(rob, mainFrame); - // Check all the buttons - for (int i = 0; i < BUTTON_COUNT; i++) { - checkButton(mainFrame, i, rob); - } - }); + // Check all the buttons + for (int i = 0; i < BUTTON_COUNT; i++) { + checkButton(mainFrame, i, rob); + } } public void checkButton(JFrameOperator jfo, int i, Robot rob) { diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/SwingSet/src/ButtonDemoTest.java --- a/jdk/test/sanity/client/SwingSet/src/ButtonDemoTest.java Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/test/sanity/client/SwingSet/src/ButtonDemoTest.java Wed Apr 27 17:47:17 2016 -0700 @@ -21,6 +21,7 @@ * questions. */ +import org.jtregext.GuiTestListener; import com.sun.swingset3.demos.JHyperlink; import com.sun.swingset3.demos.button.ButtonDemo; import java.util.concurrent.ArrayBlockingQueue; @@ -38,7 +39,7 @@ import static com.sun.swingset3.demos.button.ButtonDemo.*; import org.jemmy2ext.JemmyExt; import org.jemmy2ext.JemmyExt.MultiThreadedTryCatch; -import static org.jemmy2ext.JemmyExt.captureDebugInfoOnFail; +import org.testng.annotations.Listeners; /* * @test @@ -48,12 +49,13 @@ * on buttons before and after click. * * @library /sanity/client/lib/jemmy/src - * @library /sanity/client/lib/Jemmy2Ext/src + * @library /sanity/client/lib/Extensions/src * @library /sanity/client/lib/SwingSet3/src * @build org.jemmy2ext.JemmyExt * @build com.sun.swingset3.demos.button.ButtonDemo * @run testng ButtonDemoTest */ +@Listeners(GuiTestListener.class) public class ButtonDemoTest { private static final String[] BUTTON_TEXT_AFTER = { @@ -92,34 +94,30 @@ @Test public void test() throws Exception { - captureDebugInfoOnFail(() -> { - - new ClassReference(ButtonDemo.class.getCanonicalName()).startApplication(); + new ClassReference(ButtonDemo.class.getCanonicalName()).startApplication(); - JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE); - mainFrame.setComparator(EXACT_STRING_COMPARATOR); - - // Check all the buttons - for (int i = 0; i < BUTTON_TOOLTIP.length; i++) { - String tooltip = BUTTON_TOOLTIP[i]; - - JButtonOperator button = new JButtonOperator(mainFrame, new ByToolTipChooser(tooltip)); + JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE); + mainFrame.setComparator(EXACT_STRING_COMPARATOR); - assertEquals(BUTTON_TEXT_BEFORE[i], button.getText()); + // Check all the buttons + for (int i = 0; i < BUTTON_TOOLTIP.length; i++) { + String tooltip = BUTTON_TOOLTIP[i]; + + JButtonOperator button = new JButtonOperator(mainFrame, new ByToolTipChooser(tooltip)); - // Two buttons are hyperlinks, we don't want to click them - if (!button.getSource().getClass().equals(JHyperlink.class)) { - checkButton(button); - } + assertEquals(BUTTON_TEXT_BEFORE[i], button.getText()); - if (BUTTON_TEXT_AFTER.length > i) { - assertEquals(BUTTON_TEXT_AFTER[i], button.getText()); - } else { - assertEquals(BUTTON_TEXT_BEFORE[i], button.getText()); - } + // Two buttons are hyperlinks, we don't want to click them + if (!button.getSource().getClass().equals(JHyperlink.class)) { + checkButton(button); } - }); + if (BUTTON_TEXT_AFTER.length > i) { + assertEquals(BUTTON_TEXT_AFTER[i], button.getText()); + } else { + assertEquals(BUTTON_TEXT_BEFORE[i], button.getText()); + } + } } private void checkButton(JButtonOperator button) throws Exception { diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/SwingSet/src/ComboBoxDemoTest.java --- a/jdk/test/sanity/client/SwingSet/src/ComboBoxDemoTest.java Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/test/sanity/client/SwingSet/src/ComboBoxDemoTest.java Wed Apr 27 17:47:17 2016 -0700 @@ -21,6 +21,7 @@ * questions. */ +import org.jtregext.GuiTestListener; import com.sun.swingset3.demos.combobox.ComboBoxDemo; import static org.testng.AssertJUnit.*; import org.testng.annotations.Test; @@ -28,7 +29,7 @@ import org.netbeans.jemmy.operators.JComboBoxOperator; import org.netbeans.jemmy.operators.JFrameOperator; import static com.sun.swingset3.demos.combobox.ComboBoxDemo.*; -import static org.jemmy2ext.JemmyExt.captureDebugInfoOnFail; +import org.testng.annotations.Listeners; /* * @test @@ -37,12 +38,13 @@ * each value of each ComboBox. * * @library /sanity/client/lib/jemmy/src - * @library /sanity/client/lib/Jemmy2Ext/src + * @library /sanity/client/lib/Extensions/src * @library /sanity/client/lib/SwingSet3/src * @build org.jemmy2ext.JemmyExt * @build com.sun.swingset3.demos.combobox.ComboBoxDemo * @run testng ComboBoxDemoTest */ +@Listeners(GuiTestListener.class) public class ComboBoxDemoTest { private static enum ComboBoxInfo { @@ -61,14 +63,13 @@ @Test public void test() throws Exception { - captureDebugInfoOnFail(() -> { - new ClassReference(ComboBoxDemo.class.getCanonicalName()).startApplication(); + + new ClassReference(ComboBoxDemo.class.getCanonicalName()).startApplication(); - JFrameOperator frame = new JFrameOperator(DEMO_TITLE); - for (ComboBoxInfo comboBoxInfo : ComboBoxInfo.values()) { - comboBoxChecker(frame, comboBoxInfo); - } - }); + JFrameOperator frame = new JFrameOperator(DEMO_TITLE); + for (ComboBoxInfo comboBoxInfo : ComboBoxInfo.values()) { + comboBoxChecker(frame, comboBoxInfo); + } } private void comboBoxChecker(JFrameOperator jfo, ComboBoxInfo comboBoxInfo) { diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/SwingSet/src/ListDemoTest.java --- a/jdk/test/sanity/client/SwingSet/src/ListDemoTest.java Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/test/sanity/client/SwingSet/src/ListDemoTest.java Wed Apr 27 17:47:17 2016 -0700 @@ -21,6 +21,7 @@ * questions. */ +import org.jtregext.GuiTestListener; import com.sun.swingset3.demos.list.ListDemo; import static com.sun.swingset3.demos.list.ListDemo.DEMO_TITLE; import static org.testng.AssertJUnit.*; @@ -30,7 +31,7 @@ import org.netbeans.jemmy.operators.JCheckBoxOperator; import org.netbeans.jemmy.operators.JFrameOperator; import org.netbeans.jemmy.operators.JListOperator; -import static org.jemmy2ext.JemmyExt.captureDebugInfoOnFail; +import org.testng.annotations.Listeners; /* * @test @@ -40,64 +41,64 @@ * list. * * @library /sanity/client/lib/jemmy/src - * @library /sanity/client/lib/Jemmy2Ext/src + * @library /sanity/client/lib/Extensions/src * @library /sanity/client/lib/SwingSet3/src * @build org.jemmy2ext.JemmyExt * @build com.sun.swingset3.demos.list.ListDemo * @run testng ListDemoTest */ +@Listeners(GuiTestListener.class) public class ListDemoTest { private static final int CHECKBOX_COUNT = 50; @Test public void test() throws Exception { - captureDebugInfoOnFail(() -> { - new ClassReference(ListDemo.class.getCanonicalName()).startApplication(); + + new ClassReference(ListDemo.class.getCanonicalName()).startApplication(); + + JFrameOperator frame = new JFrameOperator(DEMO_TITLE); + JListOperator listOp = new JListOperator(frame); + + // Check *NO* Prefix and Suffixes Marked + for (int i = 0; i < CHECKBOX_COUNT; i++) { + JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); + checkBox.changeSelection(false); + } + System.out.println("######## Number of Items = " + listOp.getModel().getSize()); + assertEquals("Select None number of items is correct", 0, listOp.getModel().getSize()); - JFrameOperator frame = new JFrameOperator(DEMO_TITLE); - JListOperator listOp = new JListOperator(frame); + // Check *ALL* Prefix and Suffixes Marked + for (int i = 0; i < CHECKBOX_COUNT; i++) { + JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); + checkBox.changeSelection(true); + } + System.out.println("######## Number of Items = " + listOp.getModel().getSize()); + assertEquals("Select All number of items is correct", CHECKBOX_COUNT / 2 * CHECKBOX_COUNT / 2, listOp.getModel().getSize()); - // Check *NO* Prefix and Suffixes Marked - for (int i = 0; i < CHECKBOX_COUNT; i++) { - JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); + // Check *ALL* Prefix and *NO* Suffixes Marked + for (int i = 0; i < CHECKBOX_COUNT; i++) { + JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); + if (i < CHECKBOX_COUNT / 2) { + checkBox.changeSelection(true); + } else { checkBox.changeSelection(false); } - System.out.println("######## Number of Items = " + listOp.getModel().getSize()); - assertEquals("Select None number of items is correct", 0, listOp.getModel().getSize()); + } + System.out.println("######## Number of Items = " + listOp.getModel().getSize()); + assertEquals("Select All Prefixes and NO Suffixes number of items is correct", 0, listOp.getModel().getSize()); - // Check *ALL* Prefix and Suffixes Marked - for (int i = 0; i < CHECKBOX_COUNT; i++) { - JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); + // Check *NO* Prefix and *ALL* Suffixes Marked + for (int i = 0; i < CHECKBOX_COUNT; i++) { + JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); + if (i < CHECKBOX_COUNT / 2) { + checkBox.changeSelection(false); + } else { checkBox.changeSelection(true); } - System.out.println("######## Number of Items = " + listOp.getModel().getSize()); - assertEquals("Select All number of items is correct", CHECKBOX_COUNT / 2 * CHECKBOX_COUNT / 2, listOp.getModel().getSize()); - - // Check *ALL* Prefix and *NO* Suffixes Marked - for (int i = 0; i < CHECKBOX_COUNT; i++) { - JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); - if (i < CHECKBOX_COUNT / 2) { - checkBox.changeSelection(true); - } else { - checkBox.changeSelection(false); - } - } - System.out.println("######## Number of Items = " + listOp.getModel().getSize()); - assertEquals("Select All Prefixes and NO Suffixes number of items is correct", 0, listOp.getModel().getSize()); - - // Check *NO* Prefix and *ALL* Suffixes Marked - for (int i = 0; i < CHECKBOX_COUNT; i++) { - JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); - if (i < CHECKBOX_COUNT / 2) { - checkBox.changeSelection(false); - } else { - checkBox.changeSelection(true); - } - } - System.out.println("######## Number of Items = " + listOp.getModel().getSize()); - assertEquals("Select NO Prefixes and All Suffixes number of items is correct", 0, listOp.getModel().getSize()); - }); + } + System.out.println("######## Number of Items = " + listOp.getModel().getSize()); + assertEquals("Select NO Prefixes and All Suffixes number of items is correct", 0, listOp.getModel().getSize()); } private JCheckBoxOperator getJCheckBoxOperator(JFrameOperator frame, int index) { diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/SwingSet/src/OptionPaneDemoTest.java --- a/jdk/test/sanity/client/SwingSet/src/OptionPaneDemoTest.java Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/test/sanity/client/SwingSet/src/OptionPaneDemoTest.java Wed Apr 27 17:47:17 2016 -0700 @@ -21,10 +21,10 @@ * questions. */ +import org.jtregext.GuiTestListener; import com.sun.swingset3.demos.optionpane.OptionPaneDemo; import static com.sun.swingset3.demos.optionpane.OptionPaneDemo.*; import javax.swing.UIManager; -import static org.jemmy2ext.JemmyExt.*; import static org.testng.AssertJUnit.*; import org.testng.annotations.Test; import org.netbeans.jemmy.ClassReference; @@ -34,6 +34,7 @@ import org.netbeans.jemmy.operators.JFrameOperator; import org.netbeans.jemmy.operators.JLabelOperator; import org.netbeans.jemmy.operators.JTextFieldOperator; +import org.testng.annotations.Listeners; /* @@ -43,12 +44,13 @@ * and choosing different options in them. * * @library /sanity/client/lib/jemmy/src - * @library /sanity/client/lib/Jemmy2Ext/src + * @library /sanity/client/lib/Extensions/src * @library /sanity/client/lib/SwingSet3/src * @build org.jemmy2ext.JemmyExt * @build com.sun.swingset3.demos.optionpane.OptionPaneDemo * @run testng OptionPaneDemoTest */ +@Listeners(GuiTestListener.class) public class OptionPaneDemoTest { public static final String SOME_TEXT_TO_TYPE = "I am some text"; @@ -59,21 +61,20 @@ public static final String TEXT_TO_TYPE = "Hooray! I'm a textField"; public static final String NO = "No"; public static final String YES = "Yes"; - public static final String SELECT_AN__OPTION = UIManager.getString("OptionPane.titleText"); + public static final String SELECT_AN_OPTION = UIManager.getString("OptionPane.titleText"); @Test public void test() throws Exception { - captureDebugInfoOnFail(() -> { - new ClassReference(OptionPaneDemo.class.getCanonicalName()).startApplication(); - JFrameOperator frame = new JFrameOperator(DEMO_TITLE); + new ClassReference(OptionPaneDemo.class.getCanonicalName()).startApplication(); + + JFrameOperator frame = new JFrameOperator(DEMO_TITLE); - showInputDialog(frame); - showWarningDialog(frame); - showMessageDialog(frame); - showComponentDialog(frame); - showConfirmationDialog(frame); - }); + showInputDialog(frame); + showWarningDialog(frame); + showMessageDialog(frame); + showComponentDialog(frame); + showConfirmationDialog(frame); } public void showInputDialog(JFrameOperator jfo) throws Exception { @@ -286,7 +287,7 @@ { new JButtonOperator(jfo, CONFIRM_BUTTON).pushNoBlock(); - JDialogOperator jdo = new JDialogOperator(SELECT_AN__OPTION); + JDialogOperator jdo = new JDialogOperator(SELECT_AN_OPTION); new JButtonOperator(jdo, YES).pushNoBlock(); JDialogOperator jdo1 = new JDialogOperator(MESSAGE); @@ -306,7 +307,7 @@ { new JButtonOperator(jfo, CONFIRM_BUTTON).pushNoBlock(); - JDialogOperator jdo = new JDialogOperator(SELECT_AN__OPTION); + JDialogOperator jdo = new JDialogOperator(SELECT_AN_OPTION); new JButtonOperator(jdo, NO).pushNoBlock(); JDialogOperator jdo1 = new JDialogOperator(MESSAGE); @@ -326,7 +327,7 @@ { new JButtonOperator(jfo, CONFIRM_BUTTON).pushNoBlock(); - JDialogOperator jdo = new JDialogOperator(SELECT_AN__OPTION); + JDialogOperator jdo = new JDialogOperator(SELECT_AN_OPTION); assertTrue("Show Confirmation Dialog Cancel Option", jdo.isShowing()); diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/SwingSet/src/ProgressBarDemoTest.java --- a/jdk/test/sanity/client/SwingSet/src/ProgressBarDemoTest.java Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/test/sanity/client/SwingSet/src/ProgressBarDemoTest.java Wed Apr 27 17:47:17 2016 -0700 @@ -21,6 +21,7 @@ * questions. */ +import org.jtregext.GuiTestListener; import com.sun.swingset3.demos.progressbar.ProgressBarDemo; import static com.sun.swingset3.demos.progressbar.ProgressBarDemo.*; import java.awt.Component; @@ -31,7 +32,7 @@ import org.netbeans.jemmy.operators.JButtonOperator; import org.netbeans.jemmy.operators.JFrameOperator; import org.netbeans.jemmy.operators.JProgressBarOperator; -import static org.jemmy2ext.JemmyExt.captureDebugInfoOnFail; +import org.testng.annotations.Listeners; /* * @test @@ -40,31 +41,31 @@ * buttons and checking the progress bar and the buttons state. * * @library /sanity/client/lib/jemmy/src - * @library /sanity/client/lib/Jemmy2Ext/src + * @library /sanity/client/lib/Extensions/src * @library /sanity/client/lib/SwingSet3/src * @build org.jemmy2ext.JemmyExt * @build com.sun.swingset3.demos.progressbar.ProgressBarDemo * @run testng ProgressBarDemoTest */ +@Listeners(GuiTestListener.class) public class ProgressBarDemoTest { @Test public void test() throws Exception { - captureDebugInfoOnFail(() -> { - new ClassReference(ProgressBarDemo.class.getCanonicalName()).startApplication(); - JFrameOperator frame = new JFrameOperator(DEMO_TITLE); + new ClassReference(ProgressBarDemo.class.getCanonicalName()).startApplication(); + + JFrameOperator frame = new JFrameOperator(DEMO_TITLE); - JButtonOperator startButton = new JButtonOperator(frame, START_BUTTON); - JButtonOperator stopButton = new JButtonOperator(frame, STOP_BUTTON); - JProgressBarOperator jpbo = new JProgressBarOperator(frame); + JButtonOperator startButton = new JButtonOperator(frame, START_BUTTON); + JButtonOperator stopButton = new JButtonOperator(frame, STOP_BUTTON); + JProgressBarOperator jpbo = new JProgressBarOperator(frame); - // Check that progress completes and corect enable/disable of start/stop buttons - checkCompleteProgress(frame, startButton, stopButton, jpbo); + // Check that progress completes and corect enable/disable of start/stop buttons + checkCompleteProgress(frame, startButton, stopButton, jpbo); - // Check progess bar progression and start/stop button disabled/enabled states - checkStartStop(frame, startButton, stopButton, jpbo); - }); + // Check progess bar progression and start/stop button disabled/enabled states + checkStartStop(frame, startButton, stopButton, jpbo); } // Check that progress completes and corect enable/disable of start/stop buttons diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/SwingSet/src/ScrollPaneDemoTest.java --- a/jdk/test/sanity/client/SwingSet/src/ScrollPaneDemoTest.java Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/test/sanity/client/SwingSet/src/ScrollPaneDemoTest.java Wed Apr 27 17:47:17 2016 -0700 @@ -21,6 +21,7 @@ * questions. */ +import org.jtregext.GuiTestListener; import com.sun.swingset3.demos.scrollpane.ScrollPaneDemo; import static com.sun.swingset3.demos.scrollpane.ScrollPaneDemo.DEMO_TITLE; import static org.testng.AssertJUnit.*; @@ -28,7 +29,7 @@ import org.netbeans.jemmy.ClassReference; import org.netbeans.jemmy.operators.JFrameOperator; import org.netbeans.jemmy.operators.JScrollPaneOperator; -import static org.jemmy2ext.JemmyExt.captureDebugInfoOnFail; +import org.testng.annotations.Listeners; /* * @test @@ -37,73 +38,73 @@ * to left and to right and checking scroll bar values. * * @library /sanity/client/lib/jemmy/src - * @library /sanity/client/lib/Jemmy2Ext/src + * @library /sanity/client/lib/Extensions/src * @library /sanity/client/lib/SwingSet3/src * @build org.jemmy2ext.JemmyExt * @build com.sun.swingset3.demos.scrollpane.ScrollPaneDemo * @run testng ScrollPaneDemoTest */ +@Listeners(GuiTestListener.class) public class ScrollPaneDemoTest { @Test public void test() throws Exception { - captureDebugInfoOnFail(() -> { - new ClassReference(ScrollPaneDemo.class.getName()).startApplication(); + + new ClassReference(ScrollPaneDemo.class.getName()).startApplication(); - JFrameOperator frame = new JFrameOperator(DEMO_TITLE); - JScrollPaneOperator jspo = new JScrollPaneOperator(frame); + JFrameOperator frame = new JFrameOperator(DEMO_TITLE); + JScrollPaneOperator jspo = new JScrollPaneOperator(frame); - // Set initial scrollbar positions - int initialVerticalValue = jspo.getVerticalScrollBar().getValue(); - int initialHorizontalValue = jspo.getHorizontalScrollBar().getValue(); + // Set initial scrollbar positions + int initialVerticalValue = jspo.getVerticalScrollBar().getValue(); + int initialHorizontalValue = jspo.getHorizontalScrollBar().getValue(); - System.out.println("Initial Vertical Value = " + jspo.getVerticalScrollBar().getValue()); - System.out.println("Initial HoriZontal Value = " + jspo.getHorizontalScrollBar().getValue()); + System.out.println("Initial Vertical Value = " + jspo.getVerticalScrollBar().getValue()); + System.out.println("Initial HoriZontal Value = " + jspo.getHorizontalScrollBar().getValue()); - // Check scroll to Bottom - { - jspo.scrollToBottom(); - int currentValue = jspo.getVerticalScrollBar().getValue(); - System.out.println("Final Value = " + currentValue); - assertTrue("Scroll to Bottom of Pane " - + "(initialVerticalValue, actual value: " + initialVerticalValue + " " - + "< currentValue, actual value = " + currentValue + ")", - initialVerticalValue < currentValue); - } + // Check scroll to Bottom + { + jspo.scrollToBottom(); + int currentValue = jspo.getVerticalScrollBar().getValue(); + System.out.println("Final Value = " + currentValue); + assertTrue("Scroll to Bottom of Pane " + + "(initialVerticalValue, actual value: " + initialVerticalValue + " " + + "< currentValue, actual value = " + currentValue + ")", + initialVerticalValue < currentValue); + } - // Check scroll to Top - { - jspo.scrollToTop(); - int currentValue = jspo.getVerticalScrollBar().getValue(); - System.out.println("Top Scroll Final Value = " + currentValue); - assertTrue("Scroll to Top of Pane " - + "(initialVerticalValue, actual value: " + initialVerticalValue + " " - + "> currentValue, actual value = " + currentValue + ")", - initialVerticalValue > currentValue); - } + // Check scroll to Top + { + jspo.scrollToTop(); + int currentValue = jspo.getVerticalScrollBar().getValue(); + System.out.println("Top Scroll Final Value = " + currentValue); + assertTrue("Scroll to Top of Pane " + + "(initialVerticalValue, actual value: " + initialVerticalValue + " " + + "> currentValue, actual value = " + currentValue + ")", + initialVerticalValue > currentValue); + } - // Check scroll to Left - { - jspo.scrollToLeft(); - int currentValue = jspo.getHorizontalScrollBar().getValue(); - System.out.println("Scroll to Left Final Value = " + currentValue); - assertTrue("Scroll to Left of Pane " - + "(initialHorizontalValue, actual value: " + initialHorizontalValue + " " - + "> currentValue, actual value = " + currentValue + ")", - initialHorizontalValue > currentValue); - } + // Check scroll to Left + { + jspo.scrollToLeft(); + int currentValue = jspo.getHorizontalScrollBar().getValue(); + System.out.println("Scroll to Left Final Value = " + currentValue); + assertTrue("Scroll to Left of Pane " + + "(initialHorizontalValue, actual value: " + initialHorizontalValue + " " + + "> currentValue, actual value = " + currentValue + ")", + initialHorizontalValue > currentValue); + } - // Check scroll to Right - { - jspo.scrollToRight(); - int currentValue = jspo.getHorizontalScrollBar().getValue(); - System.out.println("Scroll to Right Final Value = " + currentValue); - assertTrue("Scroll to Right of Pane " - + "(initialHorizontalValue, actual value: " + initialHorizontalValue + " " - + "< currentValue, actual value = " + currentValue + ")", - initialHorizontalValue < currentValue); - } - }); + // Check scroll to Right + { + jspo.scrollToRight(); + int currentValue = jspo.getHorizontalScrollBar().getValue(); + System.out.println("Scroll to Right Final Value = " + currentValue); + assertTrue("Scroll to Right of Pane " + + "(initialHorizontalValue, actual value: " + initialHorizontalValue + " " + + "< currentValue, actual value = " + currentValue + ")", + initialHorizontalValue < currentValue); + } } } diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/SwingSet/src/SpinnerDemoTest.java --- a/jdk/test/sanity/client/SwingSet/src/SpinnerDemoTest.java Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/test/sanity/client/SwingSet/src/SpinnerDemoTest.java Wed Apr 27 17:47:17 2016 -0700 @@ -21,6 +21,7 @@ * questions. */ +import org.jtregext.GuiTestListener; import com.sun.swingset3.demos.spinner.SpinnerDemo; import static com.sun.swingset3.demos.spinner.SpinnerDemo.DEMO_TITLE; import java.text.DecimalFormat; @@ -30,7 +31,7 @@ import org.netbeans.jemmy.operators.JFrameOperator; import org.netbeans.jemmy.operators.JSpinnerOperator; import org.netbeans.jemmy.operators.JTextFieldOperator; -import static org.jemmy2ext.JemmyExt.captureDebugInfoOnFail; +import org.testng.annotations.Listeners; /* * @test @@ -39,12 +40,13 @@ * the spinner button and checking text field value. * * @library /sanity/client/lib/jemmy/src - * @library /sanity/client/lib/Jemmy2Ext/src + * @library /sanity/client/lib/Extensions/src * @library /sanity/client/lib/SwingSet3/src * @build org.jemmy2ext.JemmyExt * @build com.sun.swingset3.demos.spinner.SpinnerDemo * @run testng SpinnerDemoTest */ +@Listeners(GuiTestListener.class) public class SpinnerDemoTest { private static final int SPINNERS_COUNT = 9; @@ -52,16 +54,14 @@ @Test public void test() throws Exception { - captureDebugInfoOnFail(() -> { - new ClassReference(SpinnerDemo.class.getCanonicalName()).startApplication(); + new ClassReference(SpinnerDemo.class.getCanonicalName()).startApplication(); - JFrameOperator frame = new JFrameOperator(DEMO_TITLE); + JFrameOperator frame = new JFrameOperator(DEMO_TITLE); - // Check changing different spinners - for (int i = 0; i < SPINNERS_COUNT; i++) { - changeValues(frame, i); - } - }); + // Check changing different spinners + for (int i = 0; i < SPINNERS_COUNT; i++) { + changeValues(frame, i); + } } private void changeValues(JFrameOperator jfo, int spinnerIndex) throws Exception { diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/SwingSet/src/SplitPaneDemoTest.java --- a/jdk/test/sanity/client/SwingSet/src/SplitPaneDemoTest.java Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/test/sanity/client/SwingSet/src/SplitPaneDemoTest.java Wed Apr 27 17:47:17 2016 -0700 @@ -21,6 +21,7 @@ * questions. */ +import org.jtregext.GuiTestListener; import com.sun.swingset3.demos.splitpane.SplitPaneDemo; import static com.sun.swingset3.demos.splitpane.SplitPaneDemo.*; import java.awt.event.KeyEvent; @@ -35,6 +36,7 @@ import org.netbeans.jemmy.operators.JSplitPaneOperator; import org.netbeans.jemmy.operators.JTextFieldOperator; import static org.jemmy2ext.JemmyExt.*; +import org.testng.annotations.Listeners; /* * @test @@ -44,39 +46,39 @@ * and changing the divider orientation. * * @library /sanity/client/lib/jemmy/src - * @library /sanity/client/lib/Jemmy2Ext/src + * @library /sanity/client/lib/Extensions/src * @library /sanity/client/lib/SwingSet3/src * @build org.jemmy2ext.JemmyExt * @build com.sun.swingset3.demos.splitpane.SplitPaneDemo * @run testng SplitPaneDemoTest */ +@Listeners(GuiTestListener.class) public class SplitPaneDemoTest { @Test public void test() throws Exception { - captureDebugInfoOnFail(() -> { - new ClassReference(SplitPaneDemo.class.getCanonicalName()).startApplication(); - JFrameOperator frame = new JFrameOperator(DEMO_TITLE); + new ClassReference(SplitPaneDemo.class.getCanonicalName()).startApplication(); + + JFrameOperator frame = new JFrameOperator(DEMO_TITLE); - JSplitPaneOperator splitPane = new JSplitPaneOperator(frame); + JSplitPaneOperator splitPane = new JSplitPaneOperator(frame); - // Toggle OneTouch Expandable - checkOneTouch(frame, splitPane, true); - checkOneTouch(frame, splitPane, false); + // Toggle OneTouch Expandable + checkOneTouch(frame, splitPane, true); + checkOneTouch(frame, splitPane, false); - // Check changing divider size to minimum and maximum values - changeDividerSize(frame, splitPane, 50); - changeDividerSize(frame, splitPane, 6); + // Check changing divider size to minimum and maximum values + changeDividerSize(frame, splitPane, 50); + changeDividerSize(frame, splitPane, 6); - // Check moving the divider - checkDividerMoves(frame, splitPane, false); - checkDividerMoves(frame, splitPane, true); + // Check moving the divider + checkDividerMoves(frame, splitPane, false); + checkDividerMoves(frame, splitPane, true); - // Check different minumum Day/Night sizes - changeMinimumSizes(frame, splitPane, 100); - changeMinimumSizes(frame, splitPane, 0); - }); + // Check different minumum Day/Night sizes + changeMinimumSizes(frame, splitPane, 100); + changeMinimumSizes(frame, splitPane, 0); } // Check for different day and night minimum size diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/SwingSet/src/TabbedPaneDemoTest.java --- a/jdk/test/sanity/client/SwingSet/src/TabbedPaneDemoTest.java Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/test/sanity/client/SwingSet/src/TabbedPaneDemoTest.java Wed Apr 27 17:47:17 2016 -0700 @@ -21,6 +21,7 @@ * questions. */ +import org.jtregext.GuiTestListener; import com.sun.swingset3.demos.tabbedpane.TabbedPaneDemo; import static com.sun.swingset3.demos.tabbedpane.TabbedPaneDemo.*; import static org.jemmy2ext.JemmyExt.getLabeledContainerOperator; @@ -31,7 +32,7 @@ import org.netbeans.jemmy.operators.JFrameOperator; import org.netbeans.jemmy.operators.JRadioButtonOperator; import org.netbeans.jemmy.operators.JTabbedPaneOperator; -import static org.jemmy2ext.JemmyExt.captureDebugInfoOnFail; +import org.testng.annotations.Listeners; /* * @test @@ -40,25 +41,24 @@ * positions, opening each tab and verifying the the tab gets selected. * * @library /sanity/client/lib/jemmy/src - * @library /sanity/client/lib/Jemmy2Ext/src + * @library /sanity/client/lib/Extensions/src * @library /sanity/client/lib/SwingSet3/src * @build org.jemmy2ext.JemmyExt * @build com.sun.swingset3.demos.tabbedpane.TabbedPaneDemo * @run testng TabbedPaneDemoTest */ +@Listeners(GuiTestListener.class) public class TabbedPaneDemoTest { @Test public void test() throws Exception { - captureDebugInfoOnFail(() -> { - new ClassReference(TabbedPaneDemo.class.getCanonicalName()).startApplication(); + new ClassReference(TabbedPaneDemo.class.getCanonicalName()).startApplication(); - JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE); + JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE); - for (String tp : new String[]{TOP, LEFT, BOTTOM, RIGHT}) { - testTabs(mainFrame, tp); - } - }); + for (String tp : new String[]{TOP, LEFT, BOTTOM, RIGHT}) { + testTabs(mainFrame, tp); + } } public void testTabs(JFrameOperator mainFrame, String tabPlacement) throws Exception { diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/SwingSet/src/TextFieldDemoTest.java --- a/jdk/test/sanity/client/SwingSet/src/TextFieldDemoTest.java Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/test/sanity/client/SwingSet/src/TextFieldDemoTest.java Wed Apr 27 17:47:17 2016 -0700 @@ -21,6 +21,7 @@ * questions. */ +import org.jtregext.GuiTestListener; import com.sun.swingset3.demos.textfield.JHistoryTextField; import com.sun.swingset3.demos.textfield.TextFieldDemo; import static com.sun.swingset3.demos.textfield.TextFieldDemo.*; @@ -41,6 +42,7 @@ import org.netbeans.jemmy.operators.JLabelOperator; import org.netbeans.jemmy.operators.JPasswordFieldOperator; import org.netbeans.jemmy.operators.JTextFieldOperator; +import org.testng.annotations.Listeners; /* * @test @@ -49,25 +51,25 @@ * checking that app reacts accordingly. * * @library /sanity/client/lib/jemmy/src - * @library /sanity/client/lib/Jemmy2Ext/src + * @library /sanity/client/lib/Extensions/src * @library /sanity/client/lib/SwingSet3/src * @build org.jemmy2ext.JemmyExt * @build com.sun.swingset3.demos.textfield.TextFieldDemo * @run testng TextFieldDemoTest */ +@Listeners(GuiTestListener.class) public class TextFieldDemoTest { @Test public void test() throws Exception { - captureDebugInfoOnFail(() -> { - new ClassReference(TextFieldDemo.class.getCanonicalName()).startApplication(); - JFrameOperator frame = new JFrameOperator(DEMO_TITLE); + new ClassReference(TextFieldDemo.class.getCanonicalName()).startApplication(); - historyTextField(frame); - dateTextField(frame); - passwordField(frame); - }); + JFrameOperator frame = new JFrameOperator(DEMO_TITLE); + + historyTextField(frame); + dateTextField(frame); + passwordField(frame); } private void historyTextField(JFrameOperator jfo) throws Exception { diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/SwingSet/src/ToggleButtonDemoTest.java --- a/jdk/test/sanity/client/SwingSet/src/ToggleButtonDemoTest.java Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/test/sanity/client/SwingSet/src/ToggleButtonDemoTest.java Wed Apr 27 17:47:17 2016 -0700 @@ -21,6 +21,7 @@ * questions. */ +import org.jtregext.GuiTestListener; import com.sun.swingset3.DemoProperties; import com.sun.swingset3.demos.togglebutton.DirectionPanel; import com.sun.swingset3.demos.togglebutton.LayoutControlPanel; @@ -40,7 +41,7 @@ import org.netbeans.jemmy.operators.JFrameOperator; import org.netbeans.jemmy.operators.JRadioButtonOperator; import org.netbeans.jemmy.operators.JTabbedPaneOperator; -import static org.jemmy2ext.JemmyExt.captureDebugInfoOnFail; +import org.testng.annotations.Listeners; /* * @test @@ -53,50 +54,49 @@ * selected. * * @library /sanity/client/lib/jemmy/src - * @library /sanity/client/lib/Jemmy2Ext/src + * @library /sanity/client/lib/Extensions/src * @library /sanity/client/lib/SwingSet3/src * @build org.jemmy2ext.JemmyExt * @build com.sun.swingset3.demos.togglebutton.ToggleButtonDemo * @run testng ToggleButtonDemoTest */ +@Listeners(GuiTestListener.class) public class ToggleButtonDemoTest { @Test public void test() throws Exception { - captureDebugInfoOnFail(() -> { - new ClassReference(ToggleButtonDemo.class.getCanonicalName()).startApplication(); + new ClassReference(ToggleButtonDemo.class.getCanonicalName()).startApplication(); - JFrameOperator mainFrame = new JFrameOperator(ToggleButtonDemo.class.getAnnotation(DemoProperties.class).value()); - JTabbedPaneOperator tabPane = new JTabbedPaneOperator(mainFrame); + JFrameOperator mainFrame = new JFrameOperator(ToggleButtonDemo.class.getAnnotation(DemoProperties.class).value()); + JTabbedPaneOperator tabPane = new JTabbedPaneOperator(mainFrame); - // Radio Button Toggles - testRadioButtons(getBorderTitledJPanelOperator(mainFrame, TEXT_RADIO_BUTTONS), 3, null); - testRadioButtons(getBorderTitledJPanelOperator(mainFrame, IMAGE_RADIO_BUTTONS), 3, null); - testRadioButtons(getLabeledContainerOperator(mainFrame, PAD_AMOUNT), 3, (t, i) -> DEFAULT.equals(t)); + // Radio Button Toggles + testRadioButtons(getBorderTitledJPanelOperator(mainFrame, TEXT_RADIO_BUTTONS), 3, null); + testRadioButtons(getBorderTitledJPanelOperator(mainFrame, IMAGE_RADIO_BUTTONS), 3, null); + testRadioButtons(getLabeledContainerOperator(mainFrame, PAD_AMOUNT), 3, (t, i) -> DEFAULT.equals(t)); - // switch to the Check Boxes Tab - tabPane.selectPage(CHECK_BOXES); + // switch to the Check Boxes Tab + tabPane.selectPage(CHECK_BOXES); - // Check Box Toggles - ContainerOperator textCheckBoxesJPanel = getBorderTitledJPanelOperator(mainFrame, TEXT_CHECKBOXES); - testCheckBox(textCheckBoxesJPanel, CHECK1, false); - testCheckBox(textCheckBoxesJPanel, CHECK2, false); - testCheckBox(textCheckBoxesJPanel, CHECK3, false); + // Check Box Toggles + ContainerOperator textCheckBoxesJPanel = getBorderTitledJPanelOperator(mainFrame, TEXT_CHECKBOXES); + testCheckBox(textCheckBoxesJPanel, CHECK1, false); + testCheckBox(textCheckBoxesJPanel, CHECK2, false); + testCheckBox(textCheckBoxesJPanel, CHECK3, false); - ContainerOperator imageCheckBoxesJPanel = getBorderTitledJPanelOperator(mainFrame, IMAGE_CHECKBOXES); - testCheckBox(imageCheckBoxesJPanel, CHECK1, false); - testCheckBox(imageCheckBoxesJPanel, CHECK2, false); - testCheckBox(imageCheckBoxesJPanel, CHECK3, false); + ContainerOperator imageCheckBoxesJPanel = getBorderTitledJPanelOperator(mainFrame, IMAGE_CHECKBOXES); + testCheckBox(imageCheckBoxesJPanel, CHECK1, false); + testCheckBox(imageCheckBoxesJPanel, CHECK2, false); + testCheckBox(imageCheckBoxesJPanel, CHECK3, false); - ContainerOperator displayOptionsContainer = getLabeledContainerOperator(mainFrame, DISPLAY_OPTIONS); - testCheckBox(displayOptionsContainer, PAINT_BORDER, false); - testCheckBox(displayOptionsContainer, PAINT_FOCUS, true); - testCheckBox(displayOptionsContainer, ENABLED, true); - testCheckBox(displayOptionsContainer, CONTENT_FILLED, true); + ContainerOperator displayOptionsContainer = getLabeledContainerOperator(mainFrame, DISPLAY_OPTIONS); + testCheckBox(displayOptionsContainer, PAINT_BORDER, false); + testCheckBox(displayOptionsContainer, PAINT_FOCUS, true); + testCheckBox(displayOptionsContainer, ENABLED, true); + testCheckBox(displayOptionsContainer, CONTENT_FILLED, true); - // Direction Button Toggles - testToggleButtons(mainFrame); - }); + // Direction Button Toggles + testToggleButtons(mainFrame); } /** diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/SwingSet/src/TreeDemoTest.java --- a/jdk/test/sanity/client/SwingSet/src/TreeDemoTest.java Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/test/sanity/client/SwingSet/src/TreeDemoTest.java Wed Apr 27 17:47:17 2016 -0700 @@ -21,6 +21,7 @@ * questions. */ +import org.jtregext.GuiTestListener; import com.sun.swingset3.demos.tree.TreeDemo; import static com.sun.swingset3.demos.tree.TreeDemo.DEMO_TITLE; import javax.swing.tree.TreePath; @@ -29,7 +30,7 @@ import org.netbeans.jemmy.ClassReference; import org.netbeans.jemmy.operators.JFrameOperator; import org.netbeans.jemmy.operators.JTreeOperator; -import static org.jemmy2ext.JemmyExt.captureDebugInfoOnFail; +import org.testng.annotations.Listeners; /* * @test @@ -42,67 +43,67 @@ * vertically (as ScrollPane allows it). * * @library /sanity/client/lib/jemmy/src - * @library /sanity/client/lib/Jemmy2Ext/src + * @library /sanity/client/lib/Extensions/src * @library /sanity/client/lib/SwingSet3/src * @build org.jemmy2ext.JemmyExt * @build com.sun.swingset3.demos.tree.TreeDemo * @run testng TreeDemoTest */ +@Listeners(GuiTestListener.class) public class TreeDemoTest { @Test public void test() throws Exception { - captureDebugInfoOnFail(() -> { - new ClassReference(TreeDemo.class.getCanonicalName()).startApplication(); - JFrameOperator frame = new JFrameOperator(DEMO_TITLE); + new ClassReference(TreeDemo.class.getCanonicalName()).startApplication(); + + JFrameOperator frame = new JFrameOperator(DEMO_TITLE); - JTreeOperator tree = new JTreeOperator(frame); + JTreeOperator tree = new JTreeOperator(frame); - assertEquals("Initial number of rows in the tree", 4, tree.getRowCount()); + assertEquals("Initial number of rows in the tree", 4, tree.getRowCount()); - int initialTreeHeight = tree.getHeight(); + int initialTreeHeight = tree.getHeight(); - // expand all nodes - int expandsCount = 0; - for (int i = 0; i < tree.getRowCount(); i++) { - TreePath tp = tree.getPathForRow(i); - if (tree.getChildCount(tp) > 0 && !tree.isExpanded(tp)) { - tree.expandRow(i); - expandsCount++; - } + // expand all nodes + int expandsCount = 0; + for (int i = 0; i < tree.getRowCount(); i++) { + TreePath tp = tree.getPathForRow(i); + if (tree.getChildCount(tp) > 0 && !tree.isExpanded(tp)) { + tree.expandRow(i); + expandsCount++; } + } - assertEquals("Number of rows expanded", 75, expandsCount); - assertEquals("Number of rows in the tree after expanding all of them", - 616, tree.getRowCount()); + assertEquals("Number of rows expanded", 75, expandsCount); + assertEquals("Number of rows in the tree after expanding all of them", + 616, tree.getRowCount()); - int expandedTreeHeight = tree.getHeight(); - assertTrue("Expanded tree height has increased, current " - + expandedTreeHeight + " > initial " + initialTreeHeight, - expandedTreeHeight > initialTreeHeight); + int expandedTreeHeight = tree.getHeight(); + assertTrue("Expanded tree height has increased, current " + + expandedTreeHeight + " > initial " + initialTreeHeight, + expandedTreeHeight > initialTreeHeight); - // collapse all nodes - int collapsesCount = 0; - for (int i = tree.getRowCount() - 1; i >= 0; i--) { - TreePath tp = tree.getPathForRow(i); - if (tree.getChildCount(tp) > 0 && tree.isExpanded(tp)) { - tree.collapseRow(i); - collapsesCount++; - } + // collapse all nodes + int collapsesCount = 0; + for (int i = tree.getRowCount() - 1; i >= 0; i--) { + TreePath tp = tree.getPathForRow(i); + if (tree.getChildCount(tp) > 0 && tree.isExpanded(tp)) { + tree.collapseRow(i); + collapsesCount++; } + } - assertEquals("Number of rows collapsed", 76, collapsesCount); - assertEquals("Number of rows in the tree after collapsing all of them", - 1, tree.getRowCount()); + assertEquals("Number of rows collapsed", 76, collapsesCount); + assertEquals("Number of rows in the tree after collapsing all of them", + 1, tree.getRowCount()); - int collapsedTreeHeight = tree.getHeight(); - assertTrue("Collpased tree height is not longer than initial, " - + "current " + collapsedTreeHeight + " <= initial " - + initialTreeHeight, - collapsedTreeHeight <= initialTreeHeight); + int collapsedTreeHeight = tree.getHeight(); + assertTrue("Collpased tree height is not longer than initial, " + + "current " + collapsedTreeHeight + " <= initial " + + initialTreeHeight, + collapsedTreeHeight <= initialTreeHeight); - }); } } diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/SwingSet/src/WindowDemoTest.java --- a/jdk/test/sanity/client/SwingSet/src/WindowDemoTest.java Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/test/sanity/client/SwingSet/src/WindowDemoTest.java Wed Apr 27 17:47:17 2016 -0700 @@ -21,6 +21,7 @@ * questions. */ +import org.jtregext.GuiTestListener; import com.sun.swingset3.demos.window.WindowDemo; import static com.sun.swingset3.demos.window.WindowDemo.*; import static org.jemmy2ext.JemmyExt.*; @@ -31,6 +32,7 @@ import org.netbeans.jemmy.operators.JFrameOperator; import org.netbeans.jemmy.operators.JLabelOperator; import org.netbeans.jemmy.operators.WindowOperator; +import org.testng.annotations.Listeners; /* * @test @@ -40,37 +42,37 @@ * when the "Show JWindow..." button is clicked. * * @library /sanity/client/lib/jemmy/src - * @library /sanity/client/lib/Jemmy2Ext/src + * @library /sanity/client/lib/Extensions/src * @library /sanity/client/lib/SwingSet3/src * @build org.jemmy2ext.JemmyExt * @build com.sun.swingset3.demos.window.WindowDemo * @run testng WindowDemoTest */ +@Listeners(GuiTestListener.class) public class WindowDemoTest { @Test public void test() throws Exception { - captureDebugInfoOnFail(() -> { - new ClassReference(WindowDemo.class.getCanonicalName()).startApplication(); + + new ClassReference(WindowDemo.class.getCanonicalName()).startApplication(); - JFrameOperator frame = new JFrameOperator(); + JFrameOperator frame = new JFrameOperator(); - assertEquals("Only one JWindow is shown", 1, getJWindowCount()); + assertEquals("Only one JWindow is shown", 1, getJWindowCount()); - WindowOperator window = new WindowOperator(getJWindow()); + WindowOperator window = new WindowOperator(getJWindow()); - assertTrue("JFrame is showing", frame.isShowing()); - assertFalse("JFrame is not iconified", isIconified(frame)); - assertTrue("JWindow is showing", window.isShowing()); + assertTrue("JFrame is showing", frame.isShowing()); + assertFalse("JFrame is not iconified", isIconified(frame)); + assertTrue("JWindow is showing", window.isShowing()); - final String labelText = I_HAVE_NO_SYSTEM_BORDER; - JLabelOperator jLabelOperator = new JLabelOperator(window, labelText); - assertEquals("JWindow contains the label with corresponding text", labelText, jLabelOperator.getText()); + final String labelText = I_HAVE_NO_SYSTEM_BORDER; + JLabelOperator jLabelOperator = new JLabelOperator(window, labelText); + assertEquals("JWindow contains the label with corresponding text", labelText, jLabelOperator.getText()); - new JButtonOperator(frame, SHOW_J_WINDOW).push(); + new JButtonOperator(frame, SHOW_J_WINDOW).push(); - assertEquals("Only one JWindow is shown", 1, getJWindowCount()); - }); + assertEquals("Only one JWindow is shown", 1, getJWindowCount()); } } diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/lib/Extensions/src/org/jemmy2ext/JemmyExt.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sanity/client/lib/Extensions/src/org/jemmy2ext/JemmyExt.java Wed Apr 27 17:47:17 2016 -0700 @@ -0,0 +1,613 @@ +/* + * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.jemmy2ext; + +import java.awt.Component; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.Window; +import java.awt.image.BufferedImage; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.function.Function; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.IntStream; +import javax.imageio.ImageIO; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JWindow; +import javax.swing.border.Border; +import javax.swing.border.CompoundBorder; +import javax.swing.border.TitledBorder; +import org.netbeans.jemmy.ComponentChooser; +import org.netbeans.jemmy.DefaultCharBindingMap; +import org.netbeans.jemmy.QueueTool; +import org.netbeans.jemmy.TimeoutExpiredException; +import org.netbeans.jemmy.Waitable; +import org.netbeans.jemmy.Waiter; +import org.netbeans.jemmy.drivers.scrolling.JSpinnerDriver; +import org.netbeans.jemmy.image.StrictImageComparator; +import org.netbeans.jemmy.operators.ComponentOperator; +import org.netbeans.jemmy.operators.ContainerOperator; +import org.netbeans.jemmy.operators.FrameOperator; +import org.netbeans.jemmy.operators.JButtonOperator; +import org.netbeans.jemmy.operators.JFrameOperator; +import org.netbeans.jemmy.operators.JLabelOperator; +import org.netbeans.jemmy.operators.Operator; +import org.netbeans.jemmy.util.Dumper; +import org.netbeans.jemmy.util.PNGEncoder; +import static org.testng.AssertJUnit.*; + +/** + * This class solves two tasks: 1. It adds functionality that is missing in + * Jemmy 2. It references all the Jemmy API that is needed by tests so that they + * can just @build JemmyExt class and do not worry about Jemmy + * + * @author akouznet + */ +public class JemmyExt { + + /** + * Statically referencing all the classes that are needed by tests so that + * they're compiled by jtreg + */ + static final Class[] DEPENDENCIES = { + JSpinnerDriver.class, + DefaultCharBindingMap.class + }; + + public static void assertNotBlack(BufferedImage image) { + int w = image.getWidth(); + int h = image.getHeight(); + try { + assertFalse("All pixels are not black", IntStream.range(0, w).parallel().allMatch(x + -> IntStream.range(0, h).allMatch(y -> (image.getRGB(x, y) & 0xffffff) == 0) + )); + } catch (Throwable t) { + save(image, "allPixelsAreBlack.png"); + throw t; + } + } + + public static void waitArmed(JButtonOperator button) { + button.waitState(new ComponentChooser() { + + @Override + public boolean checkComponent(Component comp) { + return isArmed(button); + } + + @Override + public String getDescription() { + return "Button is armed"; + } + }); + } + + public static boolean isArmed(JButtonOperator button) { + return button.getQueueTool().invokeSmoothly(new QueueTool.QueueAction("getModel().isArmed()") { + + @Override + public Boolean launch() throws Exception { + return ((JButton) button.getSource()).getModel().isArmed(); + } + }); + } + + public static void waitPressed(JButtonOperator button) { + button.waitState(new ComponentChooser() { + + @Override + public boolean checkComponent(Component comp) { + return isPressed(button); + } + + @Override + public String getDescription() { + return "Button is pressed"; + } + }); + } + + public static boolean isPressed(JButtonOperator button) { + return button.getQueueTool().invokeSmoothly(new QueueTool.QueueAction("getModel().isPressed()") { + + @Override + public Boolean launch() throws Exception { + return ((JButton) button.getSource()).getModel().isPressed(); + } + }); + } + + public static void assertEquals(String string, StrictImageComparator comparator, BufferedImage expected, BufferedImage actual) { + try { + assertTrue(string, comparator.compare(expected, actual)); + } catch (Error err) { + save(expected, "expected.png"); + save(actual, "actual.png"); + throw err; + } + } + + public static void assertNotEquals(String string, StrictImageComparator comparator, BufferedImage notExpected, BufferedImage actual) { + try { + assertFalse(string, comparator.compare(notExpected, actual)); + } catch (Error err) { + save(notExpected, "notExpected.png"); + save(actual, "actual.png"); + throw err; + } + } + + public static void save(BufferedImage image, String filename) { + String filepath = filename; + try { + filepath = new File(filename).getCanonicalPath(); + System.out.println("Saving screenshot to " + filepath); + BufferedOutputStream file = new BufferedOutputStream(new FileOutputStream(filepath)); + new PNGEncoder(file, PNGEncoder.COLOR_MODE).encode(image); + } catch (IOException ioe) { + throw new RuntimeException("Failed to save image to " + filepath, ioe); + } + } + + public static void waitImageIsStill(Robot rob, ComponentOperator operator) { + operator.waitState(new ComponentChooser() { + + private BufferedImage previousImage = null; + private int index = 0; + private final StrictImageComparator sComparator = new StrictImageComparator(); + + @Override + public boolean checkComponent(Component comp) { + BufferedImage currentImage = capture(rob, operator); + save(currentImage, "waitImageIsStill" + index + ".png"); + index++; + boolean compareResult = previousImage == null ? false : sComparator.compare(currentImage, previousImage); + previousImage = currentImage; + return compareResult; + } + + @Override + public String getDescription() { + return "Image of " + operator + " is still"; + } + }); + } + + private static class ThrowableHolder { + + volatile Throwable t; + } + + public static void waitFor(String description, RunnableWithException r) throws Exception { + Waiter waiter = new Waiter<>(new Waitable() { + + @Override + public Boolean actionProduced(ThrowableHolder obj) { + try { + r.run(); + return true; + } catch (Throwable t) { + obj.t = t; + return null; + } + } + + @Override + public String getDescription() { + return description; + } + }); + ThrowableHolder th = new ThrowableHolder(); + try { + waiter.waitAction(th); + } catch (TimeoutExpiredException tee) { + Throwable t = th.t; + if (t != null) { + t.addSuppressed(tee); + if (t instanceof Exception) { + throw (Exception) t; + } else if (t instanceof Error) { + throw (Error) t; + } else if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } else { + throw new IllegalStateException("Unexpected exception type", t); + } + } + } + } + + public static BufferedImage capture(Robot rob, ComponentOperator operator) { + Rectangle boundary = new Rectangle(operator.getLocationOnScreen(), + operator.getSize()); + return rob.createScreenCapture(boundary); + } + + /** + * Dispose all AWT/Swing windows causing event thread to stop + */ + public static void disposeAllWindows() { + System.out.println("disposeAllWindows"); + try { + EventQueue.invokeAndWait(() -> { + Window[] windows = Window.getWindows(); + for (Window w : windows) { + w.dispose(); + } + }); + } catch (InterruptedException | InvocationTargetException ex) { + Logger.getLogger(JemmyExt.class.getName()).log(Level.SEVERE, "Failed to dispose all windows", ex); + } + } + + /** + * This is a helper class which allows to catch throwables thrown in other + * threads and throw them in the main test thread + */ + public static class MultiThreadedTryCatch { + + private final List throwables + = Collections.synchronizedList(new ArrayList<>()); + + /** + * Throws registered throwables. If the list of the registered + * throwables is not empty, it re-throws the first throwable in the list + * adding all others into its suppressed list. Can be used in any + * thread. + * + * @throws Exception + */ + public void throwRegistered() throws Exception { + Throwable root = null; + synchronized (throwables) { + if (!throwables.isEmpty()) { + root = throwables.remove(0); + while (!throwables.isEmpty()) { + root.addSuppressed(throwables.remove(0)); + } + } + } + if (root != null) { + if (root instanceof Error) { + throw (Error) root; + } else if (root instanceof Exception) { + throw (Exception) root; + } else { + throw new AssertionError("Unexpected exception type: " + root.getClass() + " (" + root + ")"); + } + } + } + + /** + * Registers a throwable and adds it to the list of throwables. Can be + * used in any thread. + * + * @param t + */ + public void register(Throwable t) { + t.printStackTrace(); + throwables.add(t); + } + + /** + * Registers a throwable and adds it as the first item of the list of + * catched throwables. + * + * @param t + */ + public void registerRoot(Throwable t) { + t.printStackTrace(); + throwables.add(0, t); + } + } + + /** + * Trying to capture as much information as possible. Currently it includes + * full dump and a screenshot of the whole screen. + */ + public static void captureAll() { + PNGEncoder.captureScreen("failure.png", PNGEncoder.COLOR_MODE); + try { + Dumper.dumpAll("dumpAll.xml"); + } catch (FileNotFoundException ex) { + Logger.getLogger(JemmyExt.class.getName()).log(Level.SEVERE, null, ex); + } + captureWindows(); + } + + /** + * Captures each showing window image using Window.paint() method. + */ + private static void captureWindows() { + try { + EventQueue.invokeAndWait(() -> { + Window[] windows = Window.getWindows(); + int index = 0; + for (Window w : windows) { + if (!w.isShowing()) { + continue; + } + BufferedImage img = new BufferedImage(w.getWidth(), w.getHeight(), BufferedImage.TYPE_INT_ARGB); + Graphics g = img.getGraphics(); + w.paint(g); + g.dispose(); + + try { + ImageIO.write(img, "png", new File("window" + index++ + ".png")); + } catch (IOException e) { + e.printStackTrace(); + } + } + }); + } catch (InterruptedException | InvocationTargetException ex) { + Logger.getLogger(JemmyExt.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public static interface RunnableWithException { + + public void run() throws Exception; + } + + public static void waitIsFocused(JFrameOperator jfo) { + jfo.waitState(new ComponentChooser() { + + @Override + public boolean checkComponent(Component comp) { + return jfo.isFocused(); + } + + @Override + public String getDescription() { + return "JFrame is focused"; + } + }); + } + + public static int getJWindowCount() { + return new QueueTool().invokeAndWait(new QueueTool.QueueAction(null) { + + @Override + public Integer launch() throws Exception { + Window[] windows = Window.getWindows(); + int windowCount = 0; + for (Window w : windows) { + if (w.getClass().equals(JWindow.class)) { + windowCount++; + } + } + return windowCount; + } + }); + } + + public static JWindow getJWindow() { + return getJWindow(0); + } + + public static JWindow getJWindow(int index) { + return new QueueTool().invokeAndWait(new QueueTool.QueueAction(null) { + + @Override + public JWindow launch() throws Exception { + Window[] windows = Window.getWindows(); + int windowIndex = 0; + for (Window w : windows) { + if (w.getClass().equals(JWindow.class)) { + if (windowIndex == index) { + return (JWindow) w; + } + windowIndex++; + } + } + return null; + } + }); + } + + public static boolean isIconified(FrameOperator frameOperator) { + return frameOperator.getQueueTool().invokeAndWait(new QueueTool.QueueAction("Frame is iconified") { + + @Override + public Boolean launch() throws Exception { + return (((Frame) frameOperator.getSource()).getState() & Frame.ICONIFIED) != 0; + } + }); + } + + public static final Operator.DefaultStringComparator EXACT_STRING_COMPARATOR + = new Operator.DefaultStringComparator(true, true); + + /** + * Finds a label with the exact labelText and returns the operator for its + * parent container. + * + * @param container + * @param labelText + * @return + */ + public static ContainerOperator getLabeledContainerOperator(ContainerOperator container, String labelText) { + + container.setComparator(EXACT_STRING_COMPARATOR); + + JLabelOperator jLabelOperator = new JLabelOperator(container, labelText); + + assert labelText.equals(jLabelOperator.getText()); + + return new ContainerOperator<>(jLabelOperator.getParent()); + } + + /** + * Finds a JPanel with exact title text. + * + * @param container + * @param titleText + * @return + */ + public static ContainerOperator getBorderTitledJPanelOperator(ContainerOperator container, String titleText) { + return new ContainerOperator<>(container, new JPanelByBorderTitleFinder(titleText, EXACT_STRING_COMPARATOR)); + } + + public static final QueueTool QUEUE_TOOL = new QueueTool(); + + /** + * Allows to find JPanel by the title text in its border. + */ + public static class JPanelByBorderTitleFinder implements ComponentChooser { + + String titleText; + Operator.StringComparator comparator; + + /** + * @param titleText title text pattern + * @param comparator specifies string comparison algorithm. + */ + public JPanelByBorderTitleFinder(String titleText, Operator.StringComparator comparator) { + this.titleText = titleText; + this.comparator = comparator; + } + + /** + * @param titleText title text pattern + */ + public JPanelByBorderTitleFinder(String titleText) { + this(titleText, Operator.getDefaultStringComparator()); + } + + @Override + public boolean checkComponent(Component comp) { + assert EventQueue.isDispatchThread(); + if (comp instanceof JPanel) { + return checkBorder(((JPanel) comp).getBorder()); + } + return false; + } + + public boolean checkBorder(Border border) { + if (border instanceof TitledBorder) { + String title = ((TitledBorder) border).getTitle(); + return comparator.equals(title, titleText); + } else if (border instanceof CompoundBorder) { + CompoundBorder compoundBorder = (CompoundBorder) border; + return checkBorder(compoundBorder.getInsideBorder()) || checkBorder(compoundBorder.getOutsideBorder()); + } else { + return false; + } + } + + @Override + public String getDescription() { + return ("JPanel with border title text \"" + titleText + "\" with comparator " + comparator); + } + } + + public static class ByClassSimpleNameChooser implements ComponentChooser { + + private final String className; + + public ByClassSimpleNameChooser(String className) { + this.className = className; + } + + @Override + public boolean checkComponent(Component comp) { + return comp.getClass().getSimpleName().equals(className); + } + + @Override + public String getDescription() { + return "Component with the simple class name of " + className; + } + + } + + public static class ByClassChooser implements ComponentChooser { + + private final Class clazz; + + public ByClassChooser(Class clazz) { + this.clazz = clazz; + } + + @Override + public boolean checkComponent(Component comp) { + return comp.getClass().equals(clazz); + } + + @Override + public String getDescription() { + return "Component with the class of " + clazz; + } + + } + + public static class ByToolTipChooser implements ComponentChooser { + + private final String tooltip; + + public ByToolTipChooser(String tooltip) { + if (tooltip == null) { + throw new NullPointerException("Tooltip cannot be null"); + } + this.tooltip = tooltip; + } + + @Override + public boolean checkComponent(Component comp) { + return (comp instanceof JComponent) + ? tooltip.equals(((JComponent) comp).getToolTipText()) + : false; + } + + @Override + public String getDescription() { + return "JComponent with the tooltip '" + tooltip + "'"; + } + + } + + @SuppressWarnings(value = "unchecked") + public static R getUIValue(O operator, Function getter) { + return operator.getQueueTool().invokeSmoothly(new QueueTool.QueueAction("getting UI value through the queue using " + getter) { + + @Override + public R launch() throws Exception { + return getter.apply((S) operator.getSource()); + } + }); + } +} diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/lib/Extensions/src/org/jtregext/GuiTestListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sanity/client/lib/Extensions/src/org/jtregext/GuiTestListener.java Wed Apr 27 17:47:17 2016 -0700 @@ -0,0 +1,72 @@ +package org.jtregext; + +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +import org.jemmy2ext.JemmyExt; +import static org.jemmy2ext.JemmyExt.captureAll; +import org.testng.ITestContext; +import org.testng.ITestListener; +import org.testng.ITestResult; + +// TODO: Remove this once https://bugs.openjdk.java.net/browse/JDK-8151671 is fixed +public class GuiTestListener implements ITestListener { + + private void afterTest() { + JemmyExt.disposeAllWindows(); + } + + @Override + public void onTestStart(ITestResult result) { + } + + @Override + public void onTestSuccess(ITestResult result) { + System.out.println("TEST PASSED"); + afterTest(); + } + + @Override + public void onTestFailure(ITestResult result) { + captureAll(); + afterTest(); + } + + @Override + public void onTestSkipped(ITestResult result) { + } + + @Override + public void onTestFailedButWithinSuccessPercentage(ITestResult result) { + } + + @Override + public void onStart(ITestContext context) { + } + + @Override + public void onFinish(ITestContext context) { + } + +} diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/lib/Jemmy2Ext/src/org/jemmy2ext/JemmyExt.java --- a/jdk/test/sanity/client/lib/Jemmy2Ext/src/org/jemmy2ext/JemmyExt.java Wed Apr 27 20:36:02 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,614 +0,0 @@ -/* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package org.jemmy2ext; - -import java.awt.Component; -import java.awt.EventQueue; -import java.awt.Frame; -import java.awt.Graphics; -import java.awt.Rectangle; -import java.awt.Robot; -import java.awt.Window; -import java.awt.image.BufferedImage; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Function; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.stream.IntStream; -import javax.imageio.ImageIO; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.JWindow; -import javax.swing.border.Border; -import javax.swing.border.CompoundBorder; -import javax.swing.border.TitledBorder; -import org.netbeans.jemmy.ComponentChooser; -import org.netbeans.jemmy.DefaultCharBindingMap; -import org.netbeans.jemmy.QueueTool; -import org.netbeans.jemmy.TimeoutExpiredException; -import org.netbeans.jemmy.Waitable; -import org.netbeans.jemmy.Waiter; -import org.netbeans.jemmy.drivers.scrolling.JSpinnerDriver; -import org.netbeans.jemmy.image.StrictImageComparator; -import org.netbeans.jemmy.operators.ComponentOperator; -import org.netbeans.jemmy.operators.ContainerOperator; -import org.netbeans.jemmy.operators.FrameOperator; -import org.netbeans.jemmy.operators.JButtonOperator; -import org.netbeans.jemmy.operators.JFrameOperator; -import org.netbeans.jemmy.operators.JLabelOperator; -import org.netbeans.jemmy.operators.Operator; -import org.netbeans.jemmy.util.Dumper; -import org.netbeans.jemmy.util.PNGEncoder; -import static org.testng.AssertJUnit.*; - -/** - * This class solves two tasks: 1. It adds functionality that is missing in - * Jemmy 2. It references all the Jemmy API that is needed by tests so that they - * can just @build JemmyExt class and do not worry about Jemmy - * - * @author akouznet - */ -public class JemmyExt { - - /** - * Statically referencing all the classes that are needed by tests so that - * they're compiled by jtreg - */ - static final Class[] DEPENDENCIES = { - JSpinnerDriver.class, - DefaultCharBindingMap.class - }; - - public static void assertNotBlack(BufferedImage image) { - int w = image.getWidth(); - int h = image.getHeight(); - try { - assertFalse("All pixels are not black", IntStream.range(0, w).parallel().allMatch(x - -> IntStream.range(0, h).allMatch(y -> (image.getRGB(x, y) & 0xffffff) == 0) - )); - } catch (Throwable t) { - save(image, "allPixelsAreBlack.png"); - throw t; - } - } - - public static void waitArmed(JButtonOperator button) { - button.waitState(new ComponentChooser() { - - @Override - public boolean checkComponent(Component comp) { - return isArmed(button); - } - - @Override - public String getDescription() { - return "Button is armed"; - } - }); - } - - public static boolean isArmed(JButtonOperator button) { - return button.getQueueTool().invokeSmoothly(new QueueTool.QueueAction("getModel().isArmed()") { - - @Override - public Boolean launch() throws Exception { - return ((JButton) button.getSource()).getModel().isArmed(); - } - }); - } - - public static void waitPressed(JButtonOperator button) { - button.waitState(new ComponentChooser() { - - @Override - public boolean checkComponent(Component comp) { - return isPressed(button); - } - - @Override - public String getDescription() { - return "Button is pressed"; - } - }); - } - - public static boolean isPressed(JButtonOperator button) { - return button.getQueueTool().invokeSmoothly(new QueueTool.QueueAction("getModel().isPressed()") { - - @Override - public Boolean launch() throws Exception { - return ((JButton) button.getSource()).getModel().isPressed(); - } - }); - } - - public static void assertEquals(String string, StrictImageComparator comparator, BufferedImage expected, BufferedImage actual) { - try { - assertTrue(string, comparator.compare(expected, actual)); - } catch (Error err) { - save(expected, "expected.png"); - save(actual, "actual.png"); - throw err; - } - } - - public static void assertNotEquals(String string, StrictImageComparator comparator, BufferedImage notExpected, BufferedImage actual) { - try { - assertFalse(string, comparator.compare(notExpected, actual)); - } catch (Error err) { - save(notExpected, "notExpected.png"); - save(actual, "actual.png"); - throw err; - } - } - - public static void save(BufferedImage image, String filename) { - String filepath = filename; - try { - filepath = new File(filename).getCanonicalPath(); - System.out.println("Saving screenshot to " + filepath); - BufferedOutputStream file = new BufferedOutputStream(new FileOutputStream(filepath)); - new PNGEncoder(file, PNGEncoder.COLOR_MODE).encode(image); - } catch (IOException ioe) { - throw new RuntimeException("Failed to save image to " + filepath, ioe); - } - } - - public static void waitImageIsStill(Robot rob, ComponentOperator operator) { - operator.waitState(new ComponentChooser() { - - private BufferedImage previousImage = null; - private int index = 0; - private final StrictImageComparator sComparator = new StrictImageComparator(); - - @Override - public boolean checkComponent(Component comp) { - BufferedImage currentImage = capture(rob, operator); - save(currentImage, "waitImageIsStill" + index + ".png"); - index++; - boolean compareResult = previousImage == null ? false : sComparator.compare(currentImage, previousImage); - previousImage = currentImage; - return compareResult; - } - - @Override - public String getDescription() { - return "Image of " + operator + " is still"; - } - }); - } - - private static class ThrowableHolder { - - volatile Throwable t; - } - - public static void waitFor(String description, RunnableWithException r) throws Exception { - Waiter waiter = new Waiter<>(new Waitable() { - - @Override - public Boolean actionProduced(ThrowableHolder obj) { - try { - r.run(); - return true; - } catch (Throwable t) { - obj.t = t; - return null; - } - } - - @Override - public String getDescription() { - return description; - } - }); - ThrowableHolder th = new ThrowableHolder(); - try { - waiter.waitAction(th); - } catch (TimeoutExpiredException tee) { - Throwable t = th.t; - if (t != null) { - t.addSuppressed(tee); - if (t instanceof Exception) { - throw (Exception) t; - } else if (t instanceof Error) { - throw (Error) t; - } else if (t instanceof RuntimeException) { - throw (RuntimeException) t; - } else { - throw new IllegalStateException("Unexpected exception type", t); - } - } - } - } - - public static BufferedImage capture(Robot rob, ComponentOperator operator) { - Rectangle boundary = new Rectangle(operator.getLocationOnScreen(), - operator.getSize()); - return rob.createScreenCapture(boundary); - } - - /** - * Wraps the test code so that in case of any failure as much information as - * possible is captured - * - * @param r test code Runnable - * @throws Exception whatever exception the test may throw - */ - public static void captureDebugInfoOnFail(RunnableWithException r) throws Exception { - // TODO: Remove this once https://bugs.openjdk.java.net/browse/JDK-8151671 is fixed - try { - r.run(); - System.out.println("TEST PASSED"); - } catch (Throwable t) { - captureAll(); - throw t; - } - } - - /** - * This is a helper class which allows to catch throwables thrown in other - * threads and throw them in the main test thread - */ - public static class MultiThreadedTryCatch { - - private final List throwables - = Collections.synchronizedList(new ArrayList<>()); - - /** - * Throws registered throwables. If the list of the registered - * throwables is not empty, it re-throws the first throwable in the list - * adding all others into its suppressed list. Can be used in any - * thread. - * - * @throws Exception - */ - public void throwRegistered() throws Exception { - Throwable root = null; - synchronized (throwables) { - if (!throwables.isEmpty()) { - root = throwables.remove(0); - while (!throwables.isEmpty()) { - root.addSuppressed(throwables.remove(0)); - } - } - } - if (root != null) { - if (root instanceof Error) { - throw (Error) root; - } else if (root instanceof Exception) { - throw (Exception) root; - } else { - throw new AssertionError("Unexpected exception type: " + root.getClass() + " (" + root + ")"); - } - } - } - - /** - * Registers a throwable and adds it to the list of throwables. Can be - * used in any thread. - * - * @param t - */ - public void register(Throwable t) { - t.printStackTrace(); - throwables.add(t); - } - - /** - * Registers a throwable and adds it as the first item of the list of - * catched throwables. - * - * @param t - */ - public void registerRoot(Throwable t) { - t.printStackTrace(); - throwables.add(0, t); - } - } - - /** - * Trying to capture as much information as possible. Currently it includes - * full dump and a screenshot of the whole screen. - */ - public static void captureAll() { - PNGEncoder.captureScreen("failure.png", PNGEncoder.COLOR_MODE); - try { - Dumper.dumpAll("dumpAll.xml"); - } catch (FileNotFoundException ex) { - Logger.getLogger(JemmyExt.class.getName()).log(Level.SEVERE, null, ex); - } - captureWindows(); - } - - /** - * Captures each showing window image using Window.paint() method. - */ - private static void captureWindows() { - try { - EventQueue.invokeAndWait(() -> { - Window[] windows = Window.getWindows(); - int index = 0; - for (Window w : windows) { - if (!w.isShowing()) { - continue; - } - BufferedImage img = new BufferedImage(w.getWidth(), w.getHeight(), BufferedImage.TYPE_INT_ARGB); - Graphics g = img.getGraphics(); - w.paint(g); - g.dispose(); - - try { - ImageIO.write(img, "png", new File("window" + index++ + ".png")); - } catch (IOException e) { - e.printStackTrace(); - } - } - }); - } catch (InterruptedException | InvocationTargetException ex) { - Logger.getLogger(JemmyExt.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public static interface RunnableWithException { - - public void run() throws Exception; - } - - public static void waitIsFocused(JFrameOperator jfo) { - jfo.waitState(new ComponentChooser() { - - @Override - public boolean checkComponent(Component comp) { - return jfo.isFocused(); - } - - @Override - public String getDescription() { - return "JFrame is focused"; - } - }); - } - - public static int getJWindowCount() { - return new QueueTool().invokeAndWait(new QueueTool.QueueAction(null) { - - @Override - public Integer launch() throws Exception { - Window[] windows = Window.getWindows(); - int windowCount = 0; - for (Window w : windows) { - if (w.getClass().equals(JWindow.class)) { - windowCount++; - } - } - return windowCount; - } - }); - } - - public static JWindow getJWindow() { - return getJWindow(0); - } - - public static JWindow getJWindow(int index) { - return new QueueTool().invokeAndWait(new QueueTool.QueueAction(null) { - - @Override - public JWindow launch() throws Exception { - Window[] windows = Window.getWindows(); - int windowIndex = 0; - for (Window w : windows) { - if (w.getClass().equals(JWindow.class)) { - if (windowIndex == index) { - return (JWindow) w; - } - windowIndex++; - } - } - return null; - } - }); - } - - public static boolean isIconified(FrameOperator frameOperator) { - return frameOperator.getQueueTool().invokeAndWait(new QueueTool.QueueAction("Frame is iconified") { - - @Override - public Boolean launch() throws Exception { - return (((Frame) frameOperator.getSource()).getState() & Frame.ICONIFIED) != 0; - } - }); - } - - public static final Operator.DefaultStringComparator EXACT_STRING_COMPARATOR - = new Operator.DefaultStringComparator(true, true); - - /** - * Finds a label with the exact labelText and returns the operator for its - * parent container. - * - * @param container - * @param labelText - * @return - */ - public static ContainerOperator getLabeledContainerOperator(ContainerOperator container, String labelText) { - - container.setComparator(EXACT_STRING_COMPARATOR); - - JLabelOperator jLabelOperator = new JLabelOperator(container, labelText); - - assert labelText.equals(jLabelOperator.getText()); - - return new ContainerOperator<>(jLabelOperator.getParent()); - } - - /** - * Finds a JPanel with exact title text. - * - * @param container - * @param titleText - * @return - */ - public static ContainerOperator getBorderTitledJPanelOperator(ContainerOperator container, String titleText) { - return new ContainerOperator<>(container, new JPanelByBorderTitleFinder(titleText, EXACT_STRING_COMPARATOR)); - } - - public static final QueueTool QUEUE_TOOL = new QueueTool(); - - /** - * Allows to find JPanel by the title text in its border. - */ - public static class JPanelByBorderTitleFinder implements ComponentChooser { - - String titleText; - Operator.StringComparator comparator; - - /** - * @param titleText title text pattern - * @param comparator specifies string comparison algorithm. - */ - public JPanelByBorderTitleFinder(String titleText, Operator.StringComparator comparator) { - this.titleText = titleText; - this.comparator = comparator; - } - - /** - * @param titleText title text pattern - */ - public JPanelByBorderTitleFinder(String titleText) { - this(titleText, Operator.getDefaultStringComparator()); - } - - @Override - public boolean checkComponent(Component comp) { - assert EventQueue.isDispatchThread(); - if (comp instanceof JPanel) { - return checkBorder(((JPanel) comp).getBorder()); - } - return false; - } - - public boolean checkBorder(Border border) { - if (border instanceof TitledBorder) { - String title = ((TitledBorder) border).getTitle(); - return comparator.equals(title, titleText); - } else if (border instanceof CompoundBorder) { - CompoundBorder compoundBorder = (CompoundBorder) border; - return checkBorder(compoundBorder.getInsideBorder()) || checkBorder(compoundBorder.getOutsideBorder()); - } else { - return false; - } - } - - @Override - public String getDescription() { - return ("JPanel with border title text \"" + titleText + "\" with comparator " + comparator); - } - } - - public static class ByClassSimpleNameChooser implements ComponentChooser { - - private final String className; - - public ByClassSimpleNameChooser(String className) { - this.className = className; - } - - @Override - public boolean checkComponent(Component comp) { - return comp.getClass().getSimpleName().equals(className); - } - - @Override - public String getDescription() { - return "Component with the simple class name of " + className; - } - - } - - public static class ByClassChooser implements ComponentChooser { - - private final Class clazz; - - public ByClassChooser(Class clazz) { - this.clazz = clazz; - } - - @Override - public boolean checkComponent(Component comp) { - return comp.getClass().equals(clazz); - } - - @Override - public String getDescription() { - return "Component with the class of " + clazz; - } - - } - - public static class ByToolTipChooser implements ComponentChooser { - - private final String tooltip; - - public ByToolTipChooser(String tooltip) { - if (tooltip == null) { - throw new NullPointerException("Tooltip cannot be null"); - } - this.tooltip = tooltip; - } - - @Override - public boolean checkComponent(Component comp) { - return (comp instanceof JComponent) - ? tooltip.equals(((JComponent) comp).getToolTipText()) - : false; - } - - @Override - public String getDescription() { - return "JComponent with the tooltip '" + tooltip + "'"; - } - - } - - @SuppressWarnings(value = "unchecked") - public static R getUIValue(O operator, Function getter) { - return operator.getQueueTool().invokeSmoothly(new QueueTool.QueueAction("getting UI value through the queue using " + getter) { - - @Override - public R launch() throws Exception { - return getter.apply((S) operator.getSource()); - } - }); - } -} diff -r 24ef455da1b0 -r 9774eca96b01 jdk/test/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/tabbedpane/TabbedPaneDemo.java --- a/jdk/test/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/tabbedpane/TabbedPaneDemo.java Wed Apr 27 20:36:02 2016 +0100 +++ b/jdk/test/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/tabbedpane/TabbedPaneDemo.java Wed Apr 27 17:47:17 2016 -0700 @@ -204,7 +204,9 @@ } public void go() { - animator = new javax.swing.Timer(22 + 22 + 22, this); + if (animator == null) { + animator = new javax.swing.Timer(22 + 22 + 22, this); + } animator.start(); } @@ -246,7 +248,7 @@ @Override public void actionPerformed(ActionEvent e) { - if (isVisible()) { + if (isShowing()) { repaint(); } else { animator.stop();