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
.XAccessibleContext
;
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
.beans
.PropertyValue
;
28 import com
.sun
.star
.frame
.XController
;
29 import com
.sun
.star
.frame
.XDesktop
;
30 import com
.sun
.star
.frame
.XDispatch
;
31 import com
.sun
.star
.frame
.XDispatchProvider
;
32 import com
.sun
.star
.frame
.XModel
;
33 import com
.sun
.star
.text
.XTextDocument
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
36 import com
.sun
.star
.util
.URL
;
37 import com
.sun
.star
.util
.XURLTransformer
;
39 import java
.io
.PrintWriter
;
41 import lib
.StatusException
;
43 import lib
.TestEnvironment
;
44 import lib
.TestParameters
;
46 import util
.AccessibilityTools
;
47 import util
.DesktopTools
;
48 import util
.SOfficeFactory
;
52 * Test for object that implements the following interfaces :
55 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
57 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
60 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
62 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
65 * ::com::sun::star::accessibility::XAccessibleSelection
69 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
70 * @see com.sun.star.accessibility.XAccessibleContext
71 * @see com.sun.star.accessibility.XAccessibleComponent
72 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
73 * @see com.sun.star.accessibility.XAccessibleSelection
74 * @see ifc.accessibility._XAccessibleEventBroadcaster
75 * @see ifc.accessibility._XAccessibleContext
76 * @see ifc.accessibility._XAccessibleComponent
77 * @see ifc.accessibility._XAccessibleExtendedComponent
78 * @see ifc.accessibility._XAccessibleSelection
80 public class AccessibleTabControl
extends TestCase
{
81 private static XTextDocument xTextDoc
;
82 private static XAccessibleAction accCloseButton
= null;
85 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
88 protected void initialize(TestParameters Param
, PrintWriter log
) {
89 UnoRuntime
.queryInterface(XDesktop
.class,
90 DesktopTools
.createDesktop(
95 * Closes an InsertFields dialog, disposes the document, if exists, created in
96 * <code>createTestEnvironment</code> method.
99 protected void cleanup(TestParameters Param
, PrintWriter log
) {
101 if (accCloseButton
!= null) {
102 log
.println("closing InsertFields Dialog");
103 accCloseButton
.doAccessibleAction(0);
105 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
106 e
.printStackTrace(log
);
109 log
.println("disposing xTextDoc");
111 if (xTextDoc
!= null) {
112 util
.DesktopTools
.closeDoc(xTextDoc
);
117 * Creates a text document, opens an InsertField dialog.
118 * Then obtains an accessible object with
119 * the role <code>AccessibleRole.PAGETABLIST</code>.
120 * Object relations created :
122 * <li> <code>'EventProducer'</code> for
123 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
124 * selects items </li>
125 * <li> <code>'XAccessibleSelection.multiSelection'</code>
126 * of type <code>Boolean</code> for
127 * {@link ifc.accessibility._XAccessibleSelection}:
128 * indicates that component supports single selection mode.</li>
131 * @param tParam test parameters
132 * @param log writer to log information while testing
134 * @see com.sun.star.awt.Toolkit
135 * @see com.sun.star.accessibility.AccessibleRole
136 * @see ifc.accessibility._XAccessibleEventBroadcaster
137 * @see ifc.accessibility._XAccessibleSelection
138 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
139 * @see com.sun.star.accessibility.XAccessibleSelection
142 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
144 log
.println("creating a test environment");
146 if (xTextDoc
!= null) {
147 util
.DesktopTools
.closeDoc(xTextDoc
);
150 // get a soffice factory object
151 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
155 log
.println("creating a text document");
156 xTextDoc
= SOF
.createTextDoc(null);
157 } catch (com
.sun
.star
.uno
.Exception e
) {
158 // Some exception occurs.FAILED
159 e
.printStackTrace(log
);
160 throw new StatusException("Couldn't create document", e
);
163 util
.utils
.pause(500);
165 XModel aModel1
= UnoRuntime
.queryInterface(XModel
.class,
168 XController secondController
= aModel1
.getCurrentController();
170 XDispatchProvider aProv
= UnoRuntime
.queryInterface(
171 XDispatchProvider
.class,
174 XURLTransformer urlTransf
= null;
177 XInterface transf
= (XInterface
) tParam
.getMSF().createInstance(
178 "com.sun.star.util.URLTransformer");
179 urlTransf
= UnoRuntime
.queryInterface(
180 XURLTransformer
.class, transf
);
181 } catch (com
.sun
.star
.uno
.Exception e
) {
182 e
.printStackTrace(log
);
183 throw new StatusException("Couldn't create URLTransformer", e
);
186 XDispatch getting
= null;
187 log
.println("opening InsertField dialog");
189 URL
[] url
= new URL
[1];
191 url
[0].Complete
= ".uno:InsertField";
192 urlTransf
.parseStrict(url
);
193 getting
= aProv
.queryDispatch(url
[0], "", 0);
195 PropertyValue
[] noArgs
= new PropertyValue
[0];
196 getting
.dispatch(url
[0], noArgs
);
198 util
.utils
.pause(500);
200 XInterface oObj
= null;
203 oObj
= (XInterface
) tParam
.getMSF().createInstance(
204 "com.sun.star.awt.Toolkit");
205 } catch (com
.sun
.star
.uno
.Exception e
) {
206 log
.println("Couldn't get toolkit");
207 e
.printStackTrace(log
);
208 throw new StatusException("Couldn't get toolkit", e
);
211 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
212 XExtendedToolkit
.class, oObj
);
214 util
.utils
.pause(500);
216 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
217 tk
.getActiveTopWindow());
219 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
221 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
222 AccessibleRole
.PAGE_TAB_LIST
);
224 XAccessibleContext closeButton
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
225 AccessibleRole
.PUSH_BUTTON
,
228 accCloseButton
= UnoRuntime
.queryInterface(
229 XAccessibleAction
.class, closeButton
);
231 log
.println("ImplementationName: " + util
.utils
.getImplName(oObj
));
233 TestEnvironment tEnv
= new TestEnvironment(oObj
);
235 final XAccessibleSelection selection
= UnoRuntime
.queryInterface(
236 XAccessibleSelection
.class,
239 tEnv
.addObjRelation("EventProducer",
240 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
241 public void fireEvent() {
243 selection
.selectAccessibleChild(1);
244 selection
.selectAccessibleChild(0);
245 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
250 tEnv
.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
253 tEnv
.addObjRelation("XAccessibleSelection.multiSelection",