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
.accessibility
.XAccessibleSelection
;
26 import com
.sun
.star
.awt
.XExtendedToolkit
;
27 import com
.sun
.star
.awt
.XWindow
;
28 import com
.sun
.star
.beans
.PropertyValue
;
29 import com
.sun
.star
.frame
.XController
;
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
;
40 import java
.io
.PrintWriter
;
43 import lib
.TestEnvironment
;
44 import lib
.TestParameters
;
45 import util
.AccessibilityTools
;
46 import util
.SOfficeFactory
;
50 public class AccessibleList
extends TestCase
{
51 private static XTextDocument xTextDoc
= null;
52 private static XAccessibleAction action
= null;
53 private static XMultiServiceFactory msf
= null;
56 * Opens 'Insert Hyperlink' dialog using document dispatch provider.
57 * Finds active top window (the dialog
58 * window) and finds button 'Close' (for closing this dialog when
59 * disposing) walking through the accessible component tree.
60 * Then the TREE component is found and the 'New Document' tab is
61 * selected to make list box visible. After that list box is obtained.
64 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
65 PrintWriter log
) throws Exception
{
66 XInterface oObj
= (XInterface
) msf
.createInstance("com.sun.star.awt.Toolkit");
68 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
69 XExtendedToolkit
.class, oObj
);
71 util
.utils
.waitForEventIdle(Param
.getMSF());
73 XModel aModel1
= UnoRuntime
.queryInterface(XModel
.class,
76 XController secondController
= aModel1
.getCurrentController();
78 XDispatchProvider aProv
= UnoRuntime
.queryInterface(
79 XDispatchProvider
.class,
82 XURLTransformer urlTransf
= null;
84 XInterface transf
= (XInterface
) msf
.createInstance(
85 "com.sun.star.util.URLTransformer");
86 urlTransf
= UnoRuntime
.queryInterface(
87 XURLTransformer
.class, transf
);
89 XDispatch getting
= null;
90 log
.println("opening HyperlinkDialog");
92 URL
[] url
= new URL
[1];
94 url
[0].Complete
= ".uno:HyperlinkDialog";
95 urlTransf
.parseStrict(url
);
96 getting
= aProv
.queryDispatch(url
[0], "", 0);
98 PropertyValue
[] noArgs
= new PropertyValue
[0];
99 getting
.dispatch(url
[0], noArgs
);
101 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
102 tk
.getActiveTopWindow());
104 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
107 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
108 // obtaining 'Close' button
109 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PUSH_BUTTON
,
111 action
= UnoRuntime
.queryInterface(
112 XAccessibleAction
.class, oObj
);
114 // Selecting 'New Document' tab
115 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TREE
);
117 XAccessibleSelection xAccSel
= UnoRuntime
.queryInterface(
118 XAccessibleSelection
.class,
120 xAccSel
.selectAccessibleChild(3);
121 util
.utils
.waitForEventIdle(Param
.getMSF());
123 log
.println("# Getting the ListBox");
125 XAccessibleContext parent
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
126 AccessibleRole
.PANEL
,
128 "com.sun.star.comp.toolkit.AccessibleListBox");
130 log
.println("# Getting the first child");
133 oObj
= parent
.getAccessibleChild(0);
134 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
137 log
.println("ImplementationName " + utils
.getImplName(oObj
));
139 TestEnvironment tEnv
= new TestEnvironment(oObj
);
141 tEnv
.addObjRelation("XAccessibleSelection.multiSelection",
144 final XAccessibleComponent acomp
= UnoRuntime
.queryInterface(
145 XAccessibleComponent
.class,
147 final XAccessibleComponent acomp1
= UnoRuntime
.queryInterface(
148 XAccessibleComponent
.class,
151 tEnv
.addObjRelation("EventProducer",
152 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
153 public void fireEvent() {
154 System
.out
.println("Grabbing focus ... ");
164 * Closes dialog using action of button 'Close'
167 protected void cleanup(TestParameters Param
, PrintWriter log
) {
168 log
.println(" Closing dialog ... ");
171 action
.doAccessibleAction(0);
172 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ioe
) {
173 log
.println("Couldn't close dialog");
174 } catch (com
.sun
.star
.lang
.DisposedException de
) {
175 log
.println("Dialog already disposed");
178 util
.DesktopTools
.closeDoc(xTextDoc
);
182 * Creates writer document
185 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
186 msf
= Param
.getMSF();
188 SOfficeFactory SOF
= SOfficeFactory
.getFactory(msf
);
189 xTextDoc
= SOF
.createTextDoc(null);