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
.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
;
40 import lib
.StatusException
;
42 import lib
.TestEnvironment
;
43 import lib
.TestParameters
;
45 import util
.AccessibilityTools
;
46 import util
.SOfficeFactory
;
51 * Test for object which is represented by edit field
52 * of 'Insert Hyperlink' dialog. <p>
54 * Object implements the following interfaces :
56 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
58 * <li> <code>::com::sun::star::accessibility::XAccessibleEditableText</code></li>
59 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
60 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
61 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
64 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
65 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
66 * @see com.sun.star.accessibility.XAccessibleEditableText
67 * @see com.sun.star.accessibility.XAccessibleComponent
68 * @see com.sun.star.accessibility.XAccessibleContext
69 * @see com.sun.star.accessibility.XAccessibleText
70 * @see ifc.accessibility._XAccessibleExtendedComponent
71 * @see ifc.accessibility._XAccessibleEventBroadcaster
72 * @see ifc.accessibility._XAccessibleEditableText
73 * @see ifc.accessibility._XAccessibleComponent
74 * @see ifc.accessibility._XAccessibleContext
75 * @see ifc.accessibility._XAccessibleText
77 public class AccessibleEdit
extends TestCase
{
78 private static XTextDocument xTextDoc
= null;
79 private static XAccessibleAction action
= null;
82 * Opens 'Insert Hyperlink' dialog using document dispatch provider.
83 * Finds active top window (the dialog
84 * window) and finds first accessible edit field and
85 * button 'Close' (for closing this dialog when disposing)
86 * walking through the accessible component tree.
89 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
91 XInterface oObj
= null;
94 oObj
= (XInterface
) 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
) 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
);
138 util
.utils
.pause(500);
140 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
141 tk
.getActiveTopWindow());
143 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
145 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PUSH_BUTTON
,
147 action
= UnoRuntime
.queryInterface(
148 XAccessibleAction
.class, oObj
);
150 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TEXT
);
152 log
.println("ImplementationName " + utils
.getImplName(oObj
));
154 TestEnvironment tEnv
= new TestEnvironment(oObj
);
156 final XAccessibleEditableText edText
= UnoRuntime
.queryInterface(
157 XAccessibleEditableText
.class,
159 edText
.setText("AccessibleEdit");
161 tEnv
.addObjRelation("EventProducer",
162 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
163 public void fireEvent() {
164 edText
.setText("firing event ...");
165 edText
.setText("firing event ... 2");
166 edText
.setText("AccessibleEdit");
170 XAccessibleText text
= UnoRuntime
.queryInterface(
171 XAccessibleText
.class, oObj
);
173 tEnv
.addObjRelation("XAccessibleText.Text", text
.getText());
175 tEnv
.addObjRelation("XAccessibleEditableText.hasAttr", Boolean
.FALSE
);
181 * Closes dialog using action of button 'Close'
184 protected void cleanup(TestParameters Param
, PrintWriter log
) {
185 log
.println(" Closing dialog ... ");
188 action
.doAccessibleAction(0);
189 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ioe
) {
190 log
.println("Couldn't close dialog");
191 } catch (com
.sun
.star
.lang
.DisposedException de
) {
192 log
.println("Dialog already disposed");
195 util
.DesktopTools
.closeDoc(xTextDoc
);
199 * Creates writer document
202 protected void initialize(TestParameters Param
, PrintWriter log
) {
204 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
206 xTextDoc
= SOF
.createTextDoc(null);
207 } catch (com
.sun
.star
.uno
.Exception e
) {
208 throw new StatusException("Can't create document", e
);