Try make this more robust in slow environments

...where the previous .uno:PrintPreview request has not yet been processed, the
same way it had been made more robust for ScAccessiblePageHeader.java in
5b5c52a3a4d048bba8c18dfb06ffca25c670d099 "Try make this more robust in slow
environments" plus b5dd2b4218f966e177d880bcc29fa5fba3bfe1c1 "Also cope with
intermittend DisposedExceptions."

Change-Id: I4d429a96b7b595776aaf3fa20e3e03b00ca886bc
This commit is contained in:
Stephan Bergmann 2013-10-08 10:52:56 +02:00
parent f52d78bf7c
commit dcee4cfcdc

View File

@ -38,6 +38,7 @@ import com.sun.star.frame.XController;
import com.sun.star.frame.XDispatch; import com.sun.star.frame.XDispatch;
import com.sun.star.frame.XDispatchProvider; import com.sun.star.frame.XDispatchProvider;
import com.sun.star.frame.XModel; import com.sun.star.frame.XModel;
import com.sun.star.lang.DisposedException;
import com.sun.star.lang.XComponent; import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.sheet.XSpreadsheet; import com.sun.star.sheet.XSpreadsheet;
@ -86,7 +87,6 @@ public class AccessibleEditableTextPara_PreviewCell extends TestCase {
*/ */
protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
XAccessibleContext oObj = null;
XCell xCell = null; XCell xCell = null;
try { try {
@ -136,19 +136,38 @@ public class AccessibleEditableTextPara_PreviewCell extends TestCase {
throw new StatusException(Status.failed("Couldn't change mode")); throw new StatusException(Status.failed("Couldn't change mode"));
} }
shortWait(); XAccessibleContext oObj = null;
for (int i = 0;; ++i) {
try {
XWindow xWindow = AccessibilityTools.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), xModel); Thread.sleep(500);
XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow); } catch (InterruptedException e) {
//AccessibilityTools.printAccessibleTree(log,xRoot); throw new RuntimeException(e);
AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE_CELL,true); }
try {
xRoot = AccessibilityTools.SearchedAccessible; XAccessible xRoot = AccessibilityTools.getAccessibleObject(
AccessibilityTools.getCurrentWindow(
//AccessibilityTools.printAccessibleTree(log,xRoot); (XMultiServiceFactory) Param.getMSF(), xModel));
if (xRoot != null) {
oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot,AccessibleRole.PARAGRAPH); AccessibilityTools.getAccessibleObjectForRole(
xRoot, AccessibleRole.TABLE_CELL, true);
xRoot = AccessibilityTools.SearchedAccessible;
if (xRoot != null) {
oObj = AccessibilityTools.getAccessibleObjectForRole(
xRoot, AccessibleRole.PARAGRAPH);
if (oObj != null) {
break;
}
}
}
} catch (DisposedException e) {
log.println("Ignoring DisposedException");
}
if (i == 20) { // give up after 10 sec
throw new RuntimeException(
"Couldn't get AccessibleRoot.HEADER object");
}
log.println("No TABLE_CELL/PARAGRAPH found yet, retrying");
}
log.println("ImplementationName " + utils.getImplName(oObj)); log.println("ImplementationName " + utils.getImplName(oObj));
log.println("AccessibleName " + oObj.getAccessibleName()); log.println("AccessibleName " + oObj.getAccessibleName());
@ -169,12 +188,4 @@ public class AccessibleEditableTextPara_PreviewCell extends TestCase {
return tEnv; return tEnv;
} }
protected void shortWait() {
try {
Thread.sleep(1000) ;
} catch (InterruptedException e) {
System.out.println("While waiting :" + e);
}
}
} }