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.accessibility.XAccessibleSelection; 31 import com.sun.star.accessibility.XAccessibleValue; 32 import com.sun.star.awt.XExtendedToolkit; 33 import com.sun.star.awt.XWindow; 34 import com.sun.star.beans.PropertyValue; 35 import com.sun.star.frame.XController; 36 import com.sun.star.frame.XDesktop; 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.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 * <li><code> 73 * ::com::sun::star::accessibility::XAccessibleValue</code></li> 74 * <li><code> 75 * ::com::sun::star::accessibility::XAccessibleText</code></li> 76 * </ul> <p> 77 * 78 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 79 * @see com.sun.star.accessibility.XAccessibleContext 80 * @see com.sun.star.accessibility.XAccessibleComponent 81 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 82 * @see com.sun.star.accessibility.XAccessibleValue 83 * @see com.sun.star.accessibility.XAccessibleText 84 * @see ifc.accessibility._XAccessibleEventBroadcaster 85 * @see ifc.accessibility._XAccessibleContext 86 * @see ifc.accessibility._XAccessibleComponent 87 * @see ifc.accessibility._XAccessibleExtendedComponent 88 * @see ifc.accessibility._XAccessibleValue 89 * @see ifc.accessibility._XAccessibleText 90 */ 91 public class AccessibleRadioButton extends TestCase { 92 private static XDesktop the_Desk; 93 private static XTextDocument xTextDoc; 94 private static XAccessibleAction accCloseButton; 95 96 97 /** 98 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>). 99 */ initialize(TestParameters Param, PrintWriter log)100 protected void initialize(TestParameters Param, PrintWriter log) { 101 the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, 102 DesktopTools.createDesktop( 103 (XMultiServiceFactory) Param.getMSF())); 104 } 105 106 /** 107 * Closes a Hyperlink dialog, disposes the document, if exists, created in 108 * <code>createTestEnvironment</code> method. 109 */ cleanup(TestParameters Param, PrintWriter log)110 protected void cleanup(TestParameters Param, PrintWriter log) { 111 try { 112 if (accCloseButton != null) { 113 log.println("closing HyperlinkDialog"); 114 accCloseButton.doAccessibleAction(0); 115 } 116 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 117 e.printStackTrace(log); 118 } catch (com.sun.star.lang.DisposedException de) { 119 log.println("Already disposed"); 120 } 121 122 log.println("disposing xTextDoc"); 123 124 if (xTextDoc != null) { 125 closeDoc(); 126 } 127 } 128 129 /** 130 * Creates a text document, opens a hypelink dialog, selects a first item 131 * in IconChoiceCtrl. 132 * Then obtains an accessible object with 133 * the role <code>AccessibleRole.RADIOBUTTON</code> with the name <code> 134 * "Internet"</code>. 135 * Object relations created : 136 * <ul> 137 * <li> <code>'EventProducer'</code> for 138 * {@link ifc.accessibility._XAccessibleEventBroadcaster}: 139 * grabs focus </li> 140 * <li> <code>'XAccessibleText.Text'</code> for 141 * {@link ifc.accessibility._XAccessibleText}: 142 * the text of the component </li> 143 * <li> <code>'XAccessibleValue.anotherFromGroup'</code> for 144 * {@link ifc.accessibility._XAccessibleValue}: 145 * <code>'FTP'</code> button </li> 146 * </ul> 147 * 148 * @param tParam test parameters 149 * @param log writer to log information while testing 150 * 151 * @see com.sun.star.awt.Toolkit 152 * @see com.sun.star.accessibility.AccessibleRole 153 * @see ifc.accessibility._XAccessibleEventBroadcaster 154 * @see ifc.accessibility._XAccessibleText 155 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 156 * @see com.sun.star.accessibility.XAccessibleText 157 */ createTestEnvironment(TestParameters tParam, PrintWriter log)158 protected TestEnvironment createTestEnvironment(TestParameters tParam, 159 PrintWriter log) { 160 log.println("creating a test environment"); 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 util.utils.shortWait(2000); 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 HyperlinkDialog"); 200 201 URL[] url = new URL[1]; 202 url[0] = new URL(); 203 url[0].Complete = ".uno:HyperlinkDialog"; 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 util.utils.shortWait(2000); 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 util.utils.shortWait(2000); 229 230 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, 231 tk.getActiveTopWindow()); 232 233 XAccessible xRoot = at.getAccessibleObject(xWindow); 234 235 XAccessibleContext iconChoiceCtrl = at.getAccessibleObjectForRole( 236 xRoot, AccessibleRole.TREE, 237 "IconChoiceControl"); 238 239 XAccessibleSelection sel = (XAccessibleSelection) UnoRuntime.queryInterface( 240 XAccessibleSelection.class, 241 iconChoiceCtrl); 242 243 try { 244 sel.selectAccessibleChild(0); 245 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 246 log.println("Unexpected exception"); 247 e.printStackTrace(log); 248 } 249 250 at.printAccessibleTree(log,xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 251 252 oObj = at.getAccessibleObjectForRole(xRoot, 253 AccessibleRole.RADIO_BUTTON, 254 "Web"); 255 256 XAccessibleContext anotherButton = at.getAccessibleObjectForRole(xRoot, 257 AccessibleRole.RADIO_BUTTON, 258 "FTP"); 259 260 XAccessibleContext closeButton = at.getAccessibleObjectForRole(xRoot, 261 AccessibleRole.PUSH_BUTTON, 262 "Close"); 263 264 265 accCloseButton = (XAccessibleAction) UnoRuntime.queryInterface( 266 XAccessibleAction.class, closeButton); 267 268 log.println("ImplementationName: " + util.utils.getImplName(oObj)); 269 270 TestEnvironment tEnv = new TestEnvironment(oObj); 271 272 tEnv.addObjRelation("EditOnly", 273 "This method isn't supported in this component"); 274 275 tEnv.addObjRelation("LimitedBounds", "yes"); 276 277 final XAccessibleComponent acomp = (XAccessibleComponent) UnoRuntime.queryInterface( 278 XAccessibleComponent.class, 279 oObj); 280 281 tEnv.addObjRelation("EventProducer", 282 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 283 public void fireEvent() { 284 acomp.grabFocus(); 285 } 286 }); 287 288 tEnv.addObjRelation("XAccessibleText.Text", "Web"); 289 290 tEnv.addObjRelation("EditOnly", 291 "Can't change or select Text in AccessibleRadioButton"); 292 293 XAccessibleValue anotherButtonValue = (XAccessibleValue) UnoRuntime.queryInterface( 294 XAccessibleValue.class, 295 anotherButton); 296 297 tEnv.addObjRelation("XAccessibleValue.anotherFromGroup", 298 anotherButtonValue); 299 300 return tEnv; 301 } 302 closeDoc()303 protected void closeDoc() { 304 util.DesktopTools.closeDoc(xTextDoc); 305 } 306 } 307