Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.ui.genericeditor.tests')
-rw-r--r--org.eclipse.ui.genericeditor.tests/plugin.xml4
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java24
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestSuite.java6
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestUtils.java10
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java15
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/BarContentAssistProcessor.java6
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/LongRunningBarContentAssistProcessor.java67
7 files changed, 110 insertions, 22 deletions
diff --git a/org.eclipse.ui.genericeditor.tests/plugin.xml b/org.eclipse.ui.genericeditor.tests/plugin.xml
index 0a869d463..192e1be82 100644
--- a/org.eclipse.ui.genericeditor.tests/plugin.xml
+++ b/org.eclipse.ui.genericeditor.tests/plugin.xml
@@ -17,6 +17,10 @@
class="org.eclipse.ui.genericeditor.tests.contributions.BarContentAssistProcessor"
contentType="org.eclipse.core.runtime.text">
</contentAssistProcessor>
+ <contentAssistProcessor
+ class="org.eclipse.ui.genericeditor.tests.contributions.LongRunningBarContentAssistProcessor"
+ contentType="org.eclipse.core.runtime.text">
+ </contentAssistProcessor>
</extension>
<extension
point="org.eclipse.ui.genericeditor.hoverProviders">
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java
index 8f7e69a6d..46e5bf4ed 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java
@@ -11,6 +11,7 @@
package org.eclipse.ui.genericeditor.tests;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.HashSet;
@@ -32,6 +33,8 @@ import org.eclipse.swt.widgets.Widget;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.genericeditor.tests.contributions.BarContentAssistProcessor;
+import org.eclipse.ui.genericeditor.tests.contributions.LongRunningBarContentAssistProcessor;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.AbstractTextEditor;
@@ -76,14 +79,29 @@ public class CompletionTest {
ContentAssistAction action = (ContentAssistAction) editor.getAction(ITextEditorActionConstants.CONTENT_ASSIST);
action.update();
action.run();
+ GenericEditorTestUtils.waitAndDispatch(100);
Set<Shell> afterShell = new HashSet<>(Arrays.asList(Display.getDefault().getShells()));
afterShell.removeAll(beforeShell);
assertEquals("No completion", 1, afterShell.size());
Shell completionShell= afterShell.iterator().next();
Table completionProposalList = findCompletionSelectionControl(completionShell);
- assertEquals(1, completionProposalList.getItemCount());
- TableItem completionProposalItem = completionProposalList.getItem(0);
- assertEquals("s are good for a beer.", ((ICompletionProposal)completionProposalItem.getData()).getDisplayString());
+ // instantaneous
+ assertEquals(2, completionProposalList.getItemCount());
+ TableItem computingItem = completionProposalList.getItem(0);
+ assertTrue("Missing computing info entry", computingItem.getText().contains("Computing")); //$NON-NLS-1$ //$NON-NLS-2$
+ TableItem completionProposalItem = completionProposalList.getItem(1);
+ ICompletionProposal completionProposal = (ICompletionProposal)completionProposalItem.getData();
+ assertEquals(BarContentAssistProcessor.PROPOSAL, completionProposal .getDisplayString());
+ completionProposalList.setSelection(completionProposalItem);
+ GenericEditorTestUtils.waitAndDispatch(LongRunningBarContentAssistProcessor.DELAY + 100);
+ // asynchronous
+ assertEquals(2, completionProposalList.getItemCount());
+ completionProposalItem = completionProposalList.getItem(0);
+ assertEquals(BarContentAssistProcessor.PROPOSAL, ((ICompletionProposal)completionProposalItem.getData()).getDisplayString());
+ TableItem otherProposalItem = completionProposalList.getItem(1);
+ assertEquals(LongRunningBarContentAssistProcessor.PROPOSAL, ((ICompletionProposal)otherProposalItem.getData()).getDisplayString());
+ assertEquals("Addition of completion proposal should keep selection", completionProposal, completionProposalList.getSelection()[0].getData());
+
// TODO find a way to actually trigger completion and verify result against Editor content
// Assert.assertEquals("Completion didn't complete", "bars are good for a beer.", ((StyledText)editor.getAdapter(Control.class)).getText());
completionShell.close();
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestSuite.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestSuite.java
index 9e41f7e30..115f6005e 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestSuite.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestSuite.java
@@ -15,11 +15,6 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
-/**
- * Test Suite for org.eclipse.ui.editors.
- *
- * @since 3.0
- */
@RunWith(Suite.class)
@SuiteClasses({
CompletionTest.class,
@@ -28,4 +23,5 @@ import org.junit.runners.Suite.SuiteClasses;
})
public class GenericEditorTestSuite {
// see @SuiteClasses
+
}
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestUtils.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestUtils.java
index 33caf13be..9d0562613 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestUtils.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestUtils.java
@@ -12,6 +12,8 @@ package org.eclipse.ui.genericeditor.tests;
import java.io.ByteArrayInputStream;
+import org.eclipse.swt.widgets.Display;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -47,5 +49,13 @@ public class GenericEditorTestUtils {
public static IFile getFile(){
return file;
}
+
+ public static void waitAndDispatch(long milliseconds) {
+ long timeout = milliseconds; //ms
+ long start = System.currentTimeMillis();
+ while (start + timeout > System.currentTimeMillis()) {
+ Display.getDefault().readAndDispatch();
+ }
+ }
}
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java
index 6d29a391f..f8fbd32da 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java
@@ -24,7 +24,6 @@ import org.junit.Test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.core.resources.IMarker;
@@ -96,7 +95,7 @@ public class HoverTest {
private Object getHoverData() throws Exception {
this.editor.selectAndReveal(2, 0);
- waitAndDispatch();
+ GenericEditorTestUtils.waitAndDispatch(1000);
// sending event to trigger hover computation
StyledText editorTextWidget = (StyledText) this.editor.getAdapter(Control.class);
editorTextWidget.getShell().forceActive();
@@ -112,7 +111,7 @@ public class HoverTest {
hoverEvent.doit = true;
editorTextWidget.notifyListeners(SWT.MouseHover, hoverEvent);
// Events need to be processed for hover listener to work correctly
- waitAndDispatch();
+ GenericEditorTestUtils.waitAndDispatch(1000);
// retrieving hover content
Method getSourceViewerMethod= AbstractTextEditor.class.getDeclaredMethod("getSourceViewer");
getSourceViewerMethod.setAccessible(true);
@@ -123,16 +122,8 @@ public class HoverTest {
Field informationField = AbstractInformationControlManager.class.getDeclaredField("fInformation");
informationField.setAccessible(true);
Object hoverData = informationField.get(hover);
- waitAndDispatch();
+ GenericEditorTestUtils.waitAndDispatch(1000);
return hoverData;
}
- private void waitAndDispatch() {
- long timeout = 1000; //ms
- long start = System.currentTimeMillis();
- while (start + timeout > System.currentTimeMillis()) {
- Display.getDefault().readAndDispatch();
- }
- }
-
}
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/BarContentAssistProcessor.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/BarContentAssistProcessor.java
index 4d5f12ba4..7f6a14857 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/BarContentAssistProcessor.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/BarContentAssistProcessor.java
@@ -19,11 +19,13 @@ import org.eclipse.jface.text.contentassist.IContextInformationValidator;
public class BarContentAssistProcessor implements IContentAssistProcessor {
+ public static final String PROPOSAL = "s are good for a beer.";
+
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
- String text = viewer.getTextWidget().getText();
+ String text = viewer.getDocument().get();
if (text.length() >= 3 && text.substring(offset - 3, offset).equals("bar")) {
- String message = "s are good for a beer.";
+ String message = PROPOSAL;
CompletionProposal proposal = new CompletionProposal(message, offset, 0, message.length());
return new ICompletionProposal[] { proposal };
}
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/LongRunningBarContentAssistProcessor.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/LongRunningBarContentAssistProcessor.java
new file mode 100644
index 000000000..b90252437
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/LongRunningBarContentAssistProcessor.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Red Hat Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * - Mickael Istria (Red Hat Inc.)
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.tests.contributions;
+
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+
+public class LongRunningBarContentAssistProcessor implements IContentAssistProcessor {
+
+ public static final String PROPOSAL = "s are also good for soft drink cocktails.";
+ public static final int DELAY = 2000;
+
+ @Override
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
+ try {
+ Thread.sleep(DELAY);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ String text = viewer.getDocument().get();
+ if (text.length() >= 3 && text.substring(offset - 3, offset).equals("bar")) {
+ String message = PROPOSAL;
+ CompletionProposal proposal = new CompletionProposal(message, offset, 0, message.length());
+ return new ICompletionProposal[] { proposal };
+ }
+ return new ICompletionProposal[0];
+ }
+
+ @Override
+ public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
+ return null;
+ }
+
+ @Override
+ public char[] getCompletionProposalAutoActivationCharacters() {
+ return null;
+ }
+
+ @Override
+ public char[] getContextInformationAutoActivationCharacters() {
+ return null;
+ }
+
+ @Override
+ public String getErrorMessage() {
+ return null;
+ }
+
+ @Override
+ public IContextInformationValidator getContextInformationValidator() {
+ return null;
+ }
+
+}

Back to the top