Skip to content

Commit

Permalink
Improve and add assertions for random failing HoverTest eclipse-platf…
Browse files Browse the repository at this point in the history
…orm#926 eclipse-platform#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
eclipse-platform#926
Contributes to
eclipse-platform#1808
  • Loading branch information
HeikoKlare committed Nov 8, 2024
1 parent 10d96b5 commit 2c07aa7
Showing 1 changed file with 37 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
*/
public class HoverTest extends AbstratGenericEditorTest {

private static final int MAXIMUM_HOVER_RETRY_COUNT = 5;

@Rule
public TestName testName= new TestName();

Expand Down Expand Up @@ -227,38 +229,43 @@ private Object getHoverData(AbstractInformationControlManager manager) {
}

private AbstractInformationControlManager triggerCompletionAndRetrieveInformationControlManager() {
final int caretLocation= 2;
this.editor.selectAndReveal(caretLocation, 0);
final StyledText editorTextWidget= (StyledText) this.editor.getAdapter(Control.class);
new DisplayHelper() {
@Override
protected boolean condition() {
return editorTextWidget.isFocusControl() && editorTextWidget.getSelection().x == caretLocation;
}
}.waitForCondition(editorTextWidget.getDisplay(), 3000);
// sending event to trigger hover computation
editorTextWidget.getShell().forceActive();
editorTextWidget.getShell().setActive();
editorTextWidget.getShell().setFocus();
editorTextWidget.getShell().getDisplay().wake();
Event hoverEvent= new Event();
hoverEvent.widget= editorTextWidget;
hoverEvent.type= SWT.MouseHover;
hoverEvent.x= editorTextWidget.getClientArea().x + 5;
hoverEvent.y= editorTextWidget.getClientArea().y + 5;
hoverEvent.display= editorTextWidget.getDisplay();
hoverEvent.doit= true;
editorTextWidget.getDisplay().setCursorLocation(editorTextWidget.toDisplay(hoverEvent.x, hoverEvent.y));
editorTextWidget.notifyListeners(SWT.MouseHover, hoverEvent);
boolean foundHoverData = false;
int attemptNumber = 0;

ITextViewer viewer= (ITextViewer) new Accessor(editor, AbstractTextEditor.class).invoke("getSourceViewer", new Object[0]);
AbstractInformationControlManager textHoverManager= (AbstractInformationControlManager) new Accessor(viewer, TextViewer.class).get("fTextHoverManager");
// retrieving hover content
new DisplayHelper() {
@Override
protected boolean condition() {
return getHoverData(textHoverManager) != null;
}
}.waitForCondition(hoverEvent.display, 6000);

while (!foundHoverData && attemptNumber++ < MAXIMUM_HOVER_RETRY_COUNT) {
final int caretLocation= 2;
editor.setFocus();
this.editor.selectAndReveal(caretLocation, 0);
final StyledText editorTextWidget= (StyledText) this.editor.getAdapter(Control.class);
new DisplayHelper() {
@Override
protected boolean condition() {
return editorTextWidget.isFocusControl() && editorTextWidget.getSelection().x == caretLocation;
}
}.waitForCondition(editorTextWidget.getDisplay(), 3000);
assertTrue("editor does not have focus", editorTextWidget.isFocusControl());
// sending event to trigger hover computation
Event hoverEvent= new Event();
hoverEvent.widget= editorTextWidget;
hoverEvent.type= SWT.MouseHover;
hoverEvent.x= editorTextWidget.getClientArea().x + 5;
hoverEvent.y= editorTextWidget.getClientArea().y + 5;
hoverEvent.display= editorTextWidget.getDisplay();
hoverEvent.doit= true;
editorTextWidget.getDisplay().setCursorLocation(editorTextWidget.toDisplay(hoverEvent.x, hoverEvent.y));
editorTextWidget.notifyListeners(SWT.MouseHover, hoverEvent);
// retrieving hover content
foundHoverData = new DisplayHelper() {
@Override
protected boolean condition() {
return getHoverData(textHoverManager) != null;
}
}.waitForCondition(hoverEvent.display, 6000);
}
assertTrue("hover data not found", foundHoverData);
return textHoverManager;
}
}

0 comments on commit 2c07aa7

Please sign in to comment.