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._toolkit; 28 29 import com.sun.star.accessibility.AccessibleRole; 30 import com.sun.star.accessibility.XAccessible; 31 import com.sun.star.accessibility.XAccessibleAction; 32 import com.sun.star.accessibility.XAccessibleComponent; 33 import com.sun.star.awt.XWindow; 34 import com.sun.star.frame.XModel; 35 import com.sun.star.lang.XMultiServiceFactory; 36 import com.sun.star.text.XTextDocument; 37 import com.sun.star.uno.UnoRuntime; 38 import com.sun.star.uno.XInterface; 39 40 import java.io.PrintWriter; 41 42 import lib.StatusException; 43 import lib.TestCase; 44 import lib.TestEnvironment; 45 import lib.TestParameters; 46 47 import util.AccessibilityTools; 48 import util.SOfficeFactory; 49 import util.utils; 50 51 52 /** 53 * Test for object which is represented accessible component of 54 * menu bar of a document. <p> 55 * 56 * Object implements the following interfaces : 57 * <ul> 58 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li> 59 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li> 60 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li> 61 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li> 62 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li> 63 * </ul> <p> 64 * 65 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 66 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 67 * @see com.sun.star.accessibility.XAccessibleComponent 68 * @see com.sun.star.accessibility.XAccessibleSelection 69 * @see com.sun.star.accessibility.XAccessibleContext 70 * @see ifc.accessibility._XAccessibleExtendedComponent 71 * @see ifc.accessibility._XAccessibleEventBroadcaster 72 * @see ifc.accessibility._XAccessibleComponent 73 * @see ifc.accessibility._XAccessibleSelection 74 * @see ifc.accessibility._XAccessibleContext 75 */ 76 public class AccessibleMenuBar extends TestCase { 77 private static XTextDocument xTextDoc = null; 78 private static XAccessibleAction action = null; 79 80 /** 81 * Finds accessible component with role <code>MENUBAR</code> 82 * walking through the accessible component tree of a document. 83 */ 84 protected TestEnvironment createTestEnvironment(TestParameters Param, 85 PrintWriter log) { 86 shortWait(); 87 88 AccessibilityTools at = new AccessibilityTools(); 89 90 XWindow xWindow = UnoRuntime.queryInterface(XModel.class, xTextDoc). 91 getCurrentController().getFrame().getContainerWindow(); 92 93 XAccessible xRoot = at.getAccessibleObject(xWindow); 94 95 96 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 97 XInterface oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.MENU_BAR); 98 99 log.println("ImplementationName " + utils.getImplName(oObj)); 100 101 TestEnvironment tEnv = new TestEnvironment(oObj); 102 103 final XAccessibleComponent acomp = (XAccessibleComponent) UnoRuntime.queryInterface( 104 XAccessibleComponent.class, 105 oObj); 106 107 tEnv.addObjRelation("EventProducer", 108 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 109 public void fireEvent() { 110 System.out.println("Grabbing focus ... "); 111 acomp.grabFocus(); 112 } 113 }); 114 115 tEnv.addObjRelation("XAccessibleSelection.OneAlwaysSelected", 116 new Boolean(false)); 117 118 tEnv.addObjRelation("XAccessibleSelection.multiSelection", 119 new Boolean(false)); 120 121 return tEnv; 122 } 123 124 /** 125 * Creates writer document. 126 */ 127 protected void initialize(TestParameters Param, PrintWriter log) { 128 try { 129 SOfficeFactory SOF = SOfficeFactory.getFactory( 130 (XMultiServiceFactory) Param.getMSF()); 131 xTextDoc = SOF.createTextDoc(null); 132 } catch (com.sun.star.uno.Exception e) { 133 throw new StatusException("Can't create document", e); 134 } 135 } 136 137 /** 138 * Disposes document. 139 */ 140 protected void cleanup(TestParameters Param, PrintWriter log) { 141 util.DesktopTools.closeDoc(xTextDoc); 142 ; 143 } 144 145 /** 146 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 147 * reset</code> call. 148 */ 149 private void shortWait() { 150 try { 151 Thread.sleep(500); 152 } catch (InterruptedException e) { 153 log.println("While waiting :" + e); 154 } 155 } 156 }