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.XAccessibleContext; 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.XDesktop; 39 import com.sun.star.frame.XDispatch; 40 import com.sun.star.frame.XDispatchProvider; 41 import com.sun.star.frame.XModel; 42 import com.sun.star.lang.XMultiServiceFactory; 43 import com.sun.star.text.XTextDocument; 44 import com.sun.star.uno.UnoRuntime; 45 import com.sun.star.uno.XInterface; 46 import com.sun.star.util.URL; 47 import com.sun.star.util.XURLTransformer; 48 49 import java.io.PrintWriter; 50 51 import lib.StatusException; 52 import lib.TestCase; 53 import lib.TestEnvironment; 54 import lib.TestParameters; 55 56 import util.AccessibilityTools; 57 import util.DesktopTools; 58 import util.SOfficeFactory; 59 60 61 /** 62 * Test for object that implements the following interfaces : 63 * <ul> 64 * <li><code> 65 * ::com::sun::star::accessibility::XAccessibleContext</code></li> 66 * <li><code> 67 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster 68 * </code></li> 69 * <li><code> 70 * ::com::sun::star::accessibility::XAccessibleComponent</code></li> 71 * <li><code> 72 * ::com::sun::star::accessibility::XAccessibleExtendedComponent 73 * </code></li> 74 * <li><code> 75 * ::com::sun::star::accessibility::XAccessibleSelection 76 * </code></li> 77 * </ul> <p> 78 * 79 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 80 * @see com.sun.star.accessibility.XAccessibleContext 81 * @see com.sun.star.accessibility.XAccessibleComponent 82 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 83 * @see com.sun.star.accessibility.XAccessibleSelection 84 * @see ifc.accessibility._XAccessibleEventBroadcaster 85 * @see ifc.accessibility._XAccessibleContext 86 * @see ifc.accessibility._XAccessibleComponent 87 * @see ifc.accessibility.XAccessibleExtendedComponent 88 * @see ifc.accessibility.XAccessibleSelection 89 */ 90 public class AccessibleTabControl extends TestCase { 91 private static XDesktop the_Desk; 92 private static XTextDocument xTextDoc; 93 private static XAccessibleAction accCloseButton = null; 94 95 /** 96 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>). 97 */ 98 protected void initialize(TestParameters Param, PrintWriter log) { 99 the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, 100 DesktopTools.createDesktop( 101 (XMultiServiceFactory) Param.getMSF())); 102 } 103 104 /** 105 * Closes an InsertFields dialog, disposes the document, if exists, created in 106 * <code>createTestEnvironment</code> method. 107 */ 108 protected void cleanup(TestParameters Param, PrintWriter log) { 109 try { 110 if (accCloseButton != null) { 111 log.println("closing InsertFields Dialog"); 112 accCloseButton.doAccessibleAction(0); 113 } 114 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 115 e.printStackTrace(log); 116 } 117 118 log.println("disposing xTextDoc"); 119 120 if (xTextDoc != null) { 121 util.DesktopTools.closeDoc(xTextDoc); 122 ; 123 } 124 } 125 126 /** 127 * Creates a text document, opens an InsertField dialog. 128 * Then obtains an accessible object with 129 * the role <code>AccessibleRole.PAGETABLIST</code>. 130 * Object relations created : 131 * <ul> 132 * <li> <code>'EventProducer'</code> for 133 * {@link ifc.accessibility._XAccessibleEventBroadcaster}: 134 * selects items </li> 135 * <li> <code>'XAccessibleSelection.multiSelection'</code> 136 * of type <code>Boolean</code> for 137 * {@link ifc.accessibility._XAccessibleSelection}: 138 * indicates that component supports single selection mode.</li> 139 * </ul> 140 * 141 * @param tParam test parameters 142 * @param log writer to log information while testing 143 * 144 * @see com.sun.star.awt.Toolkit 145 * @see com.sun.star.accessibility.AccessibleRole 146 * @see ifc.accessibility._XAccessibleEventBroadcaster 147 * @see ifc.accessibility._XAccessibleSelection 148 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 149 * @see com.sun.star.accessibility.XAccessibleSelection 150 */ 151 protected TestEnvironment createTestEnvironment(TestParameters tParam, 152 PrintWriter log) { 153 log.println("creating a test environment"); 154 155 if (xTextDoc != null) { 156 util.DesktopTools.closeDoc(xTextDoc); 157 ; 158 } 159 160 // get a soffice factory object 161 SOfficeFactory SOF = SOfficeFactory.getFactory( 162 (XMultiServiceFactory) tParam.getMSF()); 163 164 try { 165 log.println("creating a text document"); 166 xTextDoc = SOF.createTextDoc(null); 167 } catch (com.sun.star.uno.Exception e) { 168 // Some exception occures.FAILED 169 e.printStackTrace(log); 170 throw new StatusException("Couldn't create document", e); 171 } 172 173 shortWait(); 174 175 XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class, 176 xTextDoc); 177 178 XController secondController = aModel1.getCurrentController(); 179 180 XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface( 181 XDispatchProvider.class, 182 secondController); 183 184 XURLTransformer urlTransf = null; 185 186 try { 187 XInterface transf = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance( 188 "com.sun.star.util.URLTransformer"); 189 urlTransf = (XURLTransformer) UnoRuntime.queryInterface( 190 XURLTransformer.class, transf); 191 } catch (com.sun.star.uno.Exception e) { 192 e.printStackTrace(log); 193 throw new StatusException("Couldn't create URLTransformer", e); 194 } 195 196 XDispatch getting = null; 197 log.println("opening InsertField dialog"); 198 199 URL[] url = new URL[1]; 200 url[0] = new URL(); 201 url[0].Complete = ".uno:InsertField"; 202 urlTransf.parseStrict(url); 203 getting = aProv.queryDispatch(url[0], "", 0); 204 205 PropertyValue[] noArgs = new PropertyValue[0]; 206 getting.dispatch(url[0], noArgs); 207 208 shortWait(); 209 210 XInterface oObj = null; 211 212 try { 213 oObj = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance( 214 "com.sun.star.awt.Toolkit"); 215 } catch (com.sun.star.uno.Exception e) { 216 log.println("Couldn't get toolkit"); 217 e.printStackTrace(log); 218 throw new StatusException("Couldn't get toolkit", e); 219 } 220 221 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface( 222 XExtendedToolkit.class, oObj); 223 224 AccessibilityTools at = new AccessibilityTools(); 225 226 shortWait(); 227 228 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, 229 tk.getActiveTopWindow()); 230 231 XAccessible xRoot = at.getAccessibleObject(xWindow); 232 233 oObj = at.getAccessibleObjectForRole(xRoot, 234 AccessibleRole.PAGE_TAB_LIST); 235 236 XAccessibleContext closeButton = at.getAccessibleObjectForRole(xRoot, 237 AccessibleRole.PUSH_BUTTON, 238 "Close"); 239 240 accCloseButton = (XAccessibleAction) UnoRuntime.queryInterface( 241 XAccessibleAction.class, closeButton); 242 243 log.println("ImplementationName: " + util.utils.getImplName(oObj)); 244 245 TestEnvironment tEnv = new TestEnvironment(oObj); 246 247 final XAccessibleSelection selection = (XAccessibleSelection) (XAccessibleSelection) UnoRuntime.queryInterface( 248 XAccessibleSelection.class, 249 oObj); 250 251 tEnv.addObjRelation("EventProducer", 252 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 253 public void fireEvent() { 254 try { 255 selection.selectAccessibleChild(1); 256 selection.selectAccessibleChild(0); 257 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 258 } 259 } 260 }); 261 262 tEnv.addObjRelation("XAccessibleSelection.OneAlwaysSelected", 263 new Boolean(true)); 264 265 tEnv.addObjRelation("XAccessibleSelection.multiSelection", 266 new Boolean(false)); 267 268 return tEnv; 269 } 270 271 /** 272 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 273 * reset</code> call. 274 */ 275 private void shortWait() { 276 try { 277 Thread.currentThread().sleep(500); 278 } catch (InterruptedException e) { 279 System.out.println("While waiting :" + e); 280 } 281 } 282 }