Skip to content

Commit 6777ba1

Browse files
committed
Process events until parent shell is activated
It may take some event cycles before the parent shell that is getting focus/activation back gets the notification. Therefore wait until the Activate listener is called This test had bitrotten due to order of operation issues, see #2591 for details on that. This test was a regression test for https://bugs.eclipse.org/436841, but only tested 1 of the 4 events. I added to the test all the events. The test was also written before GTK4 (???) and was disabled on non-x11. The test is now enabled on x11.
1 parent 1eabfa3 commit 6777ba1

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Shell.java

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
import static org.junit.jupiter.api.Assertions.assertSame;
2323
import static org.junit.jupiter.api.Assertions.assertTrue;
2424
import static org.junit.jupiter.api.Assertions.fail;
25+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2526

2627
import java.io.IOException;
2728
import java.util.ArrayList;
2829
import java.util.List;
30+
import java.util.concurrent.atomic.AtomicBoolean;
2931

3032
import org.eclipse.swt.SWT;
3133
import org.eclipse.swt.events.SelectionAdapter;
@@ -653,21 +655,48 @@ public void test_setBoundsLorg_eclipse_swt_graphics_Rectangle() {
653655
* events when opening context menu. Only applicable on GTK x11.
654656
*/
655657
@Test
656-
public void test_activateEventSend() {
657-
if (SwtTestUtil.isGTK && SwtTestUtil.isX11) {
658-
Shell testShell = new Shell(shell, SWT.SHELL_TRIM);
659-
testShell.addListener(SWT.Activate, e -> {
660-
listenerCalled = true;
661-
});
662-
testShell.open();
663-
int[] styles = {SWT.ON_TOP, SWT.APPLICATION_MODAL, SWT.PRIMARY_MODAL, SWT.SYSTEM_MODAL, SWT.NO_TRIM, SWT.BORDER, SWT.SHELL_TRIM};
664-
for (int style : styles) {
665-
Shell childShell = new Shell(testShell, style);
666-
listenerCalled = false;
667-
childShell.open();
668-
childShell.dispose();
669-
assertTrue(listenerCalled);
670-
}
658+
public void test_activateEventSend() throws InterruptedException {
659+
assumeTrue((SwtTestUtil.isGTK && SwtTestUtil.isX11) || SwtTestUtil.isGTK4,
660+
"Feature only works on GTK3 in x11 or GTK4 - https://bugs.eclipse.org/436841");
661+
662+
AtomicBoolean activateCalled = new AtomicBoolean();
663+
AtomicBoolean deactivateCalled = new AtomicBoolean();
664+
AtomicBoolean focusInCalled = new AtomicBoolean();
665+
AtomicBoolean focusOutCalled = new AtomicBoolean();
666+
Shell testShell = new Shell(shell, SWT.SHELL_TRIM);
667+
testShell.addListener(SWT.Activate, e -> {
668+
activateCalled.set(true);
669+
});
670+
testShell.addListener(SWT.FocusIn, e -> {
671+
focusInCalled.set(true);
672+
});
673+
testShell.addListener(SWT.Deactivate, e -> {
674+
deactivateCalled.set(true);
675+
});
676+
testShell.addListener(SWT.FocusOut, e -> {
677+
focusOutCalled.set(true);
678+
});
679+
activateCalled.set(false);
680+
testShell.open();
681+
SwtTestUtil.processEvents(10000, () -> activateCalled.get() && focusInCalled.get());
682+
assertTrue(activateCalled.get());
683+
assertTrue(focusInCalled.get());
684+
int[] styles = { SWT.ON_TOP, SWT.APPLICATION_MODAL, SWT.PRIMARY_MODAL, SWT.SYSTEM_MODAL, SWT.NO_TRIM, SWT.BORDER,
685+
SWT.SHELL_TRIM };
686+
for (int style : styles) {
687+
deactivateCalled.set(false);
688+
focusOutCalled.set(false);
689+
Shell childShell = new Shell(testShell, style);
690+
childShell.open();
691+
SwtTestUtil.processEvents(10000, () -> deactivateCalled.get() && focusOutCalled.get());
692+
assertTrue(deactivateCalled.get());
693+
assertTrue(focusOutCalled.get());
694+
activateCalled.set(false);
695+
focusInCalled.set(false);
696+
childShell.dispose();
697+
SwtTestUtil.processEvents(10000, () -> activateCalled.get() && focusInCalled.get());
698+
assertTrue(activateCalled.get());
699+
assertTrue(focusInCalled.get());
671700
}
672701
}
673702

0 commit comments

Comments
 (0)