use of org.eclipse.jface.text.tests.util.DisplayHelper in project eclipse.platform.text by eclipse.
the class HoverTest method triggerCompletionAndRetrieveInformationControlManager.
private AbstractInformationControlManager triggerCompletionAndRetrieveInformationControlManager() {
this.editor.selectAndReveal(2, 0);
final StyledText editorTextWidget = (StyledText) this.editor.getAdapter(Control.class);
new DisplayHelper() {
@Override
protected boolean condition() {
return editorTextWidget.isFocusControl() && editorTextWidget.getSelection().x == 2;
}
}.waitForCondition(editorTextWidget.getDisplay(), 1000);
// 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);
// Events need to be processed for hover listener to work correctly
DisplayHelper.sleep(editorTextWidget.getDisplay(), 1000);
// retrieving hover content
ITextViewer viewer = (ITextViewer) new Accessor(editor, AbstractTextEditor.class).invoke("getSourceViewer", new Object[0]);
AbstractInformationControlManager textHoverManager = (AbstractInformationControlManager) new Accessor(viewer, TextViewer.class).get("fTextHoverManager");
return textHoverManager;
}
use of org.eclipse.jface.text.tests.util.DisplayHelper in project eclipse.platform.text by eclipse.
the class HoverTest method testProblemHover.
@Test
public void testProblemHover() throws Exception {
String problemMessage = "Huston...";
IMarker marker = null;
try {
marker = this.file.createMarker(IMarker.PROBLEM);
marker.setAttribute(IMarker.LINE_NUMBER, 1);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
marker.setAttribute(IMarker.CHAR_START, 0);
marker.setAttribute(IMarker.CHAR_END, 5);
marker.setAttribute(IMarker.MESSAGE, problemMessage);
marker.setAttribute(MarkerResolutionGenerator.FIXME, true);
AbstractInformationControlManager manager = triggerCompletionAndRetrieveInformationControlManager();
Object hoverData = getHoverData(manager);
assertTrue(hoverData instanceof Map);
assertTrue(((Map<?, ?>) hoverData).containsValue(Collections.singletonList(marker)));
assertTrue(((Map<?, ?>) hoverData).containsValue(AlrightyHoverProvider.LABEL));
assertFalse(((Map<?, ?>) hoverData).containsValue(HelloHoverProvider.LABEL));
// check dialog content
Shell shell = getHoverShell(manager);
assertNotNull(findControl(shell, Label.class, marker.getAttribute(IMarker.MESSAGE, "NONE")));
assertNotNull(findControl(shell, StyledText.class, AlrightyHoverProvider.LABEL));
assertNull(findControl(shell, StyledText.class, HelloHoverProvider.LABEL));
// check quick-fix works
Link link = findControl(shell, Link.class, MarkerResolutionGenerator.FIXME);
assertNotNull(link);
Event event = new Event();
event.widget = link;
event.display = link.getDisplay();
event.doit = true;
event.type = SWT.Selection;
link.notifyListeners(SWT.Selection, event);
final IMarker m = marker;
new DisplayHelper() {
@Override
protected boolean condition() {
return !m.exists();
}
}.waitForCondition(event.display, 1000);
assertFalse(marker.exists());
} finally {
if (marker != null && marker.exists()) {
marker.delete();
}
}
}
use of org.eclipse.jface.text.tests.util.DisplayHelper in project eclipse.platform.text by eclipse.
the class ReconcilerTest method performTestOnEditor.
private void performTestOnEditor(String startingText, ExtensionBasedTextEditor textEditor, String expectedText) throws Exception {
IDocumentProvider dp = textEditor.getDocumentProvider();
IDocument doc = dp.getDocument(textEditor.getEditorInput());
doc.set(startingText);
new DisplayHelper() {
@Override
protected boolean condition() {
try {
return doc.get(0, doc.getLineLength(0)).contains(expectedText);
} catch (BadLocationException e) {
return false;
}
}
}.waitForCondition(Display.getDefault().getActiveShell().getDisplay(), 2000);
Assert.assertTrue("file was not affected by reconciler", doc.get().contains(expectedText));
}
use of org.eclipse.jface.text.tests.util.DisplayHelper in project eclipse.platform.text by eclipse.
the class CompletionTest method checkCompletionContent.
/**
* Checks that completion behaves as expected:
* 1. Computing is shown instantaneously
* 2. 1st proposal shown instantaneously
* 3. 2s later, 2nd proposal is shown
* @param completionProposalList the completion list
*/
private void checkCompletionContent(final Table completionProposalList) {
// should be instantaneous, but happens to go asynchronous on CI so let's allow a wait
new DisplayHelper() {
@Override
protected boolean condition() {
return completionProposalList.getItemCount() == 2;
}
}.waitForCondition(completionProposalList.getDisplay(), 200);
assertEquals(2, completionProposalList.getItemCount());
final TableItem computingItem = completionProposalList.getItem(0);
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue("Missing computing info entry", computingItem.getText().contains("Computing"));
TableItem completionProposalItem = completionProposalList.getItem(1);
final ICompletionProposal selectedProposal = (ICompletionProposal) completionProposalItem.getData();
assertTrue("Incorrect proposal content", BarContentAssistProcessor.PROPOSAL.endsWith(selectedProposal.getDisplayString()));
completionProposalList.setSelection(completionProposalItem);
// asynchronous
new DisplayHelper() {
@Override
protected boolean condition() {
return completionProposalList.getItem(0) != computingItem && completionProposalList.getItemCount() == 2;
}
}.waitForCondition(completionProposalList.getDisplay(), LongRunningBarContentAssistProcessor.DELAY + 200);
completionProposalItem = completionProposalList.getItem(0);
assertTrue("Proposal content seems incorrect", BarContentAssistProcessor.PROPOSAL.endsWith(((ICompletionProposal) completionProposalItem.getData()).getDisplayString()));
TableItem otherProposalItem = completionProposalList.getItem(1);
assertTrue("Proposal content seems incorrect", LongRunningBarContentAssistProcessor.PROPOSAL.endsWith(((ICompletionProposal) otherProposalItem.getData()).getDisplayString()));
assertEquals("Addition of completion proposal should keep selection", selectedProposal, completionProposalList.getSelection()[0].getData());
}
use of org.eclipse.jface.text.tests.util.DisplayHelper in project eclipse.platform.text by eclipse.
the class CompletionTest method testCompletionFreeze_bug521484.
@Test
public void testCompletionFreeze_bug521484() throws Exception {
final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
editor.selectAndReveal(3, 0);
ContentAssistAction action = (ContentAssistAction) editor.getAction(ITextEditorActionConstants.CONTENT_ASSIST);
action.update();
action.run();
waitAndDispatch(100);
this.completionShell = findNewShell(beforeShells);
final Table completionProposalList = findCompletionSelectionControl(this.completionShell);
// should be instantaneous, but happens to go asynchronous on CI so let's allow a wait
new DisplayHelper() {
@Override
protected boolean condition() {
return completionProposalList.getItemCount() == 2;
}
}.waitForCondition(completionShell.getDisplay(), 200);
assertEquals(2, completionProposalList.getItemCount());
final TableItem computingItem = completionProposalList.getItem(0);
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue("Missing computing info entry", computingItem.getText().contains("Computing"));
// Some processors are long running, moving cursor can cause freeze (bug 521484)
// asynchronous
long timestamp = System.currentTimeMillis();
emulatePressLeftArrowKey();
// give time to process events
DisplayHelper.sleep(editor.getSite().getShell().getDisplay(), 200);
long processingDuration = System.currentTimeMillis() - timestamp;
assertTrue("UI Thread frozen for " + processingDuration + "ms", processingDuration < LongRunningBarContentAssistProcessor.DELAY);
}
Aggregations