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