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
.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
.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
;
42 import lib
.TestEnvironment
;
43 import lib
.TestParameters
;
44 import util
.AccessibilityTools
;
45 import util
.SOfficeFactory
;
50 * Test for object which is represented accessible component
51 * of 'File type' list box item situated in 'Insert Hyperlink'
52 * dialog on tab 'New Document'. <p>
54 * Object implements the following interfaces :
56 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
58 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
59 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
62 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
63 * @see com.sun.star.accessibility.XAccessibleComponent
64 * @see com.sun.star.accessibility.XAccessibleContext
65 * @see com.sun.star.accessibility.XAccessibleText
66 * @see ifc.accessibility._XAccessibleEventBroadcaster
67 * @see ifc.accessibility._XAccessibleComponent
68 * @see ifc.accessibility._XAccessibleContext
69 * @see ifc.accessibility._XAccessibleText
71 public class AccessibleListItem
extends TestCase
{
72 private static XTextDocument xTextDoc
= null;
73 private static XAccessibleAction action
= null;
76 * Opens 'Insert Hyperlink' dialog using document dispatch provider.
77 * Finds active top window (the dialog
78 * window) and finds button 'Close' (for closing this dialog when
79 * disposing) walking through the accessible component tree.
80 * Then the TREE component is found and the 'New Document' tab is
81 * selected to make list box visible. After that listbox item is obtained.
84 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
85 PrintWriter log
) throws Exception
{
86 XMultiServiceFactory msf
= Param
.getMSF();
87 XInterface oObj
= (XInterface
) msf
.createInstance("com.sun.star.awt.Toolkit");
89 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
90 XExtendedToolkit
.class, oObj
);
92 util
.utils
.waitForEventIdle(Param
.getMSF());
94 XModel aModel1
= UnoRuntime
.queryInterface(XModel
.class,
97 XController secondController
= aModel1
.getCurrentController();
99 XDispatchProvider aProv
= UnoRuntime
.queryInterface(
100 XDispatchProvider
.class,
103 XURLTransformer urlTransf
= null;
105 XInterface transf
= (XInterface
) msf
.createInstance(
106 "com.sun.star.util.URLTransformer");
107 urlTransf
= UnoRuntime
.queryInterface(
108 XURLTransformer
.class, transf
);
110 XDispatch getting
= null;
111 log
.println("opening HyperlinkDialog");
113 URL
[] url
= new URL
[1];
115 url
[0].Complete
= ".uno:HyperlinkDialog";
116 urlTransf
.parseStrict(url
);
117 getting
= aProv
.queryDispatch(url
[0], "", 0);
119 PropertyValue
[] noArgs
= new PropertyValue
[0];
120 getting
.dispatch(url
[0], noArgs
);
122 util
.utils
.waitForEventIdle(Param
.getMSF());
124 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
125 tk
.getActiveTopWindow());
127 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
130 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
131 // obtaining 'Close' button
132 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PUSH_BUTTON
,
134 action
= UnoRuntime
.queryInterface(
135 XAccessibleAction
.class, oObj
);
137 // Selecting 'New Document' tab
138 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TREE
);
140 XAccessibleSelection xAccSel
= UnoRuntime
.queryInterface(
141 XAccessibleSelection
.class,
143 xAccSel
.selectAccessibleChild(3);
144 util
.utils
.waitForEventIdle(Param
.getMSF());
146 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.LIST_ITEM
,"Spr");
148 log
.println("ImplementationName " + utils
.getImplName(oObj
));
150 TestEnvironment tEnv
= new TestEnvironment(oObj
);
152 tEnv
.addObjRelation("EditOnly",
153 "This method isn't supported in this component");
155 tEnv
.addObjRelation("LimitedBounds", "yes");
157 final XAccessibleComponent acomp
= UnoRuntime
.queryInterface(
158 XAccessibleComponent
.class,
160 tEnv
.addObjRelation("EventProducer",
161 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
162 public void fireEvent() {
171 * Closes dialog using action of button 'Close'
174 protected void cleanup(TestParameters Param
, PrintWriter log
) {
175 log
.println(" Closing dialog ... ");
178 action
.doAccessibleAction(0);
179 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ioe
) {
180 log
.println("Couldn't close dialog");
181 } catch (com
.sun
.star
.lang
.DisposedException de
) {
182 log
.println("Dialog already disposed");
185 util
.DesktopTools
.closeDoc(xTextDoc
);
189 * Creates writer document
192 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
193 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
195 xTextDoc
= SOF
.createTextDoc(null);