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 .
21 import lib
.MultiMethodTest
;
23 import lib
.StatusException
;
24 import util
.SOfficeFactory
;
26 import com
.sun
.star
.beans
.PropertyValue
;
27 import com
.sun
.star
.frame
.XDesktop
;
28 import com
.sun
.star
.frame
.XFrame
;
29 import com
.sun
.star
.frame
.XFrameLoader
;
30 import com
.sun
.star
.frame
.XLoadEventListener
;
31 import com
.sun
.star
.lang
.EventObject
;
32 import com
.sun
.star
.lang
.XComponent
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
37 * Testing <code>com.sun.star.frame.XFrameLoader</code>
40 * <li><code> load()</code></li>
41 * <li><code> cancel()</code></li>
43 * This test needs the following object relations :
45 * <li> <code>'FrameLoader.URL'</code> (of type <code>String</code>):
46 * an url or component to be loaded </li>
47 * <li> <code>'FrameLoader.Frame'</code> <b>(optional)</b>
48 * (of type <code>com.sun.star.frame.XFrame</code>):
49 * a target frame where component to be loaded. If this
50 * relation is omitted then a text document created and its
51 * frame is used. </li>
52 * <li> <code>'FrameLoader.args'</code> <b>(optional)</b>
53 * (of type <code>Object[]</code>):
54 * necessary arguuments for loading a component. If omitted
55 * then zero length array is passed as parameter</li>
57 * Test is <b> NOT </b> multithread compliant. <p>
58 * @see com.sun.star.frame.XFrameLoader
60 public class _XFrameLoader
extends MultiMethodTest
{
62 public XFrameLoader oObj
= null; // oObj filled by MultiMethodTest
63 private String url
= null ;
64 private XFrame frame
= null ;
65 private PropertyValue
[] args
= new PropertyValue
[0] ;
68 * Implemetation of load listener which geristers all its calls.
70 protected class TestListener
implements XLoadEventListener
{
71 public boolean finished
= false ;
72 public boolean cancelled
= false ;
74 public void loadFinished(XFrameLoader l
) {
77 public void loadCancelled(XFrameLoader l
) {
80 public void disposing(EventObject e
) {}
83 TestListener listener
= new TestListener() ;
84 XComponent frameSup
= null ;
87 * Retrieves all relations. If optional ones are not found
88 * creates their default values. <p>
89 * @throws StatusException If one of required relations not found.
92 public void before() {
93 url
= (String
) tEnv
.getObjRelation("FrameLoader.URL") ;
94 frame
= (XFrame
) tEnv
.getObjRelation("FrameLoader.Frame") ;
97 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
100 log
.println( "creating a textdocument" );
101 frameSup
= SOF
.createTextDoc( null );
103 Object oDsk
= tParam
.getMSF()
104 .createInstance("com.sun.star.frame.Desktop") ;
105 XDesktop dsk
= UnoRuntime
.queryInterface(XDesktop
.class, oDsk
) ;
107 util
.utils
.shortWait();
108 frame
= dsk
.getCurrentFrame() ;
109 } catch ( com
.sun
.star
.uno
.Exception e
) {
110 // Some exception occurs.FAILED
111 e
.printStackTrace( log
);
112 throw new StatusException( "Couldn't create a frame.", e
);
116 Object args
= tEnv
.getObjRelation("FrameLoader.args") ;
117 if (args
!= null) this.args
= (PropertyValue
[]) args
;
119 if (url
== null /*|| frame == null*/) {
120 throw new StatusException
121 (Status
.failed("Some relations not found")) ;
125 private boolean loaded
= false ;
128 * First <code>cancel</code> method test is called.
129 * If in that test loaing process was interrupted by
130 * <code>cancel</code> call then <code>load</code> test
131 * executes. It loads a component, waits some moment to
132 * listener have a chance to be called and then checks
133 * if the load listener was called.<p>
134 * Has <b>OK</b> status if <code>cancel</code> method test
135 * didn't interrupt loading and it was successful, or
136 * if in this method it loads successful and listener's
137 * <code>finished</code> method was called.
138 * The following method tests are to be executed before:
140 * <li> <code> cancel() </code> </li>
143 public void _load() {
144 executeMethod("cancel()") ;
147 oObj
.load(frame
, url
, args
, listener
) ;
149 util
.utils
.shortWait();
151 loaded
= listener
.finished
;
154 tRes
.tested("load()", loaded
) ;
158 * Starts to load a component and then immediately tries to
159 * cancel the process. <p>
160 * Has <b>OK</b> status if the process was cancelled or
161 * finished (appropriate listener methods were called).
163 public void _cancel() {
164 boolean result
= true ;
166 oObj
.load(frame
, url
, args
, listener
) ;
169 util
.utils
.shortWait();
171 if (listener
.cancelled
) {
172 log
.println("Loading was canceled.") ;
174 if (listener
.finished
) {
175 log
.println("Loading was finished.") ;
178 if (!listener
.cancelled
&& !listener
.finished
) {
179 log
.println("Loading was not canceled and not finished") ;
183 tRes
.tested("cancel()", result
) ;
187 public void after() {
188 if (frameSup
!= null) frameSup
.dispose() ;