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.
92 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
94 XMultiServiceFactory msf
= Param
.getMSF();
95 log
.println("Creating text document");
97 if (xTextDoc
== null) {
99 SOfficeFactory SOF
= SOfficeFactory
.getFactory(msf
);
100 xTextDoc
= SOF
.createTextDoc(null);
101 } catch (com
.sun
.star
.uno
.Exception e
) {
102 throw new StatusException("Can't create document", e
);
106 util
.utils
.pause(Param
.getInt("ShortWait"));
108 XInterface oObj
= null;
110 log
.println("getting toolkit");
113 oObj
= (XInterface
) msf
.createInstance("com.sun.star.awt.Toolkit");
114 } catch (com
.sun
.star
.uno
.Exception e
) {
115 log
.println("Couldn't get toolkit");
116 e
.printStackTrace(log
);
117 throw new StatusException("Couldn't get toolkit", e
);
120 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
121 XExtendedToolkit
.class, oObj
);
123 util
.utils
.pause(Param
.getInt("ShortWait"));
125 log
.println("Opening Dialog in second thread");
127 psDiag
= new DiagThread(xTextDoc
, msf
);
130 util
.utils
.pause(Param
.getInt("ShortWait"));
132 util
.utils
.pause(Param
.getInt("ShortWait"));
134 log
.println("Getting the active TopWindow");
136 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
137 tk
.getActiveTopWindow());
139 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
142 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
143 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PUSH_BUTTON
,
146 action
= UnoRuntime
.queryInterface(
147 XAccessibleAction
.class, oObj
);
149 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.CHECK_BOX
);
151 log
.println("ImplementationName " + utils
.getImplName(oObj
));
153 TestEnvironment tEnv
= new TestEnvironment(oObj
);
155 final XAccessibleComponent acomp
= UnoRuntime
.queryInterface(
156 XAccessibleComponent
.class,
159 tEnv
.addObjRelation("EventProducer",
160 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
161 public void fireEvent() {
162 System
.out
.println("Grabbing focus ... ");
167 XAccessibleText text
= UnoRuntime
.queryInterface(
168 XAccessibleText
.class, oObj
);
170 tEnv
.addObjRelation("XAccessibleText.Text", text
.getText());
172 tEnv
.addObjRelation("EditOnly",
173 "This method isn't supported in this component");
175 tEnv
.addObjRelation("LimitedBounds", "yes");
181 * Closes the dialog using accessible button 'Cancel' found in
182 * <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");
203 protected void initialize(TestParameters Param
, PrintWriter log
) {
207 * Thread for opening modal dialog 'Insert Table'.
209 private class DiagThread
extends Thread
{
210 private XTextDocument xTextDoc
= null;
211 private XMultiServiceFactory msf
= null;
213 private DiagThread(XTextDocument xTextDoc
, XMultiServiceFactory msf
) {
214 this.xTextDoc
= xTextDoc
;
220 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class,
223 XController xController
= aModel
.getCurrentController();
225 //Opening PrinterSetupDialog
227 String aSlotID
= ".uno:InsertTable";
228 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(
229 XDispatchProvider
.class,
231 XURLTransformer xParser
= UnoRuntime
.queryInterface(
232 XURLTransformer
.class,
234 "com.sun.star.util.URLTransformer"));
236 // Because it's an in/out parameter we must use an array of URL objects.
237 URL
[] aParseURL
= new URL
[1];
238 aParseURL
[0] = new URL();
239 aParseURL
[0].Complete
= aSlotID
;
240 xParser
.parseStrict(aParseURL
);
242 URL aURL
= aParseURL
[0];
243 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
245 if (xDispatcher
!= null) {
246 xDispatcher
.dispatch(aURL
, null);
248 } catch (com
.sun
.star
.uno
.Exception e
) {
249 log
.println("Couldn't open dialog");