Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleListItem.java
blobfc195441b12823c47db1c6b79959bd321f33ae8d
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: AccessibleListItem.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.beans.PropertyValue;
40 import com.sun.star.frame.XController;
41 import com.sun.star.frame.XDispatch;
42 import com.sun.star.frame.XDispatchProvider;
43 import com.sun.star.frame.XModel;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.text.XTextDocument;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
48 import com.sun.star.util.URL;
49 import com.sun.star.util.XURLTransformer;
51 import java.io.PrintWriter;
53 import lib.StatusException;
54 import lib.TestCase;
55 import lib.TestEnvironment;
56 import lib.TestParameters;
58 import util.AccessibilityTools;
59 import util.SOfficeFactory;
60 import util.utils;
63 /**
64 * Test for object which is represented accessible component
65 * of 'File type' list box item situated in 'Insert Hyperlink'
66 * dialog on tab 'New Document'. <p>
68 * Object implements the following interfaces :
69 * <ul>
70 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
71 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
72 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
73 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
74 * </ul> <p>
76 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
77 * @see com.sun.star.accessibility.XAccessibleComponent
78 * @see com.sun.star.accessibility.XAccessibleContext
79 * @see com.sun.star.accessibility.XAccessibleText
80 * @see ifc.accessibility._XAccessibleEventBroadcaster
81 * @see ifc.accessibility._XAccessibleComponent
82 * @see ifc.accessibility._XAccessibleContext
83 * @see ifc.accessibility._XAccessibleText
85 public class AccessibleListItem extends TestCase {
86 private static XTextDocument xTextDoc = null;
87 private static XAccessibleAction action = null;
89 /**
90 * Opens 'Insert Hyperlink' dialog using document dispatch provider.
91 * Finds active top window (the dialog
92 * window) and finds button 'Close' (for closing this dialog when
93 * disposing) walking through the accessible component tree.
94 * Then the TREE component is found and the 'New Document' tab is
95 * selected to make list box visible. After that listbox item is obtained.
97 protected TestEnvironment createTestEnvironment(TestParameters Param,
98 PrintWriter log) {
99 XInterface oObj = null;
100 XMultiServiceFactory msf = (XMultiServiceFactory) Param.getMSF();
102 try {
103 oObj = (XInterface) msf.createInstance("com.sun.star.awt.Toolkit");
104 } catch (com.sun.star.uno.Exception e) {
105 log.println("Couldn't get toolkit");
106 e.printStackTrace(log);
107 throw new StatusException("Couldn't get toolkit", e);
110 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
111 XExtendedToolkit.class, oObj);
113 shortWait();
115 XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class,
116 xTextDoc);
118 XController secondController = aModel1.getCurrentController();
120 XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface(
121 XDispatchProvider.class,
122 secondController);
124 XURLTransformer urlTransf = null;
126 try {
127 XInterface transf = (XInterface) msf.createInstance(
128 "com.sun.star.util.URLTransformer");
129 urlTransf = (XURLTransformer) UnoRuntime.queryInterface(
130 XURLTransformer.class, transf);
131 } catch (com.sun.star.uno.Exception e) {
132 e.printStackTrace(log);
133 throw new StatusException("Couldn't create URLTransformer", e);
136 XDispatch getting = null;
137 log.println("opening HyperlinkDialog");
139 URL[] url = new URL[1];
140 url[0] = new URL();
141 url[0].Complete = ".uno:HyperlinkDialog";
142 urlTransf.parseStrict(url);
143 getting = aProv.queryDispatch(url[0], "", 0);
145 PropertyValue[] noArgs = new PropertyValue[0];
146 getting.dispatch(url[0], noArgs);
148 shortWait();
150 AccessibilityTools at = new AccessibilityTools();
152 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class,
153 tk.getActiveTopWindow());
155 XAccessible xRoot = at.getAccessibleObject(xWindow);
158 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
159 // obtaining 'Close' button
160 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON,
161 "Close");
162 action = (XAccessibleAction) UnoRuntime.queryInterface(
163 XAccessibleAction.class, oObj);
165 // Selecting 'New Document' tab
166 try {
167 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TREE);
169 XAccessibleSelection xAccSel = (XAccessibleSelection) UnoRuntime.queryInterface(
170 XAccessibleSelection.class,
171 oObj);
172 xAccSel.selectAccessibleChild(3);
173 shortWait();
174 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
175 throw new StatusException("Can't switch to required tab", e);
178 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.LIST_ITEM,"Spr");
180 log.println("ImplementationName " + utils.getImplName(oObj));
182 TestEnvironment tEnv = new TestEnvironment(oObj);
184 tEnv.addObjRelation("EditOnly",
185 "This method isn't supported in this component");
187 tEnv.addObjRelation("LimitedBounds", "yes");
189 final XAccessibleComponent acomp = (XAccessibleComponent) UnoRuntime.queryInterface(
190 XAccessibleComponent.class,
191 oObj);
192 tEnv.addObjRelation("EventProducer",
193 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
194 public void fireEvent() {
195 acomp.grabFocus();
199 return tEnv;
203 * Closes dialog using action of button 'Close'
205 protected void cleanup(TestParameters Param, PrintWriter log) {
206 log.println(" Closing dialog ... ");
208 try {
209 action.doAccessibleAction(0);
210 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
211 log.println("Couldn't close dialog");
212 } catch (com.sun.star.lang.DisposedException de) {
213 log.println("Dialog already disposed");
216 util.DesktopTools.closeDoc(xTextDoc);
221 * Creates writer document
223 protected void initialize(TestParameters Param, PrintWriter log) {
224 try {
225 SOfficeFactory SOF = SOfficeFactory.getFactory(
226 (XMultiServiceFactory) Param.getMSF());
227 xTextDoc = SOF.createTextDoc(null);
228 } catch (com.sun.star.uno.Exception e) {
229 throw new StatusException("Can't create document", e);
234 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
235 * reset</code> call.
237 private void shortWait() {
238 try {
239 Thread.sleep(1000);
240 } catch (InterruptedException e) {
241 log.println("While waiting :" + e);