Skip to content

Commit 2c07aa7

Browse files
committed
Improve and add assertions for random failing HoverTest #926 #1808
This contributes to fixing the randomly failing HoverTests: - Removes unnecessary focus enforcing: The code checks for the text editor having focus and afterwards uses different methods to force focus to the widget's shell again. This is unnecessary and is only prone to introduce further problems. - Introduces further assertions: in order to better locate the cause of the failing tests, assertions are added for the conditions, on which the execution waits, to be actually fulfilled. - Adds a retry functionality for simulating the hover event. Contributes to #926 Contributes to #1808
1 parent 10d96b5 commit 2c07aa7

File tree

1 file changed

+37
-30
lines changed
  • tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests

1 file changed

+37
-30
lines changed

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
*/
6666
public class HoverTest extends AbstratGenericEditorTest {
6767

68+
private static final int MAXIMUM_HOVER_RETRY_COUNT = 5;
69+
6870
@Rule
6971
public TestName testName= new TestName();
7072

@@ -227,38 +229,43 @@ private Object getHoverData(AbstractInformationControlManager manager) {
227229
}
228230

229231
private AbstractInformationControlManager triggerCompletionAndRetrieveInformationControlManager() {
230-
final int caretLocation= 2;
231-
this.editor.selectAndReveal(caretLocation, 0);
232-
final StyledText editorTextWidget= (StyledText) this.editor.getAdapter(Control.class);
233-
new DisplayHelper() {
234-
@Override
235-
protected boolean condition() {
236-
return editorTextWidget.isFocusControl() && editorTextWidget.getSelection().x == caretLocation;
237-
}
238-
}.waitForCondition(editorTextWidget.getDisplay(), 3000);
239-
// sending event to trigger hover computation
240-
editorTextWidget.getShell().forceActive();
241-
editorTextWidget.getShell().setActive();
242-
editorTextWidget.getShell().setFocus();
243-
editorTextWidget.getShell().getDisplay().wake();
244-
Event hoverEvent= new Event();
245-
hoverEvent.widget= editorTextWidget;
246-
hoverEvent.type= SWT.MouseHover;
247-
hoverEvent.x= editorTextWidget.getClientArea().x + 5;
248-
hoverEvent.y= editorTextWidget.getClientArea().y + 5;
249-
hoverEvent.display= editorTextWidget.getDisplay();
250-
hoverEvent.doit= true;
251-
editorTextWidget.getDisplay().setCursorLocation(editorTextWidget.toDisplay(hoverEvent.x, hoverEvent.y));
252-
editorTextWidget.notifyListeners(SWT.MouseHover, hoverEvent);
232+
boolean foundHoverData = false;
233+
int attemptNumber = 0;
234+
253235
ITextViewer viewer= (ITextViewer) new Accessor(editor, AbstractTextEditor.class).invoke("getSourceViewer", new Object[0]);
254236
AbstractInformationControlManager textHoverManager= (AbstractInformationControlManager) new Accessor(viewer, TextViewer.class).get("fTextHoverManager");
255-
// retrieving hover content
256-
new DisplayHelper() {
257-
@Override
258-
protected boolean condition() {
259-
return getHoverData(textHoverManager) != null;
260-
}
261-
}.waitForCondition(hoverEvent.display, 6000);
237+
238+
while (!foundHoverData && attemptNumber++ < MAXIMUM_HOVER_RETRY_COUNT) {
239+
final int caretLocation= 2;
240+
editor.setFocus();
241+
this.editor.selectAndReveal(caretLocation, 0);
242+
final StyledText editorTextWidget= (StyledText) this.editor.getAdapter(Control.class);
243+
new DisplayHelper() {
244+
@Override
245+
protected boolean condition() {
246+
return editorTextWidget.isFocusControl() && editorTextWidget.getSelection().x == caretLocation;
247+
}
248+
}.waitForCondition(editorTextWidget.getDisplay(), 3000);
249+
assertTrue("editor does not have focus", editorTextWidget.isFocusControl());
250+
// sending event to trigger hover computation
251+
Event hoverEvent= new Event();
252+
hoverEvent.widget= editorTextWidget;
253+
hoverEvent.type= SWT.MouseHover;
254+
hoverEvent.x= editorTextWidget.getClientArea().x + 5;
255+
hoverEvent.y= editorTextWidget.getClientArea().y + 5;
256+
hoverEvent.display= editorTextWidget.getDisplay();
257+
hoverEvent.doit= true;
258+
editorTextWidget.getDisplay().setCursorLocation(editorTextWidget.toDisplay(hoverEvent.x, hoverEvent.y));
259+
editorTextWidget.notifyListeners(SWT.MouseHover, hoverEvent);
260+
// retrieving hover content
261+
foundHoverData = new DisplayHelper() {
262+
@Override
263+
protected boolean condition() {
264+
return getHoverData(textHoverManager) != null;
265+
}
266+
}.waitForCondition(hoverEvent.display, 6000);
267+
}
268+
assertTrue("hover data not found", foundHoverData);
262269
return textHoverManager;
263270
}
264271
}

0 commit comments

Comments
 (0)