From 1c392f3c142a79ac0e29c3adffd1b7472e665342 Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Tue, 11 Oct 2022 17:41:59 -0400 Subject: [PATCH] Test fixes for updated mouse event handling --- .../generic/test/AbstractGenericTest.java | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/Ghidra/Framework/Generic/src/main/java/generic/test/AbstractGenericTest.java b/Ghidra/Framework/Generic/src/main/java/generic/test/AbstractGenericTest.java index c5fae10fef..1e4939ece0 100644 --- a/Ghidra/Framework/Generic/src/main/java/generic/test/AbstractGenericTest.java +++ b/Ghidra/Framework/Generic/src/main/java/generic/test/AbstractGenericTest.java @@ -967,16 +967,15 @@ public abstract class AbstractGenericTest extends AbstractGTest { public static void clickMouse(Component comp, int button, int x, int y, int clickCount, int modifiers, boolean popupTrigger) { - int updatedModifiers = convertToExtendedModifiers(modifiers, button); - + int nonRelesedModifiers = convertToExtendedModifiers(modifiers, button, false); + int relesedModifiers = convertToExtendedModifiers(modifiers, button, true); for (int cnt = 1; cnt <= clickCount; ++cnt) { - postEvent(new MouseEvent(comp, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), - updatedModifiers, x, y, cnt, false, button)); + nonRelesedModifiers, x, y, cnt, false, button)); postEvent(new MouseEvent(comp, MouseEvent.MOUSE_CLICKED, System.currentTimeMillis(), - updatedModifiers, x, y, cnt, false, button)); + nonRelesedModifiers, x, y, cnt, false, button)); postEvent(new MouseEvent(comp, MouseEvent.MOUSE_RELEASED, System.currentTimeMillis(), - updatedModifiers, x, y, cnt, popupTrigger, button)); + relesedModifiers, x, y, cnt, popupTrigger, button)); } } @@ -1010,13 +1009,14 @@ public abstract class AbstractGenericTest extends AbstractGTest { public static void dragMouse(final Component comp, int button, final int startX, final int startY, final int endX, final int endY, int modifiers) { - int updateModifiers = convertToExtendedModifiers(modifiers, button); + int nonRelesedModifiers = convertToExtendedModifiers(modifiers, button, false); + int relesedModifiers = convertToExtendedModifiers(modifiers, button, true); postEvent(new MouseEvent(comp, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), - updateModifiers, startX, startY, 1, false, button)); + nonRelesedModifiers, startX, startY, 1, false, button)); postEvent(new MouseEvent(comp, MouseEvent.MOUSE_DRAGGED, System.currentTimeMillis(), - updateModifiers, endX, endY, 1, false, button)); + nonRelesedModifiers, endX, endY, 1, false, button)); postEvent(new MouseEvent(comp, MouseEvent.MOUSE_RELEASED, System.currentTimeMillis(), - updateModifiers, endX, endY, 1, false, button)); + relesedModifiers, endX, endY, 1, false, button)); } @@ -1034,7 +1034,7 @@ public abstract class AbstractGenericTest extends AbstractGTest { } @SuppressWarnings("deprecation") - private static int convertToExtendedModifiers(int modifiers, int button) { + private static int convertToExtendedModifiers(int modifiers, int button, boolean isRelease) { // TODO: Eliminate duplication of similar modifier modification logic // which exists in KeyBindingData @@ -1073,16 +1073,22 @@ public abstract class AbstractGenericTest extends AbstractGTest { modifiers = modifiers | InputEvent.META_DOWN_MASK; } - switch (button) { - case 1: - modifiers |= InputEvent.BUTTON1_DOWN_MASK; - break; - case 2: - modifiers |= InputEvent.BUTTON2_DOWN_MASK; - break; - case 3: - modifiers |= InputEvent.BUTTON3_DOWN_MASK; - break; + if (!isRelease) { + // + // There are no mouse buttons down on a 'release' in Java's extended event processing. + // (The original non-extended events did include the button in the release event.) + // + switch (button) { + case 1: + modifiers |= InputEvent.BUTTON1_DOWN_MASK; + break; + case 2: + modifiers |= InputEvent.BUTTON2_DOWN_MASK; + break; + case 3: + modifiers |= InputEvent.BUTTON3_DOWN_MASK; + break; + } } return modifiers; }