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 .
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
.XAccessibleSelection
;
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
.XDispatch
;
30 import com
.sun
.star
.frame
.XDispatchProvider
;
31 import com
.sun
.star
.frame
.XModel
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.text
.XTextDocument
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
36 import com
.sun
.star
.util
.URL
;
37 import com
.sun
.star
.util
.XURLTransformer
;
39 import java
.io
.PrintWriter
;
41 import lib
.StatusException
;
43 import lib
.TestEnvironment
;
44 import lib
.TestParameters
;
46 import util
.AccessibilityTools
;
47 import util
.SOfficeFactory
;
52 * Test for object which is represented accessible component
53 * of 'File type' list box situated in 'Insert Hyperlink'
54 * dialog on tab 'New Document'. <p>
56 * Object implements the following interfaces :
58 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
59 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
60 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
61 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li>
62 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
65 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
66 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
67 * @see com.sun.star.accessibility.XAccessibleComponent
68 * @see com.sun.star.accessibility.XAccessibleSelection
69 * @see com.sun.star.accessibility.XAccessibleContext
70 * @see ifc.accessibility._XAccessibleExtendedComponent
71 * @see ifc.accessibility._XAccessibleEventBroadcaster
72 * @see ifc.accessibility._XAccessibleComponent
73 * @see ifc.accessibility._XAccessibleSelection
74 * @see ifc.accessibility._XAccessibleContext
76 public class AccessibleListBox
extends TestCase
{
77 private static XTextDocument xTextDoc
= null;
78 private static XAccessibleAction action
= null;
81 * Opens 'Insert Hyperlink' dialog using document dispatch provider.
82 * Finds active top window (the dialog
83 * window) and finds button 'Close' (for closing this dialog when
84 * disposing) walking through the accessible component tree.
85 * Then the TREE component is found and the 'New Document' tab is
86 * selected to make list box visible. After that list box is obtained.
88 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
90 XInterface oObj
= null;
93 oObj
= (XInterface
) ((XMultiServiceFactory
) Param
.getMSF()).createInstance(
94 "com.sun.star.awt.Toolkit");
95 } catch (com
.sun
.star
.uno
.Exception e
) {
96 log
.println("Couldn't get toolkit");
97 e
.printStackTrace(log
);
98 throw new StatusException("Couldn't get toolkit", e
);
101 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
102 XExtendedToolkit
.class, oObj
);
106 XModel aModel1
= UnoRuntime
.queryInterface(XModel
.class,
109 XController secondController
= aModel1
.getCurrentController();
111 XDispatchProvider aProv
= UnoRuntime
.queryInterface(
112 XDispatchProvider
.class,
115 XURLTransformer urlTransf
= null;
118 XInterface transf
= (XInterface
) ((XMultiServiceFactory
) Param
.getMSF()).createInstance(
119 "com.sun.star.util.URLTransformer");
120 urlTransf
= UnoRuntime
.queryInterface(
121 XURLTransformer
.class, transf
);
122 } catch (com
.sun
.star
.uno
.Exception e
) {
123 e
.printStackTrace(log
);
124 throw new StatusException("Couldn't create URLTransformer", e
);
127 XDispatch getting
= null;
128 log
.println("opening HyperlinkDialog");
130 URL
[] url
= new URL
[1];
132 url
[0].Complete
= ".uno:HyperlinkDialog";
133 urlTransf
.parseStrict(url
);
134 getting
= aProv
.queryDispatch(url
[0], "", 0);
136 PropertyValue
[] noArgs
= new PropertyValue
[0];
137 getting
.dispatch(url
[0], noArgs
);
141 AccessibilityTools at
= new AccessibilityTools();
143 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
144 tk
.getActiveTopWindow());
146 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
148 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
151 // obtaining 'Close' button
152 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PUSH_BUTTON
,
154 action
= UnoRuntime
.queryInterface(
155 XAccessibleAction
.class, oObj
);
157 // Selecting 'New Document' tab
159 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TREE
);
161 XAccessibleSelection xAccSel
= UnoRuntime
.queryInterface(
162 XAccessibleSelection
.class,
164 xAccSel
.selectAccessibleChild(3);
166 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
167 throw new StatusException("Can't switch to required tab", e
);
170 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PANEL
, "",
171 "com.sun.star.comp.toolkit.AccessibleListBox");
173 Object list
= AccessibilityTools
.getAccessibleObjectForRole(AccessibilityTools
.SearchedAccessible
,
174 AccessibleRole
.LIST
);
176 log
.println("ImplementationName " + utils
.getImplName(oObj
));
178 TestEnvironment tEnv
= new TestEnvironment(oObj
);
180 final XAccessibleComponent acomp
= UnoRuntime
.queryInterface(
181 XAccessibleComponent
.class,
183 final XAccessibleComponent acomp1
= UnoRuntime
.queryInterface(
184 XAccessibleComponent
.class,
187 tEnv
.addObjRelation("EventProducer",
188 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
189 public void fireEvent() {
190 System
.out
.println("Grabbing focus ... ");
200 * Closes dialog using action of button 'Close'
202 protected void cleanup(TestParameters Param
, PrintWriter log
) {
203 log
.println(" Closing dialog ... ");
206 action
.doAccessibleAction(0);
207 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ioe
) {
208 log
.println("Couldn't close dialog");
209 } catch (com
.sun
.star
.lang
.DisposedException de
) {
210 log
.println("Dialog already disposed");
213 util
.DesktopTools
.closeDoc(xTextDoc
);
217 * Creates writer document
219 protected void initialize(TestParameters Param
, PrintWriter log
) {
221 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
222 (XMultiServiceFactory
) Param
.getMSF());
223 xTextDoc
= SOF
.createTextDoc(null);
224 } catch (com
.sun
.star
.uno
.Exception e
) {
225 throw new StatusException("Can't create document", e
);
230 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
233 private void shortWait() {
236 } catch (InterruptedException e
) {
237 log
.println("While waiting :" + e
);