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