1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package mod._sc; 28 29 import java.io.PrintWriter; 30 31 import lib.StatusException; 32 import lib.TestCase; 33 import lib.TestEnvironment; 34 import lib.TestParameters; 35 import util.AccessibilityTools; 36 import util.SOfficeFactory; 37 import util.utils; 38 39 import com.sun.star.accessibility.AccessibleRole; 40 import com.sun.star.accessibility.XAccessible; 41 import com.sun.star.accessibility.XAccessibleAction; 42 import com.sun.star.accessibility.XAccessibleContext; 43 import com.sun.star.accessibility.XAccessibleEditableText; 44 import com.sun.star.accessibility.XAccessibleText; 45 import com.sun.star.awt.XExtendedToolkit; 46 import com.sun.star.awt.XWindow; 47 import com.sun.star.frame.XController; 48 import com.sun.star.frame.XDispatch; 49 import com.sun.star.frame.XDispatchProvider; 50 import com.sun.star.frame.XModel; 51 import com.sun.star.lang.XComponent; 52 import com.sun.star.lang.XMultiServiceFactory; 53 import com.sun.star.uno.UnoRuntime; 54 import com.sun.star.util.URL; 55 import com.sun.star.util.XURLTransformer; 56 57 58 public class AccessibleEditableTextPara_HeaderFooter extends TestCase { 59 protected static XComponent xCalcDoc = null; 60 protected static XMultiServiceFactory msf = null; 61 protected static XAccessibleAction action = null; 62 63 protected TestEnvironment createTestEnvironment(TestParameters Param, 64 PrintWriter log) { 65 XAccessibleContext oObj = null; 66 Object toolkit = null; 67 68 try { 69 toolkit = msf.createInstance("com.sun.star.awt.Toolkit"); 70 } catch (com.sun.star.uno.Exception e) { 71 log.println("Couldn't get toolkit"); 72 e.printStackTrace(log); 73 throw new StatusException("Couldn't get toolkit", e); 74 } 75 76 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface( 77 XExtendedToolkit.class, toolkit); 78 79 util.utils.shortWait(Param.getInt("ShortWait")); 80 81 DiagThread psDiag = new DiagThread(xCalcDoc, msf); 82 psDiag.start(); 83 84 util.utils.shortWait(Param.getInt("ShortWait")*5); 85 86 Object atw = tk.getActiveTopWindow(); 87 88 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, 89 atw); 90 91 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow); 92 93 util.utils.shortWait(Param.getInt("ShortWait")); 94 95 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 96 XAccessibleContext ok_button = AccessibilityTools.getAccessibleObjectForRole(xRoot, 97 AccessibleRole.PUSH_BUTTON, 98 "Cancel"); 99 100 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PARAGRAPH); 101 102 log.println("ImplementationName " + utils.getImplName(oObj)); 103 log.println("AccessibleName " + oObj.getAccessibleName()); 104 log.println("ParentDescription " + 105 oObj.getAccessibleParent().getAccessibleContext() 106 .getAccessibleDescription()); 107 108 TestEnvironment tEnv = new TestEnvironment(oObj); 109 110 action = (XAccessibleAction) UnoRuntime.queryInterface( 111 XAccessibleAction.class, ok_button); 112 113 XAccessibleText text = (XAccessibleText) UnoRuntime.queryInterface( 114 XAccessibleText.class, oObj); 115 116 XAccessibleEditableText eText = (XAccessibleEditableText) UnoRuntime.queryInterface( 117 XAccessibleEditableText.class, 118 oObj); 119 120 eText.setText("LEFT"); 121 122 tEnv.addObjRelation("XAccessibleText.Text", text.getText()); 123 124 tEnv.addObjRelation("Destroy", "AccessibleEditableTextPara_PreviewCell"); 125 126 final XAccessibleEditableText editText = eText; 127 128 tEnv.addObjRelation("EventProducer", 129 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 130 public void fireEvent() { 131 editText.setText("LEFT_EVENT"); 132 } 133 }); 134 135 return tEnv; 136 } 137 138 /** 139 * Closes the dialog using accessible button 'OK' found in 140 * <code>createTestEnvironment()</code>. 141 */ 142 protected void cleanup(TestParameters Param, PrintWriter log) { 143 log.println(" disposing xCalcDoc "); 144 145 try { 146 action.doAccessibleAction(0); 147 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) { 148 log.println("Couldn't close dialog"); 149 } catch (com.sun.star.lang.DisposedException de) { 150 log.println("Dialog already disposed"); 151 } 152 153 util.DesktopTools.closeDoc(xCalcDoc); 154 } 155 156 /** 157 * Opens new writer document. 158 */ 159 protected void initialize(TestParameters Param, PrintWriter log) { 160 msf = (XMultiServiceFactory) Param.getMSF(); 161 162 try { 163 SOfficeFactory SOF = SOfficeFactory.getFactory(msf); 164 xCalcDoc = (XComponent) UnoRuntime.queryInterface(XComponent.class, 165 SOF.createCalcDoc( 166 null)); 167 } catch (com.sun.star.uno.Exception e) { 168 throw new StatusException("Can't create document", e); 169 } 170 } 171 172 173 /** 174 * Thread for opening modal dialog 'Print Settings'. 175 */ 176 public class DiagThread extends Thread { 177 public XComponent xCalcDoc = null; 178 public XMultiServiceFactory msf = null; 179 180 public DiagThread(XComponent xCalcDoc, XMultiServiceFactory msf) { 181 this.xCalcDoc = xCalcDoc; 182 this.msf = msf; 183 } 184 185 public void run() { 186 XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class, 187 xCalcDoc); 188 189 XController xController = aModel.getCurrentController(); 190 191 //Opening HeaderFooterDialog 192 try { 193 String aSlotID = ".uno:EditHeaderAndFooter"; 194 XDispatchProvider xDispProv = (XDispatchProvider) UnoRuntime.queryInterface( 195 XDispatchProvider.class, 196 xController); 197 XURLTransformer xParser = (com.sun.star.util.XURLTransformer) UnoRuntime.queryInterface( 198 XURLTransformer.class, 199 msf.createInstance( 200 "com.sun.star.util.URLTransformer")); 201 202 // Because it's an in/out parameter 203 // we must use an array of URL objects. 204 URL[] aParseURL = new URL[1]; 205 aParseURL[0] = new URL(); 206 aParseURL[0].Complete = aSlotID; 207 xParser.parseStrict(aParseURL); 208 209 URL aURL = aParseURL[0]; 210 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0); 211 212 if (xDispatcher != null) { 213 xDispatcher.dispatch(aURL, null); 214 } 215 } catch (com.sun.star.uno.Exception e) { 216 log.println("Couldn't open dialog"); 217 } 218 } 219 } 220 }