1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package mod._toolkit; 24 25 import com.sun.star.accessibility.AccessibleRole; 26 import com.sun.star.accessibility.XAccessible; 27 import com.sun.star.accessibility.XAccessibleAction; 28 import com.sun.star.accessibility.XAccessibleComponent; 29 import com.sun.star.accessibility.XAccessibleText; 30 import com.sun.star.awt.XExtendedToolkit; 31 import com.sun.star.awt.XWindow; 32 import com.sun.star.frame.XController; 33 import com.sun.star.frame.XDispatch; 34 import com.sun.star.frame.XDispatchProvider; 35 import com.sun.star.frame.XModel; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.text.XTextDocument; 38 import com.sun.star.uno.UnoRuntime; 39 import com.sun.star.uno.XInterface; 40 import com.sun.star.util.URL; 41 import com.sun.star.util.XURLTransformer; 42 43 import java.io.PrintWriter; 44 45 import lib.StatusException; 46 import lib.TestCase; 47 import lib.TestEnvironment; 48 import lib.TestParameters; 49 50 import util.AccessibilityTools; 51 import util.SOfficeFactory; 52 import util.utils; 53 54 55 /** 56 * Test for object which is represented by accessible compoent of 57 * check box in 'InsertTable' dialog. <p> 58 * 59 * Object implements the following interfaces : 60 * <ul> 61 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li> 62 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li> 63 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li> 64 * <li> <code>::com::sun::star::accessibility::XAccessibleValue</code></li> 65 * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li> 66 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li> 67 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li> 68 * </ul> <p> 69 * 70 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 71 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 72 * @see com.sun.star.accessibility.XAccessibleComponent 73 * @see com.sun.star.accessibility.XAccessibleValue 74 * @see com.sun.star.accessibility.XAccessibleAction 75 * @see com.sun.star.accessibility.XAccessibleContext 76 * @see com.sun.star.accessibility.XAccessibleText 77 * @see ifc.accessibility._XAccessibleExtendedComponent 78 * @see ifc.accessibility._XAccessibleEventBroadcaster 79 * @see ifc.accessibility._XAccessibleComponent 80 * @see ifc.accessibility._XAccessibleValue 81 * @see ifc.accessibility._XAccessibleAction 82 * @see ifc.accessibility._XAccessibleContext 83 * @see ifc.accessibility._XAccessibleText 84 */ 85 public class AccessibleCheckBox extends TestCase { 86 private static XTextDocument xTextDoc = null; 87 private static XAccessibleAction action = null; 88 private static DiagThread psDiag = null; 89 90 /** 91 * Opens 'Insert Table' dialog using document dispatch provider 92 * running in a separate thread. Finds active top window (the dialog 93 * window) and finds first accessible check box walking through the 94 * accessible component tree. 95 */ 96 protected TestEnvironment createTestEnvironment(TestParameters Param, 97 PrintWriter log) { 98 XMultiServiceFactory msf = (XMultiServiceFactory) Param.getMSF(); 99 log.println("Creating text document"); 100 101 if (xTextDoc == null) { 102 try { 103 SOfficeFactory SOF = SOfficeFactory.getFactory(msf); 104 xTextDoc = SOF.createTextDoc(null); 105 } catch (com.sun.star.uno.Exception e) { 106 throw new StatusException("Can't create document", e); 107 } 108 } 109 110 util.utils.shortWait(Param.getInt("ShortWait")); 111 112 XInterface oObj = null; 113 114 log.println("getting toolkit"); 115 116 try { 117 oObj = (XInterface) msf.createInstance("com.sun.star.awt.Toolkit"); 118 } catch (com.sun.star.uno.Exception e) { 119 log.println("Couldn't get toolkit"); 120 e.printStackTrace(log); 121 throw new StatusException("Couldn't get toolkit", e); 122 } 123 124 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface( 125 XExtendedToolkit.class, oObj); 126 127 util.utils.shortWait(Param.getInt("ShortWait")); 128 129 log.println("Opening Dialog in second thread"); 130 131 psDiag = new DiagThread(xTextDoc, msf); 132 psDiag.start(); 133 134 util.utils.shortWait(Param.getInt("ShortWait")); 135 136 AccessibilityTools at = new AccessibilityTools(); 137 138 util.utils.shortWait(Param.getInt("ShortWait")); 139 140 log.println("Getting the active TopWindow"); 141 142 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, 143 tk.getActiveTopWindow()); 144 145 XAccessible xRoot = at.getAccessibleObject(xWindow); 146 147 148 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 149 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON, 150 "Cancel"); 151 152 action = (XAccessibleAction) UnoRuntime.queryInterface( 153 XAccessibleAction.class, oObj); 154 155 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.CHECK_BOX); 156 157 log.println("ImplementationName " + utils.getImplName(oObj)); 158 159 TestEnvironment tEnv = new TestEnvironment(oObj); 160 161 final XAccessibleComponent acomp = (XAccessibleComponent) UnoRuntime.queryInterface( 162 XAccessibleComponent.class, 163 oObj); 164 165 tEnv.addObjRelation("EventProducer", 166 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 167 public void fireEvent() { 168 System.out.println("Grabbing focus ... "); 169 acomp.grabFocus(); 170 } 171 }); 172 173 XAccessibleText text = (XAccessibleText) UnoRuntime.queryInterface( 174 XAccessibleText.class, oObj); 175 176 tEnv.addObjRelation("XAccessibleText.Text", text.getText()); 177 178 tEnv.addObjRelation("EditOnly", 179 "This method isn't supported in this component"); 180 181 tEnv.addObjRelation("LimitedBounds", "yes"); 182 183 return tEnv; 184 } 185 186 /** 187 * Closes the dialog using accessible button 'Cancel' found in 188 * <code>createTestEnvironment()</code>. 189 */ 190 protected void cleanup(TestParameters Param, PrintWriter log) { 191 try { 192 log.println("closing dialog"); 193 action.doAccessibleAction(0); 194 log.println("interrupting corresponding Thread"); 195 psDiag.interrupt(); 196 log.println("closing the document"); 197 util.DesktopTools.closeDoc(xTextDoc); 198 ; 199 log.println("reinitialize the variable"); 200 xTextDoc = null; 201 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) { 202 log.println("Couldn't close dialog"); 203 } catch (com.sun.star.lang.DisposedException de) { 204 log.println("Dialog already disposed"); 205 } 206 } 207 208 protected void initialize(TestParameters Param, PrintWriter log) { 209 } 210 211 /** 212 * Thread for opening modal dialog 'Insert Table'. 213 */ 214 public class DiagThread extends Thread { 215 public XTextDocument xTextDoc = null; 216 public XMultiServiceFactory msf = null; 217 218 public DiagThread(XTextDocument xTextDoc, XMultiServiceFactory msf) { 219 this.xTextDoc = xTextDoc; 220 this.msf = msf; 221 } 222 223 public void run() { 224 XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class, 225 xTextDoc); 226 227 XController xController = aModel.getCurrentController(); 228 229 //Opening PrinterSetupDialog 230 try { 231 String aSlotID = ".uno:InsertTable"; 232 XDispatchProvider xDispProv = (XDispatchProvider) UnoRuntime.queryInterface( 233 XDispatchProvider.class, 234 xController); 235 XURLTransformer xParser = (com.sun.star.util.XURLTransformer) UnoRuntime.queryInterface( 236 XURLTransformer.class, 237 msf.createInstance( 238 "com.sun.star.util.URLTransformer")); 239 240 // Because it's an in/out parameter we must use an array of URL objects. 241 URL[] aParseURL = new URL[1]; 242 aParseURL[0] = new URL(); 243 aParseURL[0].Complete = aSlotID; 244 xParser.parseStrict(aParseURL); 245 246 URL aURL = aParseURL[0]; 247 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0); 248 249 if (xDispatcher != null) { 250 xDispatcher.dispatch(aURL, null); 251 } 252 } catch (com.sun.star.uno.Exception e) { 253 log.println("Couldn't open dialog"); 254 } 255 } 256 } 257 }