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.TestEnvironment; 47 import lib.TestParameters; 48 49 import util.AccessibilityTools; 50 import util.SOfficeFactory; 51 import util.utils; 52 53 54 /** 55 * Object implements the following interfaces : 56 * <ul> 57 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li> 58 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li> 59 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li> 60 * <li> <code>::com::sun::star::accessibility::XAccessibleValue</code></li> 61 * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li> 62 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li> 63 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li> 64 * </ul> <p> 65 * 66 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 67 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 68 * @see com.sun.star.accessibility.XAccessibleComponent 69 * @see com.sun.star.accessibility.XAccessibleValue 70 * @see com.sun.star.accessibility.XAccessibleAction 71 * @see com.sun.star.accessibility.XAccessibleContext 72 * @see com.sun.star.accessibility.XAccessibleText 73 * @see ifc.accessibility._XAccessibleExtendedComponent 74 * @see ifc.accessibility._XAccessibleEventBroadcaster 75 * @see ifc.accessibility._XAccessibleComponent 76 * @see ifc.accessibility._XAccessibleValue 77 * @see ifc.accessibility._XAccessibleAction 78 * @see ifc.accessibility._XAccessibleContext 79 * @see ifc.accessibility._XAccessibleText 80 */ 81 public class AccessibleButton extends lib.TestCase { 82 private static XTextDocument xTextDoc = null; 83 private static XAccessibleAction action = null; 84 85 /** 86 * Opens 'Printer Settings' dialog using document dispatch provider 87 * running in a separate thread. Finds active top window (the dialog 88 * window) and finds accessible button 'OK' walking through the 89 * accessible component tree. 90 */ 91 protected TestEnvironment createTestEnvironment(TestParameters Param, 92 PrintWriter log) { 93 XInterface oObj = null; 94 XMultiServiceFactory msf = (XMultiServiceFactory) Param.getMSF(); 95 96 try { 97 oObj = (XInterface) msf.createInstance("com.sun.star.awt.Toolkit"); 98 } catch (com.sun.star.uno.Exception e) { 99 log.println("Couldn't get toolkit"); 100 e.printStackTrace(log); 101 throw new StatusException("Couldn't get toolkit", e); 102 } 103 104 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface( 105 XExtendedToolkit.class, oObj); 106 107 util.utils.shortWait(Param.getInt("ShortWait")); 108 109 DiagThread psDiag = new DiagThread(xTextDoc, msf); 110 psDiag.start(); 111 112 util.utils.shortWait(Param.getInt("ShortWait")); 113 114 AccessibilityTools at = new AccessibilityTools(); 115 116 util.utils.shortWait(Param.getInt("ShortWait")); 117 118 Object atw = tk.getActiveTopWindow(); 119 120 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, 121 atw); 122 123 XAccessible xRoot = at.getAccessibleObject(xWindow); 124 125 126 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 127 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON, 128 "Cancel"); 129 130 log.println("ImplementationName " + utils.getImplName(oObj)); 131 132 TestEnvironment tEnv = new TestEnvironment(oObj); 133 134 action = (XAccessibleAction) UnoRuntime.queryInterface( 135 XAccessibleAction.class, oObj); 136 137 final XAccessibleComponent acomp = (XAccessibleComponent) UnoRuntime.queryInterface( 138 XAccessibleComponent.class, 139 oObj); 140 141 tEnv.addObjRelation("EventProducer", 142 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 143 public void fireEvent() { 144 System.out.println("Grabbing focus ... "); 145 acomp.grabFocus(); 146 } 147 }); 148 149 XAccessibleText text = (XAccessibleText) UnoRuntime.queryInterface( 150 XAccessibleText.class, oObj); 151 152 tEnv.addObjRelation("XAccessibleText.Text", text.getText()); 153 154 tEnv.addObjRelation("EditOnly", 155 "This method isn't supported in this component"); 156 157 tEnv.addObjRelation("LimitedBounds", "yes"); 158 159 return tEnv; 160 } 161 162 /** 163 * Closes the dialog using accessible button 'OK' found in 164 * <code>createTestEnvironment()</code>. 165 */ 166 protected void cleanup(TestParameters Param, PrintWriter log) { 167 log.println(" disposing xTextDoc "); 168 169 try { 170 action.doAccessibleAction(0); 171 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) { 172 log.println("Couldn't close dialog"); 173 } catch (com.sun.star.lang.DisposedException de) { 174 log.println("Dialog already disposed"); 175 } 176 177 util.DesktopTools.closeDoc(xTextDoc); 178 ; 179 } 180 181 /** 182 * Opens new writer document. 183 */ 184 protected void initialize(TestParameters Param, PrintWriter log) { 185 try { 186 SOfficeFactory SOF = SOfficeFactory.getFactory( 187 (XMultiServiceFactory) Param.getMSF()); 188 xTextDoc = SOF.createTextDoc(null); 189 } catch (com.sun.star.uno.Exception e) { 190 throw new StatusException("Can't create document", e); 191 } 192 } 193 194 195 /** 196 * Thread for opening modal dialog 'Print Settings'. 197 */ 198 public class DiagThread extends Thread { 199 public XTextDocument xTextDoc = null; 200 public XMultiServiceFactory msf = null; 201 202 public DiagThread(XTextDocument xTextDoc, XMultiServiceFactory msf) { 203 this.xTextDoc = xTextDoc; 204 this.msf = msf; 205 } 206 207 public void run() { 208 XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class, 209 xTextDoc); 210 211 XController xController = aModel.getCurrentController(); 212 213 //Opening PrinterSetupDialog 214 try { 215 String aSlotID = ".uno:Zoom"; 216 XDispatchProvider xDispProv = (XDispatchProvider) UnoRuntime.queryInterface( 217 XDispatchProvider.class, 218 xController); 219 XURLTransformer xParser = (com.sun.star.util.XURLTransformer) UnoRuntime.queryInterface( 220 XURLTransformer.class, 221 msf.createInstance( 222 "com.sun.star.util.URLTransformer")); 223 224 // Because it's an in/out parameter 225 // we must use an array of URL objects. 226 URL[] aParseURL = new URL[1]; 227 aParseURL[0] = new URL(); 228 aParseURL[0].Complete = aSlotID; 229 xParser.parseStrict(aParseURL); 230 231 URL aURL = aParseURL[0]; 232 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0); 233 234 if (xDispatcher != null) { 235 xDispatcher.dispatch(aURL, null); 236 } 237 } catch (com.sun.star.uno.Exception e) { 238 log.println("Couldn't open dialog"); 239 } 240 } 241 } 242 }