Skip to content

Commit 26235b2

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
1 parent 1eabfa3 commit 26235b2

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.io.IOException;
2727
import java.util.ArrayList;
2828
import java.util.List;
29+
import java.util.concurrent.atomic.AtomicBoolean;
2930

3031
import org.eclipse.swt.SWT;
3132
import org.eclipse.swt.events.SelectionAdapter;
@@ -43,6 +44,7 @@
4344
import org.eclipse.swt.widgets.Shell;
4445
import org.eclipse.swt.widgets.Text;
4546
import org.junit.jupiter.api.BeforeEach;
47+
import org.junit.jupiter.api.RepeatedTest;
4648
import org.junit.jupiter.api.Test;
4749

4850
/**
@@ -652,21 +654,33 @@ public void test_setBoundsLorg_eclipse_swt_graphics_Rectangle() {
652654
* Regression test for Bug 436841 - [GTK3] FocusOut/In and Activate/Deactivate
653655
* events when opening context menu. Only applicable on GTK x11.
654656
*/
655-
@Test
656-
public void test_activateEventSend() {
657+
@RepeatedTest(value = 1000)
658+
public void test_activateEventSend() throws InterruptedException {
657659
if (SwtTestUtil.isGTK && SwtTestUtil.isX11) {
660+
AtomicBoolean activateCalled = new AtomicBoolean();
661+
AtomicBoolean deactivateCalled = new AtomicBoolean();
658662
Shell testShell = new Shell(shell, SWT.SHELL_TRIM);
659663
testShell.addListener(SWT.Activate, e -> {
660-
listenerCalled = true;
664+
activateCalled.set(true);
665+
});
666+
testShell.addListener(SWT.Deactivate, e -> {
667+
deactivateCalled.set(true);
661668
});
669+
activateCalled.set(false);
662670
testShell.open();
671+
SwtTestUtil.processEvents(10000, () -> activateCalled.get());
672+
assertTrue(activateCalled.get());
663673
int[] styles = {SWT.ON_TOP, SWT.APPLICATION_MODAL, SWT.PRIMARY_MODAL, SWT.SYSTEM_MODAL, SWT.NO_TRIM, SWT.BORDER, SWT.SHELL_TRIM};
664674
for (int style : styles) {
675+
deactivateCalled.set(false);
665676
Shell childShell = new Shell(testShell, style);
666-
listenerCalled = false;
667677
childShell.open();
678+
SwtTestUtil.processEvents(10000, () -> deactivateCalled.get());
679+
assertTrue(deactivateCalled.get());
680+
activateCalled.set(false);
668681
childShell.dispose();
669-
assertTrue(listenerCalled);
682+
SwtTestUtil.processEvents(10000, () -> activateCalled.get());
683+
assertTrue(activateCalled.get());
670684
}
671685
}
672686
}

0 commit comments

Comments
 (0)