|
73 | 73 | import org.eclipse.swt.browser.VisibilityWindowAdapter;
|
74 | 74 | import org.eclipse.swt.browser.VisibilityWindowListener;
|
75 | 75 | import org.eclipse.swt.browser.WindowEvent;
|
| 76 | +import org.eclipse.swt.events.FocusListener; |
76 | 77 | import org.eclipse.swt.graphics.Point;
|
77 | 78 | import org.eclipse.swt.layout.FillLayout;
|
78 | 79 | import org.eclipse.swt.widgets.Display;
|
| 80 | +import org.eclipse.swt.widgets.Event; |
79 | 81 | import org.eclipse.swt.widgets.Shell;
|
| 82 | +import org.eclipse.swt.widgets.Text; |
80 | 83 | import org.junit.Before;
|
81 | 84 | import org.junit.FixMethodOrder;
|
82 | 85 | import org.junit.Rule;
|
@@ -2575,6 +2578,41 @@ public void completed(ProgressEvent event) {
|
2575 | 2578 | browser2.dispose();
|
2576 | 2579 | }
|
2577 | 2580 |
|
| 2581 | +@Test |
| 2582 | +public void test_TabTraversalOutOfBrowser() { |
| 2583 | + assumeFalse("Not currently working on macOS, see https://github.com/eclipse-platform/eclipse.platform.swt/issues/1644", SwtTestUtil.isCocoa); |
| 2584 | + assumeFalse("Not currently working on Linux, see https://github.com/eclipse-platform/eclipse.platform.swt/issues/1644", SwtTestUtil.isGTK); |
| 2585 | + |
| 2586 | + Text text = new Text(shell, SWT.NONE); |
| 2587 | + |
| 2588 | + // open and immediately set focus. this test therefore also covers |
| 2589 | + // https://github.com/eclipse-platform/eclipse.platform.swt/issues/1640 |
| 2590 | + shell.open(); |
| 2591 | + browser.forceFocus(); |
| 2592 | + |
| 2593 | + // wait for browser to fully load |
| 2594 | + AtomicBoolean changedFired = new AtomicBoolean(false); |
| 2595 | + browser.addLocationListener(changedAdapter(e -> changedFired.set(true))); |
| 2596 | + browser.setText("Hello world"); |
| 2597 | + assertTrue("LocationListener.changed() event was never fired", waitForPassCondition(changedFired::get)); |
| 2598 | + |
| 2599 | + // browser should have focus |
| 2600 | + assertTrue(browser.isFocusControl()); |
| 2601 | + assertFalse(text.isFocusControl()); |
| 2602 | + |
| 2603 | + // send tab key via low-level event -> focus should move to Text control |
| 2604 | + AtomicBoolean textGainedFocus = new AtomicBoolean(false); |
| 2605 | + text.addFocusListener(FocusListener.focusGainedAdapter(e -> textGainedFocus.set(true))); |
| 2606 | + Event event = new Event(); |
| 2607 | + event.type = SWT.KeyDown; |
| 2608 | + event.keyCode = SWT.TAB; |
| 2609 | + Display.getDefault().post(event); |
| 2610 | + |
| 2611 | + // focus should move to Text |
| 2612 | + assertTrue("Text did not gain focus", waitForPassCondition(textGainedFocus::get)); |
| 2613 | + assertFalse(browser.isFocusControl()); |
| 2614 | + assertTrue(text.isFocusControl()); |
| 2615 | +} |
2578 | 2616 |
|
2579 | 2617 | /* custom */
|
2580 | 2618 | /**
|
|
0 commit comments