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