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.XAccessibleEditableText; 29 import com.sun.star.accessibility.XAccessibleText; 30 import com.sun.star.awt.XExtendedToolkit; 31 import com.sun.star.awt.XWindow; 32 import com.sun.star.beans.PropertyValue; 33 import com.sun.star.frame.XController; 34 import com.sun.star.frame.XDispatch; 35 import com.sun.star.frame.XDispatchProvider; 36 import com.sun.star.frame.XModel; 37 import com.sun.star.lang.XMultiServiceFactory; 38 import com.sun.star.text.XTextDocument; 39 import com.sun.star.uno.UnoRuntime; 40 import com.sun.star.uno.XInterface; 41 import com.sun.star.util.URL; 42 import com.sun.star.util.XURLTransformer; 43 44 import java.io.PrintWriter; 45 46 import lib.StatusException; 47 import lib.TestCase; 48 import lib.TestEnvironment; 49 import lib.TestParameters; 50 51 import util.AccessibilityTools; 52 import util.SOfficeFactory; 53 import util.utils; 54 55 56 /** 57 * Test for object which is represented by edit field 58 * of 'Insert Hyperlink' dialog. <p> 59 * 60 * Object implements the following interfaces : 61 * <ul> 62 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li> 63 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li> 64 * <li> <code>::com::sun::star::accessibility::XAccessibleEditableText</code></li> 65 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li> 66 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li> 67 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li> 68 * </ul> <p> 69 * 70 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 71 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 72 * @see com.sun.star.accessibility.XAccessibleEditableText 73 * @see com.sun.star.accessibility.XAccessibleComponent 74 * @see com.sun.star.accessibility.XAccessibleContext 75 * @see com.sun.star.accessibility.XAccessibleText 76 * @see ifc.accessibility._XAccessibleExtendedComponent 77 * @see ifc.accessibility._XAccessibleEventBroadcaster 78 * @see ifc.accessibility._XAccessibleEditableText 79 * @see ifc.accessibility._XAccessibleComponent 80 * @see ifc.accessibility._XAccessibleContext 81 * @see ifc.accessibility._XAccessibleText 82 */ 83 public class AccessibleEdit extends TestCase { 84 private static XTextDocument xTextDoc = null; 85 private static XAccessibleAction action = null; 86 87 /** 88 * Opens 'Insert Hyperlink' dialog using document dispatch provider. 89 * Finds active top window (the dialog 90 * window) and finds first accessible edit field and 91 * button 'Close' (for closing this dialog when disposing) 92 * walking through the accessible component tree. 93 */ createTestEnvironment(TestParameters Param, PrintWriter log)94 protected TestEnvironment createTestEnvironment(TestParameters Param, 95 PrintWriter log) { 96 XInterface oObj = null; 97 98 try { 99 oObj = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance( 100 "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 XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class, 111 xTextDoc); 112 113 XController secondController = aModel1.getCurrentController(); 114 115 XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface( 116 XDispatchProvider.class, 117 secondController); 118 119 XURLTransformer urlTransf = null; 120 121 try { 122 XInterface transf = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance( 123 "com.sun.star.util.URLTransformer"); 124 urlTransf = (XURLTransformer) UnoRuntime.queryInterface( 125 XURLTransformer.class, transf); 126 } catch (com.sun.star.uno.Exception e) { 127 e.printStackTrace(log); 128 throw new StatusException("Couldn't create URLTransformer", e); 129 } 130 131 XDispatch getting = null; 132 log.println("opening HyperlinkDialog"); 133 134 URL[] url = new URL[1]; 135 url[0] = new URL(); 136 url[0].Complete = ".uno:HyperlinkDialog"; 137 urlTransf.parseStrict(url); 138 getting = aProv.queryDispatch(url[0], "", 0); 139 140 PropertyValue[] noArgs = new PropertyValue[0]; 141 getting.dispatch(url[0], noArgs); 142 143 shortWait(); 144 145 AccessibilityTools at = new AccessibilityTools(); 146 147 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, 148 tk.getActiveTopWindow()); 149 150 XAccessible xRoot = at.getAccessibleObject(xWindow); 151 152 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON, 153 "Close"); 154 action = (XAccessibleAction) UnoRuntime.queryInterface( 155 XAccessibleAction.class, oObj); 156 157 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT); 158 159 log.println("ImplementationName " + utils.getImplName(oObj)); 160 161 TestEnvironment tEnv = new TestEnvironment(oObj); 162 163 final XAccessibleEditableText edText = (XAccessibleEditableText) UnoRuntime.queryInterface( 164 XAccessibleEditableText.class, 165 oObj); 166 edText.setText("AccessibleEdit"); 167 168 tEnv.addObjRelation("EventProducer", 169 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 170 public void fireEvent() { 171 // buttonAccComp.grabFocus(); 172 // acomp.grabFocus(); 173 edText.setText("firing event ..."); 174 edText.setText("firing event ... 2"); 175 edText.setText("AccessibleEdit"); 176 } 177 }); 178 179 XAccessibleText text = (XAccessibleText) UnoRuntime.queryInterface( 180 XAccessibleText.class, oObj); 181 182 tEnv.addObjRelation("XAccessibleText.Text", text.getText()); 183 184 tEnv.addObjRelation("XAccessibleEditableText.hasAttr", Boolean.FALSE); 185 186 return tEnv; 187 } 188 189 /** 190 * Closes dialog using action of button 'Close' 191 */ cleanup(TestParameters Param, PrintWriter log)192 protected void cleanup(TestParameters Param, PrintWriter log) { 193 log.println(" Closing dialog ... "); 194 195 try { 196 action.doAccessibleAction(0); 197 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) { 198 log.println("Couldn't close dialog"); 199 } catch (com.sun.star.lang.DisposedException de) { 200 log.println("Dialog already disposed"); 201 } 202 203 util.DesktopTools.closeDoc(xTextDoc); 204 } 205 206 /** 207 * Creates writer document 208 */ initialize(TestParameters Param, PrintWriter log)209 protected void initialize(TestParameters Param, PrintWriter log) { 210 try { 211 SOfficeFactory SOF = SOfficeFactory.getFactory( 212 (XMultiServiceFactory) Param.getMSF()); 213 xTextDoc = SOF.createTextDoc(null); 214 } catch (com.sun.star.uno.Exception e) { 215 throw new StatusException("Can't create document", e); 216 } 217 } 218 219 /** 220 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 221 * reset</code> call. 222 */ shortWait()223 private void shortWait() { 224 try { 225 Thread.sleep(500); 226 } catch (InterruptedException e) { 227 log.println("While waiting :" + e); 228 } 229 } 230 } 231