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.XAccessibleSelection; 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 component 57 * of the 'Font' combo box in Format->Character... dislog box. <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::XAccessibleContext</code></li> 65 * </ul> <p> 66 * 67 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 68 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 69 * @see com.sun.star.accessibility.XAccessibleComponent 70 * @see com.sun.star.accessibility.XAccessibleContext 71 * @see ifc.accessibility._XAccessibleExtendedComponent 72 * @see ifc.accessibility._XAccessibleEventBroadcaster 73 * @see ifc.accessibility._XAccessibleComponent 74 * @see ifc.accessibility._XAccessibleContext 75 */ 76 public class AccessibleComboBox extends TestCase { 77 private static XTextDocument xTextDoc = null; 78 private static XAccessibleAction action = null; 79 80 /** 81 * Opens CharacterStyle dialog and 82 * finds AccessibleComboBox walking through the 83 * accessible component tree. 84 */ 85 protected TestEnvironment createTestEnvironment(TestParameters Param, 86 PrintWriter log) { 87 XInterface oObj = null; 88 89 try { 90 oObj = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance( 91 "com.sun.star.awt.Toolkit"); 92 } catch (com.sun.star.uno.Exception e) { 93 log.println("Couldn't get toolkit"); 94 e.printStackTrace(log); 95 throw new StatusException("Couldn't get toolkit", e); 96 } 97 98 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface( 99 XExtendedToolkit.class, oObj); 100 101 DiagThread psDiag = new DiagThread(xTextDoc, 102 (XMultiServiceFactory) Param.getMSF()); 103 psDiag.start(); 104 105 util.utils.shortWait(Param.getInt("ShortWait")); 106 107 AccessibilityTools at = new AccessibilityTools(); 108 109 util.utils.shortWait(Param.getInt("ShortWait")); 110 111 Object atw = tk.getActiveTopWindow(); 112 113 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, 114 atw); 115 116 XAccessible xRoot = at.getAccessibleObject(xWindow); 117 118 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON, 119 "Cancel"); 120 action = (XAccessibleAction) UnoRuntime.queryInterface( 121 XAccessibleAction.class, oObj); 122 123 oObj = at.getAccessibleObjectForRole(xRoot, 124 AccessibleRole.PAGE_TAB_LIST); 125 126 XAccessibleSelection xAccSel = (XAccessibleSelection) UnoRuntime.queryInterface( 127 XAccessibleSelection.class, 128 oObj); 129 130 try { 131 xAccSel.selectAccessibleChild(0); 132 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 133 e.printStackTrace(log); 134 } 135 util.utils.shortWait(Param.getInt("ShortWait")); 136 137 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 138 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL, "", 139 "AccessibleComboBox"); 140 141 log.println("ImplementationName " + utils.getImplName(oObj)); 142 143 TestEnvironment tEnv = new TestEnvironment(oObj); 144 145 final XAccessibleComponent acomp = (XAccessibleComponent) UnoRuntime.queryInterface( 146 XAccessibleComponent.class, 147 oObj); 148 final XAccessibleComponent acomp1 = (XAccessibleComponent) UnoRuntime.queryInterface( 149 XAccessibleComponent.class, 150 action); 151 152 tEnv.addObjRelation("EventProducer", 153 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 154 public void fireEvent() { 155 acomp1.grabFocus(); 156 acomp.grabFocus(); 157 } 158 }); 159 160 return tEnv; 161 } 162 163 /** 164 * Closes the dialog using accessible button 'Cancel' found in 165 * <code>createTestEnvironment()</code>. 166 */ 167 protected void cleanup(TestParameters Param, PrintWriter log) { 168 log.println(" closing dialog "); 169 170 try { 171 action.doAccessibleAction(0); 172 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) { 173 log.println("Couldn't close dialog"); 174 } catch (com.sun.star.lang.DisposedException de) { 175 log.println("Dialog already disposed"); 176 } 177 178 util.DesktopTools.closeDoc(xTextDoc); 179 ; 180 } 181 182 /** 183 * Creates writer doc 184 */ 185 protected void initialize(TestParameters Param, PrintWriter log) { 186 try { 187 SOfficeFactory SOF = SOfficeFactory.getFactory( 188 (XMultiServiceFactory) Param.getMSF()); 189 xTextDoc = SOF.createTextDoc(null); 190 } catch (com.sun.star.uno.Exception e) { 191 throw new StatusException("Can't create document", e); 192 } 193 } 194 195 196 /** 197 * Thread for opening modal dialog 'Character style'. 198 */ 199 public class DiagThread extends Thread { 200 public XTextDocument xTextDoc = null; 201 public XMultiServiceFactory msf = null; 202 203 public DiagThread(XTextDocument xTextDoc, XMultiServiceFactory msf) { 204 this.xTextDoc = xTextDoc; 205 this.msf = msf; 206 } 207 208 public void run() { 209 XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class, 210 xTextDoc); 211 212 XController xController = aModel.getCurrentController(); 213 214 //Opening PrinterSetupDialog 215 try { 216 String aSlotID = ".uno:FontDialog"; 217 XDispatchProvider xDispProv = (XDispatchProvider) UnoRuntime.queryInterface( 218 XDispatchProvider.class, 219 xController); 220 XURLTransformer xParser = (com.sun.star.util.XURLTransformer) UnoRuntime.queryInterface( 221 XURLTransformer.class, 222 msf.createInstance( 223 "com.sun.star.util.URLTransformer")); 224 225 // Because it's an in/out parameter 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 }