1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package mod._toolkit; 24 25 import com.sun.star.accessibility.AccessibleRole; 26 import com.sun.star.accessibility.XAccessible; 27 import com.sun.star.accessibility.XAccessibleAction; 28 import com.sun.star.awt.XWindow; 29 import com.sun.star.lang.XMultiServiceFactory; 30 import com.sun.star.text.XTextDocument; 31 import com.sun.star.uno.UnoRuntime; 32 import com.sun.star.uno.XInterface; 33 34 import java.io.PrintWriter; 35 36 import lib.StatusException; 37 import lib.TestCase; 38 import lib.TestEnvironment; 39 import lib.TestParameters; 40 41 import util.AccessibilityTools; 42 import util.DesktopTools; 43 import util.SOfficeFactory; 44 import util.utils; 45 46 47 /** 48 * Test for object which is represented by style list box 49 * on toolbar of a document. <p> 50 * 51 * Object implements the following interfaces : 52 * <ul> 53 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li> 54 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li> 55 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li> 56 * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li> 57 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li> 58 * </ul> <p> 59 * 60 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 61 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 62 * @see com.sun.star.accessibility.XAccessibleComponent 63 * @see com.sun.star.accessibility.XAccessibleAction 64 * @see com.sun.star.accessibility.XAccessibleContext 65 * @see ifc.accessibility._XAccessibleExtendedComponent 66 * @see ifc.accessibility._XAccessibleEventBroadcaster 67 * @see ifc.accessibility._XAccessibleComponent 68 * @see ifc.accessibility._XAccessibleAction 69 * @see ifc.accessibility._XAccessibleContext 70 */ 71 public class AccessibleDropDownListBox extends TestCase { 72 private static XTextDocument xTextDoc = null; 73 private static XAccessibleAction action = null; 74 75 /** 76 * Finds AccessibleDropDownListBox walking through the 77 * accessible component tree of a writer document. 78 */ createTestEnvironment(TestParameters Param, PrintWriter log)79 protected TestEnvironment createTestEnvironment(TestParameters Param, 80 PrintWriter log) { 81 XInterface oObj = null; 82 83 shortWait(); 84 85 AccessibilityTools at = new AccessibilityTools(); 86 87 XWindow xWindow = at.getCurrentWindow( 88 (XMultiServiceFactory) Param.getMSF(), 89 xTextDoc); 90 91 XAccessible xRoot = at.getAccessibleObject(xWindow); 92 93 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 94 95 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.COMBO_BOX, 96 "", "AccessibleDropDownListBox"); 97 98 log.println("ImplementationName " + utils.getImplName(oObj)); 99 100 TestEnvironment tEnv = new TestEnvironment(oObj); 101 102 final XAccessibleAction acomp = (XAccessibleAction) UnoRuntime.queryInterface( 103 XAccessibleAction.class, oObj); 104 tEnv.addObjRelation("EventProducer", 105 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 106 public void fireEvent() { 107 try { 108 acomp.doAccessibleAction(0); 109 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 110 throw new StatusException("Can't perform action 0", e); 111 } 112 } 113 }); 114 115 return tEnv; 116 } 117 118 /** 119 * Creates writer document. 120 */ initialize(TestParameters Param, PrintWriter log)121 protected void initialize(TestParameters Param, PrintWriter log) { 122 try { 123 SOfficeFactory SOF = SOfficeFactory.getFactory( 124 (XMultiServiceFactory) Param.getMSF()); 125 DesktopTools.dockStylist((XMultiServiceFactory) Param.getMSF()); 126 xTextDoc = SOF.createTextDoc(null); 127 } catch (com.sun.star.uno.Exception e) { 128 throw new StatusException("Can't create document", e); 129 } 130 } 131 132 /** 133 * Disposes writer document. 134 */ cleanup(TestParameters Param, PrintWriter log)135 protected void cleanup(TestParameters Param, PrintWriter log) { 136 util.DesktopTools.closeDoc(xTextDoc); 137 } 138 139 /** 140 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 141 * reset</code> call. 142 */ shortWait()143 private void shortWait() { 144 try { 145 Thread.sleep(500); 146 } catch (InterruptedException e) { 147 log.println("While waiting :" + e); 148 } 149 } 150 }