test fixed for the case when the *@$ing VCSRefresh activity suddenly stomped in, started modal progress and consumed all events via IdeEventQueue.pumpEventsForHierarchy

This commit is contained in:
Alexey Kudravtsev
2017-03-21 15:37:31 +03:00
parent c9a8508c0f
commit 041a0b47e9
@@ -19,6 +19,7 @@ import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.util.ReflectionUtil;
import com.intellij.util.ui.UIUtil;
import gnu.trove.THashSet;
import javax.swing.*;
import java.awt.*;
@@ -26,6 +27,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.InvocationEvent;
import java.awt.event.KeyEvent;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
public class IdeEventQueueTest extends PlatformTestCase {
@@ -44,11 +46,12 @@ public class IdeEventQueueTest extends PlatformTestCase {
public void testKeyboardEventsAreDetected() throws InterruptedException {
assertTrue(EventQueue.isDispatchThread());
IdeEventQueue ideEventQueue = IdeEventQueue.getInstance();
assertSame(ideEventQueue, Toolkit.getDefaultToolkit().getSystemEventQueue());
PlatformTestUtil.dispatchAllEventsInIdeEventQueue();
Set<AWTEvent> isDispatched = new THashSet<>();
ideEventQueue.addDispatcher(e -> {
isDispatched.add(e);
LOG.debug("dispatch: "+e);
return false;
}, getTestRootDisposable());
@@ -67,7 +70,9 @@ public class IdeEventQueueTest extends PlatformTestCase {
postCarefully(pressX);
assertEquals(posted+1, ideEventQueue.myKeyboardEventsPosted.get());
assertEquals(dispatched, ideEventQueue.myKeyboardEventsDispatched.get());
assertEquals(pressX, dispatchAllInvocationEventsUntilOtherEvent(ideEventQueue));
dispatchAllInvocationEventsUntilOtherEvent(ideEventQueue);
// either it's dispatched by this method or the f*@$ing VCSRefresh activity stomped in, started modal progress and consumed all events via IdeEventQueue.pumpEventsForHierarchy
assertTrue(isDispatched.contains(pressX) || isConsumed(pressX));
assertEquals(posted+1, ideEventQueue.myKeyboardEventsPosted.get());
assertEquals(dispatched+1, ideEventQueue.myKeyboardEventsDispatched.get());
@@ -89,7 +94,9 @@ public class IdeEventQueueTest extends PlatformTestCase {
assertEquals(posted+2, ideEventQueue.myKeyboardEventsPosted.get());
assertEquals(dispatched+1, ideEventQueue.myKeyboardEventsDispatched.get());
assertEquals(keyRelease, dispatchAllInvocationEventsUntilOtherEvent(ideEventQueue));
dispatchAllInvocationEventsUntilOtherEvent(ideEventQueue);
// either it's dispatched by this method or the f*@$ing VCSRefresh activity stomped in, started modal progress and consumed all events via IdeEventQueue.pumpEventsForHierarchy
assertTrue(isDispatched.contains(keyRelease) || isConsumed(keyRelease));
assertEquals(posted+2, ideEventQueue.myKeyboardEventsPosted.get());
assertEquals(dispatched+2, ideEventQueue.myKeyboardEventsDispatched.get());
@@ -104,6 +111,9 @@ public class IdeEventQueueTest extends PlatformTestCase {
assertEquals(mustBeConsumed, ReflectionUtil.getField(AWTEvent.class, event, boolean.class, "consumed").booleanValue());
assertTrue(ReflectionUtil.getField(AWTEvent.class, event, boolean.class, "isPosted"));
}
private boolean isConsumed(InputEvent event) {
return event.isConsumed();
}
// need this because everybody can post some crazy stuff to IdeEventQueue, so we have to filter InvocationEvents out
private static AWTEvent dispatchAllInvocationEventsUntilOtherEvent(IdeEventQueue ideEventQueue) throws InterruptedException {