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
;
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 compoent of
52 * check box in 'InsertTable' dialog. <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::XAccessibleValue</code></li>
60 * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li>
61 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
62 * <li> <code>::com::sun::star::accessibility::XAccessibleText</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.XAccessibleValue
69 * @see com.sun.star.accessibility.XAccessibleAction
70 * @see com.sun.star.accessibility.XAccessibleContext
71 * @see com.sun.star.accessibility.XAccessibleText
72 * @see ifc.accessibility._XAccessibleExtendedComponent
73 * @see ifc.accessibility._XAccessibleEventBroadcaster
74 * @see ifc.accessibility._XAccessibleComponent
75 * @see ifc.accessibility._XAccessibleValue
76 * @see ifc.accessibility._XAccessibleAction
77 * @see ifc.accessibility._XAccessibleContext
78 * @see ifc.accessibility._XAccessibleText
80 public class AccessibleCheckBox
extends TestCase
{
81 private static XTextDocument xTextDoc
= null;
82 private static XAccessibleAction action
= null;
83 private static DiagThread psDiag
= null;
86 * Opens 'Insert Table' dialog using document dispatch provider
87 * running in a separate thread. Finds active top window (the dialog
88 * window) and finds first accessible check box walking through the
89 * accessible component tree.
91 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
93 XMultiServiceFactory msf
= (XMultiServiceFactory
) Param
.getMSF();
94 log
.println("Creating text document");
96 if (xTextDoc
== null) {
98 SOfficeFactory SOF
= SOfficeFactory
.getFactory(msf
);
99 xTextDoc
= SOF
.createTextDoc(null);
100 } catch (com
.sun
.star
.uno
.Exception e
) {
101 throw new StatusException("Can't create document", e
);
105 util
.utils
.shortWait(Param
.getInt("ShortWait"));
107 XInterface oObj
= null;
109 log
.println("getting toolkit");
112 oObj
= (XInterface
) msf
.createInstance("com.sun.star.awt.Toolkit");
113 } catch (com
.sun
.star
.uno
.Exception e
) {
114 log
.println("Couldn't get toolkit");
115 e
.printStackTrace(log
);
116 throw new StatusException("Couldn't get toolkit", e
);
119 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
120 XExtendedToolkit
.class, oObj
);
122 util
.utils
.shortWait(Param
.getInt("ShortWait"));
124 log
.println("Opening Dialog in second thread");
126 psDiag
= new DiagThread(xTextDoc
, msf
);
129 util
.utils
.shortWait(Param
.getInt("ShortWait"));
131 AccessibilityTools at
= new AccessibilityTools();
133 util
.utils
.shortWait(Param
.getInt("ShortWait"));
135 log
.println("Getting the active TopWindow");
137 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
138 tk
.getActiveTopWindow());
140 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
143 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
144 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PUSH_BUTTON
,
147 action
= UnoRuntime
.queryInterface(
148 XAccessibleAction
.class, oObj
);
150 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.CHECK_BOX
);
152 log
.println("ImplementationName " + utils
.getImplName(oObj
));
154 TestEnvironment tEnv
= new TestEnvironment(oObj
);
156 final XAccessibleComponent acomp
= UnoRuntime
.queryInterface(
157 XAccessibleComponent
.class,
160 tEnv
.addObjRelation("EventProducer",
161 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
162 public void fireEvent() {
163 System
.out
.println("Grabbing focus ... ");
168 XAccessibleText text
= UnoRuntime
.queryInterface(
169 XAccessibleText
.class, oObj
);
171 tEnv
.addObjRelation("XAccessibleText.Text", text
.getText());
173 tEnv
.addObjRelation("EditOnly",
174 "This method isn't supported in this component");
176 tEnv
.addObjRelation("LimitedBounds", "yes");
182 * Closes the dialog using accessible button 'Cancel' found in
183 * <code>createTestEnvironment()</code>.
185 protected void cleanup(TestParameters Param
, PrintWriter log
) {
187 log
.println("closing dialog");
188 action
.doAccessibleAction(0);
189 log
.println("interrupting corresponding Thread");
191 log
.println("closing the document");
192 util
.DesktopTools
.closeDoc(xTextDoc
);
193 log
.println("reinitialize the variable");
195 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ioe
) {
196 log
.println("Couldn't close dialog");
197 } catch (com
.sun
.star
.lang
.DisposedException de
) {
198 log
.println("Dialog already disposed");
202 protected void initialize(TestParameters Param
, PrintWriter log
) {
206 * Thread for opening modal dialog 'Insert Table'.
208 public class DiagThread
extends Thread
{
209 public XTextDocument xTextDoc
= null;
210 public XMultiServiceFactory msf
= null;
212 public DiagThread(XTextDocument xTextDoc
, XMultiServiceFactory msf
) {
213 this.xTextDoc
= xTextDoc
;
218 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class,
221 XController xController
= aModel
.getCurrentController();
223 //Opening PrinterSetupDialog
225 String aSlotID
= ".uno:InsertTable";
226 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(
227 XDispatchProvider
.class,
229 XURLTransformer xParser
= UnoRuntime
.queryInterface(
230 XURLTransformer
.class,
232 "com.sun.star.util.URLTransformer"));
234 // Because it's an in/out parameter we must use an array of URL objects.
235 URL
[] aParseURL
= new URL
[1];
236 aParseURL
[0] = new URL();
237 aParseURL
[0].Complete
= aSlotID
;
238 xParser
.parseStrict(aParseURL
);
240 URL aURL
= aParseURL
[0];
241 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
243 if (xDispatcher
!= null) {
244 xDispatcher
.dispatch(aURL
, null);
246 } catch (com
.sun
.star
.uno
.Exception e
) {
247 log
.println("Couldn't open dialog");