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
.XAccessibleEditableText
;
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
.beans
.PropertyValue
;
28 import com
.sun
.star
.frame
.XController
;
29 import com
.sun
.star
.frame
.XDispatch
;
30 import com
.sun
.star
.frame
.XDispatchProvider
;
31 import com
.sun
.star
.frame
.XModel
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
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
.SOfficeFactory
;
52 * Test for object which is represented by edit field
53 * of 'Insert Hyperlink' dialog. <p>
55 * Object implements the following interfaces :
57 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
58 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
59 * <li> <code>::com::sun::star::accessibility::XAccessibleEditableText</code></li>
60 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</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.XAccessibleEditableText
68 * @see com.sun.star.accessibility.XAccessibleComponent
69 * @see com.sun.star.accessibility.XAccessibleContext
70 * @see com.sun.star.accessibility.XAccessibleText
71 * @see ifc.accessibility._XAccessibleExtendedComponent
72 * @see ifc.accessibility._XAccessibleEventBroadcaster
73 * @see ifc.accessibility._XAccessibleEditableText
74 * @see ifc.accessibility._XAccessibleComponent
75 * @see ifc.accessibility._XAccessibleContext
76 * @see ifc.accessibility._XAccessibleText
78 public class AccessibleEdit
extends TestCase
{
79 private static XTextDocument xTextDoc
= null;
80 private static XAccessibleAction action
= null;
83 * Opens 'Insert Hyperlink' dialog using document dispatch provider.
84 * Finds active top window (the dialog
85 * window) and finds first accessible edit field and
86 * button 'Close' (for closing this dialog when disposing)
87 * walking through the accessible component tree.
89 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
91 XInterface oObj
= null;
94 oObj
= (XInterface
) ((XMultiServiceFactory
) Param
.getMSF()).createInstance(
95 "com.sun.star.awt.Toolkit");
96 } catch (com
.sun
.star
.uno
.Exception e
) {
97 log
.println("Couldn't get toolkit");
98 e
.printStackTrace(log
);
99 throw new StatusException("Couldn't get toolkit", e
);
102 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
103 XExtendedToolkit
.class, oObj
);
105 XModel aModel1
= UnoRuntime
.queryInterface(XModel
.class,
108 XController secondController
= aModel1
.getCurrentController();
110 XDispatchProvider aProv
= UnoRuntime
.queryInterface(
111 XDispatchProvider
.class,
114 XURLTransformer urlTransf
= null;
117 XInterface transf
= (XInterface
) ((XMultiServiceFactory
) Param
.getMSF()).createInstance(
118 "com.sun.star.util.URLTransformer");
119 urlTransf
= UnoRuntime
.queryInterface(
120 XURLTransformer
.class, transf
);
121 } catch (com
.sun
.star
.uno
.Exception e
) {
122 e
.printStackTrace(log
);
123 throw new StatusException("Couldn't create URLTransformer", e
);
126 XDispatch getting
= null;
127 log
.println("opening HyperlinkDialog");
129 URL
[] url
= new URL
[1];
131 url
[0].Complete
= ".uno:HyperlinkDialog";
132 urlTransf
.parseStrict(url
);
133 getting
= aProv
.queryDispatch(url
[0], "", 0);
135 PropertyValue
[] noArgs
= new PropertyValue
[0];
136 getting
.dispatch(url
[0], noArgs
);
140 AccessibilityTools at
= new AccessibilityTools();
142 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
143 tk
.getActiveTopWindow());
145 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
147 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PUSH_BUTTON
,
149 action
= UnoRuntime
.queryInterface(
150 XAccessibleAction
.class, oObj
);
152 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TEXT
);
154 log
.println("ImplementationName " + utils
.getImplName(oObj
));
156 TestEnvironment tEnv
= new TestEnvironment(oObj
);
158 final XAccessibleEditableText edText
= UnoRuntime
.queryInterface(
159 XAccessibleEditableText
.class,
161 edText
.setText("AccessibleEdit");
163 tEnv
.addObjRelation("EventProducer",
164 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
165 public void fireEvent() {
166 // buttonAccComp.grabFocus();
167 // acomp.grabFocus();
168 edText
.setText("firing event ...");
169 edText
.setText("firing event ... 2");
170 edText
.setText("AccessibleEdit");
174 XAccessibleText text
= UnoRuntime
.queryInterface(
175 XAccessibleText
.class, oObj
);
177 tEnv
.addObjRelation("XAccessibleText.Text", text
.getText());
179 tEnv
.addObjRelation("XAccessibleEditableText.hasAttr", Boolean
.FALSE
);
185 * Closes dialog using action of button 'Close'
187 protected void cleanup(TestParameters Param
, PrintWriter log
) {
188 log
.println(" Closing dialog ... ");
191 action
.doAccessibleAction(0);
192 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ioe
) {
193 log
.println("Couldn't close dialog");
194 } catch (com
.sun
.star
.lang
.DisposedException de
) {
195 log
.println("Dialog already disposed");
198 util
.DesktopTools
.closeDoc(xTextDoc
);
202 * Creates writer document
204 protected void initialize(TestParameters Param
, PrintWriter log
) {
206 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
207 (XMultiServiceFactory
) Param
.getMSF());
208 xTextDoc
= SOF
.createTextDoc(null);
209 } catch (com
.sun
.star
.uno
.Exception e
) {
210 throw new StatusException("Can't create document", e
);
215 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
218 private void shortWait() {
221 } catch (InterruptedException e
) {
222 log
.println("While waiting :" + e
);