# HG changeset patch # User akolarkunnu # Date 1535366804 25200 # Node ID c70a01619679a823ee7315d9baf4a3e1c0cff74e # Parent a8cf90dc87826992314744c6396630d2641a25e3 8209789: Synchronize test/jdk/sanity/client/lib/jemmy with code-tools/jemmy/v2 Reviewed-by: serb Contributed-by: abdul.kolarkunnu@oracle.com diff -r a8cf90dc8782 -r c70a01619679 test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/ComponentOperator.java --- a/test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/ComponentOperator.java Mon Aug 27 09:46:24 2018 -0700 +++ b/test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/ComponentOperator.java Mon Aug 27 03:46:44 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2018, 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 @@ -59,8 +59,6 @@ import java.util.Hashtable; import java.util.Locale; -import static java.lang.Math.abs; - import org.netbeans.jemmy.CharBindingMap; import org.netbeans.jemmy.ComponentChooser; import org.netbeans.jemmy.ComponentSearcher; @@ -1222,6 +1220,48 @@ } /** + * Wait till the component reaches exact location on screen. + * + * @param exactLocation exact expected screen location. + */ + public void waitComponentLocationOnScreen(Point exactlocation) { + waitComponentLocationOnScreen(exactlocation, exactlocation); + } + + /** + * Wait till the component location on screen reaches between minLocation + * and maxLocation + * + * @param minLocation minimum expected location on screen. + * @param maxLocation maximum expected location on screen. + */ + public void waitComponentLocationOnScreen( + final Point minLocation, final Point maxLocation) { + waitState(new ComponentChooser() { + @Override + public boolean checkComponent(Component comp) { + Point location = comp.getLocationOnScreen(); + return location.x >= minLocation.x + && location.x <= maxLocation.x + && location.y >= minLocation.y + && location.y <= maxLocation.y; + } + + @Override + public String getDescription() { + return "Component location on screen reaches between :" + + minLocation + "and " + maxLocation; + } + + @Override + public String toString() { + return "ComponentOperator.waitComponentLocationOnScreen" + + ".Waitable{description = " + getDescription() + '}'; + } + }); + } + + /** * Returns information about component. */ @Override diff -r a8cf90dc8782 -r c70a01619679 test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/JComponentOperator.java --- a/test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/JComponentOperator.java Mon Aug 27 09:46:24 2018 -0700 +++ b/test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/JComponentOperator.java Mon Aug 27 03:46:44 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2018, 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 @@ -47,7 +47,6 @@ import org.netbeans.jemmy.ComponentChooser; import org.netbeans.jemmy.ComponentSearcher; -import org.netbeans.jemmy.JemmyProperties; import org.netbeans.jemmy.Outputable; import org.netbeans.jemmy.TestOut; import org.netbeans.jemmy.TimeoutExpiredException; @@ -307,15 +306,7 @@ } public JToolTip waitToolTip() { - return ((JToolTip) waitComponent(WindowOperator. - waitWindow(new JToolTipWindowFinder(), - 0, - getTimeouts(), - getOutput()), - new JToolTipFinder(), - 0, - getTimeouts(), - getOutput())); + return JToolTipOperator.waitJToolTip(this); } /** @@ -1228,61 +1219,4 @@ } } - static class JToolTipWindowFinder implements ComponentChooser { - - ComponentChooser ppFinder; - - public JToolTipWindowFinder() { - ppFinder = new ComponentChooser() { - @Override - public boolean checkComponent(Component comp) { - return (comp.isShowing() - && comp.isVisible() - && comp instanceof JToolTip); - } - - @Override - public String getDescription() { - return "A tool tip"; - } - - @Override - public String toString() { - return "JComponentOperator.JToolTipWindowFinder.ComponentChooser{description = " + getDescription() + '}'; - } - }; - } - - @Override - public boolean checkComponent(Component comp) { - if (comp.isShowing() && comp instanceof Window) { - ComponentSearcher cs = new ComponentSearcher((Container) comp); - cs.setOutput(JemmyProperties.getCurrentOutput().createErrorOutput()); - return (cs.findComponent(ppFinder) - != null); - } - return false; - } - - @Override - public String getDescription() { - return "A tool tip window"; - } - - @Override - public String toString() { - return "JToolTipWindowFinder{" + "ppFinder=" + ppFinder + '}'; - } - } - - class JToolTipFinder extends Finder { - - public JToolTipFinder(ComponentChooser sf) { - super(JToolTip.class, sf); - } - - public JToolTipFinder() { - super(JToolTip.class); - } - } } diff -r a8cf90dc8782 -r c70a01619679 test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/JToolTipOperator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/JToolTipOperator.java Mon Aug 27 03:46:44 2018 -0700 @@ -0,0 +1,519 @@ +/* + * Copyright (c) 2018, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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.netbeans.jemmy.operators; + +import java.awt.Component; +import java.awt.Window; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Hashtable; +import java.util.List; + +import javax.swing.JComponent; +import javax.swing.JToolTip; +import javax.swing.plaf.ToolTipUI; + +import org.netbeans.jemmy.ComponentChooser; +import org.netbeans.jemmy.ComponentSearcher; +import org.netbeans.jemmy.TimeoutExpiredException; +import org.netbeans.jemmy.Waitable; + +/** + *
+ *
+ * Timeouts used:
+ * {@code ComponentOperator.WaitComponentTimeout} - time to wait component + * displayed.
+ * {@code ComponentOperator.WaitStateTimeout} - time to wait for tip text.
+ * + * @see org.netbeans.jemmy.Timeouts + */ +public class JToolTipOperator extends JComponentOperator { + + /** + * Identifier for a "tip text" property. + * + * @see #getDump() + */ + public static final String TIP_TEXT_DPROP = "TipText"; + + /** + * Constructs a JToolTipOperator object, waiting for a shown + * JToolTip. + */ + public JToolTipOperator() { + this(TRUE_CHOOSER); + } + + /** + * Constructs a JToolTipOperator object for a given JToolTip component. + * + * @param toolTip + * a component + */ + public JToolTipOperator(JToolTip toolTip) { + super(toolTip); + } + + /** + * Constructs a JToolTipOperator object waiting for the JToolTip having a + * given tip text (compared using default string comparator). + * + * @param tipText + * tip text. + * @see #getDefaultStringComparator() + */ + public JToolTipOperator(String tipText) { + this(waitJToolTip(new JToolTipByTipTextFinder(tipText, + getDefaultStringComparator()))); + } + + /** + * Constructs a JToolTipOperator object waiting for the JToolTip + * associated with the given component. Uses {@code comp}'s timeout and + * output for waiting. Copies environment from {@code comp}. + * + * @param comp + * component on which tool tip associated + * @see #copyEnvironment(org.netbeans.jemmy.operators.Operator) + */ + public JToolTipOperator(ComponentOperator comp) { + this(comp, TRUE_CHOOSER); + } + + /** + * Constructs a JToolTipOperator object waiting for the JToolTip + * conforming to the given component chooser. + * + * @param chooser + * a component chooser specifying searching criteria. + */ + public JToolTipOperator(ComponentChooser chooser) { + this(null, chooser); + } + + /** + * Constructs a JToolTipOperator object waiting for the JToolTip + * associated with the given component and conforming to the given + * component chooser. Uses {@code comp}'s timeout and output for waiting. + * Copies environment from {@code comp}. + * + * @param comp + * component on which tool tip associated + * @param chooser + * a component chooser specifying searching criteria. + * @see #copyEnvironment(org.netbeans.jemmy.operators.Operator) + */ + public JToolTipOperator(ComponentOperator comp, ComponentChooser chooser) { + this(waitJToolTip(comp, chooser)); + if(comp != null) { + copyEnvironment(comp); + } + } + + /** + * Constructs a JToolTipOperator object waiting for the JToolTip + * associated with the given component and having the given tip text. + * Uses {@code comp}'s string comparator for tip text comparison, timeout + * and output for waiting. Copies environment from {@code comp}. + * + * @param comp + * component on which tool tip associated + * @param tipText + * tip text + * @see #getComparator() + * @see #copyEnvironment(org.netbeans.jemmy.operators.Operator) + */ + public JToolTipOperator(ComponentOperator comp, String tipText) { + this(waitJToolTip(comp, + new JToolTipByTipTextFinder(tipText, comp.getComparator()))); + copyEnvironment(comp); + } + + /** + * Searches for the JToolTip associated with the given component and + * conforming to the given component chooser. Uses {@code comp}'s timeout + * and output for waiting. + * + * @param comp + * component on which tool tip associated + * @param chooser + * a component chooser specifying searching criteria. + * @return JToolTip instance or null if component was not found. + */ + public static JToolTip findJToolTip(ComponentOperator comp, + ComponentChooser chooser) { + List windowList; + if(comp != null && comp.getWindow() != null) { + windowList = new ArrayList<>( + Arrays.asList(comp.getWindow().getOwnedWindows())); + windowList.add(comp.getWindow()); + } else { + windowList = new ArrayList<>( + Arrays.asList(WindowOperator.getWindows())); + } + ComponentChooser toolTipChooser = new JToolTipFinder(chooser); + for (Window w : windowList) { + ComponentSearcher searcher = new ComponentSearcher(w); + Component[] components = searcher.findComponents(toolTipChooser); + if (components.length > 0) { + if(comp!= null && comp.getSource() != null) { + if(comp.getSource().equals( + ((JToolTip) components[0]).getComponent())) { + return (JToolTip) components[0]; + } + } else { + return (JToolTip) components[0]; + } + } + } + return null; + } + + + /** + * Searches for a JToolTip. + * + * @return JToolTip instance or null if component was not found. + */ + public static JToolTip findJToolTip() { + return findJToolTip(null); + } + + /** + * Searches for the JToolTip associated with the given component. Uses + * {@code comp}'s timeout and output for waiting. + * + * @param comp + * component on which tool tip associated + * @return JToolTip instance or null if component was not found. + */ + public static JToolTip findJToolTip(ComponentOperator comp) { + return findJToolTip(comp, TRUE_CHOOSER); + } + + /** + * Searches for the JToolTip associated with the given component and + * looking for given tip text using specified string comparator options. + * Uses {@code comp}'s timeout and output for waiting. + * + * @param comp + * component on which tool tip associated + * @param tipText + * Tip text. + * @param ce + * Compare text exactly. + * @param ccs + * Compare text case sensitively. + * @return JToolTip instance or null if component was not found. + * @see DefaultStringComparator + * @see JToolTipByTipTextFinder + */ + public static JToolTip findJToolTip(ComponentOperator comp, String tipText, + boolean ce, boolean ccs) { + return findJToolTip(comp, new JToolTipByTipTextFinder(tipText, + new DefaultStringComparator(ce, ccs))); + } + + /** + * Waits for a JToolTip. + * + * @return JToolTip instance. + * @see TimeoutExpiredException + */ + public static JToolTip waitJToolTip() { + return waitJToolTip(TRUE_CHOOSER); + } + + + /** + * Waits for the first JToolTip associated with the given component. + * + * @param comp + * component on which tool tip associated + * @return JToolTip instance. + * @see TimeoutExpiredException + */ + public static JToolTip waitJToolTip(ComponentOperator comp) { + return waitJToolTip(comp, TRUE_CHOOSER); + } + + /** + * Waits for the JToolTip conforming to the given component + * chooser. + * + * @param chooser + * a component chooser specifying searching criteria. + * @return JToolTip instance. + * @see TimeoutExpiredException + */ + public static JToolTip waitJToolTip(ComponentChooser chooser) { + return waitJToolTip(null, chooser); + } + + /** + * Waits for the JToolTip associated with the given component and + * conforming to the specified component chooser. + * + * @param comp + * component on which tool tip associated + * @param chooser + * a component chooser specifying searching criteria. + * @return JToolTip instance. + * @see TimeoutExpiredException + */ + public static JToolTip waitJToolTip(ComponentOperator comp, + ComponentChooser chooser) { + return Operator.getEnvironmentOperator(). + waitState(new Waitable() { + @Override + public JToolTip actionProduced(Void obj) { + return findJToolTip(comp, chooser); + } + + @Override + public String getDescription() { + return "Wait for JTooltip to be displayed for Component = " + + comp + ", " + "chooser = " + chooser; + } + + @Override + public String toString() { + return "JToolTipOperator.waitJToolTip.Waitable{description = " + + getDescription() + '}'; + } + }); + } + + /** + * Waits for the JToolTip associated with the given component and having + * the given tip text compared using given string comparator options. + * + * @param comp + * component on which tool tip associated + * @param tipText + * Tip text. + * @param ce + * Compare text exactly. + * @param ccs + * Compare text case sensitively. + * @return JToolTip instance. + * @see TimeoutExpiredException + */ + public static JToolTip waitJToolTip(ComponentOperator comp, String tipText, + boolean ce, boolean ccs) { + return waitJToolTip(comp, new JToolTipByTipTextFinder(tipText, + new DefaultStringComparator(ce, ccs))); + } + + /** + * Waits for the given tip text. Uses {@linkplain #getComparator()} + * comparator. + * + * @param tipText + * Tip text to wait for. + * @see TimeoutExpiredException + */ + public void waitTipText(String tipText) { + getOutput().printLine("Wait \"" + tipText + + "\" tip text in JToolTip \n : " + toStringSource()); + getOutput().printGolden("Wait \"" + tipText + "\" tip text"); + waitState(new JToolTipByTipTextFinder(tipText, getComparator())); + } + + /** + * Returns information about the component. + * + * @return Map of component properties. + */ + @Override + public Hashtable getDump() { + Hashtable result = super.getDump(); + String tipText = getTipText(); + if (tipText != null) { + result.put(TIP_TEXT_DPROP, tipText); + } else { + result.put(TIP_TEXT_DPROP, "null"); + } + return result; + } + + //////////////////////////////////////////////////////// + // Mapping // + + /** + * Maps {@linkplain JToolTip#getTipText()} through queue + * + * @return + */ + public String getTipText() { + return runMapping(new MapAction("getTipText") { + @Override + public String map() { + return ((JToolTip) getSource()).getTipText(); + } + }); + } + + /** + * Maps {@linkplain JToolTip#getComponent()} through queue + * + * @return + */ + public JComponent getComponent() { + return runMapping(new MapAction("getComponent") { + @Override + public JComponent map() { + return ((JToolTip) getSource()).getComponent(); + } + }); + } + + /** + * Maps {@linkplain JToolTip#getUI()} through queue + * + * @return + */ + public ToolTipUI getUI() { + return runMapping(new MapAction("getUI") { + @Override + public ToolTipUI map() { + return ((JToolTip) getSource()).getUI(); + } + }); + } + + /** + * Maps {@linkplain JToolTip#setTipText(String)} through queue + * + * @param tipText + */ + public void setTipText(final String tipText) { + runMapping(new MapVoidAction("setTipText") { + @Override + public void map() { + ((JToolTip) getSource()).setTipText(tipText); + } + }); + } + + /** + * Maps {@linkplain JToolTip#setComponent(JComponent)} through queue + * + * @param component + */ + public void setComponent(final JComponent component) { + runMapping(new MapVoidAction("setComponent") { + @Override + public void map() { + ((JToolTip) getSource()).setComponent(component); + } + }); + } + // End of mapping // + //////////////////////////////////////////////////////// + + + /** + * Allows to find JToolTip by tip text. + */ + public static class JToolTipByTipTextFinder implements ComponentChooser { + + String tipText; + StringComparator comparator; + + /** + * Constructs JToolTipByTipTextFinder. + * + * @param tipText + * a tip text pattern + * @param comparator + * specifies string comparison algorithm. + */ + public JToolTipByTipTextFinder(String tipText, + StringComparator comparator) { + this.tipText = tipText; + this.comparator = comparator; + } + + /** + * Constructs JToolTipByTipTextFinder. + * + * @param tipText + * a tip text pattern + */ + public JToolTipByTipTextFinder(String tipText) { + this(tipText, Operator.getDefaultStringComparator()); + } + + @Override + public boolean checkComponent(Component comp) { + if (comp instanceof JToolTip) { + if (((JToolTip) comp).getTipText() != null) { + return (comparator.equals(((JToolTip) comp).getTipText(), + tipText)); + } + } + return false; + } + + @Override + public String getDescription() { + return "JToolTip with tip text \"" + tipText + "\""; + } + + @Override + public String toString() { + return "JToolTipByTipTextFinder{" + "tipText=" + tipText + + ", comparator=" + comparator + '}'; + } + } + + /** + * Allows to find JToolTips among components. + */ + public static class JToolTipFinder extends Finder { + + /** + * Constructs JToolTipFinder chaining another component chooser. + * + * @param sf + * other searching criteria. + */ + public JToolTipFinder(ComponentChooser sf) { + super(JToolTip.class, sf); + } + + /** + * Constructs JToolTipFinder. + */ + public JToolTipFinder() { + super(JToolTip.class); + } + } + + private static final ComponentChooser TRUE_CHOOSER = ComponentSearcher + .getTrueChooser("Any JToolTip"); +} diff -r a8cf90dc8782 -r c70a01619679 test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/Operator.java --- a/test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/Operator.java Mon Aug 27 09:46:24 2018 -0700 +++ b/test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/Operator.java Mon Aug 27 03:46:44 2018 -0700 @@ -693,7 +693,7 @@ * defined by {@code "ComponentOperator.WaitStateTimeout"} */ public void waitState(final ComponentChooser state) { - Waiter stateWaiter = new Waiter<>(new Waitable() { + waitState(new Waitable() { @Override public String actionProduced(Void obj) { return state.checkComponent(getSource()) ? "" : null; @@ -710,13 +710,20 @@ return "Operator.waitState.Waitable{description = " + getDescription() + '}'; } }); - stateWaiter.setTimeoutsToCloneOf(getTimeouts(), "ComponentOperator.WaitStateTimeout"); + } + + public R waitState(Waitable waitable) { + Waiter stateWaiter = new Waiter<>(waitable); + stateWaiter.setTimeoutsToCloneOf(getTimeouts(), + "ComponentOperator.WaitStateTimeout"); stateWaiter.setOutput(getOutput().createErrorOutput()); try { - stateWaiter.waitAction(null); + return stateWaiter.waitAction(null); } catch (InterruptedException e) { - throw (new JemmyException("Waiting of \"" + state.getDescription() - + "\" state has been interrupted!")); + Thread.currentThread().interrupt(); + throw (new JemmyException( + "Waiting of \"" + waitable.getDescription() + + "\" state has been interrupted!")); } } diff -r a8cf90dc8782 -r c70a01619679 test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/WindowOperator.java --- a/test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/WindowOperator.java Mon Aug 27 09:46:24 2018 -0700 +++ b/test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/WindowOperator.java Mon Aug 27 03:46:44 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2018, 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 @@ -36,6 +36,7 @@ import org.netbeans.jemmy.JemmyException; import org.netbeans.jemmy.JemmyProperties; import org.netbeans.jemmy.Outputable; +import org.netbeans.jemmy.QueueTool; import org.netbeans.jemmy.TestOut; import org.netbeans.jemmy.TimeoutExpiredException; import org.netbeans.jemmy.Timeouts; @@ -585,6 +586,21 @@ }); } + /** + * Maps {@code Window.getWindows()} through queue + * + * @return result of {@code Window.getWindows()} + */ + public static Window[] getWindows() { + return new QueueTool().invokeSmoothly( + new QueueTool.QueueAction("getWindows") { + @Override + public Window[] launch() throws Exception { + return Window.getWindows(); + } + }); + } + //End of mapping // //////////////////////////////////////////////////////// //////////////////////////////////////////////////////// diff -r a8cf90dc8782 -r c70a01619679 test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/version_info --- a/test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/version_info Mon Aug 27 09:46:24 2018 -0700 +++ b/test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/version_info Mon Aug 27 03:46:44 2018 -0700 @@ -1,6 +1,6 @@ Manifest-version: 1.0 Main-Class: org.netbeans.jemmy.JemmyProperties Jemmy-MajorVersion: 3.0 -Jemmy-MinorVersion: 3.0 +Jemmy-MinorVersion: 4.0 Jemmy-Build: @BUILD_NUMBER@