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
.frame
.XController
;
28 import com
.sun
.star
.frame
.XDispatch
;
29 import com
.sun
.star
.frame
.XDispatchProvider
;
30 import com
.sun
.star
.frame
.XModel
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.text
.XTextDocument
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.uno
.XInterface
;
35 import com
.sun
.star
.util
.URL
;
36 import com
.sun
.star
.util
.XURLTransformer
;
38 import java
.io
.PrintWriter
;
40 import lib
.StatusException
;
42 import lib
.TestEnvironment
;
43 import lib
.TestParameters
;
45 import util
.AccessibilityTools
;
46 import util
.SOfficeFactory
;
51 * Test for object which is represented by accessible component
52 * of the 'Font' combo box in Format->Character... dislog box. <p>
54 * Object implements the following interfaces :
56 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
58 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
59 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
62 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
63 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
64 * @see com.sun.star.accessibility.XAccessibleComponent
65 * @see com.sun.star.accessibility.XAccessibleContext
66 * @see ifc.accessibility._XAccessibleExtendedComponent
67 * @see ifc.accessibility._XAccessibleEventBroadcaster
68 * @see ifc.accessibility._XAccessibleComponent
69 * @see ifc.accessibility._XAccessibleContext
71 public class AccessibleComboBox
extends TestCase
{
72 private static XTextDocument xTextDoc
= null;
73 private static XAccessibleAction action
= null;
76 * Opens CharacterStyle dialog and
77 * finds AccessibleComboBox walking through the
78 * accessible component tree.
80 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
82 XInterface oObj
= null;
85 oObj
= (XInterface
) ((XMultiServiceFactory
) Param
.getMSF()).createInstance(
86 "com.sun.star.awt.Toolkit");
87 } catch (com
.sun
.star
.uno
.Exception e
) {
88 log
.println("Couldn't get toolkit");
89 e
.printStackTrace(log
);
90 throw new StatusException("Couldn't get toolkit", e
);
93 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
94 XExtendedToolkit
.class, oObj
);
96 DiagThread psDiag
= new DiagThread(xTextDoc
,
97 (XMultiServiceFactory
) Param
.getMSF());
100 util
.utils
.shortWait(Param
.getInt("ShortWait"));
102 AccessibilityTools at
= new AccessibilityTools();
104 util
.utils
.shortWait(Param
.getInt("ShortWait"));
106 Object atw
= tk
.getActiveTopWindow();
108 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
111 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
113 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PUSH_BUTTON
,
115 action
= UnoRuntime
.queryInterface(
116 XAccessibleAction
.class, oObj
);
118 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
119 AccessibleRole
.PAGE_TAB_LIST
);
121 XAccessibleSelection xAccSel
= UnoRuntime
.queryInterface(
122 XAccessibleSelection
.class,
126 xAccSel
.selectAccessibleChild(0);
127 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
128 e
.printStackTrace(log
);
130 util
.utils
.shortWait(Param
.getInt("ShortWait"));
132 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
133 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PANEL
, "",
134 "AccessibleComboBox");
136 log
.println("ImplementationName " + utils
.getImplName(oObj
));
138 TestEnvironment tEnv
= new TestEnvironment(oObj
);
140 final XAccessibleComponent acomp
= UnoRuntime
.queryInterface(
141 XAccessibleComponent
.class,
143 final XAccessibleComponent acomp1
= UnoRuntime
.queryInterface(
144 XAccessibleComponent
.class,
147 tEnv
.addObjRelation("EventProducer",
148 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
149 public void fireEvent() {
159 * Closes the dialog using accessible button 'Cancel' found in
160 * <code>createTestEnvironment()</code>.
162 protected void cleanup(TestParameters Param
, PrintWriter log
) {
163 log
.println(" closing dialog ");
166 action
.doAccessibleAction(0);
167 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ioe
) {
168 log
.println("Couldn't close dialog");
169 } catch (com
.sun
.star
.lang
.DisposedException de
) {
170 log
.println("Dialog already disposed");
173 util
.DesktopTools
.closeDoc(xTextDoc
);
179 protected void initialize(TestParameters Param
, PrintWriter log
) {
181 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
182 (XMultiServiceFactory
) Param
.getMSF());
183 xTextDoc
= SOF
.createTextDoc(null);
184 } catch (com
.sun
.star
.uno
.Exception e
) {
185 throw new StatusException("Can't create document", e
);
191 * Thread for opening modal dialog 'Character style'.
193 public class DiagThread
extends Thread
{
194 public XTextDocument xTextDoc
= null;
195 public XMultiServiceFactory msf
= null;
197 public DiagThread(XTextDocument xTextDoc
, XMultiServiceFactory msf
) {
198 this.xTextDoc
= xTextDoc
;
203 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class,
206 XController xController
= aModel
.getCurrentController();
208 //Opening PrinterSetupDialog
210 String aSlotID
= ".uno:FontDialog";
211 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(
212 XDispatchProvider
.class,
214 XURLTransformer xParser
= UnoRuntime
.queryInterface(
215 XURLTransformer
.class,
217 "com.sun.star.util.URLTransformer"));
219 // Because it's an in/out parameter we must use an array of URL objects.
220 URL
[] aParseURL
= new URL
[1];
221 aParseURL
[0] = new URL();
222 aParseURL
[0].Complete
= aSlotID
;
223 xParser
.parseStrict(aParseURL
);
225 URL aURL
= aParseURL
[0];
226 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
228 if (xDispatcher
!= null) {
229 xDispatcher
.dispatch(aURL
, null);
231 } catch (com
.sun
.star
.uno
.Exception e
) {
232 log
.println("Couldn't open dialog");