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