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 28 package mod._svtools; 29 30 import com.sun.star.accessibility.AccessibleRole; 31 import com.sun.star.accessibility.XAccessibleComponent; 32 import com.sun.star.accessibility.XAccessibleContext; 33 import com.sun.star.awt.Point; 34 import java.awt.Robot; 35 import java.awt.event.InputEvent; 36 import java.io.PrintWriter; 37 38 import lib.StatusException; 39 import lib.TestCase; 40 import lib.TestEnvironment; 41 import lib.TestParameters; 42 import util.AccessibilityTools; 43 import util.SOfficeFactory; 44 45 import com.sun.star.accessibility.XAccessible; 46 import com.sun.star.awt.XExtendedToolkit; 47 import com.sun.star.awt.XWindow; 48 import com.sun.star.lang.XComponent; 49 import com.sun.star.lang.XMultiServiceFactory; 50 import com.sun.star.uno.UnoRuntime; 51 import com.sun.star.uno.XInterface; 52 53 /** 54 * Test for object that implements the following interfaces : 55 * <ul> 56 * <li><code>::com::sun::star::accessibility::XAccessibleComponent 57 * </code></li> 58 * <li><code>::com::sun::star::accessibility::XAccessibleContext 59 * </code></li> 60 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster 61 * </code></li> 62 * <li> 63 * <code>::com::sun::star::accessibility::XAccessibleExtendedComponent 64 * </code></li> 65 * </ul> <p> 66 * 67 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 68 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 69 * @see com.sun.star.accessibility.XAccessibleContext 70 * @see com.sun.star.accessibility.XAccessibleComponent 71 * @see ifc.accessibility._XAccessibleComponent 72 * @see ifc.accessibility._XAccessibleExtendedComponent 73 * @see ifc.accessibility._XAccessibleEventBroadcaster 74 * @see ifc.accessibility._XAccessibleContext 75 */ 76 public class AccessibleTabBarPage extends TestCase { 77 78 static XComponent xDoc; 79 80 /** 81 * Disposes the document, if exists, created in 82 * <code>createTestEnvironment</code> method. 83 */ 84 protected void cleanup( TestParameters Param, PrintWriter log) { 85 86 log.println("disposing xCalcDoc"); 87 if (xDoc != null) { 88 util.DesktopTools.closeDoc(xDoc); 89 } 90 } 91 92 /** 93 * Creates a spreadsheet document. Then obtains an accessible object with 94 * the role <code>AccessibleRole.PAGETAB</code>. 95 * Object relations created : 96 * <ul> 97 * <li> <code>'EventProducer'</code> for 98 * {@link ifc.accessibility._XAccessibleEventBroadcaster}: 99 * </li> 100 * </ul> 101 * 102 * @param tParam test parameters 103 * @param log writer to log information while testing 104 * 105 * @see com.sun.star.awt.Toolkit 106 * @see com.sun.star.accessibility.AccessibleRole 107 * @see ifc.accessibility._XAccessibleEventBroadcaster 108 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 109 */ 110 protected TestEnvironment createTestEnvironment(TestParameters tParam, 111 PrintWriter log) { 112 113 log.println( "creating a test environment" ); 114 115 if (xDoc != null) xDoc.dispose(); 116 117 // get a soffice factory object 118 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 119 120 try { 121 log.println( "creating a calc document" ); 122 xDoc = (XComponent) UnoRuntime.queryInterface(XComponent.class, SOF.createCalcDoc(null));// SOF.createDrawDoc(null); 123 } catch ( com.sun.star.uno.Exception e ) { 124 // Some exception occures.FAILED 125 e.printStackTrace( log ); 126 throw new StatusException( "Couldn't create document", e ); 127 } 128 129 shortWait(); 130 131 XInterface oObj = null; 132 133 try { 134 oObj = (XInterface) ((XMultiServiceFactory)tParam.getMSF()).createInstance 135 ("com.sun.star.awt.Toolkit") ; 136 } catch (com.sun.star.uno.Exception e) { 137 log.println("Couldn't get toolkit"); 138 e.printStackTrace(log); 139 throw new StatusException("Couldn't get toolkit", e ); 140 } 141 142 143 XExtendedToolkit tk = (XExtendedToolkit) 144 UnoRuntime.queryInterface(XExtendedToolkit.class, oObj); 145 146 147 AccessibilityTools at = new AccessibilityTools(); 148 149 shortWait(); 150 151 XWindow xWindow = (XWindow) 152 UnoRuntime.queryInterface(XWindow.class,tk.getActiveTopWindow()); 153 154 XAccessible xRoot = at.getAccessibleObject(xWindow); 155 at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 156 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PAGE_TAB, "Sheet1"); 157 XAccessibleContext acc = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PAGE_TAB, "Sheet2"); 158 XAccessibleComponent accComp = (XAccessibleComponent) UnoRuntime.queryInterface( 159 XAccessibleComponent.class, 160 acc); 161 final Point point = accComp.getLocationOnScreen(); 162 log.println("ImplementationName: " + util.utils.getImplName(oObj)); 163 164 TestEnvironment tEnv = new TestEnvironment( oObj ); 165 tEnv.addObjRelation("Destroy","yes"); 166 tEnv.addObjRelation("EventProducer", 167 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){ 168 public void fireEvent() { 169 try { 170 Robot rob = new Robot(); 171 rob.mouseMove(point.X + 25, point.Y + 5); 172 rob.mousePress(InputEvent.BUTTON1_MASK); 173 } catch (java.awt.AWTException e) { 174 System.out.println("couldn't fire event"); 175 } 176 } 177 }); 178 179 return tEnv; 180 } 181 182 /** 183 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 184 * reset</code> call. 185 */ 186 private void shortWait() { 187 try { 188 Thread.sleep(5000); 189 } catch (InterruptedException e) { 190 System.out.println("While waiting :" + e) ; 191 } 192 } 193 194 } 195