1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10ef39d40dSAndrew Rist * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ef39d40dSAndrew Rist * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19ef39d40dSAndrew Rist * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir package mod._toolkit; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleRole; 26cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible; 27cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleAction; 28cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleComponent; 29cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleText; 30cdf0e10cSrcweir import com.sun.star.awt.XExtendedToolkit; 31cdf0e10cSrcweir import com.sun.star.awt.XWindow; 32cdf0e10cSrcweir import com.sun.star.frame.XController; 33cdf0e10cSrcweir import com.sun.star.frame.XDispatch; 34cdf0e10cSrcweir import com.sun.star.frame.XDispatchProvider; 35cdf0e10cSrcweir import com.sun.star.frame.XModel; 36cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 37cdf0e10cSrcweir import com.sun.star.text.XTextDocument; 38cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 39cdf0e10cSrcweir import com.sun.star.uno.XInterface; 40cdf0e10cSrcweir import com.sun.star.util.URL; 41cdf0e10cSrcweir import com.sun.star.util.XURLTransformer; 42cdf0e10cSrcweir 43cdf0e10cSrcweir import java.io.PrintWriter; 44cdf0e10cSrcweir 45cdf0e10cSrcweir import lib.StatusException; 46cdf0e10cSrcweir import lib.TestCase; 47cdf0e10cSrcweir import lib.TestEnvironment; 48cdf0e10cSrcweir import lib.TestParameters; 49cdf0e10cSrcweir 50cdf0e10cSrcweir import util.AccessibilityTools; 51cdf0e10cSrcweir import util.SOfficeFactory; 52cdf0e10cSrcweir import util.utils; 53cdf0e10cSrcweir 54cdf0e10cSrcweir 55cdf0e10cSrcweir /** 56cdf0e10cSrcweir * Test for object which is represented by accessible compoent of 57cdf0e10cSrcweir * check box in 'InsertTable' dialog. <p> 58cdf0e10cSrcweir * 59cdf0e10cSrcweir * Object implements the following interfaces : 60cdf0e10cSrcweir * <ul> 61cdf0e10cSrcweir * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li> 62cdf0e10cSrcweir * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li> 63cdf0e10cSrcweir * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li> 64cdf0e10cSrcweir * <li> <code>::com::sun::star::accessibility::XAccessibleValue</code></li> 65cdf0e10cSrcweir * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li> 66cdf0e10cSrcweir * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li> 67cdf0e10cSrcweir * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li> 68cdf0e10cSrcweir * </ul> <p> 69cdf0e10cSrcweir * 70cdf0e10cSrcweir * @see com.sun.star.accessibility.XAccessibleExtendedComponent 71cdf0e10cSrcweir * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 72cdf0e10cSrcweir * @see com.sun.star.accessibility.XAccessibleComponent 73cdf0e10cSrcweir * @see com.sun.star.accessibility.XAccessibleValue 74cdf0e10cSrcweir * @see com.sun.star.accessibility.XAccessibleAction 75cdf0e10cSrcweir * @see com.sun.star.accessibility.XAccessibleContext 76cdf0e10cSrcweir * @see com.sun.star.accessibility.XAccessibleText 77cdf0e10cSrcweir * @see ifc.accessibility._XAccessibleExtendedComponent 78cdf0e10cSrcweir * @see ifc.accessibility._XAccessibleEventBroadcaster 79cdf0e10cSrcweir * @see ifc.accessibility._XAccessibleComponent 80cdf0e10cSrcweir * @see ifc.accessibility._XAccessibleValue 81cdf0e10cSrcweir * @see ifc.accessibility._XAccessibleAction 82cdf0e10cSrcweir * @see ifc.accessibility._XAccessibleContext 83cdf0e10cSrcweir * @see ifc.accessibility._XAccessibleText 84cdf0e10cSrcweir */ 85cdf0e10cSrcweir public class AccessibleCheckBox extends TestCase { 86cdf0e10cSrcweir private static XTextDocument xTextDoc = null; 87cdf0e10cSrcweir private static XAccessibleAction action = null; 88cdf0e10cSrcweir private static DiagThread psDiag = null; 89cdf0e10cSrcweir 90cdf0e10cSrcweir /** 91cdf0e10cSrcweir * Opens 'Insert Table' dialog using document dispatch provider 92cdf0e10cSrcweir * running in a separate thread. Finds active top window (the dialog 93cdf0e10cSrcweir * window) and finds first accessible check box walking through the 94cdf0e10cSrcweir * accessible component tree. 95cdf0e10cSrcweir */ createTestEnvironment(TestParameters Param, PrintWriter log)96cdf0e10cSrcweir protected TestEnvironment createTestEnvironment(TestParameters Param, 97cdf0e10cSrcweir PrintWriter log) { 98cdf0e10cSrcweir XMultiServiceFactory msf = (XMultiServiceFactory) Param.getMSF(); 99cdf0e10cSrcweir log.println("Creating text document"); 100cdf0e10cSrcweir 101cdf0e10cSrcweir if (xTextDoc == null) { 102cdf0e10cSrcweir try { 103cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory(msf); 104cdf0e10cSrcweir xTextDoc = SOF.createTextDoc(null); 105cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 106cdf0e10cSrcweir throw new StatusException("Can't create document", e); 107cdf0e10cSrcweir } 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir util.utils.shortWait(Param.getInt("ShortWait")); 111cdf0e10cSrcweir 112cdf0e10cSrcweir XInterface oObj = null; 113cdf0e10cSrcweir 114cdf0e10cSrcweir log.println("getting toolkit"); 115cdf0e10cSrcweir 116cdf0e10cSrcweir try { 117cdf0e10cSrcweir oObj = (XInterface) msf.createInstance("com.sun.star.awt.Toolkit"); 118cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 119cdf0e10cSrcweir log.println("Couldn't get toolkit"); 120cdf0e10cSrcweir e.printStackTrace(log); 121cdf0e10cSrcweir throw new StatusException("Couldn't get toolkit", e); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface( 125cdf0e10cSrcweir XExtendedToolkit.class, oObj); 126cdf0e10cSrcweir 127cdf0e10cSrcweir util.utils.shortWait(Param.getInt("ShortWait")); 128cdf0e10cSrcweir 129cdf0e10cSrcweir log.println("Opening Dialog in second thread"); 130cdf0e10cSrcweir 131cdf0e10cSrcweir psDiag = new DiagThread(xTextDoc, msf); 132cdf0e10cSrcweir psDiag.start(); 133cdf0e10cSrcweir 134cdf0e10cSrcweir util.utils.shortWait(Param.getInt("ShortWait")); 135cdf0e10cSrcweir 136cdf0e10cSrcweir AccessibilityTools at = new AccessibilityTools(); 137cdf0e10cSrcweir 138cdf0e10cSrcweir util.utils.shortWait(Param.getInt("ShortWait")); 139cdf0e10cSrcweir 140cdf0e10cSrcweir log.println("Getting the active TopWindow"); 141cdf0e10cSrcweir 142cdf0e10cSrcweir XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, 143cdf0e10cSrcweir tk.getActiveTopWindow()); 144cdf0e10cSrcweir 145cdf0e10cSrcweir XAccessible xRoot = at.getAccessibleObject(xWindow); 146cdf0e10cSrcweir 147cdf0e10cSrcweir 148cdf0e10cSrcweir at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 149cdf0e10cSrcweir oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON, 150cdf0e10cSrcweir "Cancel"); 151cdf0e10cSrcweir 152cdf0e10cSrcweir action = (XAccessibleAction) UnoRuntime.queryInterface( 153cdf0e10cSrcweir XAccessibleAction.class, oObj); 154cdf0e10cSrcweir 155cdf0e10cSrcweir oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.CHECK_BOX); 156cdf0e10cSrcweir 157cdf0e10cSrcweir log.println("ImplementationName " + utils.getImplName(oObj)); 158cdf0e10cSrcweir 159cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment(oObj); 160cdf0e10cSrcweir 161cdf0e10cSrcweir final XAccessibleComponent acomp = (XAccessibleComponent) UnoRuntime.queryInterface( 162cdf0e10cSrcweir XAccessibleComponent.class, 163cdf0e10cSrcweir oObj); 164cdf0e10cSrcweir 165cdf0e10cSrcweir tEnv.addObjRelation("EventProducer", 166cdf0e10cSrcweir new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 167cdf0e10cSrcweir public void fireEvent() { 168cdf0e10cSrcweir System.out.println("Grabbing focus ... "); 169cdf0e10cSrcweir acomp.grabFocus(); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir }); 172cdf0e10cSrcweir 173cdf0e10cSrcweir XAccessibleText text = (XAccessibleText) UnoRuntime.queryInterface( 174cdf0e10cSrcweir XAccessibleText.class, oObj); 175cdf0e10cSrcweir 176cdf0e10cSrcweir tEnv.addObjRelation("XAccessibleText.Text", text.getText()); 177cdf0e10cSrcweir 178cdf0e10cSrcweir tEnv.addObjRelation("EditOnly", 179cdf0e10cSrcweir "This method isn't supported in this component"); 180cdf0e10cSrcweir 181cdf0e10cSrcweir tEnv.addObjRelation("LimitedBounds", "yes"); 182cdf0e10cSrcweir 183cdf0e10cSrcweir return tEnv; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir /** 187cdf0e10cSrcweir * Closes the dialog using accessible button 'Cancel' found in 188cdf0e10cSrcweir * <code>createTestEnvironment()</code>. 189cdf0e10cSrcweir */ cleanup(TestParameters Param, PrintWriter log)190cdf0e10cSrcweir protected void cleanup(TestParameters Param, PrintWriter log) { 191cdf0e10cSrcweir try { 192cdf0e10cSrcweir log.println("closing dialog"); 193cdf0e10cSrcweir action.doAccessibleAction(0); 194cdf0e10cSrcweir log.println("interrupting corresponding Thread"); 195cdf0e10cSrcweir psDiag.interrupt(); 196cdf0e10cSrcweir log.println("closing the document"); 197cdf0e10cSrcweir util.DesktopTools.closeDoc(xTextDoc); 198cdf0e10cSrcweir log.println("reinitialize the variable"); 199cdf0e10cSrcweir xTextDoc = null; 200cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) { 201cdf0e10cSrcweir log.println("Couldn't close dialog"); 202cdf0e10cSrcweir } catch (com.sun.star.lang.DisposedException de) { 203cdf0e10cSrcweir log.println("Dialog already disposed"); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir } 206cdf0e10cSrcweir initialize(TestParameters Param, PrintWriter log)207cdf0e10cSrcweir protected void initialize(TestParameters Param, PrintWriter log) { 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir /** 211cdf0e10cSrcweir * Thread for opening modal dialog 'Insert Table'. 212cdf0e10cSrcweir */ 213cdf0e10cSrcweir public class DiagThread extends Thread { 214cdf0e10cSrcweir public XTextDocument xTextDoc = null; 215cdf0e10cSrcweir public XMultiServiceFactory msf = null; 216cdf0e10cSrcweir DiagThread(XTextDocument xTextDoc, XMultiServiceFactory msf)217cdf0e10cSrcweir public DiagThread(XTextDocument xTextDoc, XMultiServiceFactory msf) { 218cdf0e10cSrcweir this.xTextDoc = xTextDoc; 219cdf0e10cSrcweir this.msf = msf; 220cdf0e10cSrcweir } 221cdf0e10cSrcweir run()222cdf0e10cSrcweir public void run() { 223cdf0e10cSrcweir XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class, 224cdf0e10cSrcweir xTextDoc); 225cdf0e10cSrcweir 226cdf0e10cSrcweir XController xController = aModel.getCurrentController(); 227cdf0e10cSrcweir 228cdf0e10cSrcweir //Opening PrinterSetupDialog 229cdf0e10cSrcweir try { 230cdf0e10cSrcweir String aSlotID = ".uno:InsertTable"; 231cdf0e10cSrcweir XDispatchProvider xDispProv = (XDispatchProvider) UnoRuntime.queryInterface( 232cdf0e10cSrcweir XDispatchProvider.class, 233cdf0e10cSrcweir xController); 234cdf0e10cSrcweir XURLTransformer xParser = (com.sun.star.util.XURLTransformer) UnoRuntime.queryInterface( 235cdf0e10cSrcweir XURLTransformer.class, 236cdf0e10cSrcweir msf.createInstance( 237cdf0e10cSrcweir "com.sun.star.util.URLTransformer")); 238cdf0e10cSrcweir 239cdf0e10cSrcweir // Because it's an in/out parameter we must use an array of URL objects. 240cdf0e10cSrcweir URL[] aParseURL = new URL[1]; 241cdf0e10cSrcweir aParseURL[0] = new URL(); 242cdf0e10cSrcweir aParseURL[0].Complete = aSlotID; 243cdf0e10cSrcweir xParser.parseStrict(aParseURL); 244cdf0e10cSrcweir 245cdf0e10cSrcweir URL aURL = aParseURL[0]; 246cdf0e10cSrcweir XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0); 247cdf0e10cSrcweir 248cdf0e10cSrcweir if (xDispatcher != null) { 249cdf0e10cSrcweir xDispatcher.dispatch(aURL, null); 250cdf0e10cSrcweir } 251cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 252cdf0e10cSrcweir log.println("Couldn't open dialog"); 253cdf0e10cSrcweir } 254cdf0e10cSrcweir } 255cdf0e10cSrcweir } 256*170fb961SPedro Giffuni } 257