Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _svtools / AccessibleBrowseBoxHeaderBar.java
blob8a4d3c2fb857651679a6f94fcbcf8e992e850f4e
1 /*
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 .
18 package mod._svtools;
20 import com.sun.star.view.XSelectionSupplier;
21 import java.awt.Robot;
22 import java.awt.event.InputEvent;
23 import java.io.PrintWriter;
25 import lib.StatusException;
26 import lib.TestCase;
27 import lib.TestEnvironment;
28 import lib.TestParameters;
29 import util.AccessibilityTools;
30 import util.DesktopTools;
31 import util.SOfficeFactory;
33 import com.sun.star.accessibility.AccessibleRole;
34 import com.sun.star.accessibility.XAccessible;
35 import com.sun.star.accessibility.XAccessibleComponent;
36 import com.sun.star.awt.Point;
37 import com.sun.star.awt.XWindow;
38 import com.sun.star.beans.PropertyValue;
39 import com.sun.star.frame.XController;
40 import com.sun.star.frame.XDesktop;
41 import com.sun.star.frame.XDispatch;
42 import com.sun.star.frame.XDispatchProvider;
43 import com.sun.star.frame.XFrame;
44 import com.sun.star.frame.XModel;
45 import com.sun.star.text.XTextDocument;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
48 import com.sun.star.util.URL;
51 /**
52 * Test for object that implements the following interfaces :
53 * <ul>
54 * <li>
55 * <code>::com::sun::star::accessibility::XAccessibleContext
56 * </code></li>
57 * <li>
58 * <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
59 * </code></li>
60 * </ul> <p>
62 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
63 * @see com.sun.star.accessibility.XAccessibleContext
64 * @see ifc.accessibility._XAccessibleEventBroadcaster
65 * @see ifc.accessibility._XAccessibleContext
67 public class AccessibleBrowseBoxHeaderBar extends TestCase {
68 static XDesktop the_Desk;
69 static XTextDocument xTextDoc;
71 /**
72 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
74 @Override
75 protected void initialize(TestParameters Param, PrintWriter log) {
76 the_Desk = UnoRuntime.queryInterface(XDesktop.class,
77 DesktopTools.createDesktop(
78 Param.getMSF()));
81 /**
82 * Disposes the document, if exists, created in
83 * <code>createTestEnvironment</code> method.
85 @Override
86 protected void cleanup(TestParameters Param, PrintWriter log) {
87 log.println("disposing xTextDoc");
89 if (xTextDoc != null) {
90 xTextDoc.dispose();
94 /**
95 * Creates a text document. Opens the DataSource browser.
96 * Creates an instance of the service <code>com.sun.star.awt.Toolkit</code>
97 * and gets active top window. Then obtains an accessible object with
98 * the role <code>AccessibleRole.TABLE</code>.
99 * Object relations created :
100 * <ul>
101 * <li> <code>'EventProducer'</code> for
102 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
103 * </li>
104 * </ul>
106 * @param tParam test parameters
107 * @param log writer to log information while testing
109 * @see com.sun.star.awt.Toolkit
110 * @see com.sun.star.accessibility.AccessibleRole
111 * @see ifc.accessibility._XAccessibleEventBroadcaster
112 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
114 @Override
115 protected TestEnvironment createTestEnvironment(TestParameters tParam,
116 PrintWriter log) {
117 log.println("creating a test environment");
119 if (xTextDoc != null) {
120 xTextDoc.dispose();
123 // get a soffice factory object
124 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
126 try {
127 log.println("creating a text document");
128 xTextDoc = SOF.createTextDoc(null);
129 } catch (com.sun.star.uno.Exception e) {
130 // Some exception occurs.FAILED
131 e.printStackTrace(log);
132 throw new StatusException("Couldn't create document", e);
135 util.utils.pause(5000);
137 XModel aModel1 = UnoRuntime.queryInterface(XModel.class,
138 xTextDoc);
140 XController secondController = aModel1.getCurrentController();
142 XDispatchProvider aProv = UnoRuntime.queryInterface(
143 XDispatchProvider.class,
144 secondController);
146 XDispatch getting = null;
148 log.println("opening DatasourceBrowser");
150 URL the_url = new URL();
151 the_url.Complete = ".component:DB/DataSourceBrowser";
152 getting = aProv.queryDispatch(the_url, "_beamer", 12);
154 //am controller ein XSelectionSupplier->mit params rufen
155 PropertyValue[] noArgs = new PropertyValue[0];
156 getting.dispatch(the_url, noArgs);
158 PropertyValue[] params = new PropertyValue[3];
159 PropertyValue param1 = new PropertyValue();
160 param1.Name = "DataSourceName";
161 param1.Value = "Bibliography";
162 params[0] = param1;
164 PropertyValue param2 = new PropertyValue();
165 param2.Name = "CommandType";
166 param2.Value = Integer.valueOf(com.sun.star.sdb.CommandType.TABLE);
167 params[1] = param2;
169 PropertyValue param3 = new PropertyValue();
170 param3.Name = "Command";
171 param3.Value = "biblio";
172 params[2] = param3;
174 util.utils.pause(5000);
176 XFrame the_frame1 = the_Desk.getCurrentFrame();
178 if (the_frame1 == null) {
179 log.println("Current frame was not found !!!");
182 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
184 the_frame2.setName("DatasourceBrowser");
186 XController xCont = the_frame2.getController();
188 XSelectionSupplier xSelect = UnoRuntime.queryInterface(
189 XSelectionSupplier.class, xCont);
191 try {
192 xSelect.select(params);
193 } catch (com.sun.star.lang.IllegalArgumentException ex) {
194 throw new StatusException("Could not select Biblio-Database", ex);
197 XInterface oObj = null;
199 XWindow xWindow = secondController.getFrame().getContainerWindow();
201 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
203 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE);
205 AccessibilityTools.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
206 log.println("ImplementationName: " + util.utils.getImplName(oObj));
208 TestEnvironment tEnv = new TestEnvironment(oObj);
210 util.utils.pause(5000);
212 XAccessibleComponent accComp = UnoRuntime.queryInterface(
213 XAccessibleComponent.class,
214 oObj);
215 final Point point = accComp.getLocationOnScreen();
217 util.utils.pause(5000);
219 tEnv.addObjRelation("EventProducer",
220 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
221 public void fireEvent() {
222 try {
223 Robot rob = new Robot();
224 rob.mouseMove(point.X + 5, point.Y + 5);
225 rob.mousePress(InputEvent.BUTTON1_MASK);
226 } catch (java.awt.AWTException e) {
227 System.out.println("couldn't fire event");
232 return tEnv;