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.beans.PropertyValue; 37 import com.sun.star.frame.XController; 38 import com.sun.star.frame.XDispatch; 39 import com.sun.star.frame.XDispatchProvider; 40 import com.sun.star.frame.XModel; 41 import com.sun.star.lang.XMultiServiceFactory; 42 import com.sun.star.text.XTextDocument; 43 import com.sun.star.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 import com.sun.star.util.URL; 46 import com.sun.star.util.XURLTransformer; 47 48 import java.io.PrintWriter; 49 50 import lib.StatusException; 51 import lib.TestCase; 52 import lib.TestEnvironment; 53 import lib.TestParameters; 54 55 import util.AccessibilityTools; 56 import util.SOfficeFactory; 57 import util.utils; 58 59 60 /** 61 * Test for object which is represented accessible component 62 * of 'File type' list box situated in 'Insert Hyperlink' 63 * dialog on tab 'New Document'. <p> 64 * 65 * Object implements the following interfaces : 66 * <ul> 67 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li> 68 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li> 69 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li> 70 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li> 71 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li> 72 * </ul> <p> 73 * 74 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 75 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 76 * @see com.sun.star.accessibility.XAccessibleComponent 77 * @see com.sun.star.accessibility.XAccessibleSelection 78 * @see com.sun.star.accessibility.XAccessibleContext 79 * @see ifc.accessibility._XAccessibleExtendedComponent 80 * @see ifc.accessibility._XAccessibleEventBroadcaster 81 * @see ifc.accessibility._XAccessibleComponent 82 * @see ifc.accessibility._XAccessibleSelection 83 * @see ifc.accessibility._XAccessibleContext 84 */ 85 public class AccessibleListBox extends TestCase { 86 private static XTextDocument xTextDoc = null; 87 private static XAccessibleAction action = null; 88 89 /** 90 * Opens 'Insert Hyperlink' dialog using document dispatch provider. 91 * Finds active top window (the dialog 92 * window) and finds button 'Close' (for closing this dialog when 93 * disposing) walking through the accessible component tree. 94 * Then the TREE component is found and the 'New Document' tab is 95 * selected to make list box visible. After that list box is obtained. 96 */ 97 protected TestEnvironment createTestEnvironment(TestParameters Param, 98 PrintWriter log) { 99 XInterface oObj = null; 100 101 try { 102 oObj = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance( 103 "com.sun.star.awt.Toolkit"); 104 } catch (com.sun.star.uno.Exception e) { 105 log.println("Couldn't get toolkit"); 106 e.printStackTrace(log); 107 throw new StatusException("Couldn't get toolkit", e); 108 } 109 110 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface( 111 XExtendedToolkit.class, oObj); 112 113 shortWait(); 114 115 XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class, 116 xTextDoc); 117 118 XController secondController = aModel1.getCurrentController(); 119 120 XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface( 121 XDispatchProvider.class, 122 secondController); 123 124 XURLTransformer urlTransf = null; 125 126 try { 127 XInterface transf = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance( 128 "com.sun.star.util.URLTransformer"); 129 urlTransf = (XURLTransformer) UnoRuntime.queryInterface( 130 XURLTransformer.class, transf); 131 } catch (com.sun.star.uno.Exception e) { 132 e.printStackTrace(log); 133 throw new StatusException("Couldn't create URLTransformer", e); 134 } 135 136 XDispatch getting = null; 137 log.println("opening HyperlinkDialog"); 138 139 URL[] url = new URL[1]; 140 url[0] = new URL(); 141 url[0].Complete = ".uno:HyperlinkDialog"; 142 urlTransf.parseStrict(url); 143 getting = aProv.queryDispatch(url[0], "", 0); 144 145 PropertyValue[] noArgs = new PropertyValue[0]; 146 getting.dispatch(url[0], noArgs); 147 148 shortWait(); 149 150 AccessibilityTools at = new AccessibilityTools(); 151 152 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, 153 tk.getActiveTopWindow()); 154 155 XAccessible xRoot = at.getAccessibleObject(xWindow); 156 157 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 158 159 160 // obtaining 'Close' button 161 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON, 162 "Close"); 163 action = (XAccessibleAction) UnoRuntime.queryInterface( 164 XAccessibleAction.class, oObj); 165 166 // Selecting 'New Document' tab 167 try { 168 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TREE); 169 170 XAccessibleSelection xAccSel = (XAccessibleSelection) UnoRuntime.queryInterface( 171 XAccessibleSelection.class, 172 oObj); 173 xAccSel.selectAccessibleChild(3); 174 shortWait(); 175 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 176 throw new StatusException("Can't switch to required tab", e); 177 } 178 179 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL, "", 180 "com.sun.star.comp.toolkit.AccessibleListBox"); 181 182 Object list = at.getAccessibleObjectForRole(at.SearchedAccessible, 183 AccessibleRole.LIST); 184 185 log.println("ImplementationName " + utils.getImplName(oObj)); 186 187 TestEnvironment tEnv = new TestEnvironment(oObj); 188 189 final XAccessibleComponent acomp = (XAccessibleComponent) UnoRuntime.queryInterface( 190 XAccessibleComponent.class, 191 list); 192 final XAccessibleComponent acomp1 = (XAccessibleComponent) UnoRuntime.queryInterface( 193 XAccessibleComponent.class, 194 action); 195 196 tEnv.addObjRelation("EventProducer", 197 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 198 public void fireEvent() { 199 System.out.println("Grabbing focus ... "); 200 acomp1.grabFocus(); 201 acomp.grabFocus(); 202 } 203 }); 204 205 return tEnv; 206 } 207 208 /** 209 * Closes dialog using action of button 'Close' 210 */ 211 protected void cleanup(TestParameters Param, PrintWriter log) { 212 log.println(" Closing dialog ... "); 213 214 try { 215 action.doAccessibleAction(0); 216 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) { 217 log.println("Couldn't close dialog"); 218 } catch (com.sun.star.lang.DisposedException de) { 219 log.println("Dialog already disposed"); 220 } 221 222 util.DesktopTools.closeDoc(xTextDoc); 223 ; 224 } 225 226 /** 227 * Creates writer document 228 */ 229 protected void initialize(TestParameters Param, PrintWriter log) { 230 try { 231 SOfficeFactory SOF = SOfficeFactory.getFactory( 232 (XMultiServiceFactory) Param.getMSF()); 233 xTextDoc = SOF.createTextDoc(null); 234 } catch (com.sun.star.uno.Exception e) { 235 throw new StatusException("Can't create document", e); 236 } 237 } 238 239 /** 240 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 241 * reset</code> call. 242 */ 243 private void shortWait() { 244 try { 245 Thread.sleep(1000); 246 } catch (InterruptedException e) { 247 log.println("While waiting :" + e); 248 } 249 } 250 }