bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleTabPage.java
blob9d09508b5f976138b189b4a92b36549737640273
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.XAccessibleContext;
25 import com.sun.star.awt.XExtendedToolkit;
26 import com.sun.star.awt.XWindow;
27 import com.sun.star.beans.PropertyValue;
28 import com.sun.star.frame.XController;
29 import com.sun.star.frame.XDesktop;
30 import com.sun.star.frame.XDispatch;
31 import com.sun.star.frame.XDispatchProvider;
32 import com.sun.star.frame.XModel;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
37 import com.sun.star.util.URL;
38 import com.sun.star.util.XURLTransformer;
41 import java.io.PrintWriter;
43 import lib.StatusException;
44 import lib.TestCase;
45 import lib.TestEnvironment;
46 import lib.TestParameters;
48 import util.AccessibilityTools;
49 import util.DesktopTools;
50 import util.SOfficeFactory;
53 /**
54 * Test for object that implements the following interfaces :
55 * <ul>
56 * <li><code>
57 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
58 * <li><code>
59 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
60 * </code></li>
61 * <li><code>
62 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
63 * <li><code>
64 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
65 * </code></li>
66 * </ul> <p>
68 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
69 * @see com.sun.star.accessibility.XAccessibleContext
70 * @see com.sun.star.accessibility.XAccessibleComponent
71 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
72 * @see ifc.accessibility._XAccessibleEventBroadcaster
73 * @see ifc.accessibility._XAccessibleContext
74 * @see ifc.accessibility._XAccessibleComponent
75 * @see ifc.accessibility._XAccessibleExtendedComponent
77 public class AccessibleTabPage extends TestCase {
78 private static XTextDocument xTextDoc;
79 private static XAccessibleAction accCloseButton = null;
81 /**
82 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
84 protected void initialize(TestParameters Param, PrintWriter log) {
85 UnoRuntime.queryInterface(XDesktop.class,
86 DesktopTools.createDesktop(
87 (XMultiServiceFactory) Param.getMSF()));
90 /**
91 * Closes an InsertFields dialog, disposes the document, if exists, created in
92 * <code>createTestEnvironment</code> method.
94 protected void cleanup(TestParameters Param, PrintWriter log) {
95 try {
96 if (accCloseButton != null) {
97 log.println("closing InsertFields Dialog");
98 accCloseButton.doAccessibleAction(0);
99 shortWait();
101 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
102 e.printStackTrace(log);
103 } catch (com.sun.star.lang.DisposedException e) {
104 log.println("Couldn't close dialog " + e.getMessage());
107 log.println("disposing xTextDoc");
109 if (xTextDoc != null) {
110 closeDoc();
115 * Creates a text document, opens an InsertField dialog.
116 * Then obtains an accessible object with
117 * the role <code>AccessibleRole.PAGETAB</code>.
118 * Object relations created :
119 * <ul>
120 * <li> <code>'EventProducer'</code> for
121 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
122 * grabs focus </li>
123 * </ul>
125 * @param tParam test parameters
126 * @param log writer to log information while testing
128 * @see com.sun.star.awt.Toolkit
129 * @see com.sun.star.accessibility.AccessibleRole
130 * @see ifc.accessibility._XAccessibleEventBroadcaster
131 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
133 protected TestEnvironment createTestEnvironment(TestParameters tParam,
134 PrintWriter log) {
135 log.println("creating a test environment");
137 try {
138 if (accCloseButton != null) {
139 log.println("closing InsertFields Dialog");
140 accCloseButton.doAccessibleAction(0);
141 shortWait();
143 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
144 e.printStackTrace(log);
145 } catch (com.sun.star.lang.DisposedException e) {
146 log.println("Couldn't close dialog " + e.getMessage());
149 log.println("disposing xTextDoc");
151 if (xTextDoc != null) {
152 closeDoc();
155 // get a soffice factory object
156 SOfficeFactory SOF = SOfficeFactory.getFactory(
157 (XMultiServiceFactory) tParam.getMSF());
159 try {
160 log.println("creating a text document");
161 xTextDoc = SOF.createTextDoc(null);
162 } catch (com.sun.star.uno.Exception e) {
163 // Some exception occurs.FAILED
164 e.printStackTrace(log);
165 throw new StatusException("Couldn't create document", e);
168 shortWait();
170 XModel aModel1 = UnoRuntime.queryInterface(XModel.class,
171 xTextDoc);
173 XController secondController = aModel1.getCurrentController();
175 XDispatchProvider aProv = UnoRuntime.queryInterface(
176 XDispatchProvider.class,
177 secondController);
179 XURLTransformer urlTransf = null;
181 try {
182 XInterface transf = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
183 "com.sun.star.util.URLTransformer");
184 urlTransf = UnoRuntime.queryInterface(
185 XURLTransformer.class, transf);
186 } catch (com.sun.star.uno.Exception e) {
187 e.printStackTrace(log);
188 throw new StatusException("Couldn't create URLTransformer", e);
191 XDispatch getting = null;
192 log.println("opening InsertField dialog");
194 URL[] url = new URL[1];
195 url[0] = new URL();
196 url[0].Complete = ".uno:InsertField";
197 urlTransf.parseStrict(url);
198 getting = aProv.queryDispatch(url[0], "", 0);
200 PropertyValue[] noArgs = new PropertyValue[0];
201 getting.dispatch(url[0], noArgs);
203 shortWait();
205 XInterface oObj = null;
207 try {
208 oObj = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
209 "com.sun.star.awt.Toolkit");
210 } catch (com.sun.star.uno.Exception e) {
211 log.println("Couldn't get toolkit");
212 e.printStackTrace(log);
213 throw new StatusException("Couldn't get toolkit", e);
216 XExtendedToolkit tk = UnoRuntime.queryInterface(
217 XExtendedToolkit.class, oObj);
219 AccessibilityTools at = new AccessibilityTools();
221 shortWait();
223 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,
224 tk.getActiveTopWindow());
226 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
228 XAccessibleContext closeButton = AccessibilityTools.getAccessibleObjectForRole(xRoot,
229 AccessibleRole.PUSH_BUTTON,
230 "Close");
232 accCloseButton = UnoRuntime.queryInterface(
233 XAccessibleAction.class, closeButton);
235 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PAGE_TAB);
237 log.println("ImplementationName: " + util.utils.getImplName(oObj));
239 TestEnvironment tEnv = new TestEnvironment(oObj);
241 tEnv.addObjRelation("EditOnly", "toolkit.AccessibleTabPage");
242 tEnv.addObjRelation("LimitedBounds", "toolkit.AccessibleTabPage");
244 XAccessibleComponent accComp = UnoRuntime.queryInterface(
245 XAccessibleComponent.class,
246 oObj);
247 accComp.getLocationOnScreen();
249 shortWait();
251 XInterface xEventInt = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PAGE_TAB, "Variables");
252 final XAccessibleComponent eventAccComp = UnoRuntime.queryInterface(
253 XAccessibleComponent.class,
254 xEventInt);
256 tEnv.addObjRelation("EventProducer",
257 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
258 public void fireEvent() {
259 eventAccComp.grabFocus();
263 return tEnv;
267 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
268 * reset</code> call.
270 private void shortWait() {
271 try {
272 Thread.sleep(1000);
273 } catch (InterruptedException e) {
274 System.out.println("While waiting :" + e);
278 protected void closeDoc() {
279 util.DesktopTools.closeDoc(xTextDoc);