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._svtools; 28 29 import com.sun.star.view.XSelectionSupplier; 30 import java.awt.Robot; 31 import java.awt.event.InputEvent; 32 import java.io.PrintWriter; 33 34 import lib.StatusException; 35 import lib.TestCase; 36 import lib.TestEnvironment; 37 import lib.TestParameters; 38 import util.AccessibilityTools; 39 import util.DesktopTools; 40 import util.SOfficeFactory; 41 42 import com.sun.star.accessibility.AccessibleRole; 43 import com.sun.star.accessibility.XAccessible; 44 import com.sun.star.accessibility.XAccessibleComponent; 45 import com.sun.star.awt.Point; 46 import com.sun.star.awt.XWindow; 47 import com.sun.star.beans.PropertyValue; 48 import com.sun.star.frame.XController; 49 import com.sun.star.frame.XDesktop; 50 import com.sun.star.frame.XDispatch; 51 import com.sun.star.frame.XDispatchProvider; 52 import com.sun.star.frame.XFrame; 53 import com.sun.star.frame.XModel; 54 import com.sun.star.lang.XMultiServiceFactory; 55 import com.sun.star.text.XTextDocument; 56 import com.sun.star.uno.UnoRuntime; 57 import com.sun.star.uno.XInterface; 58 import com.sun.star.util.URL; 59 60 61 /** 62 * Test for object that implements the following interfaces : 63 * <ul> 64 * <li> 65 * <code>::com::sun::star::accessibility::XAccessibleContext 66 * </code></li> 67 * <li> 68 * <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster 69 * </code></li> 70 * </ul> <p> 71 * 72 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 73 * @see com.sun.star.accessibility.XAccessibleContext 74 * @see ifc.accessibility._XAccessibleEventBroadcaster 75 * @see ifc.accessibility._XAccessibleContext 76 */ 77 public class AccessibleBrowseBoxHeaderBar extends TestCase { 78 static XDesktop the_Desk; 79 static XTextDocument xTextDoc; 80 81 /** 82 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>). 83 */ 84 protected void initialize(TestParameters Param, PrintWriter log) { 85 the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, 86 DesktopTools.createDesktop( 87 (XMultiServiceFactory) Param.getMSF())); 88 } 89 90 /** 91 * Disposes the document, if exists, created in 92 * <code>createTestEnvironment</code> method. 93 */ 94 protected void cleanup(TestParameters Param, PrintWriter log) { 95 log.println("disposing xTextDoc"); 96 97 if (xTextDoc != null) { 98 xTextDoc.dispose(); 99 } 100 } 101 102 /** 103 * Creates a text document. Opens the DataSource browser. 104 * Creates an instance of the service <code>com.sun.star.awt.Toolkit</code> 105 * and gets active top window. Then obtains an accessible object with 106 * the role <code>AccessibleRole.TABLE</code>. 107 * Object relations created : 108 * <ul> 109 * <li> <code>'EventProducer'</code> for 110 * {@link ifc.accessibility._XAccessibleEventBroadcaster}: 111 * </li> 112 * </ul> 113 * 114 * @param tParam test parameters 115 * @param log writer to log information while testing 116 * 117 * @see com.sun.star.awt.Toolkit 118 * @see com.sun.star.accessibility.AccessibleRole 119 * @see ifc.accessibility._XAccessibleEventBroadcaster 120 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 121 */ 122 protected TestEnvironment createTestEnvironment(TestParameters tParam, 123 PrintWriter log) { 124 log.println("creating a test environment"); 125 126 if (xTextDoc != null) { 127 xTextDoc.dispose(); 128 } 129 130 // get a soffice factory object 131 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF()); 132 133 try { 134 log.println("creating a text document"); 135 xTextDoc = SOF.createTextDoc(null); 136 } catch (com.sun.star.uno.Exception e) { 137 // Some exception occures.FAILED 138 e.printStackTrace(log); 139 throw new StatusException("Couldn't create document", e); 140 } 141 142 shortWait(); 143 144 XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class, 145 xTextDoc); 146 147 XController secondController = aModel1.getCurrentController(); 148 149 XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface( 150 XDispatchProvider.class, 151 secondController); 152 153 XDispatch getting = null; 154 155 log.println("opening DatasourceBrowser"); 156 157 URL the_url = new URL(); 158 the_url.Complete = ".component:DB/DataSourceBrowser"; 159 getting = aProv.queryDispatch(the_url, "_beamer", 12); 160 161 //am controller ein XSelectionSupplier->mit params rufen 162 PropertyValue[] noArgs = new PropertyValue[0]; 163 getting.dispatch(the_url, noArgs); 164 165 PropertyValue[] params = new PropertyValue[3]; 166 PropertyValue param1 = new PropertyValue(); 167 param1.Name = "DataSourceName"; 168 param1.Value = "Bibliography"; 169 params[0] = param1; 170 171 PropertyValue param2 = new PropertyValue(); 172 param2.Name = "CommandType"; 173 param2.Value = new Integer(com.sun.star.sdb.CommandType.TABLE); 174 params[1] = param2; 175 176 PropertyValue param3 = new PropertyValue(); 177 param3.Name = "Command"; 178 param3.Value = "biblio"; 179 params[2] = param3; 180 181 shortWait(); 182 183 XFrame the_frame1 = the_Desk.getCurrentFrame(); 184 185 if (the_frame1 == null) { 186 log.println("Current frame was not found !!!"); 187 } 188 189 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4); 190 191 the_frame2.setName("DatasourceBrowser"); 192 193 XController xCont = the_frame2.getController(); 194 195 XSelectionSupplier xSelect = (XSelectionSupplier) UnoRuntime.queryInterface( 196 XSelectionSupplier.class, xCont); 197 198 try { 199 xSelect.select(params); 200 } catch (com.sun.star.lang.IllegalArgumentException ex) { 201 throw new StatusException("Could not select Biblio-Database", ex); 202 } 203 204 XInterface oObj = null; 205 206 AccessibilityTools at = new AccessibilityTools(); 207 208 XWindow xWindow = secondController.getFrame().getContainerWindow(); 209 210 XAccessible xRoot = at.getAccessibleObject(xWindow); 211 212 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE); 213 214 at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 215 log.println("ImplementationName: " + util.utils.getImplName(oObj)); 216 217 TestEnvironment tEnv = new TestEnvironment(oObj); 218 219 shortWait(); 220 221 XAccessibleComponent accComp = (XAccessibleComponent) UnoRuntime.queryInterface( 222 XAccessibleComponent.class, 223 oObj); 224 final Point point = accComp.getLocationOnScreen(); 225 226 shortWait(); 227 228 tEnv.addObjRelation("EventProducer", 229 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 230 public void fireEvent() { 231 try { 232 Robot rob = new Robot(); 233 rob.mouseMove(point.X + 5, point.Y + 5); 234 rob.mousePress(InputEvent.BUTTON1_MASK); 235 } catch (java.awt.AWTException e) { 236 System.out.println("couldn't fire event"); 237 } 238 } 239 }); 240 241 return tEnv; 242 } 243 244 /** 245 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 246 * reset</code> call. 247 */ 248 private void shortWait() { 249 try { 250 Thread.sleep(5000);; 251 } catch (InterruptedException e) { 252 System.out.println("While waiting :" + e); 253 } 254 } 255 } 256