bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleButton.java
blob79f8199e5723e6dedbbaaa26ad839f09f8baed86
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.XAccessibleText;
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.TestEnvironment;
42 import lib.TestParameters;
44 import util.AccessibilityTools;
45 import util.SOfficeFactory;
46 import util.utils;
49 /**
50 * Object implements the following interfaces :
51 * <ul>
52 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
53 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
54 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
55 * <li> <code>::com::sun::star::accessibility::XAccessibleValue</code></li>
56 * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
58 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
59 * </ul> <p>
61 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
62 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
63 * @see com.sun.star.accessibility.XAccessibleComponent
64 * @see com.sun.star.accessibility.XAccessibleValue
65 * @see com.sun.star.accessibility.XAccessibleAction
66 * @see com.sun.star.accessibility.XAccessibleContext
67 * @see com.sun.star.accessibility.XAccessibleText
68 * @see ifc.accessibility._XAccessibleExtendedComponent
69 * @see ifc.accessibility._XAccessibleEventBroadcaster
70 * @see ifc.accessibility._XAccessibleComponent
71 * @see ifc.accessibility._XAccessibleValue
72 * @see ifc.accessibility._XAccessibleAction
73 * @see ifc.accessibility._XAccessibleContext
74 * @see ifc.accessibility._XAccessibleText
76 public class AccessibleButton extends lib.TestCase {
77 private static XTextDocument xTextDoc = null;
78 private static XAccessibleAction action = null;
80 /**
81 * Opens 'Printer Settings' dialog using document dispatch provider
82 * running in a separate thread. Finds active top window (the dialog
83 * window) and finds accessible button 'OK' walking through the
84 * accessible component tree.
86 protected TestEnvironment createTestEnvironment(TestParameters Param,
87 PrintWriter log) {
88 XInterface oObj = null;
89 XMultiServiceFactory msf = (XMultiServiceFactory) Param.getMSF();
91 try {
92 oObj = (XInterface) msf.createInstance("com.sun.star.awt.Toolkit");
93 } catch (com.sun.star.uno.Exception e) {
94 log.println("Couldn't get toolkit");
95 e.printStackTrace(log);
96 throw new StatusException("Couldn't get toolkit", e);
99 XExtendedToolkit tk = UnoRuntime.queryInterface(
100 XExtendedToolkit.class, oObj);
102 util.utils.shortWait(Param.getInt("ShortWait"));
104 DiagThread psDiag = new DiagThread(xTextDoc, msf);
105 psDiag.start();
107 util.utils.shortWait(Param.getInt("ShortWait"));
109 AccessibilityTools at = new AccessibilityTools();
111 util.utils.shortWait(Param.getInt("ShortWait"));
113 Object atw = tk.getActiveTopWindow();
115 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,
116 atw);
118 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
121 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
122 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON,
123 "Cancel");
125 log.println("ImplementationName " + utils.getImplName(oObj));
127 TestEnvironment tEnv = new TestEnvironment(oObj);
129 action = UnoRuntime.queryInterface(
130 XAccessibleAction.class, oObj);
132 final XAccessibleComponent acomp = UnoRuntime.queryInterface(
133 XAccessibleComponent.class,
134 oObj);
136 tEnv.addObjRelation("EventProducer",
137 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
138 public void fireEvent() {
139 System.out.println("Grabbing focus ... ");
140 acomp.grabFocus();
144 XAccessibleText text = UnoRuntime.queryInterface(
145 XAccessibleText.class, oObj);
147 tEnv.addObjRelation("XAccessibleText.Text", text.getText());
149 tEnv.addObjRelation("EditOnly",
150 "This method isn't supported in this component");
152 tEnv.addObjRelation("LimitedBounds", "yes");
154 return tEnv;
158 * Closes the dialog using accessible button 'OK' found in
159 * <code>createTestEnvironment()</code>.
161 protected void cleanup(TestParameters Param, PrintWriter log) {
162 log.println(" disposing xTextDoc ");
164 try {
165 action.doAccessibleAction(0);
166 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
167 log.println("Couldn't close dialog");
168 } catch (com.sun.star.lang.DisposedException de) {
169 log.println("Dialog already disposed");
172 util.DesktopTools.closeDoc(xTextDoc);
176 * Opens new writer document.
178 protected void initialize(TestParameters Param, PrintWriter log) {
179 try {
180 SOfficeFactory SOF = SOfficeFactory.getFactory(
181 (XMultiServiceFactory) 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 'Print Settings'.
192 public class DiagThread extends Thread {
193 public XTextDocument xTextDoc = null;
194 public XMultiServiceFactory msf = null;
196 public DiagThread(XTextDocument xTextDoc, XMultiServiceFactory msf) {
197 this.xTextDoc = xTextDoc;
198 this.msf = msf;
201 public void run() {
202 XModel aModel = UnoRuntime.queryInterface(XModel.class,
203 xTextDoc);
205 XController xController = aModel.getCurrentController();
207 //Opening PrinterSetupDialog
208 try {
209 String aSlotID = ".uno:Zoom";
210 XDispatchProvider xDispProv = UnoRuntime.queryInterface(
211 XDispatchProvider.class,
212 xController);
213 XURLTransformer xParser = UnoRuntime.queryInterface(
214 XURLTransformer.class,
215 msf.createInstance(
216 "com.sun.star.util.URLTransformer"));
218 // Because it's an in/out parameter
219 // 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");