1 /* 2 * Copyright (c) 2003, 2008, 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 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 89 public static XEmbedServerTester getTester(Rectangle serverBounds[], long parent) { 90 return new XEmbedServerTester(serverBounds, parent); 91 } 92 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 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 114 public void test1_2() { 115 int res = embedCompletely(); 116 waitWindowActivated(res); 117 requestFocus(); 118 checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT); 119 } 120 121 public void test1_3() { 122 embedCompletely(); 123 deactivateServer(); 124 requestFocusNoWait(); 125 checkNotFocused(); 126 } 127 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 139 public void test1_5() { 140 int res = embedCompletely(); 141 waitWindowActivated(res); 142 checkWindowActivated(); 143 } 144 145 public void test1_6() { 146 int res = embedCompletely(); 147 waitWindowActivated(res); 148 requestFocus(); 149 res = deactivateServer(); 150 checkFocused(); 151 } 152 153 public void test1_7() { 154 int res = embedCompletely(); 155 waitWindowActivated(res); 156 requestFocus(); 157 focusServer(); 158 checkFocusLost(); 159 } 160 161 public void test2_5() { 162 int res = embedCompletely(); 163 waitWindowActivated(res); 164 requestFocus(); 165 focusServerNext(); 166 checkFocusedServerNext(); 167 checkFocusLost(); 168 } 169 170 public void test2_6() { 171 int res = embedCompletely(); 172 waitWindowActivated(res); 173 requestFocus(); 174 focusServerPrev(); 175 checkFocusedServerPrev(); 176 checkFocusLost(); 177 } 178 179 public void test3_1() { 180 reparent = false; 181 embedCompletely(); 182 } 183 184 public void test3_3() { 185 reparent = true; 186 embedCompletely(); 187 } 188 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 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 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 231 public void test4_1() { 232 mapped = XEmbedHelper.XEMBED_MAPPED; 233 int res = getEventPos(); 234 embedCompletely(); 235 sleep(1000); 236 checkMapped(); 237 } 238 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 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 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 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 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 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 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 } 315 public void test6_2_1() { 316 embedCompletely(); 317 grabKey(); 318 focusServer(); 319 int res = pressAccelKey(); 320 waitSystemEvent(res, KeyPress); 321 } 322 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 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 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 363 public void test7_1() { 364 embedCompletely(); 365 int res = showModalDialog(); 366 waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_ON); 367 } 368 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 377 public void test9_1() { 378 embedCompletely(); 379 requestFocus(); 380 int res = pressAccelKey(); 381 waitForEvent(res, SYSTEM_EVENT_MASK | KeyPress); 382 } 383 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 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 424 private int getEventPos() { 425 synchronized(EVENT_LOCK) { 426 return events.size(); 427 } 428 } 429 430 private int embedCompletely() { 431 xembedLog.fine("Embedding completely"); 432 int res = getEventPos(); 433 embed(); 434 waitEmbeddedNotify(res); 435 return res; 436 } 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 } 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 } 450 private int activateServer(int prev) { 451 int res = activateServerNoWait(prev); 452 waitWindowActivated(res); 453 return res; 454 } 455 private int activateServerNoWait(int prev) { 456 xembedLog.fine("Activating server"); 457 int res = getEventPos(); 458 if (checkEventList(prev, XEmbedHelper.XEMBED_WINDOW_ACTIVATE) != -1) { 459 xembedLog.fine("Activation already received"); 460 return res; 461 } 462 Point loc = serverBounds[SERVER_BOUNDS].getLocation(); 463 loc.x += serverBounds[SERVER_BOUNDS].getWidth()/2; 464 loc.y += 5; 465 robot.mouseMove(loc.x, loc.y); 466 robot.mousePress(InputEvent.BUTTON1_MASK); 467 robot.mouseRelease(InputEvent.BUTTON1_MASK); 468 return res; 469 } 470 private int deactivateServer() { 471 xembedLog.fine("Deactivating server"); 472 int res = getEventPos(); 473 Point loc = serverBounds[OTHER_FRAME].getLocation(); 474 loc.x += serverBounds[OTHER_FRAME].getWidth()/2; 475 loc.y += serverBounds[OTHER_FRAME].getHeight()/2; 476 robot.mouseMove(loc.x, loc.y); 477 robot.mousePress(InputEvent.BUTTON1_MASK); 478 robot.delay(50); 479 robot.mouseRelease(InputEvent.BUTTON1_MASK); 480 waitWindowDeactivated(res); 481 return res; 482 } 483 private int focusServer() { 484 xembedLog.fine("Focusing server"); 485 boolean weFocused = focused; 486 int res = getEventPos(); 487 Point loc = serverBounds[SERVER_FOCUS].getLocation(); 488 loc.x += 5; 489 loc.y += 5; 490 robot.mouseMove(loc.x, loc.y); 491 robot.mousePress(InputEvent.BUTTON1_MASK); 492 robot.delay(50); 493 robot.mouseRelease(InputEvent.BUTTON1_MASK); 494 if (weFocused) { 495 waitFocusLost(res); 496 } 497 return res; 498 } 499 private int focusServerNext() { 500 xembedLog.fine("Focusing next server component"); 501 int res = getEventPos(); 502 sendMessage(XEmbedHelper.XEMBED_FOCUS_NEXT); 503 waitFocusLost(res); 504 return res; 505 } 506 private int focusServerPrev() { 507 xembedLog.fine("Focusing previous server component"); 508 int res = getEventPos(); 509 sendMessage(XEmbedHelper.XEMBED_FOCUS_PREV); 510 waitFocusLost(res); 511 return res; 512 } 513 514 private void waitEmbeddedNotify(int pos) { 515 waitForEvent(pos, XEmbedHelper.XEMBED_EMBEDDED_NOTIFY); 516 } 517 private void waitFocusGained(int pos) { 518 waitForEvent(pos, XEmbedHelper.XEMBED_FOCUS_IN); 519 } 520 private void waitFocusLost(int pos) { 521 waitForEvent(pos, XEmbedHelper.XEMBED_FOCUS_OUT); 522 } 523 private void waitWindowActivated(int pos) { 524 waitForEvent(pos, XEmbedHelper.XEMBED_WINDOW_ACTIVATE); 525 } 526 private void waitWindowDeactivated(int pos) { 527 waitForEvent(pos, XEmbedHelper.XEMBED_WINDOW_DEACTIVATE); 528 } 529 530 private void waitSystemEvent(int position, int event) { 531 waitForEvent(position, event | SYSTEM_EVENT_MASK); 532 } 533 534 private void waitForEvent(int position, int event) { 535 synchronized(EVENT_LOCK) { 536 // Check for already received events after the request 537 if (checkEventList(position, event) != -1) { 538 if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) { 539 xembedLog.finer("The event " + XEmbedHelper.msgidToString(event) + " has already been received"); 540 } 541 return; 542 } 543 544 if (eventReceived == event) { 545 // Already received 546 if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) { 547 xembedLog.finer("Already received " + XEmbedHelper.msgidToString(event)); 548 } 549 return; 550 } 551 eventReceived = -1; 552 eventWaited = event; 553 if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) { 554 xembedLog.finer("Waiting for " + XEmbedHelper.msgidToString(event) + " starting from " + position); 555 } 556 try { 557 EVENT_LOCK.wait(3000); 558 } catch (InterruptedException ie) { 559 xembedLog.warning("Event wait interrupted", ie); 560 } 561 eventWaited = -1; 562 if (checkEventList(position, event) == -1) { 563 dumpReceivedEvents(); 564 throw new RuntimeException("Didn't receive event " + XEmbedHelper.msgidToString(event) + " but recevied " + XEmbedHelper.msgidToString(eventReceived)); 565 } else { 566 if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) { 567 xembedLog.finer("Successfully recevied " + XEmbedHelper.msgidToString(event)); 568 } 569 } 570 } 571 } 572 /** 573 * Checks if the <code>event</code> is already in a list at position >= <code>position</code> 574 */ 575 private int checkEventList(int position, int event) { 576 if (position == -1) { 577 return -1; 578 } 579 synchronized(EVENT_LOCK) { 580 for (int i = position; i < events.size(); i++) { 581 if (events.get(i) == event) { 582 return i; 583 } 584 } 585 return -1; 586 } 587 } 588 589 private void checkFocusedServerNext() { 590 if (focusedServerComponent != 0) { 591 throw new RuntimeException("Wrong focused server component, should be 0, but it is " + focusedServerComponent); 592 } 593 } 594 private void checkFocusedServerPrev() { 595 if (focusedServerComponent != 2) { 596 throw new RuntimeException("Wrong focused server component, should be 2, but it is " + focusedServerComponent); 597 } 598 } 599 private void checkFocusGained(int kind) { 600 if (!focused) { 601 throw new RuntimeException("Didn't receive FOCUS_GAINED"); 602 } 603 if (focusedKind != kind) { 604 throw new RuntimeException("Kinds don't match, required: " + kind + ", current: " + focusedKind); 605 } 606 } 607 private void checkNotFocused() { 608 if (focused) { 609 throw new RuntimeException("Focused"); 610 } 611 } 612 private void checkFocused() { 613 if (!focused) { 614 throw new RuntimeException("Not Focused"); 615 } 616 } 617 618 private void checkFocusLost() { 619 checkNotFocused(); 620 if (focusedKind != XEmbedHelper.XEMBED_FOCUS_OUT) { 621 throw new RuntimeException("Didn't receive FOCUS_LOST"); 622 } 623 } 624 private void checkWindowActivated() { 625 if (!windowActive) { 626 throw new RuntimeException("Window is not active"); 627 } 628 } 629 private void checkMapped() { 630 if (XlibUtil.getWindowMapState(window.getWindow()) == IsUnmapped) { 631 throw new RuntimeException("Client is not mapped"); 632 } 633 } 634 private void checkNotMapped() { 635 if (XlibUtil.getWindowMapState(window.getWindow()) != IsUnmapped) { 636 throw new RuntimeException("Client is mapped"); 637 } 638 } 639 640 private void sendMessage(int message) { 641 xembed.sendMessage(parent, message); 642 } 643 private void sendMessage(int message, int detail, long data1, long data2) { 644 xembed.sendMessage(parent, message, detail, data1, data2); 645 } 646 647 public void dispatchEvent(XEvent ev) { 648 if (ev.get_type() == ClientMessage) { 649 XClientMessageEvent msg = ev.get_xclient(); 650 if (msg.get_message_type() == xembed.XEmbed.getAtom()) { 651 if (xembedLog.isLoggable(PlatformLogger.Level.FINE)) { 652 xembedLog.fine("Embedded message: " + XEmbedHelper.msgidToString((int)msg.get_data(1))); 653 } 654 switch ((int)msg.get_data(1)) { 655 case XEmbedHelper.XEMBED_EMBEDDED_NOTIFY: // Notification about embedding protocol start 656 xembedActive = true; 657 server_version = (int)msg.get_data(3); 658 break; 659 case XEmbedHelper.XEMBED_WINDOW_ACTIVATE: 660 windowActive = true; 661 break; 662 case XEmbedHelper.XEMBED_WINDOW_DEACTIVATE: 663 windowActive = false; 664 break; 665 case XEmbedHelper.XEMBED_FOCUS_IN: // We got focus! 666 focused = true; 667 focusedKind = (int)msg.get_data(2); 668 break; 669 case XEmbedHelper.XEMBED_FOCUS_OUT: 670 focused = false; 671 focusedKind = XEmbedHelper.XEMBED_FOCUS_OUT; 672 focusedServerComponent = (int)msg.get_data(2); 673 break; 674 } 675 synchronized(EVENT_LOCK) { 676 events.add((int)msg.get_data(1)); 677 678 if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) { 679 xembedLog.finer("Tester is waiting for " + XEmbedHelper.msgidToString(eventWaited)); 680 } 681 if ((int)msg.get_data(1) == eventWaited) { 682 eventReceived = (int)msg.get_data(1); 683 if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) { 684 xembedLog.finer("Notifying waiting object for event " + System.identityHashCode(EVENT_LOCK)); 685 } 686 EVENT_LOCK.notifyAll(); 687 } 688 } 689 } 690 } else { 691 synchronized(EVENT_LOCK) { 692 int eventID = (int)ev.get_type() | SYSTEM_EVENT_MASK; 693 events.add(eventID); 694 695 if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) { 696 xembedLog.finer("Tester is waiting for " + XEmbedHelper.msgidToString(eventWaited) + ", but we received " + ev + "(" + XEmbedHelper.msgidToString(eventID) + ")"); 697 } 698 if (eventID == eventWaited) { 699 eventReceived = eventID; 700 if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) { 701 xembedLog.finer("Notifying waiting object" + System.identityHashCode(EVENT_LOCK)); 702 } 703 EVENT_LOCK.notifyAll(); 704 } 705 } 706 } 707 } 708 709 private void sleep(int amount) { 710 try { 711 Thread.sleep(amount); 712 } catch (Exception e) { 713 } 714 } 715 716 private void registerAccelerator() { 717 sendMessage(XEmbedHelper.XEMBED_REGISTER_ACCELERATOR, 1, accel_keysym, accel_mods); 718 } 719 720 private void unregisterAccelerator() { 721 sendMessage(XEmbedHelper.XEMBED_UNREGISTER_ACCELERATOR, 1, 0, 0); 722 } 723 724 private int pressAccelKey() { 725 int res = getEventPos(); 726 robot.keyPress(accel_key); 727 robot.keyRelease(accel_key); 728 return res; 729 } 730 731 private void initAccel() { 732 accel_key = KeyEvent.VK_A; 733 accel_keysym = XWindow.getKeySymForAWTKeyCode(accel_key); 734 accel_mods = 0; 735 } 736 737 private void grabKey() { 738 sendMessage(XEmbedHelper.NON_STANDARD_XEMBED_GTK_GRAB_KEY, 0, accel_keysym, accel_mods); 739 } 740 private void ungrabKey() { 741 sendMessage(XEmbedHelper.NON_STANDARD_XEMBED_GTK_UNGRAB_KEY, 0, accel_keysym, accel_mods); 742 } 743 private int showModalDialog() { 744 xembedLog.fine("Showing modal dialog"); 745 int res = getEventPos(); 746 Point loc = serverBounds[SERVER_MODAL].getLocation(); 747 loc.x += 5; 748 loc.y += 5; 749 robot.mouseMove(loc.x, loc.y); 750 robot.mousePress(InputEvent.BUTTON1_MASK); 751 robot.delay(50); 752 robot.mouseRelease(InputEvent.BUTTON1_MASK); 753 return res; 754 } 755 private int hideModalDialog() { 756 xembedLog.fine("Hide modal dialog"); 757 int res = getEventPos(); 758 // Point loc = serverBounds[MODAL_CLOSE].getLocation(); 759 // loc.x += 5; 760 // loc.y += 5; 761 // robot.mouseMove(loc.x, loc.y); 762 // robot.mousePress(InputEvent.BUTTON1_MASK); 763 // robot.delay(50); 764 // robot.mouseRelease(InputEvent.BUTTON1_MASK); 765 robot.keyPress(KeyEvent.VK_SPACE); 766 robot.keyRelease(KeyEvent.VK_SPACE); 767 return res; 768 } 769 770 }