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 java
.io
.PrintWriter
;
23 import lib
.TestEnvironment
;
24 import lib
.TestParameters
;
25 import util
.AccessibilityTools
;
26 import util
.DesktopTools
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.accessibility
.AccessibleRole
;
30 import com
.sun
.star
.accessibility
.XAccessible
;
31 import com
.sun
.star
.accessibility
.XAccessibleAction
;
32 import com
.sun
.star
.accessibility
.XAccessibleContext
;
33 import com
.sun
.star
.accessibility
.XAccessibleSelection
;
34 import com
.sun
.star
.awt
.XExtendedToolkit
;
35 import com
.sun
.star
.awt
.XWindow
;
36 import com
.sun
.star
.beans
.PropertyValue
;
37 import com
.sun
.star
.frame
.XController
;
38 import com
.sun
.star
.frame
.XDesktop
;
39 import com
.sun
.star
.frame
.XDispatch
;
40 import com
.sun
.star
.frame
.XDispatchProvider
;
41 import com
.sun
.star
.frame
.XModel
;
42 import com
.sun
.star
.text
.XTextDocument
;
43 import com
.sun
.star
.uno
.UnoRuntime
;
44 import com
.sun
.star
.uno
.XInterface
;
45 import com
.sun
.star
.util
.URL
;
46 import com
.sun
.star
.util
.XURLTransformer
;
50 * Test for object that implements the following interfaces :
53 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
55 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
58 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
60 * ::com::sun::star::accessibility::XAccessibleSelection</code></li>
63 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
64 * @see com.sun.star.accessibility.XAccessibleContext
65 * @see com.sun.star.accessibility.XAccessibleComponent
66 * @see com.sun.star.accessibility.XAccessibleSelection
67 * @see ifc.accessibility._XAccessibleEventBroadcaster
68 * @see ifc.accessibility._XAccessibleContext
69 * @see ifc.accessibility._XAccessibleComponent
70 * @see ifc.accessibility._XAccessibleSelection
72 public class AccessibleIconChoiceCtrl
extends TestCase
{
73 static XDesktop xDesktop
;
74 static XTextDocument xTextDoc
;
75 static XAccessibleAction accCloseButton
= null;
78 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
81 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
82 xDesktop
= DesktopTools
.createDesktop(Param
.getMSF());
86 * Closes the Hyperlink dialog.
87 * Disposes the document, if exists, created in
88 * <code>createTestEnvironment</code> method.
91 protected void cleanup(TestParameters Param
, PrintWriter log
) {
92 log
.println("closing HyperlinkDialog");
95 if (accCloseButton
!= null) {
96 accCloseButton
.doAccessibleAction(0);
98 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
99 e
.printStackTrace(log
);
102 log
.println("disposing xTextDoc");
104 if (xTextDoc
!= null) {
110 * Creates a text document. Opens the Hyperlink dialog.
111 * Creates an instance of the service
112 * <code>com.sun.star.awt.Toolkit</code> and gets active top window.
113 * Then obtains an accessible object with the role
114 * <code>AccessibleRole.TREE</code>.
115 * Object relations created :
117 * <li> <code>'EventProducer'</code> for
118 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
119 * method <code>fireEvent()</code> selects accessible children
123 * @param tParam test parameters
124 * @param log writer to log information while testing
126 * @see com.sun.star.awt.Toolkit
127 * @see com.sun.star.accessibility.AccessibleRole
128 * @see ifc.accessibility._XAccessibleEventBroadcaster
129 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
132 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
133 PrintWriter log
) throws Exception
{
134 log
.println("creating a test environment");
136 if (xTextDoc
!= null) {
140 // get a soffice factory object
141 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
143 log
.println("creating a text document");
144 xTextDoc
= SOF
.createTextDoc(null);
146 util
.utils
.waitForEventIdle(tParam
.getMSF());
148 XModel aModel1
= UnoRuntime
.queryInterface(XModel
.class,
151 XController secondController
= aModel1
.getCurrentController();
153 XDispatchProvider aProv
= UnoRuntime
.queryInterface(
154 XDispatchProvider
.class,
157 XURLTransformer urlTransf
= null;
159 XInterface transf
= (XInterface
) tParam
.getMSF()
160 .createInstance("com.sun.star.util.URLTransformer");
161 urlTransf
= UnoRuntime
.queryInterface(
162 XURLTransformer
.class, transf
);
164 XDispatch getting
= null;
165 log
.println("opening HyperlinkDialog");
167 URL
[] url
= new URL
[1];
169 url
[0].Complete
= ".uno:HyperlinkDialog";
170 urlTransf
.parseStrict(url
);
171 getting
= aProv
.queryDispatch(url
[0], "", 0);
173 PropertyValue
[] noArgs
= new PropertyValue
[0];
174 getting
.dispatch(url
[0], noArgs
);
176 util
.utils
.waitForEventIdle(tParam
.getMSF());
178 XInterface oObj
= (XInterface
) tParam
.getMSF()
179 .createInstance("com.sun.star.awt.Toolkit");
181 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
182 XExtendedToolkit
.class, oObj
);
184 util
.utils
.waitForEventIdle(tParam
.getMSF());
186 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
187 tk
.getActiveTopWindow());
189 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
191 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TREE
);
193 XAccessibleContext closeButton
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
194 AccessibleRole
.PUSH_BUTTON
,
197 accCloseButton
= UnoRuntime
.queryInterface(
198 XAccessibleAction
.class, closeButton
);
200 log
.println("ImplementationName: " + util
.utils
.getImplName(oObj
));
202 TestEnvironment tEnv
= new TestEnvironment(oObj
);
203 tEnv
.addObjRelation("XAccessibleSelection.multiSelection",
205 tEnv
.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
208 String
[] expectedStateNames
= new String
[] {
209 "com.sun.star.accessibility.AccessibleStateType.ENABLED",
210 "com.sun.star.accessibility.AccessibleStateType.FOCUSABLE",
211 "com.sun.star.accessibility.AccessibleStateType.SHOWING",
212 "com.sun.star.accessibility.AccessibleStateType.VISIBLE",
213 "com.sun.star.accessibility.AccessibleStateType.MANAGES_DESCENDANTS",
216 long[] expectedStates
= new long[] {
217 com
.sun
.star
.accessibility
.AccessibleStateType
.ENABLED
,
218 com
.sun
.star
.accessibility
.AccessibleStateType
.FOCUSABLE
,
219 com
.sun
.star
.accessibility
.AccessibleStateType
.SHOWING
,
220 com
.sun
.star
.accessibility
.AccessibleStateType
.VISIBLE
,
221 com
.sun
.star
.accessibility
.AccessibleStateType
.MANAGES_DESCENDANTS
,
224 tEnv
.addObjRelation("expectedStateNames", expectedStateNames
);
225 tEnv
.addObjRelation("expectedStates", expectedStates
);
227 final XAccessibleSelection selection
= UnoRuntime
.queryInterface(
228 XAccessibleSelection
.class,
231 tEnv
.addObjRelation("EventProducer",
232 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
233 public void fireEvent() {
235 selection
.selectAccessibleChild(1);
236 selection
.selectAccessibleChild(0);
237 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {