0N/A/*
2362N/A * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.awt.X11;
0N/A
0N/A//import static sun.awt.X11.XEmbed.*;
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
1696N/Aimport sun.util.logging.PlatformLogger;
0N/Aimport static sun.awt.X11.XConstants.*;
0N/Aimport java.util.LinkedList;
0N/A
0N/A/**
0N/A * Test XEmbed server implementation. See file:///home/dom/bugs/4931668/test_plan.html for
0N/A * specification and references.
0N/A */
0N/Apublic class XEmbedServerTester implements XEventDispatcher {
1696N/A private static final PlatformLogger xembedLog = PlatformLogger.getLogger("sun.awt.X11.xembed.XEmbedServerTester");
0N/A private final Object EVENT_LOCK = new Object();
0N/A static final int SYSTEM_EVENT_MASK = 0x8000;
0N/A int my_version, server_version;
0N/A XEmbedHelper xembed = new XEmbedHelper();
0N/A boolean focused;
0N/A int focusedKind;
0N/A int focusedServerComponent;
0N/A boolean reparent;
0N/A long parent;
0N/A boolean windowActive;
0N/A boolean xembedActive;
0N/A XBaseWindow window;
0N/A volatile int eventWaited = -1, eventReceived = -1;
0N/A int mapped;
0N/A int accel_key, accel_keysym, accel_mods;
0N/A static Rectangle initialBounds = new Rectangle(0, 0, 100, 100);
0N/A Robot robot;
0N/A Rectangle serverBounds[]; // first rectangle is for the server frame, second is for dummy frame, others are for its children
0N/A private static final int SERVER_BOUNDS = 0, OTHER_FRAME = 1, SERVER_FOCUS = 2, SERVER_MODAL = 3, MODAL_CLOSE = 4;
0N/A
0N/A LinkedList<Integer> events = new LinkedList<Integer>();
0N/A
0N/A private XEmbedServerTester(Rectangle serverBounds[], long parent) {
0N/A this.parent = parent;
0N/A focusedKind = -1;
0N/A focusedServerComponent = -1;
0N/A reparent = false;
0N/A windowActive = false;
0N/A xembedActive = false;
0N/A my_version = XEmbedHelper.XEMBED_VERSION;
0N/A mapped = XEmbedHelper.XEMBED_MAPPED;
0N/A this.serverBounds = serverBounds;
0N/A if (serverBounds.length < 5) {
0N/A throw new IllegalArgumentException("There must be at least five areas: server-activation, server-deactivation, server-focus, " +
0N/A "server-modal show, modal-close");
0N/A }
0N/A try {
0N/A robot = new Robot();
0N/A robot.setAutoDelay(100);
0N/A } catch (Exception e) {
0N/A throw new RuntimeException("Can't create robot");
0N/A }
0N/A initAccel();
0N/A xembedLog.finer("XEmbed client(tester), embedder window: " + Long.toHexString(parent));
0N/A }
0N/A
0N/A public static XEmbedServerTester getTester(Rectangle serverBounds[], long parent) {
0N/A return new XEmbedServerTester(serverBounds, parent);
0N/A }
0N/A
0N/A private void dumpReceivedEvents() {
0N/A xembedLog.finer("Events received so far:");
0N/A int pos = 0;
0N/A for (Integer event : events) {
0N/A xembedLog.finer((pos++) + ":" + XEmbedHelper.msgidToString(event));
0N/A }
0N/A xembedLog.finer("End of event dump");
0N/A }
0N/A
0N/A public void test1_1() {
0N/A int res = embedCompletely();
0N/A waitWindowActivated(res);
0N/A requestFocus();
0N/A deactivateServer();
0N/A res = activateServer(getEventPos());
0N/A waitFocusGained(res);
0N/A checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT);
0N/A }
0N/A
0N/A public void test1_2() {
0N/A int res = embedCompletely();
0N/A waitWindowActivated(res);
0N/A requestFocus();
0N/A checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT);
0N/A }
0N/A
0N/A public void test1_3() {
0N/A embedCompletely();
0N/A deactivateServer();
0N/A requestFocusNoWait();
0N/A checkNotFocused();
0N/A }
0N/A
0N/A public void test1_4() {
0N/A embedCompletely();
0N/A deactivateServer();
0N/A requestFocusNoWait();
0N/A checkNotFocused();
0N/A int res = getEventPos();
0N/A activateServer(res);
0N/A waitFocusGained(res);
0N/A checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT);
0N/A }
0N/A
0N/A public void test1_5() {
0N/A int res = embedCompletely();
0N/A waitWindowActivated(res);
0N/A checkWindowActivated();
0N/A }
0N/A
0N/A public void test1_6() {
0N/A int res = embedCompletely();
0N/A waitWindowActivated(res);
0N/A requestFocus();
0N/A res = deactivateServer();
0N/A checkFocused();
0N/A }
0N/A
0N/A public void test1_7() {
0N/A int res = embedCompletely();
0N/A waitWindowActivated(res);
0N/A requestFocus();
0N/A focusServer();
0N/A checkFocusLost();
0N/A }
0N/A
0N/A public void test2_5() {
0N/A int res = embedCompletely();
0N/A waitWindowActivated(res);
0N/A requestFocus();
0N/A focusServerNext();
0N/A checkFocusedServerNext();
0N/A checkFocusLost();
0N/A }
0N/A
0N/A public void test2_6() {
0N/A int res = embedCompletely();
0N/A waitWindowActivated(res);
0N/A requestFocus();
0N/A focusServerPrev();
0N/A checkFocusedServerPrev();
0N/A checkFocusLost();
0N/A }
0N/A
0N/A public void test3_1() {
0N/A reparent = false;
0N/A embedCompletely();
0N/A }
0N/A
0N/A public void test3_3() {
0N/A reparent = true;
0N/A embedCompletely();
0N/A }
0N/A
0N/A public void test3_4() {
0N/A my_version = 10;
0N/A embedCompletely();
0N/A if (server_version != XEmbedHelper.XEMBED_VERSION) {
0N/A throw new RuntimeException("Version " + server_version + " is not minimal");
0N/A }
0N/A }
0N/A
0N/A public void test3_5() {
0N/A embedCompletely();
0N/A
0N/A window.destroy();
0N/A // TODO: how can we detect that XEmbed ended? So far we are
0N/A // just checking that XEmbed server won't end up with an
0N/A // exception, which should end up testing, hopefully.
0N/A
0N/A // Sleep before exiting the tester application
0N/A sleep(1000);
0N/A }
0N/A
0N/A public void test3_6() {
0N/A embedCompletely();
0N/A
0N/A sleep(1000);
0N/A XToolkit.awtLock();
0N/A try {
0N/A XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), window.getWindow());
0N/A XlibWrapper.XReparentWindow(XToolkit.getDisplay(), window.getWindow(), XToolkit.getDefaultRootWindow(), 0, 0);
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A
0N/A int res = getEventPos();
0N/A
0N/A activateServerNoWait(res);
0N/A
0N/A sleep(1000);
0N/A if (checkEventList(res, XEmbedHelper.XEMBED_WINDOW_ACTIVATE) != -1) {
0N/A throw new RuntimeException("Focus was been given to the client after XEmbed has ended");
0N/A }
0N/A }
0N/A
0N/A public void test4_1() {
0N/A mapped = XEmbedHelper.XEMBED_MAPPED;
0N/A int res = getEventPos();
0N/A embedCompletely();
0N/A sleep(1000);
0N/A checkMapped();
0N/A }
0N/A
0N/A public void test4_2() {
0N/A mapped = 0;
0N/A embedCompletely();
0N/A sleep(1000);
0N/A
0N/A int res = getEventPos();
0N/A mapped = XEmbedHelper.XEMBED_MAPPED;
0N/A updateEmbedInfo();
0N/A sleep(1000);
0N/A checkMapped();
0N/A }
0N/A
0N/A public void test4_3() {
0N/A int res = getEventPos();
0N/A mapped = XEmbedHelper.XEMBED_MAPPED;
0N/A embedCompletely();
0N/A
0N/A res = getEventPos();
0N/A mapped = 0;
0N/A updateEmbedInfo();
0N/A sleep(1000);
0N/A checkNotMapped();
0N/A }
0N/A
0N/A public void test4_4() {
0N/A mapped = 0;
0N/A embedCompletely();
0N/A sleep(1000);
216N/A if (XlibUtil.getWindowMapState(window.getWindow()) != IsUnmapped) {
0N/A throw new RuntimeException("Client has been mapped");
0N/A }
0N/A }
0N/A
0N/A public void test6_1_1() {
0N/A embedCompletely();
0N/A registerAccelerator();
0N/A focusServer();
0N/A int res = pressAccelKey();
0N/A waitForEvent(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR);
0N/A }
0N/A
0N/A public void test6_1_2() {
0N/A embedCompletely();
0N/A registerAccelerator();
0N/A focusServer();
0N/A deactivateServer();
0N/A int res = pressAccelKey();
0N/A sleep(1000);
0N/A if (checkEventList(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR) != -1) {
0N/A throw new RuntimeException("Accelerator has been activated in inactive embedder");
0N/A }
0N/A }
0N/A
0N/A public void test6_1_3() {
0N/A embedCompletely();
0N/A registerAccelerator();
0N/A focusServer();
0N/A deactivateServer();
0N/A unregisterAccelerator();
0N/A int res = pressAccelKey();
0N/A sleep(1000);
0N/A if (checkEventList(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR) != -1) {
0N/A throw new RuntimeException("Accelerator has been activated after unregistering");
0N/A }
0N/A }
0N/A
0N/A public void test6_1_4() {
0N/A embedCompletely();
0N/A registerAccelerator();
0N/A requestFocus();
0N/A int res = pressAccelKey();
0N/A sleep(1000);
0N/A if (checkEventList(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR) != -1) {
0N/A throw new RuntimeException("Accelerator has been activated in focused client");
0N/A }
0N/A }
0N/A public void test6_2_1() {
0N/A embedCompletely();
0N/A grabKey();
0N/A focusServer();
0N/A int res = pressAccelKey();
0N/A waitSystemEvent(res, KeyPress);
0N/A }
0N/A
0N/A public void test6_2_2() {
0N/A embedCompletely();
0N/A grabKey();
0N/A focusServer();
0N/A deactivateServer();
0N/A int res = pressAccelKey();
0N/A sleep(1000);
0N/A if (checkEventList(res, SYSTEM_EVENT_MASK | KeyPress) != -1) {
0N/A throw new RuntimeException("Accelerator has been activated in inactive embedder");
0N/A }
0N/A }
0N/A
0N/A public void test6_2_3() {
0N/A embedCompletely();
0N/A grabKey();
0N/A focusServer();
0N/A deactivateServer();
0N/A ungrabKey();
0N/A int res = pressAccelKey();
0N/A sleep(1000);
0N/A if (checkEventList(res, SYSTEM_EVENT_MASK | KeyPress) != -1) {
0N/A throw new RuntimeException("Accelerator has been activated after unregistering");
0N/A }
0N/A }
0N/A
0N/A public void test6_2_4() {
0N/A embedCompletely();
0N/A grabKey();
0N/A requestFocus();
0N/A int res = pressAccelKey();
0N/A sleep(1000);
0N/A int pos = checkEventList(res, SYSTEM_EVENT_MASK | KeyPress);
0N/A if (pos != -1) {
0N/A pos = checkEventList(pos+1, SYSTEM_EVENT_MASK | KeyPress);
0N/A if (pos != -1) { // Second event
0N/A throw new RuntimeException("Accelerator has been activated in focused client");
0N/A }
0N/A }
0N/A }
0N/A
0N/A public void test7_1() {
0N/A embedCompletely();
0N/A int res = showModalDialog();
0N/A waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_ON);
0N/A }
0N/A
0N/A public void test7_2() {
0N/A embedCompletely();
0N/A int res = showModalDialog();
0N/A waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_ON);
0N/A res = hideModalDialog();
0N/A waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_OFF);
0N/A }
0N/A
0N/A public void test9_1() {
0N/A embedCompletely();
0N/A requestFocus();
0N/A int res = pressAccelKey();
0N/A waitForEvent(res, SYSTEM_EVENT_MASK | KeyPress);
0N/A }
0N/A
0N/A private int embed() {
0N/A int res = getEventPos();
0N/A XToolkit.awtLock();
0N/A try {
0N/A XCreateWindowParams params =
0N/A new XCreateWindowParams(new Object[] {
215N/A XBaseWindow.PARENT_WINDOW, Long.valueOf(reparent?XToolkit.getDefaultRootWindow():parent),
0N/A XBaseWindow.BOUNDS, initialBounds,
0N/A XBaseWindow.EMBEDDED, Boolean.TRUE,
0N/A XBaseWindow.VISIBLE, Boolean.valueOf(mapped == XEmbedHelper.XEMBED_MAPPED),
215N/A XBaseWindow.EVENT_MASK, Long.valueOf(VisibilityChangeMask | StructureNotifyMask |
0N/A SubstructureNotifyMask | KeyPressMask)});
0N/A window = new XBaseWindow(params);
0N/A
0N/A xembedLog.finer("Created tester window: " + window);
0N/A
0N/A XToolkit.addEventDispatcher(window.getWindow(), this);
0N/A updateEmbedInfo();
0N/A if (reparent) {
0N/A xembedLog.finer("Reparenting to embedder");
0N/A XlibWrapper.XReparentWindow(XToolkit.getDisplay(), window.getWindow(), parent, 0, 0);
0N/A }
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A return res;
0N/A }
0N/A
0N/A private void updateEmbedInfo() {
0N/A long[] info = new long[] { my_version, mapped };
0N/A long data = Native.card32ToData(info);
0N/A try {
0N/A XEmbedHelper.XEmbedInfo.setAtomData(window.getWindow(), data, info.length);
0N/A } finally {
0N/A XEmbedHelper.unsafe.freeMemory(data);
0N/A }
0N/A }
0N/A
0N/A private int getEventPos() {
0N/A synchronized(EVENT_LOCK) {
0N/A return events.size();
0N/A }
0N/A }
0N/A
0N/A private int embedCompletely() {
0N/A xembedLog.fine("Embedding completely");
0N/A int res = getEventPos();
0N/A embed();
0N/A waitEmbeddedNotify(res);
0N/A return res;
0N/A }
0N/A private int requestFocus() {
0N/A xembedLog.fine("Requesting focus");
0N/A int res = getEventPos();
0N/A sendMessage(XEmbedHelper.XEMBED_REQUEST_FOCUS);
0N/A waitFocusGained(res);
0N/A return res;
0N/A }
0N/A private int requestFocusNoWait() {
0N/A xembedLog.fine("Requesting focus without wait");
0N/A int res = getEventPos();
0N/A sendMessage(XEmbedHelper.XEMBED_REQUEST_FOCUS);
0N/A return res;
0N/A }
0N/A private int activateServer(int prev) {
0N/A int res = activateServerNoWait(prev);
0N/A waitWindowActivated(res);
0N/A return res;
0N/A }
0N/A private int activateServerNoWait(int prev) {
0N/A xembedLog.fine("Activating server");
0N/A int res = getEventPos();
0N/A if (checkEventList(prev, XEmbedHelper.XEMBED_WINDOW_ACTIVATE) != -1) {
0N/A xembedLog.fine("Activation already received");
0N/A return res;
0N/A }
0N/A Point loc = serverBounds[SERVER_BOUNDS].getLocation();
0N/A loc.x += serverBounds[SERVER_BOUNDS].getWidth()/2;
0N/A loc.y += 5;
0N/A robot.mouseMove(loc.x, loc.y);
0N/A robot.mousePress(InputEvent.BUTTON1_MASK);
0N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
0N/A return res;
0N/A }
0N/A private int deactivateServer() {
0N/A xembedLog.fine("Deactivating server");
0N/A int res = getEventPos();
0N/A Point loc = serverBounds[OTHER_FRAME].getLocation();
0N/A loc.x += serverBounds[OTHER_FRAME].getWidth()/2;
0N/A loc.y += serverBounds[OTHER_FRAME].getHeight()/2;
0N/A robot.mouseMove(loc.x, loc.y);
0N/A robot.mousePress(InputEvent.BUTTON1_MASK);
0N/A robot.delay(50);
0N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
0N/A waitWindowDeactivated(res);
0N/A return res;
0N/A }
0N/A private int focusServer() {
0N/A xembedLog.fine("Focusing server");
0N/A boolean weFocused = focused;
0N/A int res = getEventPos();
0N/A Point loc = serverBounds[SERVER_FOCUS].getLocation();
0N/A loc.x += 5;
0N/A loc.y += 5;
0N/A robot.mouseMove(loc.x, loc.y);
0N/A robot.mousePress(InputEvent.BUTTON1_MASK);
0N/A robot.delay(50);
0N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
0N/A if (weFocused) {
0N/A waitFocusLost(res);
0N/A }
0N/A return res;
0N/A }
0N/A private int focusServerNext() {
0N/A xembedLog.fine("Focusing next server component");
0N/A int res = getEventPos();
0N/A sendMessage(XEmbedHelper.XEMBED_FOCUS_NEXT);
0N/A waitFocusLost(res);
0N/A return res;
0N/A }
0N/A private int focusServerPrev() {
0N/A xembedLog.fine("Focusing previous server component");
0N/A int res = getEventPos();
0N/A sendMessage(XEmbedHelper.XEMBED_FOCUS_PREV);
0N/A waitFocusLost(res);
0N/A return res;
0N/A }
0N/A
0N/A private void waitEmbeddedNotify(int pos) {
0N/A waitForEvent(pos, XEmbedHelper.XEMBED_EMBEDDED_NOTIFY);
0N/A }
0N/A private void waitFocusGained(int pos) {
0N/A waitForEvent(pos, XEmbedHelper.XEMBED_FOCUS_IN);
0N/A }
0N/A private void waitFocusLost(int pos) {
0N/A waitForEvent(pos, XEmbedHelper.XEMBED_FOCUS_OUT);
0N/A }
0N/A private void waitWindowActivated(int pos) {
0N/A waitForEvent(pos, XEmbedHelper.XEMBED_WINDOW_ACTIVATE);
0N/A }
0N/A private void waitWindowDeactivated(int pos) {
0N/A waitForEvent(pos, XEmbedHelper.XEMBED_WINDOW_DEACTIVATE);
0N/A }
0N/A
0N/A private void waitSystemEvent(int position, int event) {
0N/A waitForEvent(position, event | SYSTEM_EVENT_MASK);
0N/A }
0N/A
0N/A private void waitForEvent(int position, int event) {
0N/A synchronized(EVENT_LOCK) {
0N/A // Check for already received events after the request
0N/A if (checkEventList(position, event) != -1) {
0N/A xembedLog.finer("The event " + XEmbedHelper.msgidToString(event) + " has already been received");
0N/A return;
0N/A }
0N/A
0N/A if (eventReceived == event) {
0N/A // Already received
0N/A xembedLog.finer("Already received " + XEmbedHelper.msgidToString(event));
0N/A return;
0N/A }
0N/A eventReceived = -1;
0N/A eventWaited = event;
0N/A xembedLog.finer("Waiting for " + XEmbedHelper.msgidToString(event) + " starting from " + position);
0N/A try {
0N/A EVENT_LOCK.wait(3000);
0N/A } catch (InterruptedException ie) {
1696N/A xembedLog.warning("Event wait interrupted", ie);
0N/A }
0N/A eventWaited = -1;
0N/A if (checkEventList(position, event) == -1) {
0N/A dumpReceivedEvents();
0N/A throw new RuntimeException("Didn't receive event " + XEmbedHelper.msgidToString(event) + " but recevied " + XEmbedHelper.msgidToString(eventReceived));
0N/A } else {
0N/A xembedLog.finer("Successfully recevied " + XEmbedHelper.msgidToString(event));
0N/A }
0N/A }
0N/A }
0N/A /**
0N/A * Checks if the <code>event</code> is already in a list at position >= <code>position</code>
0N/A */
0N/A private int checkEventList(int position, int event) {
0N/A if (position == -1) {
0N/A return -1;
0N/A }
0N/A synchronized(EVENT_LOCK) {
0N/A for (int i = position; i < events.size(); i++) {
0N/A if (events.get(i) == event) {
0N/A return i;
0N/A }
0N/A }
0N/A return -1;
0N/A }
0N/A }
0N/A
0N/A private void checkFocusedServerNext() {
0N/A if (focusedServerComponent != 0) {
0N/A throw new RuntimeException("Wrong focused server component, should be 0, but it is " + focusedServerComponent);
0N/A }
0N/A }
0N/A private void checkFocusedServerPrev() {
0N/A if (focusedServerComponent != 2) {
0N/A throw new RuntimeException("Wrong focused server component, should be 2, but it is " + focusedServerComponent);
0N/A }
0N/A }
0N/A private void checkFocusGained(int kind) {
0N/A if (!focused) {
0N/A throw new RuntimeException("Didn't receive FOCUS_GAINED");
0N/A }
0N/A if (focusedKind != kind) {
0N/A throw new RuntimeException("Kinds don't match, required: " + kind + ", current: " + focusedKind);
0N/A }
0N/A }
0N/A private void checkNotFocused() {
0N/A if (focused) {
0N/A throw new RuntimeException("Focused");
0N/A }
0N/A }
0N/A private void checkFocused() {
0N/A if (!focused) {
0N/A throw new RuntimeException("Not Focused");
0N/A }
0N/A }
0N/A
0N/A private void checkFocusLost() {
0N/A checkNotFocused();
0N/A if (focusedKind != XEmbedHelper.XEMBED_FOCUS_OUT) {
0N/A throw new RuntimeException("Didn't receive FOCUS_LOST");
0N/A }
0N/A }
0N/A private void checkWindowActivated() {
0N/A if (!windowActive) {
0N/A throw new RuntimeException("Window is not active");
0N/A }
0N/A }
0N/A private void checkMapped() {
216N/A if (XlibUtil.getWindowMapState(window.getWindow()) == IsUnmapped) {
0N/A throw new RuntimeException("Client is not mapped");
0N/A }
0N/A }
0N/A private void checkNotMapped() {
216N/A if (XlibUtil.getWindowMapState(window.getWindow()) != IsUnmapped) {
0N/A throw new RuntimeException("Client is mapped");
0N/A }
0N/A }
0N/A
0N/A private void sendMessage(int message) {
0N/A xembed.sendMessage(parent, message);
0N/A }
0N/A private void sendMessage(int message, int detail, long data1, long data2) {
0N/A xembed.sendMessage(parent, message, detail, data1, data2);
0N/A }
0N/A
0N/A public void dispatchEvent(XEvent ev) {
0N/A if (ev.get_type() == ClientMessage) {
0N/A XClientMessageEvent msg = ev.get_xclient();
0N/A if (msg.get_message_type() == xembed.XEmbed.getAtom()) {
1696N/A if (xembedLog.isLoggable(PlatformLogger.FINE)) xembedLog.fine("Embedded message: " + XEmbedHelper.msgidToString((int)msg.get_data(1)));
0N/A switch ((int)msg.get_data(1)) {
0N/A case XEmbedHelper.XEMBED_EMBEDDED_NOTIFY: // Notification about embedding protocol start
0N/A xembedActive = true;
0N/A server_version = (int)msg.get_data(3);
0N/A break;
0N/A case XEmbedHelper.XEMBED_WINDOW_ACTIVATE:
0N/A windowActive = true;
0N/A break;
0N/A case XEmbedHelper.XEMBED_WINDOW_DEACTIVATE:
0N/A windowActive = false;
0N/A break;
0N/A case XEmbedHelper.XEMBED_FOCUS_IN: // We got focus!
0N/A focused = true;
0N/A focusedKind = (int)msg.get_data(2);
0N/A break;
0N/A case XEmbedHelper.XEMBED_FOCUS_OUT:
0N/A focused = false;
0N/A focusedKind = XEmbedHelper.XEMBED_FOCUS_OUT;
0N/A focusedServerComponent = (int)msg.get_data(2);
0N/A break;
0N/A }
0N/A synchronized(EVENT_LOCK) {
0N/A events.add((int)msg.get_data(1));
0N/A
0N/A xembedLog.finer("Tester is waiting for " + XEmbedHelper.msgidToString(eventWaited));
0N/A if ((int)msg.get_data(1) == eventWaited) {
0N/A eventReceived = (int)msg.get_data(1);
0N/A xembedLog.finer("Notifying waiting object for event " + System.identityHashCode(EVENT_LOCK));
0N/A EVENT_LOCK.notifyAll();
0N/A }
0N/A }
0N/A }
0N/A } else {
0N/A synchronized(EVENT_LOCK) {
0N/A int eventID = (int)ev.get_type() | SYSTEM_EVENT_MASK;
0N/A events.add(eventID);
0N/A
0N/A xembedLog.finer("Tester is waiting for " + XEmbedHelper.msgidToString(eventWaited) + ", but we received " + ev + "(" + XEmbedHelper.msgidToString(eventID) + ")");
0N/A if (eventID == eventWaited) {
0N/A eventReceived = eventID;
0N/A xembedLog.finer("Notifying waiting object" + System.identityHashCode(EVENT_LOCK));
0N/A EVENT_LOCK.notifyAll();
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A private void sleep(int amount) {
0N/A try {
0N/A Thread.sleep(amount);
0N/A } catch (Exception e) {
0N/A }
0N/A }
0N/A
0N/A private void registerAccelerator() {
0N/A sendMessage(XEmbedHelper.XEMBED_REGISTER_ACCELERATOR, 1, accel_keysym, accel_mods);
0N/A }
0N/A
0N/A private void unregisterAccelerator() {
0N/A sendMessage(XEmbedHelper.XEMBED_UNREGISTER_ACCELERATOR, 1, 0, 0);
0N/A }
0N/A
0N/A private int pressAccelKey() {
0N/A int res = getEventPos();
0N/A robot.keyPress(accel_key);
0N/A robot.keyRelease(accel_key);
0N/A return res;
0N/A }
0N/A
0N/A private void initAccel() {
0N/A accel_key = KeyEvent.VK_A;
0N/A accel_keysym = XWindow.getKeySymForAWTKeyCode(accel_key);
0N/A accel_mods = 0;
0N/A }
0N/A
0N/A private void grabKey() {
0N/A sendMessage(XEmbedHelper.NON_STANDARD_XEMBED_GTK_GRAB_KEY, 0, accel_keysym, accel_mods);
0N/A }
0N/A private void ungrabKey() {
0N/A sendMessage(XEmbedHelper.NON_STANDARD_XEMBED_GTK_UNGRAB_KEY, 0, accel_keysym, accel_mods);
0N/A }
0N/A private int showModalDialog() {
0N/A xembedLog.fine("Showing modal dialog");
0N/A int res = getEventPos();
0N/A Point loc = serverBounds[SERVER_MODAL].getLocation();
0N/A loc.x += 5;
0N/A loc.y += 5;
0N/A robot.mouseMove(loc.x, loc.y);
0N/A robot.mousePress(InputEvent.BUTTON1_MASK);
0N/A robot.delay(50);
0N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
0N/A return res;
0N/A }
0N/A private int hideModalDialog() {
0N/A xembedLog.fine("Hide modal dialog");
0N/A int res = getEventPos();
0N/A// Point loc = serverBounds[MODAL_CLOSE].getLocation();
0N/A// loc.x += 5;
0N/A// loc.y += 5;
0N/A// robot.mouseMove(loc.x, loc.y);
0N/A// robot.mousePress(InputEvent.BUTTON1_MASK);
0N/A// robot.delay(50);
0N/A// robot.mouseRelease(InputEvent.BUTTON1_MASK);
0N/A robot.keyPress(KeyEvent.VK_SPACE);
0N/A robot.keyRelease(KeyEvent.VK_SPACE);
0N/A return res;
0N/A }
0N/A
0N/A}