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