bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleList.java
blobd10248760bd7006614537430095ae4efcb8a014a
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.accessibility.XAccessibleSelection;
26 import com.sun.star.awt.XExtendedToolkit;
27 import com.sun.star.awt.XWindow;
28 import com.sun.star.beans.PropertyValue;
29 import com.sun.star.frame.XController;
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;
40 import java.io.PrintWriter;
42 import lib.StatusException;
43 import lib.TestCase;
44 import lib.TestEnvironment;
45 import lib.TestParameters;
47 import util.AccessibilityTools;
48 import util.SOfficeFactory;
49 import util.utils;
52 public class AccessibleList extends TestCase {
53 private static XTextDocument xTextDoc = null;
54 private static XAccessibleAction action = null;
55 private static XMultiServiceFactory msf = null;
57 /**
58 * Opens 'Insert Hyperlink' dialog using document dispatch provider.
59 * Finds active top window (the dialog
60 * window) and finds button 'Close' (for closing this dialog when
61 * disposing) walking through the accessible component tree.
62 * Then the TREE component is found and the 'New Document' tab is
63 * selected to make list box visible. After that list box is obtained.
65 protected TestEnvironment createTestEnvironment(TestParameters Param,
66 PrintWriter log) {
67 XInterface oObj = null;
69 try {
70 oObj = (XInterface) msf.createInstance("com.sun.star.awt.Toolkit");
71 } catch (com.sun.star.uno.Exception e) {
72 log.println("Couldn't get toolkit");
73 e.printStackTrace(log);
74 throw new StatusException("Couldn't get toolkit", e);
77 XExtendedToolkit tk = UnoRuntime.queryInterface(
78 XExtendedToolkit.class, oObj);
80 shortWait();
82 XModel aModel1 = UnoRuntime.queryInterface(XModel.class,
83 xTextDoc);
85 XController secondController = aModel1.getCurrentController();
87 XDispatchProvider aProv = UnoRuntime.queryInterface(
88 XDispatchProvider.class,
89 secondController);
91 XURLTransformer urlTransf = null;
93 try {
94 XInterface transf = (XInterface) msf.createInstance(
95 "com.sun.star.util.URLTransformer");
96 urlTransf = UnoRuntime.queryInterface(
97 XURLTransformer.class, transf);
98 } catch (com.sun.star.uno.Exception e) {
99 e.printStackTrace(log);
100 throw new StatusException("Couldn't create URLTransformer", e);
103 XDispatch getting = null;
104 log.println("opening HyperlinkDialog");
106 URL[] url = new URL[1];
107 url[0] = new URL();
108 url[0].Complete = ".uno:HyperlinkDialog";
109 urlTransf.parseStrict(url);
110 getting = aProv.queryDispatch(url[0], "", 0);
112 PropertyValue[] noArgs = new PropertyValue[0];
113 getting.dispatch(url[0], noArgs);
115 shortWait();
117 AccessibilityTools at = new AccessibilityTools();
119 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,
120 tk.getActiveTopWindow());
122 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
125 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
126 // obtaining 'Close' button
127 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON,
128 "Close");
129 action = UnoRuntime.queryInterface(
130 XAccessibleAction.class, oObj);
132 // Selecting 'New Document' tab
133 try {
134 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TREE);
136 XAccessibleSelection xAccSel = UnoRuntime.queryInterface(
137 XAccessibleSelection.class,
138 oObj);
139 xAccSel.selectAccessibleChild(3);
140 shortWait();
141 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
142 throw new StatusException("Can't switch to required tab", e);
145 log.println("# Getting the ListBox");
147 XAccessibleContext parent = AccessibilityTools.getAccessibleObjectForRole(xRoot,
148 AccessibleRole.PANEL,
150 "com.sun.star.comp.toolkit.AccessibleListBox");
152 log.println("# Getting the first child");
154 try {
155 oObj = parent.getAccessibleChild(0);
156 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
159 log.println("ImplementationName " + utils.getImplName(oObj));
161 TestEnvironment tEnv = new TestEnvironment(oObj);
163 tEnv.addObjRelation("XAccessibleSelection.multiSelection",
164 new Boolean(false));
166 final XAccessibleComponent acomp = UnoRuntime.queryInterface(
167 XAccessibleComponent.class,
168 oObj);
169 final XAccessibleComponent acomp1 = UnoRuntime.queryInterface(
170 XAccessibleComponent.class,
171 action);
173 tEnv.addObjRelation("EventProducer",
174 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
175 public void fireEvent() {
176 System.out.println("Grabbing focus ... ");
177 acomp1.grabFocus();
178 acomp.grabFocus();
182 return tEnv;
186 * Closes dialog using action of button 'Close'
188 protected void cleanup(TestParameters Param, PrintWriter log) {
189 log.println(" Closing dialog ... ");
191 try {
192 action.doAccessibleAction(0);
193 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
194 log.println("Couldn't close dialog");
195 } catch (com.sun.star.lang.DisposedException de) {
196 log.println("Dialog already disposed");
199 util.DesktopTools.closeDoc(xTextDoc);
203 * Creates writer document
205 protected void initialize(TestParameters Param, PrintWriter log) {
206 try {
207 msf = (XMultiServiceFactory) Param.getMSF();
209 SOfficeFactory SOF = SOfficeFactory.getFactory(msf);
210 xTextDoc = SOF.createTextDoc(null);
211 } catch (com.sun.star.uno.Exception e) {
212 throw new StatusException("Can't create document", e);
217 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
218 * reset</code> call.
220 private void shortWait() {
221 try {
222 Thread.sleep(1000);
223 } catch (InterruptedException e) {
224 log.println("While waiting :" + e);