bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleComboBox.java
blobd48bd0b4763c0bc9a41dd9326816cac657e805c5
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package mod._toolkit;
20 import com.sun.star.accessibility.AccessibleRole;
21 import com.sun.star.accessibility.XAccessible;
22 import com.sun.star.accessibility.XAccessibleAction;
23 import com.sun.star.accessibility.XAccessibleComponent;
24 import com.sun.star.accessibility.XAccessibleSelection;
25 import com.sun.star.awt.XExtendedToolkit;
26 import com.sun.star.awt.XWindow;
27 import com.sun.star.frame.XController;
28 import com.sun.star.frame.XDispatch;
29 import com.sun.star.frame.XDispatchProvider;
30 import com.sun.star.frame.XModel;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.text.XTextDocument;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
35 import com.sun.star.util.URL;
36 import com.sun.star.util.XURLTransformer;
38 import java.io.PrintWriter;
40 import lib.StatusException;
41 import lib.TestCase;
42 import lib.TestEnvironment;
43 import lib.TestParameters;
45 import util.AccessibilityTools;
46 import util.SOfficeFactory;
47 import util.utils;
50 /**
51 * Test for object which is represented by accessible component
52 * of the 'Font' combo box in Format->Character... dislog box. <p>
54 * Object implements the following interfaces :
55 * <ul>
56 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
58 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
59 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
60 * </ul> <p>
62 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
63 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
64 * @see com.sun.star.accessibility.XAccessibleComponent
65 * @see com.sun.star.accessibility.XAccessibleContext
66 * @see ifc.accessibility._XAccessibleExtendedComponent
67 * @see ifc.accessibility._XAccessibleEventBroadcaster
68 * @see ifc.accessibility._XAccessibleComponent
69 * @see ifc.accessibility._XAccessibleContext
71 public class AccessibleComboBox extends TestCase {
72 private static XTextDocument xTextDoc = null;
73 private static XAccessibleAction action = null;
75 /**
76 * Opens CharacterStyle dialog and
77 * finds AccessibleComboBox walking through the
78 * accessible component tree.
80 @Override
81 protected TestEnvironment createTestEnvironment(TestParameters Param,
82 PrintWriter log) {
83 XInterface oObj = null;
85 try {
86 oObj = (XInterface) Param.getMSF().createInstance(
87 "com.sun.star.awt.Toolkit");
88 } catch (com.sun.star.uno.Exception e) {
89 log.println("Couldn't get toolkit");
90 e.printStackTrace(log);
91 throw new StatusException("Couldn't get toolkit", e);
94 XExtendedToolkit tk = UnoRuntime.queryInterface(
95 XExtendedToolkit.class, oObj);
97 DiagThread psDiag = new DiagThread(xTextDoc,
98 Param.getMSF());
99 psDiag.start();
101 util.utils.pause(Param.getInt("ShortWait"));
103 Object atw = tk.getActiveTopWindow();
105 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,
106 atw);
108 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
110 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON,
111 "Cancel");
112 action = UnoRuntime.queryInterface(
113 XAccessibleAction.class, oObj);
115 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot,
116 AccessibleRole.PAGE_TAB_LIST);
118 XAccessibleSelection xAccSel = UnoRuntime.queryInterface(
119 XAccessibleSelection.class,
120 oObj);
122 try {
123 xAccSel.selectAccessibleChild(0);
124 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
125 e.printStackTrace(log);
127 util.utils.pause(Param.getInt("ShortWait"));
129 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
130 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL, "",
131 "AccessibleComboBox");
133 log.println("ImplementationName " + utils.getImplName(oObj));
135 TestEnvironment tEnv = new TestEnvironment(oObj);
137 final XAccessibleComponent acomp = UnoRuntime.queryInterface(
138 XAccessibleComponent.class,
139 oObj);
140 final XAccessibleComponent acomp1 = UnoRuntime.queryInterface(
141 XAccessibleComponent.class,
142 action);
144 tEnv.addObjRelation("EventProducer",
145 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
146 public void fireEvent() {
147 acomp1.grabFocus();
148 acomp.grabFocus();
152 return tEnv;
156 * Closes the dialog using accessible button 'Cancel' found in
157 * <code>createTestEnvironment()</code>.
159 @Override
160 protected void cleanup(TestParameters Param, PrintWriter log) {
161 log.println(" closing dialog ");
163 try {
164 action.doAccessibleAction(0);
165 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
166 log.println("Couldn't close dialog");
167 } catch (com.sun.star.lang.DisposedException de) {
168 log.println("Dialog already disposed");
171 util.DesktopTools.closeDoc(xTextDoc);
175 * Creates writer doc
177 @Override
178 protected void initialize(TestParameters Param, PrintWriter log) {
179 try {
180 SOfficeFactory SOF = SOfficeFactory.getFactory(
181 Param.getMSF());
182 xTextDoc = SOF.createTextDoc(null);
183 } catch (com.sun.star.uno.Exception e) {
184 throw new StatusException("Can't create document", e);
190 * Thread for opening modal dialog 'Character style'.
192 private class DiagThread extends Thread {
193 private XTextDocument xTextDoc = null;
194 private XMultiServiceFactory msf = null;
196 private DiagThread(XTextDocument xTextDoc, XMultiServiceFactory msf) {
197 this.xTextDoc = xTextDoc;
198 this.msf = msf;
201 @Override
202 public void run() {
203 XModel aModel = UnoRuntime.queryInterface(XModel.class,
204 xTextDoc);
206 XController xController = aModel.getCurrentController();
208 //Opening PrinterSetupDialog
209 try {
210 String aSlotID = ".uno:FontDialog";
211 XDispatchProvider xDispProv = UnoRuntime.queryInterface(
212 XDispatchProvider.class,
213 xController);
214 XURLTransformer xParser = UnoRuntime.queryInterface(
215 XURLTransformer.class,
216 msf.createInstance(
217 "com.sun.star.util.URLTransformer"));
219 // Because it's an in/out parameter we must use an array of URL objects.
220 URL[] aParseURL = new URL[1];
221 aParseURL[0] = new URL();
222 aParseURL[0].Complete = aSlotID;
223 xParser.parseStrict(aParseURL);
225 URL aURL = aParseURL[0];
226 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
228 if (xDispatcher != null) {
229 xDispatcher.dispatch(aURL, null);
231 } catch (com.sun.star.uno.Exception e) {
232 log.println("Couldn't open dialog");