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
;
41 import lib
.TestEnvironment
;
42 import lib
.TestParameters
;
43 import util
.AccessibilityTools
;
44 import util
.SOfficeFactory
;
48 * Test for object which is represented by accessible component of check box in
49 * 'InsertTable' dialog.
52 * Object implements the following interfaces :
55 * <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
57 * <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>
66 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
67 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
68 * @see com.sun.star.accessibility.XAccessibleComponent
69 * @see com.sun.star.accessibility.XAccessibleValue
70 * @see com.sun.star.accessibility.XAccessibleAction
71 * @see com.sun.star.accessibility.XAccessibleContext
72 * @see com.sun.star.accessibility.XAccessibleText
73 * @see ifc.accessibility._XAccessibleExtendedComponent
74 * @see ifc.accessibility._XAccessibleEventBroadcaster
75 * @see ifc.accessibility._XAccessibleComponent
76 * @see ifc.accessibility._XAccessibleValue
77 * @see ifc.accessibility._XAccessibleAction
78 * @see ifc.accessibility._XAccessibleContext
79 * @see ifc.accessibility._XAccessibleText
81 public class AccessibleCheckBox
extends TestCase
{
82 private static XTextDocument xTextDoc
= null;
83 private static XAccessibleAction action
= null;
86 * Opens 'Insert Table' dialog using document dispatch provider running in a
87 * separate thread. Finds active top window (the dialog window) and finds
88 * first accessible check box walking through the accessible component tree.
91 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
92 PrintWriter log
) throws Exception
{
93 XMultiServiceFactory msf
= Param
.getMSF();
94 log
.println("Creating text document");
96 if (xTextDoc
== null) {
97 SOfficeFactory SOF
= SOfficeFactory
.getFactory(msf
);
98 xTextDoc
= SOF
.createTextDoc(null);
101 util
.utils
.waitForEventIdle(Param
.getMSF());
103 XInterface oObj
= null;
105 log
.println("getting toolkit");
107 oObj
= (XInterface
) msf
.createInstance("com.sun.star.awt.Toolkit");
109 XExtendedToolkit tk
= UnoRuntime
.queryInterface(XExtendedToolkit
.class,
112 util
.utils
.waitForEventIdle(Param
.getMSF());
114 log
.println("Opening Dialog in second thread");
116 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
118 XController xController
= aModel
.getCurrentController();
120 // Opening PrinterSetupDialog
121 String aSlotID
= ".uno:InsertTable";
122 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(
123 XDispatchProvider
.class, xController
);
124 XURLTransformer xParser
= UnoRuntime
.queryInterface(
125 XURLTransformer
.class,
126 msf
.createInstance("com.sun.star.util.URLTransformer"));
128 // Because it's an in/out parameter we must use an array of URL
130 URL
[] aParseURL
= new URL
[] { new URL() };
131 aParseURL
[0].Complete
= aSlotID
;
132 xParser
.parseStrict(aParseURL
);
134 XDispatch xDispatcher
= xDispProv
.queryDispatch(aParseURL
[0], "", 0);
135 if (xDispatcher
!= null) {
136 xDispatcher
.dispatch(aParseURL
[0], null);
139 util
.utils
.waitForEventIdle(msf
);
141 log
.println("Getting the active TopWindow");
143 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
144 tk
.getActiveTopWindow());
146 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
148 AccessibilityTools
.printAccessibleTree(log
, xRoot
,
149 Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
150 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
151 AccessibleRole
.PUSH_BUTTON
, "Cancel");
153 action
= UnoRuntime
.queryInterface(XAccessibleAction
.class, oObj
);
155 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
156 AccessibleRole
.CHECK_BOX
);
158 log
.println("ImplementationName " + utils
.getImplName(oObj
));
160 TestEnvironment tEnv
= new TestEnvironment(oObj
);
162 final XAccessibleComponent acomp
= UnoRuntime
.queryInterface(
163 XAccessibleComponent
.class, oObj
);
167 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
168 public void fireEvent() {
169 System
.out
.println("Grabbing focus ... ");
174 XAccessibleText text
= UnoRuntime
.queryInterface(XAccessibleText
.class,
177 tEnv
.addObjRelation("XAccessibleText.Text", text
.getText());
179 tEnv
.addObjRelation("EditOnly",
180 "This method isn't supported in this component");
182 tEnv
.addObjRelation("LimitedBounds", "yes");
188 * Closes the dialog using accessible button 'Cancel' found in
189 * <code>createTestEnvironment()</code>.
192 protected void cleanup(TestParameters Param
, PrintWriter log
) {
194 log
.println("closing dialog");
195 action
.doAccessibleAction(0);
196 log
.println("closing the document");
197 util
.DesktopTools
.closeDoc(xTextDoc
);
198 log
.println("reinitialize the variable");
200 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ioe
) {
201 log
.println("Couldn't close dialog");
202 } catch (com
.sun
.star
.lang
.DisposedException de
) {
203 log
.println("Dialog already disposed");