Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleTabPage.java
blob7e81bfceaaf8699c106bc807b70e58ea035aae89
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: AccessibleTabPage.java,v $
10 * $Revision: 1.10 $
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.XAccessibleContext;
37 import com.sun.star.awt.Point;
38 import com.sun.star.awt.XExtendedToolkit;
39 import com.sun.star.awt.XWindow;
40 import com.sun.star.beans.PropertyValue;
41 import com.sun.star.frame.XController;
42 import com.sun.star.frame.XDesktop;
43 import com.sun.star.frame.XDispatch;
44 import com.sun.star.frame.XDispatchProvider;
45 import com.sun.star.frame.XModel;
46 import com.sun.star.lang.XMultiServiceFactory;
47 import com.sun.star.text.XTextDocument;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
50 import com.sun.star.util.URL;
51 import com.sun.star.util.XURLTransformer;
54 import java.io.PrintWriter;
56 import lib.StatusException;
57 import lib.TestCase;
58 import lib.TestEnvironment;
59 import lib.TestParameters;
61 import util.AccessibilityTools;
62 import util.DesktopTools;
63 import util.SOfficeFactory;
66 /**
67 * Test for object that implements the following interfaces :
68 * <ul>
69 * <li><code>
70 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
71 * <li><code>
72 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
73 * </code></li>
74 * <li><code>
75 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
76 * <li><code>
77 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
78 * </code></li>
79 * </ul> <p>
81 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
82 * @see com.sun.star.accessibility.XAccessibleContext
83 * @see com.sun.star.accessibility.XAccessibleComponent
84 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
85 * @see ifc.accessibility._XAccessibleEventBroadcaster
86 * @see ifc.accessibility._XAccessibleContext
87 * @see ifc.accessibility._XAccessibleComponent
88 * @see ifc.accessibility.XAccessibleExtendedComponent
90 public class AccessibleTabPage extends TestCase {
91 private static XDesktop the_Desk;
92 private static XTextDocument xTextDoc;
93 private static XAccessibleAction accCloseButton = null;
95 /**
96 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
98 protected void initialize(TestParameters Param, PrintWriter log) {
99 the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
100 DesktopTools.createDesktop(
101 (XMultiServiceFactory) Param.getMSF()));
105 * Closes an InsertFields dialog, disposes the document, if exists, created in
106 * <code>createTestEnvironment</code> method.
108 protected void cleanup(TestParameters Param, PrintWriter log) {
109 try {
110 if (accCloseButton != null) {
111 log.println("closing InsertFields Dialog");
112 accCloseButton.doAccessibleAction(0);
113 shortWait();
115 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
116 e.printStackTrace(log);
117 } catch (com.sun.star.lang.DisposedException e) {
118 log.println("Couldn't close dialog " + e.getMessage());
121 log.println("disposing xTextDoc");
123 if (xTextDoc != null) {
124 closeDoc();
129 * Creates a text document, opens an InsertField dialog.
130 * Then obtains an accessible object with
131 * the role <code>AccessibleRole.PAGETAB</code>.
132 * Object relations created :
133 * <ul>
134 * <li> <code>'EventProducer'</code> for
135 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
136 * grabs focus </li>
137 * </ul>
139 * @param tParam test parameters
140 * @param log writer to log information while testing
142 * @see com.sun.star.awt.Toolkit
143 * @see com.sun.star.accessibility.AccessibleRole
144 * @see ifc.accessibility._XAccessibleEventBroadcaster
145 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
147 protected TestEnvironment createTestEnvironment(TestParameters tParam,
148 PrintWriter log) {
149 log.println("creating a test environment");
151 try {
152 if (accCloseButton != null) {
153 log.println("closing InsertFields Dialog");
154 accCloseButton.doAccessibleAction(0);
155 shortWait();
157 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
158 e.printStackTrace(log);
159 } catch (com.sun.star.lang.DisposedException e) {
160 log.println("Couldn't close dialog " + e.getMessage());
163 log.println("disposing xTextDoc");
165 if (xTextDoc != null) {
166 closeDoc();
169 // get a soffice factory object
170 SOfficeFactory SOF = SOfficeFactory.getFactory(
171 (XMultiServiceFactory) tParam.getMSF());
173 try {
174 log.println("creating a text document");
175 xTextDoc = SOF.createTextDoc(null);
176 } catch (com.sun.star.uno.Exception e) {
177 // Some exception occures.FAILED
178 e.printStackTrace(log);
179 throw new StatusException("Couldn't create document", e);
182 shortWait();
184 XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class,
185 xTextDoc);
187 XController secondController = aModel1.getCurrentController();
189 XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface(
190 XDispatchProvider.class,
191 secondController);
193 XURLTransformer urlTransf = null;
195 try {
196 XInterface transf = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
197 "com.sun.star.util.URLTransformer");
198 urlTransf = (XURLTransformer) UnoRuntime.queryInterface(
199 XURLTransformer.class, transf);
200 } catch (com.sun.star.uno.Exception e) {
201 e.printStackTrace(log);
202 throw new StatusException("Couldn't create URLTransformer", e);
205 XDispatch getting = null;
206 log.println("opening InsertField dialog");
208 URL[] url = new URL[1];
209 url[0] = new URL();
210 url[0].Complete = ".uno:InsertField";
211 urlTransf.parseStrict(url);
212 getting = aProv.queryDispatch(url[0], "", 0);
214 PropertyValue[] noArgs = new PropertyValue[0];
215 getting.dispatch(url[0], noArgs);
217 shortWait();
219 XInterface oObj = null;
221 try {
222 oObj = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
223 "com.sun.star.awt.Toolkit");
224 } catch (com.sun.star.uno.Exception e) {
225 log.println("Couldn't get toolkit");
226 e.printStackTrace(log);
227 throw new StatusException("Couldn't get toolkit", e);
230 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
231 XExtendedToolkit.class, oObj);
233 AccessibilityTools at = new AccessibilityTools();
235 shortWait();
237 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class,
238 tk.getActiveTopWindow());
240 XAccessible xRoot = at.getAccessibleObject(xWindow);
242 XAccessibleContext closeButton = at.getAccessibleObjectForRole(xRoot,
243 AccessibleRole.PUSH_BUTTON,
244 "Close");
246 accCloseButton = (XAccessibleAction) UnoRuntime.queryInterface(
247 XAccessibleAction.class, closeButton);
249 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PAGE_TAB);
251 log.println("ImplementationName: " + util.utils.getImplName(oObj));
253 TestEnvironment tEnv = new TestEnvironment(oObj);
255 tEnv.addObjRelation("EditOnly", "toolkit.AccessibleTabPage");
256 tEnv.addObjRelation("LimitedBounds", "toolkit.AccessibleTabPage");
258 XAccessibleComponent accComp = (XAccessibleComponent) UnoRuntime.queryInterface(
259 XAccessibleComponent.class,
260 oObj);
261 final Point point = accComp.getLocationOnScreen();
263 shortWait();
265 XInterface xEventInt = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PAGE_TAB, "Variables");
266 final XAccessibleComponent eventAccComp = (XAccessibleComponent) UnoRuntime.queryInterface(
267 XAccessibleComponent.class,
268 xEventInt);
270 tEnv.addObjRelation("EventProducer",
271 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
272 public void fireEvent() {
273 eventAccComp.grabFocus();
277 return tEnv;
281 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
282 * reset</code> call.
284 private void shortWait() {
285 try {
286 Thread.currentThread().sleep(1000);
287 } catch (InterruptedException e) {
288 System.out.println("While waiting :" + e);
292 protected void closeDoc() {
293 util.DesktopTools.closeDoc(xTextDoc);