|
22 | 22 | import static org.junit.jupiter.api.Assertions.assertSame;
|
23 | 23 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
24 | 24 | import static org.junit.jupiter.api.Assertions.fail;
|
| 25 | +import static org.junit.jupiter.api.Assumptions.assumeTrue; |
25 | 26 |
|
26 | 27 | import java.io.IOException;
|
27 | 28 | import java.util.ArrayList;
|
28 | 29 | import java.util.List;
|
| 30 | +import java.util.concurrent.atomic.AtomicBoolean; |
29 | 31 |
|
30 | 32 | import org.eclipse.swt.SWT;
|
31 | 33 | import org.eclipse.swt.events.SelectionAdapter;
|
@@ -653,21 +655,48 @@ public void test_setBoundsLorg_eclipse_swt_graphics_Rectangle() {
|
653 | 655 | * events when opening context menu. Only applicable on GTK x11.
|
654 | 656 | */
|
655 | 657 | @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()); |
671 | 700 | }
|
672 | 701 | }
|
673 | 702 |
|
|
0 commit comments