|
65 | 65 | */
|
66 | 66 | public class HoverTest extends AbstratGenericEditorTest {
|
67 | 67 |
|
| 68 | + private static final int MAXIMUM_HOVER_RETRY_COUNT = 5; |
| 69 | + |
68 | 70 | @Rule
|
69 | 71 | public TestName testName= new TestName();
|
70 | 72 |
|
@@ -227,38 +229,43 @@ private Object getHoverData(AbstractInformationControlManager manager) {
|
227 | 229 | }
|
228 | 230 |
|
229 | 231 | 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 | + |
253 | 235 | ITextViewer viewer= (ITextViewer) new Accessor(editor, AbstractTextEditor.class).invoke("getSourceViewer", new Object[0]);
|
254 | 236 | 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); |
262 | 269 | return textHoverManager;
|
263 | 270 | }
|
264 | 271 | }
|
0 commit comments