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 item situated in 'Insert Hyperlink'
54 * dialog on tab 'New Document'. <p>
56 * Object implements the following interfaces :
58 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
59 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
60 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
61 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
64 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
65 * @see com.sun.star.accessibility.XAccessibleComponent
66 * @see com.sun.star.accessibility.XAccessibleContext
67 * @see com.sun.star.accessibility.XAccessibleText
68 * @see ifc.accessibility._XAccessibleEventBroadcaster
69 * @see ifc.accessibility._XAccessibleComponent
70 * @see ifc.accessibility._XAccessibleContext
71 * @see ifc.accessibility._XAccessibleText
73 public class AccessibleListItem
extends TestCase
{
74 private static XTextDocument xTextDoc
= null;
75 private static XAccessibleAction action
= null;
78 * Opens 'Insert Hyperlink' dialog using document dispatch provider.
79 * Finds active top window (the dialog
80 * window) and finds button 'Close' (for closing this dialog when
81 * disposing) walking through the accessible component tree.
82 * Then the TREE component is found and the 'New Document' tab is
83 * selected to make list box visible. After that listbox item is obtained.
85 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
87 XInterface oObj
= null;
88 XMultiServiceFactory msf
= (XMultiServiceFactory
) Param
.getMSF();
91 oObj
= (XInterface
) msf
.createInstance("com.sun.star.awt.Toolkit");
92 } catch (com
.sun
.star
.uno
.Exception e
) {
93 log
.println("Couldn't get toolkit");
94 e
.printStackTrace(log
);
95 throw new StatusException("Couldn't get toolkit", e
);
98 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
99 XExtendedToolkit
.class, oObj
);
103 XModel aModel1
= UnoRuntime
.queryInterface(XModel
.class,
106 XController secondController
= aModel1
.getCurrentController();
108 XDispatchProvider aProv
= UnoRuntime
.queryInterface(
109 XDispatchProvider
.class,
112 XURLTransformer urlTransf
= null;
115 XInterface transf
= (XInterface
) msf
.createInstance(
116 "com.sun.star.util.URLTransformer");
117 urlTransf
= UnoRuntime
.queryInterface(
118 XURLTransformer
.class, transf
);
119 } catch (com
.sun
.star
.uno
.Exception e
) {
120 e
.printStackTrace(log
);
121 throw new StatusException("Couldn't create URLTransformer", e
);
124 XDispatch getting
= null;
125 log
.println("opening HyperlinkDialog");
127 URL
[] url
= new URL
[1];
129 url
[0].Complete
= ".uno:HyperlinkDialog";
130 urlTransf
.parseStrict(url
);
131 getting
= aProv
.queryDispatch(url
[0], "", 0);
133 PropertyValue
[] noArgs
= new PropertyValue
[0];
134 getting
.dispatch(url
[0], noArgs
);
138 AccessibilityTools at
= new AccessibilityTools();
140 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
141 tk
.getActiveTopWindow());
143 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
146 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
147 // obtaining 'Close' button
148 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PUSH_BUTTON
,
150 action
= UnoRuntime
.queryInterface(
151 XAccessibleAction
.class, oObj
);
153 // Selecting 'New Document' tab
155 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TREE
);
157 XAccessibleSelection xAccSel
= UnoRuntime
.queryInterface(
158 XAccessibleSelection
.class,
160 xAccSel
.selectAccessibleChild(3);
162 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
163 throw new StatusException("Can't switch to required tab", e
);
166 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.LIST_ITEM
,"Spr");
168 log
.println("ImplementationName " + utils
.getImplName(oObj
));
170 TestEnvironment tEnv
= new TestEnvironment(oObj
);
172 tEnv
.addObjRelation("EditOnly",
173 "This method isn't supported in this component");
175 tEnv
.addObjRelation("LimitedBounds", "yes");
177 final XAccessibleComponent acomp
= UnoRuntime
.queryInterface(
178 XAccessibleComponent
.class,
180 tEnv
.addObjRelation("EventProducer",
181 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
182 public void fireEvent() {
191 * Closes dialog using action of button 'Close'
193 protected void cleanup(TestParameters Param
, PrintWriter log
) {
194 log
.println(" Closing dialog ... ");
197 action
.doAccessibleAction(0);
198 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ioe
) {
199 log
.println("Couldn't close dialog");
200 } catch (com
.sun
.star
.lang
.DisposedException de
) {
201 log
.println("Dialog already disposed");
204 util
.DesktopTools
.closeDoc(xTextDoc
);
208 * Creates writer document
210 protected void initialize(TestParameters Param
, PrintWriter log
) {
212 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
213 (XMultiServiceFactory
) Param
.getMSF());
214 xTextDoc
= SOF
.createTextDoc(null);
215 } catch (com
.sun
.star
.uno
.Exception e
) {
216 throw new StatusException("Can't create document", e
);
221 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
224 private void shortWait() {
227 } catch (InterruptedException e
) {
228 log
.println("While waiting :" + e
);