From: <gda...@us...> - 2012-05-28 09:19:13
|
Revision: 2835 http://abbot.svn.sourceforge.net/abbot/?rev=2835&view=rev Author: gdavison Date: 2012-05-28 09:19:02 +0000 (Mon, 28 May 2012) Log Message: ----------- Fixes to resolve EDT violation caused by accessing the accessible context when trying to generate a component name. Modified Paths: -------------- abbot/trunk/ChangeLog abbot/trunk/projects/jdeveloper/Tests/Tests.jpr abbot/trunk/src/abbot/tester/Robot.java abbot/trunk/test/abbot/script/ComponentReferenceTest.java abbot/trunk/test/abbot/tester/ComponentTesterTest.java Modified: abbot/trunk/ChangeLog =================================================================== --- abbot/trunk/ChangeLog 2012-05-18 13:12:51 UTC (rev 2834) +++ abbot/trunk/ChangeLog 2012-05-28 09:19:02 UTC (rev 2835) @@ -1,3 +1,7 @@ +2012-05-25 Gerard Davison + * Resolve possible and actualy EDT violations in String Robot.getXXXXX methods as reported + with internal testing. + 2012-05-18 Gerard Davison * Work to resolve a stack overflow when using Costello to record in Netbeans, which it turns out wasn't enough to make the fixes in 3495968. Basically getPopupMenu was causing all child Modified: abbot/trunk/projects/jdeveloper/Tests/Tests.jpr =================================================================== --- abbot/trunk/projects/jdeveloper/Tests/Tests.jpr 2012-05-18 13:12:51 UTC (rev 2834) +++ abbot/trunk/projects/jdeveloper/Tests/Tests.jpr 2012-05-28 09:19:02 UTC (rev 2835) @@ -115,7 +115,7 @@ </hash> <value n="programArguments" v=""/> <url n="runDirectoryURL" path="../../../"/> - <value n="targetURL"/> + <url n="targetURL" path="../../../test/abbot/script/ComponentReferenceTest.java"/> </hash> </hash> </hash> Modified: abbot/trunk/src/abbot/tester/Robot.java =================================================================== --- abbot/trunk/src/abbot/tester/Robot.java 2012-05-18 13:12:51 UTC (rev 2834) +++ abbot/trunk/src/abbot/tester/Robot.java 2012-05-28 09:19:02 UTC (rev 2835) @@ -2527,9 +2527,15 @@ */ return name; } + /** Returns the index of the given component within the given container. */ public static int getIndex(Container parent, Component comp) { if (comp instanceof Window) { + + // getOwnedWindows is protoected by a synchronized block so this + // is probably safe to call + // + Window[] owned = ((Window)parent).getOwnedWindows(); for (int i=0;i < owned.length;i++) { if (owned[i] == comp) { @@ -2538,16 +2544,27 @@ } } else { - Component[] children = parent.getComponents(); - for (int i = 0; i < children.length; ++i) { - if (children[i] == comp) { - return i; + + // Getting a list of components need to be protected by the tree lock + // at least possibility if this is a problem then we are going to + // have to do a callAndWait instead. + // + + synchronized(comp.getTreeLock()) + { + Component[] children = parent.getComponents(); + for (int i = 0; i < children.length; ++i) { + if (children[i] == comp) { + return i; + } } } } return -1; } - public static String getText(Component c) { + + + public static String getText(final Component c) { if (c instanceof AbstractButton) { return ComponentTester.stripHTML(((AbstractButton)c).getText()); } @@ -2559,6 +2576,8 @@ } return null; } + + public static String getLabel(Component c) { String label = null; if (c instanceof JComponent) { @@ -2583,9 +2602,49 @@ } return ComponentTester.stripHTML(label); } - public static String getIconName(Component c) { + + private static final Object ACCESSIBLE_CONTEXT_CACHE = new Object() {}; + + public static String getIconName(final Component c) { + + if (c instanceof JComponent) + { + // So we had a case where getting hold of the AccessibleContext was causing + // work to be done off the event queue; but invoking this code everytime on a particular + // component proved to be expense, so using a clientProperty to cache this value, just + // calling the method the first time should it not exist. Appears to be a safe thing + // to do after a brief review of the swing classes + AccessibleContext ac = (AccessibleContext)((JComponent)c).getClientProperty(ACCESSIBLE_CONTEXT_CACHE); + // + if (ac==null) { + ac = callAndWait(c, new Callable<AccessibleContext>() { + public AccessibleContext call() { + AccessibleContext accessibleContext = c.getAccessibleContext(); + ((JComponent)c).putClientProperty(ACCESSIBLE_CONTEXT_CACHE, accessibleContext); + return accessibleContext; + } + + }); + } + else { + int i = 0; + } + + // Otherwise we need to access the accessible context + + return getIconName(ac); + + } + else { + // Just don't think this will happen very much + return getIconName(c.getAccessibleContext()); + } + } + + + private static String getIconName(AccessibleContext context) + { String icon = null; - AccessibleContext context = c.getAccessibleContext(); if (context != null) { AccessibleIcon[] icons = context.getAccessibleIcon(); if (icons != null && icons.length > 0) { @@ -2598,6 +2657,8 @@ } return icon; } + + public static String getBorderTitle(Component c) { String title = null; if (c instanceof JComponent) { @@ -2620,14 +2681,14 @@ } public static String getTitle(Component c) { - if (c instanceof Dialog) - return ((Dialog)c).getTitle(); - else if (c instanceof Frame) - return ((Frame)c).getTitle(); - else if (c instanceof JInternalFrame) - return ((JInternalFrame)c).getTitle(); - return null; - } + if (c instanceof Dialog) + return ((Dialog)c).getTitle(); + else if (c instanceof Frame) + return ((Frame)c).getTitle(); + else if (c instanceof JInternalFrame) + return ((JInternalFrame)c).getTitle(); + return null; + } /** Returns whether it is possible to resize windows that are not an instance of Frame or Dialog. Most X11 window managers will allow this, but stock Macintosh and Windows do not. Modified: abbot/trunk/test/abbot/script/ComponentReferenceTest.java =================================================================== --- abbot/trunk/test/abbot/script/ComponentReferenceTest.java 2012-05-18 13:12:51 UTC (rev 2834) +++ abbot/trunk/test/abbot/script/ComponentReferenceTest.java 2012-05-28 09:19:02 UTC (rev 2835) @@ -879,7 +879,8 @@ showFrame(tabs); Timer timer = new Timer(); ComponentReference ref = resolver.addComponent(button); - if (timer.elapsed() > 500) + long elapsed = timer.elapsed(); + if (elapsed > 500) fail("Creation of non-visible tabbed pane component took " + timer.elapsed() + "ms"); } Modified: abbot/trunk/test/abbot/tester/ComponentTesterTest.java =================================================================== --- abbot/trunk/test/abbot/tester/ComponentTesterTest.java 2012-05-18 13:12:51 UTC (rev 2834) +++ abbot/trunk/test/abbot/tester/ComponentTesterTest.java 2012-05-28 09:19:02 UTC (rev 2835) @@ -12,8 +12,10 @@ import abbot.util.*; import abbot.util.Bugs; +import java.util.concurrent.TimeUnit; + /** Unit test to verify the base ComponentTester class.<p> - + <ul> <li>Test all exported actions. </ul> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |