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
.XAccessibleContext
;
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
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.text
.XTextDocument
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XInterface
;
37 import com
.sun
.star
.util
.URL
;
38 import com
.sun
.star
.util
.XURLTransformer
;
41 import java
.io
.PrintWriter
;
43 import lib
.StatusException
;
45 import lib
.TestEnvironment
;
46 import lib
.TestParameters
;
48 import util
.AccessibilityTools
;
49 import util
.DesktopTools
;
50 import util
.SOfficeFactory
;
54 * Test for object that implements the following interfaces :
57 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
59 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
62 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
64 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
68 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
69 * @see com.sun.star.accessibility.XAccessibleContext
70 * @see com.sun.star.accessibility.XAccessibleComponent
71 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
72 * @see ifc.accessibility._XAccessibleEventBroadcaster
73 * @see ifc.accessibility._XAccessibleContext
74 * @see ifc.accessibility._XAccessibleComponent
75 * @see ifc.accessibility._XAccessibleExtendedComponent
77 public class AccessibleTabPage
extends TestCase
{
78 private static XTextDocument xTextDoc
;
79 private static XAccessibleAction accCloseButton
= null;
82 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
84 protected void initialize(TestParameters Param
, PrintWriter log
) {
85 UnoRuntime
.queryInterface(XDesktop
.class,
86 DesktopTools
.createDesktop(
87 (XMultiServiceFactory
) Param
.getMSF()));
91 * Closes an InsertFields dialog, disposes the document, if exists, created in
92 * <code>createTestEnvironment</code> method.
94 protected void cleanup(TestParameters Param
, PrintWriter log
) {
96 if (accCloseButton
!= null) {
97 log
.println("closing InsertFields Dialog");
98 accCloseButton
.doAccessibleAction(0);
101 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
102 e
.printStackTrace(log
);
103 } catch (com
.sun
.star
.lang
.DisposedException e
) {
104 log
.println("Couldn't close dialog " + e
.getMessage());
107 log
.println("disposing xTextDoc");
109 if (xTextDoc
!= null) {
115 * Creates a text document, opens an InsertField dialog.
116 * Then obtains an accessible object with
117 * the role <code>AccessibleRole.PAGETAB</code>.
118 * Object relations created :
120 * <li> <code>'EventProducer'</code> for
121 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
125 * @param tParam test parameters
126 * @param log writer to log information while testing
128 * @see com.sun.star.awt.Toolkit
129 * @see com.sun.star.accessibility.AccessibleRole
130 * @see ifc.accessibility._XAccessibleEventBroadcaster
131 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
133 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
135 log
.println("creating a test environment");
138 if (accCloseButton
!= null) {
139 log
.println("closing InsertFields Dialog");
140 accCloseButton
.doAccessibleAction(0);
143 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
144 e
.printStackTrace(log
);
145 } catch (com
.sun
.star
.lang
.DisposedException e
) {
146 log
.println("Couldn't close dialog " + e
.getMessage());
149 log
.println("disposing xTextDoc");
151 if (xTextDoc
!= null) {
155 // get a soffice factory object
156 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
157 (XMultiServiceFactory
) tParam
.getMSF());
160 log
.println("creating a text document");
161 xTextDoc
= SOF
.createTextDoc(null);
162 } catch (com
.sun
.star
.uno
.Exception e
) {
163 // Some exception occurs.FAILED
164 e
.printStackTrace(log
);
165 throw new StatusException("Couldn't create document", e
);
170 XModel aModel1
= UnoRuntime
.queryInterface(XModel
.class,
173 XController secondController
= aModel1
.getCurrentController();
175 XDispatchProvider aProv
= UnoRuntime
.queryInterface(
176 XDispatchProvider
.class,
179 XURLTransformer urlTransf
= null;
182 XInterface transf
= (XInterface
) ((XMultiServiceFactory
) tParam
.getMSF()).createInstance(
183 "com.sun.star.util.URLTransformer");
184 urlTransf
= UnoRuntime
.queryInterface(
185 XURLTransformer
.class, transf
);
186 } catch (com
.sun
.star
.uno
.Exception e
) {
187 e
.printStackTrace(log
);
188 throw new StatusException("Couldn't create URLTransformer", e
);
191 XDispatch getting
= null;
192 log
.println("opening InsertField dialog");
194 URL
[] url
= new URL
[1];
196 url
[0].Complete
= ".uno:InsertField";
197 urlTransf
.parseStrict(url
);
198 getting
= aProv
.queryDispatch(url
[0], "", 0);
200 PropertyValue
[] noArgs
= new PropertyValue
[0];
201 getting
.dispatch(url
[0], noArgs
);
205 XInterface oObj
= null;
208 oObj
= (XInterface
) ((XMultiServiceFactory
) tParam
.getMSF()).createInstance(
209 "com.sun.star.awt.Toolkit");
210 } catch (com
.sun
.star
.uno
.Exception e
) {
211 log
.println("Couldn't get toolkit");
212 e
.printStackTrace(log
);
213 throw new StatusException("Couldn't get toolkit", e
);
216 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
217 XExtendedToolkit
.class, oObj
);
219 AccessibilityTools at
= new AccessibilityTools();
223 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
224 tk
.getActiveTopWindow());
226 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
228 XAccessibleContext closeButton
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
229 AccessibleRole
.PUSH_BUTTON
,
232 accCloseButton
= UnoRuntime
.queryInterface(
233 XAccessibleAction
.class, closeButton
);
235 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PAGE_TAB
);
237 log
.println("ImplementationName: " + util
.utils
.getImplName(oObj
));
239 TestEnvironment tEnv
= new TestEnvironment(oObj
);
241 tEnv
.addObjRelation("EditOnly", "toolkit.AccessibleTabPage");
242 tEnv
.addObjRelation("LimitedBounds", "toolkit.AccessibleTabPage");
244 XAccessibleComponent accComp
= UnoRuntime
.queryInterface(
245 XAccessibleComponent
.class,
247 accComp
.getLocationOnScreen();
251 XInterface xEventInt
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PAGE_TAB
, "Variables");
252 final XAccessibleComponent eventAccComp
= UnoRuntime
.queryInterface(
253 XAccessibleComponent
.class,
256 tEnv
.addObjRelation("EventProducer",
257 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
258 public void fireEvent() {
259 eventAccComp
.grabFocus();
267 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
270 private void shortWait() {
273 } catch (InterruptedException e
) {
274 System
.out
.println("While waiting :" + e
);
278 protected void closeDoc() {
279 util
.DesktopTools
.closeDoc(xTextDoc
);