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
.XAccessibleText
;
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
;
41 import lib
.TestEnvironment
;
42 import lib
.TestParameters
;
44 import util
.AccessibilityTools
;
45 import util
.SOfficeFactory
;
50 * Object implements the following interfaces :
52 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
53 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
54 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
55 * <li> <code>::com::sun::star::accessibility::XAccessibleValue</code></li>
56 * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
58 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
61 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
62 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
63 * @see com.sun.star.accessibility.XAccessibleComponent
64 * @see com.sun.star.accessibility.XAccessibleValue
65 * @see com.sun.star.accessibility.XAccessibleAction
66 * @see com.sun.star.accessibility.XAccessibleContext
67 * @see com.sun.star.accessibility.XAccessibleText
68 * @see ifc.accessibility._XAccessibleExtendedComponent
69 * @see ifc.accessibility._XAccessibleEventBroadcaster
70 * @see ifc.accessibility._XAccessibleComponent
71 * @see ifc.accessibility._XAccessibleValue
72 * @see ifc.accessibility._XAccessibleAction
73 * @see ifc.accessibility._XAccessibleContext
74 * @see ifc.accessibility._XAccessibleText
76 public class AccessibleButton
extends lib
.TestCase
{
77 private static XTextDocument xTextDoc
= null;
78 private static XAccessibleAction action
= null;
81 * Opens 'Printer Settings' dialog using document dispatch provider
82 * running in a separate thread. Finds active top window (the dialog
83 * window) and finds accessible button 'OK' walking through the
84 * accessible component tree.
87 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
89 XInterface oObj
= null;
90 XMultiServiceFactory msf
= Param
.getMSF();
93 oObj
= (XInterface
) msf
.createInstance("com.sun.star.awt.Toolkit");
94 } catch (com
.sun
.star
.uno
.Exception e
) {
95 log
.println("Couldn't get toolkit");
96 e
.printStackTrace(log
);
97 throw new StatusException("Couldn't get toolkit", e
);
100 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
101 XExtendedToolkit
.class, oObj
);
103 util
.utils
.pause(Param
.getInt("ShortWait"));
105 DiagThread psDiag
= new DiagThread(xTextDoc
, msf
);
108 util
.utils
.pause(Param
.getInt("ShortWait"));
110 util
.utils
.pause(Param
.getInt("ShortWait"));
112 Object atw
= tk
.getActiveTopWindow();
114 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
117 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
120 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
121 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PUSH_BUTTON
,
124 log
.println("ImplementationName " + utils
.getImplName(oObj
));
126 TestEnvironment tEnv
= new TestEnvironment(oObj
);
128 action
= UnoRuntime
.queryInterface(
129 XAccessibleAction
.class, oObj
);
131 final XAccessibleComponent acomp
= UnoRuntime
.queryInterface(
132 XAccessibleComponent
.class,
135 tEnv
.addObjRelation("EventProducer",
136 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
137 public void fireEvent() {
138 System
.out
.println("Grabbing focus ... ");
143 XAccessibleText text
= UnoRuntime
.queryInterface(
144 XAccessibleText
.class, oObj
);
146 tEnv
.addObjRelation("XAccessibleText.Text", text
.getText());
148 tEnv
.addObjRelation("EditOnly",
149 "This method isn't supported in this component");
151 tEnv
.addObjRelation("LimitedBounds", "yes");
157 * Closes the dialog using accessible button 'OK' found in
158 * <code>createTestEnvironment()</code>.
161 protected void cleanup(TestParameters Param
, PrintWriter log
) {
162 log
.println(" disposing xTextDoc ");
165 action
.doAccessibleAction(0);
166 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ioe
) {
167 log
.println("Couldn't close dialog");
168 } catch (com
.sun
.star
.lang
.DisposedException de
) {
169 log
.println("Dialog already disposed");
172 util
.DesktopTools
.closeDoc(xTextDoc
);
176 * Opens new writer document.
179 protected void initialize(TestParameters Param
, PrintWriter log
) {
181 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
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 'Print Settings'.
193 private class DiagThread
extends Thread
{
194 private XTextDocument xTextDoc
= null;
195 private XMultiServiceFactory msf
= null;
197 private DiagThread(XTextDocument xTextDoc
, XMultiServiceFactory msf
) {
198 this.xTextDoc
= xTextDoc
;
204 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class,
207 XController xController
= aModel
.getCurrentController();
209 //Opening PrinterSetupDialog
211 String aSlotID
= ".uno:Zoom";
212 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(
213 XDispatchProvider
.class,
215 XURLTransformer xParser
= UnoRuntime
.queryInterface(
216 XURLTransformer
.class,
218 "com.sun.star.util.URLTransformer"));
220 // Because it's an in/out parameter
221 // we must use an array of URL objects.
222 URL
[] aParseURL
= new URL
[1];
223 aParseURL
[0] = new URL();
224 aParseURL
[0].Complete
= aSlotID
;
225 xParser
.parseStrict(aParseURL
);
227 URL aURL
= aParseURL
[0];
228 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
230 if (xDispatcher
!= null) {
231 xDispatcher
.dispatch(aURL
, null);
233 } catch (com
.sun
.star
.uno
.Exception e
) {
234 log
.println("Couldn't open dialog");