1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package mod._toolkit; 28 29 import com.sun.star.accessibility.AccessibleRole; 30 import com.sun.star.accessibility.XAccessible; 31 import com.sun.star.accessibility.XAccessibleAction; 32 import com.sun.star.accessibility.XAccessibleComponent; 33 import com.sun.star.accessibility.XAccessibleSelection; 34 import com.sun.star.awt.XExtendedToolkit; 35 import com.sun.star.awt.XWindow; 36 import com.sun.star.frame.XController; 37 import com.sun.star.frame.XDispatch; 38 import com.sun.star.frame.XDispatchProvider; 39 import com.sun.star.frame.XModel; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.text.XTextDocument; 42 import com.sun.star.uno.UnoRuntime; 43 import com.sun.star.uno.XInterface; 44 import com.sun.star.util.URL; 45 import com.sun.star.util.XURLTransformer; 46 47 import java.io.PrintWriter; 48 49 import lib.StatusException; 50 import lib.TestCase; 51 import lib.TestEnvironment; 52 import lib.TestParameters; 53 54 import util.AccessibilityTools; 55 import util.SOfficeFactory; 56 import util.utils; 57 58 59 /** 60 * Test for object which is represented by accessible component 61 * of the 'Font' combo box in Format->Character... dislog box. <p> 62 * 63 * Object implements the following interfaces : 64 * <ul> 65 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li> 66 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li> 67 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li> 68 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li> 69 * </ul> <p> 70 * 71 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 72 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 73 * @see com.sun.star.accessibility.XAccessibleComponent 74 * @see com.sun.star.accessibility.XAccessibleContext 75 * @see ifc.accessibility._XAccessibleExtendedComponent 76 * @see ifc.accessibility._XAccessibleEventBroadcaster 77 * @see ifc.accessibility._XAccessibleComponent 78 * @see ifc.accessibility._XAccessibleContext 79 */ 80 public class AccessibleComboBox extends TestCase { 81 private static XTextDocument xTextDoc = null; 82 private static XAccessibleAction action = null; 83 84 /** 85 * Opens CharacterStyle dialog and 86 * finds AccessibleComboBox walking through the 87 * accessible component tree. 88 */ 89 protected TestEnvironment createTestEnvironment(TestParameters Param, 90 PrintWriter log) { 91 XInterface oObj = null; 92 93 try { 94 oObj = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance( 95 "com.sun.star.awt.Toolkit"); 96 } catch (com.sun.star.uno.Exception e) { 97 log.println("Couldn't get toolkit"); 98 e.printStackTrace(log); 99 throw new StatusException("Couldn't get toolkit", e); 100 } 101 102 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface( 103 XExtendedToolkit.class, oObj); 104 105 DiagThread psDiag = new DiagThread(xTextDoc, 106 (XMultiServiceFactory) Param.getMSF()); 107 psDiag.start(); 108 109 util.utils.shortWait(Param.getInt("ShortWait")); 110 111 AccessibilityTools at = new AccessibilityTools(); 112 113 util.utils.shortWait(Param.getInt("ShortWait")); 114 115 Object atw = tk.getActiveTopWindow(); 116 117 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, 118 atw); 119 120 XAccessible xRoot = at.getAccessibleObject(xWindow); 121 122 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON, 123 "Cancel"); 124 action = (XAccessibleAction) UnoRuntime.queryInterface( 125 XAccessibleAction.class, oObj); 126 127 oObj = at.getAccessibleObjectForRole(xRoot, 128 AccessibleRole.PAGE_TAB_LIST); 129 130 XAccessibleSelection xAccSel = (XAccessibleSelection) UnoRuntime.queryInterface( 131 XAccessibleSelection.class, 132 oObj); 133 134 try { 135 xAccSel.selectAccessibleChild(0); 136 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 137 e.printStackTrace(log); 138 } 139 util.utils.shortWait(Param.getInt("ShortWait")); 140 141 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 142 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL, "", 143 "AccessibleComboBox"); 144 145 log.println("ImplementationName " + utils.getImplName(oObj)); 146 147 TestEnvironment tEnv = new TestEnvironment(oObj); 148 149 final XAccessibleComponent acomp = (XAccessibleComponent) UnoRuntime.queryInterface( 150 XAccessibleComponent.class, 151 oObj); 152 final XAccessibleComponent acomp1 = (XAccessibleComponent) UnoRuntime.queryInterface( 153 XAccessibleComponent.class, 154 action); 155 156 tEnv.addObjRelation("EventProducer", 157 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 158 public void fireEvent() { 159 acomp1.grabFocus(); 160 acomp.grabFocus(); 161 } 162 }); 163 164 return tEnv; 165 } 166 167 /** 168 * Closes the dialog using accessible button 'Cancel' found in 169 * <code>createTestEnvironment()</code>. 170 */ 171 protected void cleanup(TestParameters Param, PrintWriter log) { 172 log.println(" closing dialog "); 173 174 try { 175 action.doAccessibleAction(0); 176 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) { 177 log.println("Couldn't close dialog"); 178 } catch (com.sun.star.lang.DisposedException de) { 179 log.println("Dialog already disposed"); 180 } 181 182 util.DesktopTools.closeDoc(xTextDoc); 183 ; 184 } 185 186 /** 187 * Creates writer doc 188 */ 189 protected void initialize(TestParameters Param, PrintWriter log) { 190 try { 191 SOfficeFactory SOF = SOfficeFactory.getFactory( 192 (XMultiServiceFactory) Param.getMSF()); 193 xTextDoc = SOF.createTextDoc(null); 194 } catch (com.sun.star.uno.Exception e) { 195 throw new StatusException("Can't create document", e); 196 } 197 } 198 199 200 /** 201 * Thread for opening modal dialog 'Character style'. 202 */ 203 public class DiagThread extends Thread { 204 public XTextDocument xTextDoc = null; 205 public XMultiServiceFactory msf = null; 206 207 public DiagThread(XTextDocument xTextDoc, XMultiServiceFactory msf) { 208 this.xTextDoc = xTextDoc; 209 this.msf = msf; 210 } 211 212 public void run() { 213 XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class, 214 xTextDoc); 215 216 XController xController = aModel.getCurrentController(); 217 218 //Opening PrinterSetupDialog 219 try { 220 String aSlotID = ".uno:FontDialog"; 221 XDispatchProvider xDispProv = (XDispatchProvider) UnoRuntime.queryInterface( 222 XDispatchProvider.class, 223 xController); 224 XURLTransformer xParser = (com.sun.star.util.XURLTransformer) UnoRuntime.queryInterface( 225 XURLTransformer.class, 226 msf.createInstance( 227 "com.sun.star.util.URLTransformer")); 228 229 // Because it's an in/out parameter we must use an array of URL objects. 230 URL[] aParseURL = new URL[1]; 231 aParseURL[0] = new URL(); 232 aParseURL[0].Complete = aSlotID; 233 xParser.parseStrict(aParseURL); 234 235 URL aURL = aParseURL[0]; 236 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0); 237 238 if (xDispatcher != null) { 239 xDispatcher.dispatch(aURL, null); 240 } 241 } catch (com.sun.star.uno.Exception e) { 242 log.println("Couldn't open dialog"); 243 } 244 } 245 } 246 }