1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleTabPage.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.accessibility
.AccessibleRole
;
33 import com
.sun
.star
.accessibility
.XAccessible
;
34 import com
.sun
.star
.accessibility
.XAccessibleAction
;
35 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
36 import com
.sun
.star
.accessibility
.XAccessibleContext
;
37 import com
.sun
.star
.awt
.Point
;
38 import com
.sun
.star
.awt
.XExtendedToolkit
;
39 import com
.sun
.star
.awt
.XWindow
;
40 import com
.sun
.star
.beans
.PropertyValue
;
41 import com
.sun
.star
.frame
.XController
;
42 import com
.sun
.star
.frame
.XDesktop
;
43 import com
.sun
.star
.frame
.XDispatch
;
44 import com
.sun
.star
.frame
.XDispatchProvider
;
45 import com
.sun
.star
.frame
.XModel
;
46 import com
.sun
.star
.lang
.XMultiServiceFactory
;
47 import com
.sun
.star
.text
.XTextDocument
;
48 import com
.sun
.star
.uno
.UnoRuntime
;
49 import com
.sun
.star
.uno
.XInterface
;
50 import com
.sun
.star
.util
.URL
;
51 import com
.sun
.star
.util
.XURLTransformer
;
54 import java
.io
.PrintWriter
;
56 import lib
.StatusException
;
58 import lib
.TestEnvironment
;
59 import lib
.TestParameters
;
61 import util
.AccessibilityTools
;
62 import util
.DesktopTools
;
63 import util
.SOfficeFactory
;
67 * Test for object that implements the following interfaces :
70 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
72 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
75 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
77 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
81 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
82 * @see com.sun.star.accessibility.XAccessibleContext
83 * @see com.sun.star.accessibility.XAccessibleComponent
84 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
85 * @see ifc.accessibility._XAccessibleEventBroadcaster
86 * @see ifc.accessibility._XAccessibleContext
87 * @see ifc.accessibility._XAccessibleComponent
88 * @see ifc.accessibility.XAccessibleExtendedComponent
90 public class AccessibleTabPage
extends TestCase
{
91 private static XDesktop the_Desk
;
92 private static XTextDocument xTextDoc
;
93 private static XAccessibleAction accCloseButton
= null;
96 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
98 protected void initialize(TestParameters Param
, PrintWriter log
) {
99 the_Desk
= (XDesktop
) UnoRuntime
.queryInterface(XDesktop
.class,
100 DesktopTools
.createDesktop(
101 (XMultiServiceFactory
) Param
.getMSF()));
105 * Closes an InsertFields dialog, disposes the document, if exists, created in
106 * <code>createTestEnvironment</code> method.
108 protected void cleanup(TestParameters Param
, PrintWriter log
) {
110 if (accCloseButton
!= null) {
111 log
.println("closing InsertFields Dialog");
112 accCloseButton
.doAccessibleAction(0);
115 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
116 e
.printStackTrace(log
);
117 } catch (com
.sun
.star
.lang
.DisposedException e
) {
118 log
.println("Couldn't close dialog " + e
.getMessage());
121 log
.println("disposing xTextDoc");
123 if (xTextDoc
!= null) {
129 * Creates a text document, opens an InsertField dialog.
130 * Then obtains an accessible object with
131 * the role <code>AccessibleRole.PAGETAB</code>.
132 * Object relations created :
134 * <li> <code>'EventProducer'</code> for
135 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
139 * @param tParam test parameters
140 * @param log writer to log information while testing
142 * @see com.sun.star.awt.Toolkit
143 * @see com.sun.star.accessibility.AccessibleRole
144 * @see ifc.accessibility._XAccessibleEventBroadcaster
145 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
147 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
149 log
.println("creating a test environment");
152 if (accCloseButton
!= null) {
153 log
.println("closing InsertFields Dialog");
154 accCloseButton
.doAccessibleAction(0);
157 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
158 e
.printStackTrace(log
);
159 } catch (com
.sun
.star
.lang
.DisposedException e
) {
160 log
.println("Couldn't close dialog " + e
.getMessage());
163 log
.println("disposing xTextDoc");
165 if (xTextDoc
!= null) {
169 // get a soffice factory object
170 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
171 (XMultiServiceFactory
) tParam
.getMSF());
174 log
.println("creating a text document");
175 xTextDoc
= SOF
.createTextDoc(null);
176 } catch (com
.sun
.star
.uno
.Exception e
) {
177 // Some exception occures.FAILED
178 e
.printStackTrace(log
);
179 throw new StatusException("Couldn't create document", e
);
184 XModel aModel1
= (XModel
) UnoRuntime
.queryInterface(XModel
.class,
187 XController secondController
= aModel1
.getCurrentController();
189 XDispatchProvider aProv
= (XDispatchProvider
) UnoRuntime
.queryInterface(
190 XDispatchProvider
.class,
193 XURLTransformer urlTransf
= null;
196 XInterface transf
= (XInterface
) ((XMultiServiceFactory
) tParam
.getMSF()).createInstance(
197 "com.sun.star.util.URLTransformer");
198 urlTransf
= (XURLTransformer
) UnoRuntime
.queryInterface(
199 XURLTransformer
.class, transf
);
200 } catch (com
.sun
.star
.uno
.Exception e
) {
201 e
.printStackTrace(log
);
202 throw new StatusException("Couldn't create URLTransformer", e
);
205 XDispatch getting
= null;
206 log
.println("opening InsertField dialog");
208 URL
[] url
= new URL
[1];
210 url
[0].Complete
= ".uno:InsertField";
211 urlTransf
.parseStrict(url
);
212 getting
= aProv
.queryDispatch(url
[0], "", 0);
214 PropertyValue
[] noArgs
= new PropertyValue
[0];
215 getting
.dispatch(url
[0], noArgs
);
219 XInterface oObj
= null;
222 oObj
= (XInterface
) ((XMultiServiceFactory
) tParam
.getMSF()).createInstance(
223 "com.sun.star.awt.Toolkit");
224 } catch (com
.sun
.star
.uno
.Exception e
) {
225 log
.println("Couldn't get toolkit");
226 e
.printStackTrace(log
);
227 throw new StatusException("Couldn't get toolkit", e
);
230 XExtendedToolkit tk
= (XExtendedToolkit
) UnoRuntime
.queryInterface(
231 XExtendedToolkit
.class, oObj
);
233 AccessibilityTools at
= new AccessibilityTools();
237 XWindow xWindow
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class,
238 tk
.getActiveTopWindow());
240 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
242 XAccessibleContext closeButton
= at
.getAccessibleObjectForRole(xRoot
,
243 AccessibleRole
.PUSH_BUTTON
,
246 accCloseButton
= (XAccessibleAction
) UnoRuntime
.queryInterface(
247 XAccessibleAction
.class, closeButton
);
249 oObj
= at
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PAGE_TAB
);
251 log
.println("ImplementationName: " + util
.utils
.getImplName(oObj
));
253 TestEnvironment tEnv
= new TestEnvironment(oObj
);
255 tEnv
.addObjRelation("EditOnly", "toolkit.AccessibleTabPage");
256 tEnv
.addObjRelation("LimitedBounds", "toolkit.AccessibleTabPage");
258 XAccessibleComponent accComp
= (XAccessibleComponent
) UnoRuntime
.queryInterface(
259 XAccessibleComponent
.class,
261 final Point point
= accComp
.getLocationOnScreen();
265 XInterface xEventInt
= at
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PAGE_TAB
, "Variables");
266 final XAccessibleComponent eventAccComp
= (XAccessibleComponent
) UnoRuntime
.queryInterface(
267 XAccessibleComponent
.class,
270 tEnv
.addObjRelation("EventProducer",
271 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
272 public void fireEvent() {
273 eventAccComp
.grabFocus();
281 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
284 private void shortWait() {
286 Thread
.currentThread().sleep(1000);
287 } catch (InterruptedException e
) {
288 System
.out
.println("While waiting :" + e
);
292 protected void closeDoc() {
293 util
.DesktopTools
.closeDoc(xTextDoc
);