merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleComboBox.java
blob21af276b51a54c52bbc1603028c6b15bfa5bedbc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleComboBox.java,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package mod._toolkit;
32 import com.sun.star.accessibility.AccessibleRole;
33 import com.sun.star.accessibility.XAccessible;
34 import com.sun.star.accessibility.XAccessibleAction;
35 import com.sun.star.accessibility.XAccessibleComponent;
36 import com.sun.star.accessibility.XAccessibleSelection;
37 import com.sun.star.awt.XExtendedToolkit;
38 import com.sun.star.awt.XWindow;
39 import com.sun.star.frame.XController;
40 import com.sun.star.frame.XDispatch;
41 import com.sun.star.frame.XDispatchProvider;
42 import com.sun.star.frame.XModel;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.text.XTextDocument;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
47 import com.sun.star.util.URL;
48 import com.sun.star.util.XURLTransformer;
50 import java.io.PrintWriter;
52 import lib.StatusException;
53 import lib.TestCase;
54 import lib.TestEnvironment;
55 import lib.TestParameters;
57 import util.AccessibilityTools;
58 import util.SOfficeFactory;
59 import util.utils;
62 /**
63 * Test for object which is represented by accessible component
64 * of the 'Font' combo box in Format->Character... dislog box. <p>
66 * Object implements the following interfaces :
67 * <ul>
68 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
69 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
70 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
71 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
72 * </ul> <p>
74 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
75 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
76 * @see com.sun.star.accessibility.XAccessibleComponent
77 * @see com.sun.star.accessibility.XAccessibleContext
78 * @see ifc.accessibility._XAccessibleExtendedComponent
79 * @see ifc.accessibility._XAccessibleEventBroadcaster
80 * @see ifc.accessibility._XAccessibleComponent
81 * @see ifc.accessibility._XAccessibleContext
83 public class AccessibleComboBox extends TestCase {
84 private static XTextDocument xTextDoc = null;
85 private static XAccessibleAction action = null;
87 /**
88 * Opens CharacterStyle dialog and
89 * finds AccessibleComboBox walking through the
90 * accessible component tree.
92 protected TestEnvironment createTestEnvironment(TestParameters Param,
93 PrintWriter log) {
94 XInterface oObj = null;
96 try {
97 oObj = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance(
98 "com.sun.star.awt.Toolkit");
99 } catch (com.sun.star.uno.Exception e) {
100 log.println("Couldn't get toolkit");
101 e.printStackTrace(log);
102 throw new StatusException("Couldn't get toolkit", e);
105 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
106 XExtendedToolkit.class, oObj);
108 DiagThread psDiag = new DiagThread(xTextDoc,
109 (XMultiServiceFactory) Param.getMSF());
110 psDiag.start();
112 util.utils.shortWait(Param.getInt("ShortWait"));
114 AccessibilityTools at = new AccessibilityTools();
116 util.utils.shortWait(Param.getInt("ShortWait"));
118 Object atw = tk.getActiveTopWindow();
120 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class,
121 atw);
123 XAccessible xRoot = at.getAccessibleObject(xWindow);
125 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON,
126 "Cancel");
127 action = (XAccessibleAction) UnoRuntime.queryInterface(
128 XAccessibleAction.class, oObj);
130 oObj = at.getAccessibleObjectForRole(xRoot,
131 AccessibleRole.PAGE_TAB_LIST);
133 XAccessibleSelection xAccSel = (XAccessibleSelection) UnoRuntime.queryInterface(
134 XAccessibleSelection.class,
135 oObj);
137 try {
138 xAccSel.selectAccessibleChild(0);
139 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
140 e.printStackTrace(log);
142 util.utils.shortWait(Param.getInt("ShortWait"));
144 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
145 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL, "",
146 "AccessibleComboBox");
148 log.println("ImplementationName " + utils.getImplName(oObj));
150 TestEnvironment tEnv = new TestEnvironment(oObj);
152 final XAccessibleComponent acomp = (XAccessibleComponent) UnoRuntime.queryInterface(
153 XAccessibleComponent.class,
154 oObj);
155 final XAccessibleComponent acomp1 = (XAccessibleComponent) UnoRuntime.queryInterface(
156 XAccessibleComponent.class,
157 action);
159 tEnv.addObjRelation("EventProducer",
160 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
161 public void fireEvent() {
162 acomp1.grabFocus();
163 acomp.grabFocus();
167 return tEnv;
171 * Closes the dialog using accessible button 'Cancel' found in
172 * <code>createTestEnvironment()</code>.
174 protected void cleanup(TestParameters Param, PrintWriter log) {
175 log.println(" closing dialog ");
177 try {
178 action.doAccessibleAction(0);
179 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
180 log.println("Couldn't close dialog");
181 } catch (com.sun.star.lang.DisposedException de) {
182 log.println("Dialog already disposed");
185 util.DesktopTools.closeDoc(xTextDoc);
190 * Creates writer doc
192 protected void initialize(TestParameters Param, PrintWriter log) {
193 try {
194 SOfficeFactory SOF = SOfficeFactory.getFactory(
195 (XMultiServiceFactory) Param.getMSF());
196 xTextDoc = SOF.createTextDoc(null);
197 } catch (com.sun.star.uno.Exception e) {
198 throw new StatusException("Can't create document", e);
204 * Thread for opening modal dialog 'Character style'.
206 public class DiagThread extends Thread {
207 public XTextDocument xTextDoc = null;
208 public XMultiServiceFactory msf = null;
210 public DiagThread(XTextDocument xTextDoc, XMultiServiceFactory msf) {
211 this.xTextDoc = xTextDoc;
212 this.msf = msf;
215 public void run() {
216 XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class,
217 xTextDoc);
219 XController xController = aModel.getCurrentController();
221 //Opening PrinterSetupDialog
222 try {
223 String aSlotID = ".uno:FontDialog";
224 XDispatchProvider xDispProv = (XDispatchProvider) UnoRuntime.queryInterface(
225 XDispatchProvider.class,
226 xController);
227 XURLTransformer xParser = (com.sun.star.util.XURLTransformer) UnoRuntime.queryInterface(
228 XURLTransformer.class,
229 msf.createInstance(
230 "com.sun.star.util.URLTransformer"));
232 // Because it's an in/out parameter we must use an array of URL objects.
233 URL[] aParseURL = new URL[1];
234 aParseURL[0] = new URL();
235 aParseURL[0].Complete = aSlotID;
236 xParser.parseStrict(aParseURL);
238 URL aURL = aParseURL[0];
239 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
241 if (xDispatcher != null) {
242 xDispatcher.dispatch(aURL, null);
244 } catch (com.sun.star.uno.Exception e) {
245 log.println("Couldn't open dialog");