2
|
1 |
/*
|
|
2 |
* Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.awt.X11;
|
|
27 |
|
|
28 |
//import static sun.awt.X11.XEmbed.*;
|
|
29 |
import java.awt.*;
|
|
30 |
import java.awt.event.*;
|
|
31 |
import java.util.logging.*;
|
|
32 |
import static sun.awt.X11.XConstants.*;
|
|
33 |
import java.util.LinkedList;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* Test XEmbed server implementation. See file:///home/dom/bugs/4931668/test_plan.html for
|
|
37 |
* specification and references.
|
|
38 |
*/
|
|
39 |
public class XEmbedServerTester implements XEventDispatcher {
|
|
40 |
private static final Logger xembedLog = Logger.getLogger("sun.awt.X11.xembed.XEmbedServerTester");
|
|
41 |
private final Object EVENT_LOCK = new Object();
|
|
42 |
static final int SYSTEM_EVENT_MASK = 0x8000;
|
|
43 |
int my_version, server_version;
|
|
44 |
XEmbedHelper xembed = new XEmbedHelper();
|
|
45 |
boolean focused;
|
|
46 |
int focusedKind;
|
|
47 |
int focusedServerComponent;
|
|
48 |
boolean reparent;
|
|
49 |
long parent;
|
|
50 |
boolean windowActive;
|
|
51 |
boolean xembedActive;
|
|
52 |
XBaseWindow window;
|
|
53 |
volatile int eventWaited = -1, eventReceived = -1;
|
|
54 |
int mapped;
|
|
55 |
int accel_key, accel_keysym, accel_mods;
|
|
56 |
static Rectangle initialBounds = new Rectangle(0, 0, 100, 100);
|
|
57 |
Robot robot;
|
|
58 |
Rectangle serverBounds[]; // first rectangle is for the server frame, second is for dummy frame, others are for its children
|
|
59 |
private static final int SERVER_BOUNDS = 0, OTHER_FRAME = 1, SERVER_FOCUS = 2, SERVER_MODAL = 3, MODAL_CLOSE = 4;
|
|
60 |
|
|
61 |
LinkedList<Integer> events = new LinkedList<Integer>();
|
|
62 |
|
|
63 |
private XEmbedServerTester(Rectangle serverBounds[], long parent) {
|
|
64 |
this.parent = parent;
|
|
65 |
focusedKind = -1;
|
|
66 |
focusedServerComponent = -1;
|
|
67 |
reparent = false;
|
|
68 |
windowActive = false;
|
|
69 |
xembedActive = false;
|
|
70 |
my_version = XEmbedHelper.XEMBED_VERSION;
|
|
71 |
mapped = XEmbedHelper.XEMBED_MAPPED;
|
|
72 |
this.serverBounds = serverBounds;
|
|
73 |
if (serverBounds.length < 5) {
|
|
74 |
throw new IllegalArgumentException("There must be at least five areas: server-activation, server-deactivation, server-focus, " +
|
|
75 |
"server-modal show, modal-close");
|
|
76 |
}
|
|
77 |
try {
|
|
78 |
robot = new Robot();
|
|
79 |
robot.setAutoDelay(100);
|
|
80 |
} catch (Exception e) {
|
|
81 |
throw new RuntimeException("Can't create robot");
|
|
82 |
}
|
|
83 |
initAccel();
|
|
84 |
xembedLog.finer("XEmbed client(tester), embedder window: " + Long.toHexString(parent));
|
|
85 |
}
|
|
86 |
|
|
87 |
public static XEmbedServerTester getTester(Rectangle serverBounds[], long parent) {
|
|
88 |
return new XEmbedServerTester(serverBounds, parent);
|
|
89 |
}
|
|
90 |
|
|
91 |
private void dumpReceivedEvents() {
|
|
92 |
xembedLog.finer("Events received so far:");
|
|
93 |
int pos = 0;
|
|
94 |
for (Integer event : events) {
|
|
95 |
xembedLog.finer((pos++) + ":" + XEmbedHelper.msgidToString(event));
|
|
96 |
}
|
|
97 |
xembedLog.finer("End of event dump");
|
|
98 |
}
|
|
99 |
|
|
100 |
public void test1_1() {
|
|
101 |
int res = embedCompletely();
|
|
102 |
waitWindowActivated(res);
|
|
103 |
requestFocus();
|
|
104 |
deactivateServer();
|
|
105 |
res = activateServer(getEventPos());
|
|
106 |
waitFocusGained(res);
|
|
107 |
checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT);
|
|
108 |
}
|
|
109 |
|
|
110 |
public void test1_2() {
|
|
111 |
int res = embedCompletely();
|
|
112 |
waitWindowActivated(res);
|
|
113 |
requestFocus();
|
|
114 |
checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT);
|
|
115 |
}
|
|
116 |
|
|
117 |
public void test1_3() {
|
|
118 |
embedCompletely();
|
|
119 |
deactivateServer();
|
|
120 |
requestFocusNoWait();
|
|
121 |
checkNotFocused();
|
|
122 |
}
|
|
123 |
|
|
124 |
public void test1_4() {
|
|
125 |
embedCompletely();
|
|
126 |
deactivateServer();
|
|
127 |
requestFocusNoWait();
|
|
128 |
checkNotFocused();
|
|
129 |
int res = getEventPos();
|
|
130 |
activateServer(res);
|
|
131 |
waitFocusGained(res);
|
|
132 |
checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT);
|
|
133 |
}
|
|
134 |
|
|
135 |
public void test1_5() {
|
|
136 |
int res = embedCompletely();
|
|
137 |
waitWindowActivated(res);
|
|
138 |
checkWindowActivated();
|
|
139 |
}
|
|
140 |
|
|
141 |
public void test1_6() {
|
|
142 |
int res = embedCompletely();
|
|
143 |
waitWindowActivated(res);
|
|
144 |
requestFocus();
|
|
145 |
res = deactivateServer();
|
|
146 |
checkFocused();
|
|
147 |
}
|
|
148 |
|
|
149 |
public void test1_7() {
|
|
150 |
int res = embedCompletely();
|
|
151 |
waitWindowActivated(res);
|
|
152 |
requestFocus();
|
|
153 |
focusServer();
|
|
154 |
checkFocusLost();
|
|
155 |
}
|
|
156 |
|
|
157 |
public void test2_5() {
|
|
158 |
int res = embedCompletely();
|
|
159 |
waitWindowActivated(res);
|
|
160 |
requestFocus();
|
|
161 |
focusServerNext();
|
|
162 |
checkFocusedServerNext();
|
|
163 |
checkFocusLost();
|
|
164 |
}
|
|
165 |
|
|
166 |
public void test2_6() {
|
|
167 |
int res = embedCompletely();
|
|
168 |
waitWindowActivated(res);
|
|
169 |
requestFocus();
|
|
170 |
focusServerPrev();
|
|
171 |
checkFocusedServerPrev();
|
|
172 |
checkFocusLost();
|
|
173 |
}
|
|
174 |
|
|
175 |
public void test3_1() {
|
|
176 |
reparent = false;
|
|
177 |
embedCompletely();
|
|
178 |
}
|
|
179 |
|
|
180 |
public void test3_3() {
|
|
181 |
reparent = true;
|
|
182 |
embedCompletely();
|
|
183 |
}
|
|
184 |
|
|
185 |
public void test3_4() {
|
|
186 |
my_version = 10;
|
|
187 |
embedCompletely();
|
|
188 |
if (server_version != XEmbedHelper.XEMBED_VERSION) {
|
|
189 |
throw new RuntimeException("Version " + server_version + " is not minimal");
|
|
190 |
}
|
|
191 |
}
|
|
192 |
|
|
193 |
public void test3_5() {
|
|
194 |
embedCompletely();
|
|
195 |
|
|
196 |
window.destroy();
|
|
197 |
// TODO: how can we detect that XEmbed ended? So far we are
|
|
198 |
// just checking that XEmbed server won't end up with an
|
|
199 |
// exception, which should end up testing, hopefully.
|
|
200 |
|
|
201 |
// Sleep before exiting the tester application
|
|
202 |
sleep(1000);
|
|
203 |
}
|
|
204 |
|
|
205 |
public void test3_6() {
|
|
206 |
embedCompletely();
|
|
207 |
|
|
208 |
sleep(1000);
|
|
209 |
XToolkit.awtLock();
|
|
210 |
try {
|
|
211 |
XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), window.getWindow());
|
|
212 |
XlibWrapper.XReparentWindow(XToolkit.getDisplay(), window.getWindow(), XToolkit.getDefaultRootWindow(), 0, 0);
|
|
213 |
} finally {
|
|
214 |
XToolkit.awtUnlock();
|
|
215 |
}
|
|
216 |
|
|
217 |
int res = getEventPos();
|
|
218 |
|
|
219 |
activateServerNoWait(res);
|
|
220 |
|
|
221 |
sleep(1000);
|
|
222 |
if (checkEventList(res, XEmbedHelper.XEMBED_WINDOW_ACTIVATE) != -1) {
|
|
223 |
throw new RuntimeException("Focus was been given to the client after XEmbed has ended");
|
|
224 |
}
|
|
225 |
}
|
|
226 |
|
|
227 |
public void test4_1() {
|
|
228 |
mapped = XEmbedHelper.XEMBED_MAPPED;
|
|
229 |
int res = getEventPos();
|
|
230 |
embedCompletely();
|
|
231 |
sleep(1000);
|
|
232 |
checkMapped();
|
|
233 |
}
|
|
234 |
|
|
235 |
public void test4_2() {
|
|
236 |
mapped = 0;
|
|
237 |
embedCompletely();
|
|
238 |
sleep(1000);
|
|
239 |
|
|
240 |
int res = getEventPos();
|
|
241 |
mapped = XEmbedHelper.XEMBED_MAPPED;
|
|
242 |
updateEmbedInfo();
|
|
243 |
sleep(1000);
|
|
244 |
checkMapped();
|
|
245 |
}
|
|
246 |
|
|
247 |
public void test4_3() {
|
|
248 |
int res = getEventPos();
|
|
249 |
mapped = XEmbedHelper.XEMBED_MAPPED;
|
|
250 |
embedCompletely();
|
|
251 |
|
|
252 |
res = getEventPos();
|
|
253 |
mapped = 0;
|
|
254 |
updateEmbedInfo();
|
|
255 |
sleep(1000);
|
|
256 |
checkNotMapped();
|
|
257 |
}
|
|
258 |
|
|
259 |
public void test4_4() {
|
|
260 |
mapped = 0;
|
|
261 |
embedCompletely();
|
|
262 |
sleep(1000);
|
|
263 |
if (XlibUtil.getWindowMapState(window.getWindow()) != XlibWrapper.IsUnmapped) {
|
|
264 |
throw new RuntimeException("Client has been mapped");
|
|
265 |
}
|
|
266 |
}
|
|
267 |
|
|
268 |
public void test6_1_1() {
|
|
269 |
embedCompletely();
|
|
270 |
registerAccelerator();
|
|
271 |
focusServer();
|
|
272 |
int res = pressAccelKey();
|
|
273 |
waitForEvent(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR);
|
|
274 |
}
|
|
275 |
|
|
276 |
public void test6_1_2() {
|
|
277 |
embedCompletely();
|
|
278 |
registerAccelerator();
|
|
279 |
focusServer();
|
|
280 |
deactivateServer();
|
|
281 |
int res = pressAccelKey();
|
|
282 |
sleep(1000);
|
|
283 |
if (checkEventList(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR) != -1) {
|
|
284 |
throw new RuntimeException("Accelerator has been activated in inactive embedder");
|
|
285 |
}
|
|
286 |
}
|
|
287 |
|
|
288 |
public void test6_1_3() {
|
|
289 |
embedCompletely();
|
|
290 |
registerAccelerator();
|
|
291 |
focusServer();
|
|
292 |
deactivateServer();
|
|
293 |
unregisterAccelerator();
|
|
294 |
int res = pressAccelKey();
|
|
295 |
sleep(1000);
|
|
296 |
if (checkEventList(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR) != -1) {
|
|
297 |
throw new RuntimeException("Accelerator has been activated after unregistering");
|
|
298 |
}
|
|
299 |
}
|
|
300 |
|
|
301 |
public void test6_1_4() {
|
|
302 |
embedCompletely();
|
|
303 |
registerAccelerator();
|
|
304 |
requestFocus();
|
|
305 |
int res = pressAccelKey();
|
|
306 |
sleep(1000);
|
|
307 |
if (checkEventList(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR) != -1) {
|
|
308 |
throw new RuntimeException("Accelerator has been activated in focused client");
|
|
309 |
}
|
|
310 |
}
|
|
311 |
public void test6_2_1() {
|
|
312 |
embedCompletely();
|
|
313 |
grabKey();
|
|
314 |
focusServer();
|
|
315 |
int res = pressAccelKey();
|
|
316 |
waitSystemEvent(res, KeyPress);
|
|
317 |
}
|
|
318 |
|
|
319 |
public void test6_2_2() {
|
|
320 |
embedCompletely();
|
|
321 |
grabKey();
|
|
322 |
focusServer();
|
|
323 |
deactivateServer();
|
|
324 |
int res = pressAccelKey();
|
|
325 |
sleep(1000);
|
|
326 |
if (checkEventList(res, SYSTEM_EVENT_MASK | KeyPress) != -1) {
|
|
327 |
throw new RuntimeException("Accelerator has been activated in inactive embedder");
|
|
328 |
}
|
|
329 |
}
|
|
330 |
|
|
331 |
public void test6_2_3() {
|
|
332 |
embedCompletely();
|
|
333 |
grabKey();
|
|
334 |
focusServer();
|
|
335 |
deactivateServer();
|
|
336 |
ungrabKey();
|
|
337 |
int res = pressAccelKey();
|
|
338 |
sleep(1000);
|
|
339 |
if (checkEventList(res, SYSTEM_EVENT_MASK | KeyPress) != -1) {
|
|
340 |
throw new RuntimeException("Accelerator has been activated after unregistering");
|
|
341 |
}
|
|
342 |
}
|
|
343 |
|
|
344 |
public void test6_2_4() {
|
|
345 |
embedCompletely();
|
|
346 |
grabKey();
|
|
347 |
requestFocus();
|
|
348 |
int res = pressAccelKey();
|
|
349 |
sleep(1000);
|
|
350 |
int pos = checkEventList(res, SYSTEM_EVENT_MASK | KeyPress);
|
|
351 |
if (pos != -1) {
|
|
352 |
pos = checkEventList(pos+1, SYSTEM_EVENT_MASK | KeyPress);
|
|
353 |
if (pos != -1) { // Second event
|
|
354 |
throw new RuntimeException("Accelerator has been activated in focused client");
|
|
355 |
}
|
|
356 |
}
|
|
357 |
}
|
|
358 |
|
|
359 |
public void test7_1() {
|
|
360 |
embedCompletely();
|
|
361 |
int res = showModalDialog();
|
|
362 |
waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_ON);
|
|
363 |
}
|
|
364 |
|
|
365 |
public void test7_2() {
|
|
366 |
embedCompletely();
|
|
367 |
int res = showModalDialog();
|
|
368 |
waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_ON);
|
|
369 |
res = hideModalDialog();
|
|
370 |
waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_OFF);
|
|
371 |
}
|
|
372 |
|
|
373 |
public void test9_1() {
|
|
374 |
embedCompletely();
|
|
375 |
requestFocus();
|
|
376 |
int res = pressAccelKey();
|
|
377 |
waitForEvent(res, SYSTEM_EVENT_MASK | KeyPress);
|
|
378 |
}
|
|
379 |
|
|
380 |
private int embed() {
|
|
381 |
int res = getEventPos();
|
|
382 |
XToolkit.awtLock();
|
|
383 |
try {
|
|
384 |
XCreateWindowParams params =
|
|
385 |
new XCreateWindowParams(new Object[] {
|
|
386 |
XBaseWindow.PARENT_WINDOW, new Long(reparent?XToolkit.getDefaultRootWindow():parent),
|
|
387 |
XBaseWindow.BOUNDS, initialBounds,
|
|
388 |
XBaseWindow.EMBEDDED, Boolean.TRUE,
|
|
389 |
XBaseWindow.VISIBLE, Boolean.valueOf(mapped == XEmbedHelper.XEMBED_MAPPED),
|
|
390 |
XBaseWindow.EVENT_MASK, new Long(VisibilityChangeMask | StructureNotifyMask |
|
|
391 |
SubstructureNotifyMask | KeyPressMask)});
|
|
392 |
window = new XBaseWindow(params);
|
|
393 |
|
|
394 |
xembedLog.finer("Created tester window: " + window);
|
|
395 |
|
|
396 |
XToolkit.addEventDispatcher(window.getWindow(), this);
|
|
397 |
updateEmbedInfo();
|
|
398 |
if (reparent) {
|
|
399 |
xembedLog.finer("Reparenting to embedder");
|
|
400 |
XlibWrapper.XReparentWindow(XToolkit.getDisplay(), window.getWindow(), parent, 0, 0);
|
|
401 |
}
|
|
402 |
} finally {
|
|
403 |
XToolkit.awtUnlock();
|
|
404 |
}
|
|
405 |
return res;
|
|
406 |
}
|
|
407 |
|
|
408 |
private void updateEmbedInfo() {
|
|
409 |
long[] info = new long[] { my_version, mapped };
|
|
410 |
long data = Native.card32ToData(info);
|
|
411 |
try {
|
|
412 |
XEmbedHelper.XEmbedInfo.setAtomData(window.getWindow(), data, info.length);
|
|
413 |
} finally {
|
|
414 |
XEmbedHelper.unsafe.freeMemory(data);
|
|
415 |
}
|
|
416 |
}
|
|
417 |
|
|
418 |
private int getEventPos() {
|
|
419 |
synchronized(EVENT_LOCK) {
|
|
420 |
return events.size();
|
|
421 |
}
|
|
422 |
}
|
|
423 |
|
|
424 |
private int embedCompletely() {
|
|
425 |
xembedLog.fine("Embedding completely");
|
|
426 |
int res = getEventPos();
|
|
427 |
embed();
|
|
428 |
waitEmbeddedNotify(res);
|
|
429 |
return res;
|
|
430 |
}
|
|
431 |
private int requestFocus() {
|
|
432 |
xembedLog.fine("Requesting focus");
|
|
433 |
int res = getEventPos();
|
|
434 |
sendMessage(XEmbedHelper.XEMBED_REQUEST_FOCUS);
|
|
435 |
waitFocusGained(res);
|
|
436 |
return res;
|
|
437 |
}
|
|
438 |
private int requestFocusNoWait() {
|
|
439 |
xembedLog.fine("Requesting focus without wait");
|
|
440 |
int res = getEventPos();
|
|
441 |
sendMessage(XEmbedHelper.XEMBED_REQUEST_FOCUS);
|
|
442 |
return res;
|
|
443 |
}
|
|
444 |
private int activateServer(int prev) {
|
|
445 |
int res = activateServerNoWait(prev);
|
|
446 |
waitWindowActivated(res);
|
|
447 |
return res;
|
|
448 |
}
|
|
449 |
private int activateServerNoWait(int prev) {
|
|
450 |
xembedLog.fine("Activating server");
|
|
451 |
int res = getEventPos();
|
|
452 |
if (checkEventList(prev, XEmbedHelper.XEMBED_WINDOW_ACTIVATE) != -1) {
|
|
453 |
xembedLog.fine("Activation already received");
|
|
454 |
return res;
|
|
455 |
}
|
|
456 |
Point loc = serverBounds[SERVER_BOUNDS].getLocation();
|
|
457 |
loc.x += serverBounds[SERVER_BOUNDS].getWidth()/2;
|
|
458 |
loc.y += 5;
|
|
459 |
robot.mouseMove(loc.x, loc.y);
|
|
460 |
robot.mousePress(InputEvent.BUTTON1_MASK);
|
|
461 |
robot.mouseRelease(InputEvent.BUTTON1_MASK);
|
|
462 |
return res;
|
|
463 |
}
|
|
464 |
private int deactivateServer() {
|
|
465 |
xembedLog.fine("Deactivating server");
|
|
466 |
int res = getEventPos();
|
|
467 |
Point loc = serverBounds[OTHER_FRAME].getLocation();
|
|
468 |
loc.x += serverBounds[OTHER_FRAME].getWidth()/2;
|
|
469 |
loc.y += serverBounds[OTHER_FRAME].getHeight()/2;
|
|
470 |
robot.mouseMove(loc.x, loc.y);
|
|
471 |
robot.mousePress(InputEvent.BUTTON1_MASK);
|
|
472 |
robot.delay(50);
|
|
473 |
robot.mouseRelease(InputEvent.BUTTON1_MASK);
|
|
474 |
waitWindowDeactivated(res);
|
|
475 |
return res;
|
|
476 |
}
|
|
477 |
private int focusServer() {
|
|
478 |
xembedLog.fine("Focusing server");
|
|
479 |
boolean weFocused = focused;
|
|
480 |
int res = getEventPos();
|
|
481 |
Point loc = serverBounds[SERVER_FOCUS].getLocation();
|
|
482 |
loc.x += 5;
|
|
483 |
loc.y += 5;
|
|
484 |
robot.mouseMove(loc.x, loc.y);
|
|
485 |
robot.mousePress(InputEvent.BUTTON1_MASK);
|
|
486 |
robot.delay(50);
|
|
487 |
robot.mouseRelease(InputEvent.BUTTON1_MASK);
|
|
488 |
if (weFocused) {
|
|
489 |
waitFocusLost(res);
|
|
490 |
}
|
|
491 |
return res;
|
|
492 |
}
|
|
493 |
private int focusServerNext() {
|
|
494 |
xembedLog.fine("Focusing next server component");
|
|
495 |
int res = getEventPos();
|
|
496 |
sendMessage(XEmbedHelper.XEMBED_FOCUS_NEXT);
|
|
497 |
waitFocusLost(res);
|
|
498 |
return res;
|
|
499 |
}
|
|
500 |
private int focusServerPrev() {
|
|
501 |
xembedLog.fine("Focusing previous server component");
|
|
502 |
int res = getEventPos();
|
|
503 |
sendMessage(XEmbedHelper.XEMBED_FOCUS_PREV);
|
|
504 |
waitFocusLost(res);
|
|
505 |
return res;
|
|
506 |
}
|
|
507 |
|
|
508 |
private void waitEmbeddedNotify(int pos) {
|
|
509 |
waitForEvent(pos, XEmbedHelper.XEMBED_EMBEDDED_NOTIFY);
|
|
510 |
}
|
|
511 |
private void waitFocusGained(int pos) {
|
|
512 |
waitForEvent(pos, XEmbedHelper.XEMBED_FOCUS_IN);
|
|
513 |
}
|
|
514 |
private void waitFocusLost(int pos) {
|
|
515 |
waitForEvent(pos, XEmbedHelper.XEMBED_FOCUS_OUT);
|
|
516 |
}
|
|
517 |
private void waitWindowActivated(int pos) {
|
|
518 |
waitForEvent(pos, XEmbedHelper.XEMBED_WINDOW_ACTIVATE);
|
|
519 |
}
|
|
520 |
private void waitWindowDeactivated(int pos) {
|
|
521 |
waitForEvent(pos, XEmbedHelper.XEMBED_WINDOW_DEACTIVATE);
|
|
522 |
}
|
|
523 |
|
|
524 |
private void waitSystemEvent(int position, int event) {
|
|
525 |
waitForEvent(position, event | SYSTEM_EVENT_MASK);
|
|
526 |
}
|
|
527 |
|
|
528 |
private void waitForEvent(int position, int event) {
|
|
529 |
synchronized(EVENT_LOCK) {
|
|
530 |
// Check for already received events after the request
|
|
531 |
if (checkEventList(position, event) != -1) {
|
|
532 |
xembedLog.finer("The event " + XEmbedHelper.msgidToString(event) + " has already been received");
|
|
533 |
return;
|
|
534 |
}
|
|
535 |
|
|
536 |
if (eventReceived == event) {
|
|
537 |
// Already received
|
|
538 |
xembedLog.finer("Already received " + XEmbedHelper.msgidToString(event));
|
|
539 |
return;
|
|
540 |
}
|
|
541 |
eventReceived = -1;
|
|
542 |
eventWaited = event;
|
|
543 |
xembedLog.finer("Waiting for " + XEmbedHelper.msgidToString(event) + " starting from " + position);
|
|
544 |
try {
|
|
545 |
EVENT_LOCK.wait(3000);
|
|
546 |
} catch (InterruptedException ie) {
|
|
547 |
xembedLog.log(Level.WARNING, "Event wait interrupted", ie);
|
|
548 |
}
|
|
549 |
eventWaited = -1;
|
|
550 |
if (checkEventList(position, event) == -1) {
|
|
551 |
dumpReceivedEvents();
|
|
552 |
throw new RuntimeException("Didn't receive event " + XEmbedHelper.msgidToString(event) + " but recevied " + XEmbedHelper.msgidToString(eventReceived));
|
|
553 |
} else {
|
|
554 |
xembedLog.finer("Successfully recevied " + XEmbedHelper.msgidToString(event));
|
|
555 |
}
|
|
556 |
}
|
|
557 |
}
|
|
558 |
/**
|
|
559 |
* Checks if the <code>event</code> is already in a list at position >= <code>position</code>
|
|
560 |
*/
|
|
561 |
private int checkEventList(int position, int event) {
|
|
562 |
if (position == -1) {
|
|
563 |
return -1;
|
|
564 |
}
|
|
565 |
synchronized(EVENT_LOCK) {
|
|
566 |
for (int i = position; i < events.size(); i++) {
|
|
567 |
if (events.get(i) == event) {
|
|
568 |
return i;
|
|
569 |
}
|
|
570 |
}
|
|
571 |
return -1;
|
|
572 |
}
|
|
573 |
}
|
|
574 |
|
|
575 |
private void checkFocusedServerNext() {
|
|
576 |
if (focusedServerComponent != 0) {
|
|
577 |
throw new RuntimeException("Wrong focused server component, should be 0, but it is " + focusedServerComponent);
|
|
578 |
}
|
|
579 |
}
|
|
580 |
private void checkFocusedServerPrev() {
|
|
581 |
if (focusedServerComponent != 2) {
|
|
582 |
throw new RuntimeException("Wrong focused server component, should be 2, but it is " + focusedServerComponent);
|
|
583 |
}
|
|
584 |
}
|
|
585 |
private void checkFocusGained(int kind) {
|
|
586 |
if (!focused) {
|
|
587 |
throw new RuntimeException("Didn't receive FOCUS_GAINED");
|
|
588 |
}
|
|
589 |
if (focusedKind != kind) {
|
|
590 |
throw new RuntimeException("Kinds don't match, required: " + kind + ", current: " + focusedKind);
|
|
591 |
}
|
|
592 |
}
|
|
593 |
private void checkNotFocused() {
|
|
594 |
if (focused) {
|
|
595 |
throw new RuntimeException("Focused");
|
|
596 |
}
|
|
597 |
}
|
|
598 |
private void checkFocused() {
|
|
599 |
if (!focused) {
|
|
600 |
throw new RuntimeException("Not Focused");
|
|
601 |
}
|
|
602 |
}
|
|
603 |
|
|
604 |
private void checkFocusLost() {
|
|
605 |
checkNotFocused();
|
|
606 |
if (focusedKind != XEmbedHelper.XEMBED_FOCUS_OUT) {
|
|
607 |
throw new RuntimeException("Didn't receive FOCUS_LOST");
|
|
608 |
}
|
|
609 |
}
|
|
610 |
private void checkWindowActivated() {
|
|
611 |
if (!windowActive) {
|
|
612 |
throw new RuntimeException("Window is not active");
|
|
613 |
}
|
|
614 |
}
|
|
615 |
private void checkMapped() {
|
|
616 |
if (XlibUtil.getWindowMapState(window.getWindow()) == XlibWrapper.IsUnmapped) {
|
|
617 |
throw new RuntimeException("Client is not mapped");
|
|
618 |
}
|
|
619 |
}
|
|
620 |
private void checkNotMapped() {
|
|
621 |
if (XlibUtil.getWindowMapState(window.getWindow()) != XlibWrapper.IsUnmapped) {
|
|
622 |
throw new RuntimeException("Client is mapped");
|
|
623 |
}
|
|
624 |
}
|
|
625 |
|
|
626 |
private void sendMessage(int message) {
|
|
627 |
xembed.sendMessage(parent, message);
|
|
628 |
}
|
|
629 |
private void sendMessage(int message, int detail, long data1, long data2) {
|
|
630 |
xembed.sendMessage(parent, message, detail, data1, data2);
|
|
631 |
}
|
|
632 |
|
|
633 |
public void dispatchEvent(XEvent ev) {
|
|
634 |
if (ev.get_type() == ClientMessage) {
|
|
635 |
XClientMessageEvent msg = ev.get_xclient();
|
|
636 |
if (msg.get_message_type() == xembed.XEmbed.getAtom()) {
|
|
637 |
if (xembedLog.isLoggable(Level.FINE)) xembedLog.fine("Embedded message: " + XEmbedHelper.msgidToString((int)msg.get_data(1)));
|
|
638 |
switch ((int)msg.get_data(1)) {
|
|
639 |
case XEmbedHelper.XEMBED_EMBEDDED_NOTIFY: // Notification about embedding protocol start
|
|
640 |
xembedActive = true;
|
|
641 |
server_version = (int)msg.get_data(3);
|
|
642 |
break;
|
|
643 |
case XEmbedHelper.XEMBED_WINDOW_ACTIVATE:
|
|
644 |
windowActive = true;
|
|
645 |
break;
|
|
646 |
case XEmbedHelper.XEMBED_WINDOW_DEACTIVATE:
|
|
647 |
windowActive = false;
|
|
648 |
break;
|
|
649 |
case XEmbedHelper.XEMBED_FOCUS_IN: // We got focus!
|
|
650 |
focused = true;
|
|
651 |
focusedKind = (int)msg.get_data(2);
|
|
652 |
break;
|
|
653 |
case XEmbedHelper.XEMBED_FOCUS_OUT:
|
|
654 |
focused = false;
|
|
655 |
focusedKind = XEmbedHelper.XEMBED_FOCUS_OUT;
|
|
656 |
focusedServerComponent = (int)msg.get_data(2);
|
|
657 |
break;
|
|
658 |
}
|
|
659 |
synchronized(EVENT_LOCK) {
|
|
660 |
events.add((int)msg.get_data(1));
|
|
661 |
|
|
662 |
xembedLog.finer("Tester is waiting for " + XEmbedHelper.msgidToString(eventWaited));
|
|
663 |
if ((int)msg.get_data(1) == eventWaited) {
|
|
664 |
eventReceived = (int)msg.get_data(1);
|
|
665 |
xembedLog.finer("Notifying waiting object for event " + System.identityHashCode(EVENT_LOCK));
|
|
666 |
EVENT_LOCK.notifyAll();
|
|
667 |
}
|
|
668 |
}
|
|
669 |
}
|
|
670 |
} else {
|
|
671 |
synchronized(EVENT_LOCK) {
|
|
672 |
int eventID = (int)ev.get_type() | SYSTEM_EVENT_MASK;
|
|
673 |
events.add(eventID);
|
|
674 |
|
|
675 |
xembedLog.finer("Tester is waiting for " + XEmbedHelper.msgidToString(eventWaited) + ", but we received " + ev + "(" + XEmbedHelper.msgidToString(eventID) + ")");
|
|
676 |
if (eventID == eventWaited) {
|
|
677 |
eventReceived = eventID;
|
|
678 |
xembedLog.finer("Notifying waiting object" + System.identityHashCode(EVENT_LOCK));
|
|
679 |
EVENT_LOCK.notifyAll();
|
|
680 |
}
|
|
681 |
}
|
|
682 |
}
|
|
683 |
}
|
|
684 |
|
|
685 |
private void sleep(int amount) {
|
|
686 |
try {
|
|
687 |
Thread.sleep(amount);
|
|
688 |
} catch (Exception e) {
|
|
689 |
}
|
|
690 |
}
|
|
691 |
|
|
692 |
private void registerAccelerator() {
|
|
693 |
sendMessage(XEmbedHelper.XEMBED_REGISTER_ACCELERATOR, 1, accel_keysym, accel_mods);
|
|
694 |
}
|
|
695 |
|
|
696 |
private void unregisterAccelerator() {
|
|
697 |
sendMessage(XEmbedHelper.XEMBED_UNREGISTER_ACCELERATOR, 1, 0, 0);
|
|
698 |
}
|
|
699 |
|
|
700 |
private int pressAccelKey() {
|
|
701 |
int res = getEventPos();
|
|
702 |
robot.keyPress(accel_key);
|
|
703 |
robot.keyRelease(accel_key);
|
|
704 |
return res;
|
|
705 |
}
|
|
706 |
|
|
707 |
private void initAccel() {
|
|
708 |
accel_key = KeyEvent.VK_A;
|
|
709 |
accel_keysym = XWindow.getKeySymForAWTKeyCode(accel_key);
|
|
710 |
accel_mods = 0;
|
|
711 |
}
|
|
712 |
|
|
713 |
private void grabKey() {
|
|
714 |
sendMessage(XEmbedHelper.NON_STANDARD_XEMBED_GTK_GRAB_KEY, 0, accel_keysym, accel_mods);
|
|
715 |
}
|
|
716 |
private void ungrabKey() {
|
|
717 |
sendMessage(XEmbedHelper.NON_STANDARD_XEMBED_GTK_UNGRAB_KEY, 0, accel_keysym, accel_mods);
|
|
718 |
}
|
|
719 |
private int showModalDialog() {
|
|
720 |
xembedLog.fine("Showing modal dialog");
|
|
721 |
int res = getEventPos();
|
|
722 |
Point loc = serverBounds[SERVER_MODAL].getLocation();
|
|
723 |
loc.x += 5;
|
|
724 |
loc.y += 5;
|
|
725 |
robot.mouseMove(loc.x, loc.y);
|
|
726 |
robot.mousePress(InputEvent.BUTTON1_MASK);
|
|
727 |
robot.delay(50);
|
|
728 |
robot.mouseRelease(InputEvent.BUTTON1_MASK);
|
|
729 |
return res;
|
|
730 |
}
|
|
731 |
private int hideModalDialog() {
|
|
732 |
xembedLog.fine("Hide modal dialog");
|
|
733 |
int res = getEventPos();
|
|
734 |
// Point loc = serverBounds[MODAL_CLOSE].getLocation();
|
|
735 |
// loc.x += 5;
|
|
736 |
// loc.y += 5;
|
|
737 |
// robot.mouseMove(loc.x, loc.y);
|
|
738 |
// robot.mousePress(InputEvent.BUTTON1_MASK);
|
|
739 |
// robot.delay(50);
|
|
740 |
// robot.mouseRelease(InputEvent.BUTTON1_MASK);
|
|
741 |
robot.keyPress(KeyEvent.VK_SPACE);
|
|
742 |
robot.keyRelease(KeyEvent.VK_SPACE);
|
|
743 |
return res;
|
|
744 |
}
|
|
745 |
|
|
746 |
}
|