Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucas Bullen2017-09-08 10:05:20 -0400
committerMickael Istria2017-09-15 03:28:29 -0400
commit436cf72b5d16b64ce88662e468a4839ed8dd99e9 (patch)
tree223533de2fcc8463e5c74d8831c5f170a2e624f6 /org.eclipse.ui.genericeditor.tests
parent4c519144c9f59cb4c5b40bc9b375d94fdf9fd285 (diff)
downloadeclipse.platform.text-436cf72b5d16b64ce88662e468a4839ed8dd99e9.tar.gz
eclipse.platform.text-436cf72b5d16b64ce88662e468a4839ed8dd99e9.tar.xz
eclipse.platform.text-436cf72b5d16b64ce88662e468a4839ed8dd99e9.zip
Bug 521484 - Async content-assist can freeze UI Thread
Added async proposal filtering to avoid defaulting to sync proposal retrieval Change-Id: Ibdc3767359e7fe6f4ff8d52d8cd895e1ddea04ae Signed-off-by: Lucas Bullen <lbullen@redhat.com> Also-By: Mickael Istria <mistria@redhat.com>
Diffstat (limited to 'org.eclipse.ui.genericeditor.tests')
-rw-r--r--org.eclipse.ui.genericeditor.tests/plugin.xml2
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java50
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/BarContentAssistProcessor.java2
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/LongRunningBarContentAssistProcessor.java2
4 files changed, 52 insertions, 4 deletions
diff --git a/org.eclipse.ui.genericeditor.tests/plugin.xml b/org.eclipse.ui.genericeditor.tests/plugin.xml
index c7ce8e9b8..ea8d49a05 100644
--- a/org.eclipse.ui.genericeditor.tests/plugin.xml
+++ b/org.eclipse.ui.genericeditor.tests/plugin.xml
@@ -20,7 +20,7 @@
</contentAssistProcessor>
<contentAssistProcessor
class="org.eclipse.ui.genericeditor.tests.contributions.LongRunningBarContentAssistProcessor"
- contentType="org.eclipse.ui.genericeditor.tests.content-type">
+ contentType="org.eclipse.ui.genericeditor.tests.specialized-content-type">
</contentAssistProcessor>
</extension>
<extension
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 97b5ef1b3..7ed46a864 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
@@ -19,8 +19,13 @@ import java.util.Set;
import org.junit.Test;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ST;
+import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
@@ -80,12 +85,55 @@ public class CompletionTest extends AbstratGenericEditorTest {
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();
}
+ @Test
+ public void testCompletionFreeze_bug521484() throws Exception {
+ Set<Shell> beforeShell = new HashSet<>(Arrays.asList(Display.getDefault().getShells()));
+ editor.selectAndReveal(3, 0);
+ ContentAssistAction action = (ContentAssistAction) editor.getAction(ITextEditorActionConstants.CONTENT_ASSIST);
+ action.update();
+ action.run();
+ 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();
+ final Table completionProposalList = findCompletionSelectionControl(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);
+ assertTrue("Missing computing info entry", computingItem.getText().contains("Computing")); //$NON-NLS-1$ //$NON-NLS-2$
+ // Some processors are long running, moving cursor can cause freeze (bug 521484)
+ // asynchronous
+ StyledText styledText = (StyledText) editor.getAdapter(Control.class);
+ styledText.setSelection(styledText.getSelectionRange().x - 1);
+ Event e = new Event();
+ e.type = ST.VerifyKey;
+ e.widget = styledText;
+ e.keyCode = SWT.ARROW_LEFT;
+ e.display = styledText.getDisplay();
+ long timestamp = System.currentTimeMillis();
+ styledText.notifyListeners(ST.VerifyKey, e);
+ DisplayHelper.sleep(styledText.getDisplay(), 200); //give time to process events
+ long processingDuration = System.currentTimeMillis() - timestamp;
+ assertTrue("UI Thread frozen for " + processingDuration + "ms", processingDuration < LongRunningBarContentAssistProcessor.DELAY);
+
+ if (!completionShell.isDisposed()) {
+ completionShell.close();
+ }
+ }
+
private Table findCompletionSelectionControl(Widget control) {
if (control instanceof Table) {
return (Table)control;
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 7f6a14857..745f42dc3 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
@@ -24,7 +24,7 @@ public class BarContentAssistProcessor implements IContentAssistProcessor {
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
String text = viewer.getDocument().get();
- if (text.length() >= 3 && text.substring(offset - 3, offset).equals("bar")) {
+ if (text.length() >= 3 && offset >= 3 && text.substring(offset - 3, offset).equals("bar")) {
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
index b90252437..6f504d780 100644
--- 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
@@ -31,7 +31,7 @@ public class LongRunningBarContentAssistProcessor implements IContentAssistProce
e.printStackTrace();
}
String text = viewer.getDocument().get();
- if (text.length() >= 3 && text.substring(offset - 3, offset).equals("bar")) {
+ if (text.length() >= 3 && offset >= 3 && text.substring(offset - 3, offset).equals("bar")) {
String message = PROPOSAL;
CompletionProposal proposal = new CompletionProposal(message, offset, 0, message.length());
return new ICompletionProposal[] { proposal };

Back to the top