Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucas Bullen2018-03-27 14:20:43 -0400
committerLucas Bullen2018-03-27 14:20:43 -0400
commitd6a4c8cfc2c8a4e690383ed530c5b706e3162441 (patch)
tree538dacbf57640040a5518330156b9aca742e575f /org.eclipse.ui.genericeditor.tests
parent2c46f0a21f3a27b35898ca47d062ac7cf375c4b9 (diff)
downloadeclipse.platform.text-d6a4c8cfc2c8a4e690383ed530c5b706e3162441.tar.gz
eclipse.platform.text-d6a4c8cfc2c8a4e690383ed530c5b706e3162441.tar.xz
eclipse.platform.text-d6a4c8cfc2c8a4e690383ed530c5b706e3162441.zip
- Tests for turning on and off a property that in turn enables/disables each extension point Change-Id: Idd6805d6e6677a93e822657ab7182136636078a0 Signed-off-by: Lucas Bullen <lbullen@redhat.com>
Diffstat (limited to 'org.eclipse.ui.genericeditor.tests')
-rw-r--r--org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.ui.genericeditor.tests/plugin.xml107
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AutoEditTest.java21
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java46
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HighlightTest.java14
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java17
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/ReconcilerTest.java15
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/StylingTest.java22
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/EnabledPropertyTester.java32
9 files changed, 261 insertions, 16 deletions
diff --git a/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF b/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF
index b3738db2e..3d0e5ebbe 100644
--- a/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF
@@ -20,7 +20,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)",
org.eclipse.jface.text.tests;bundle-version="3.11.100",
org.eclipse.text.tests;bundle-version="3.11.0",
org.eclipse.ui.workbench.texteditor.tests;bundle-version="3.11.100",
- org.eclipse.ui.editors;bundle-version="3.11.0"
+ org.eclipse.ui.editors;bundle-version="3.11.0",
+ org.eclipse.core.expressions
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Eclipse-BundleShape: dir
Bundle-ActivationPolicy: lazy
diff --git a/org.eclipse.ui.genericeditor.tests/plugin.xml b/org.eclipse.ui.genericeditor.tests/plugin.xml
index 1700b8ff8..1d81989bb 100644
--- a/org.eclipse.ui.genericeditor.tests/plugin.xml
+++ b/org.eclipse.ui.genericeditor.tests/plugin.xml
@@ -23,12 +23,32 @@
class="org.eclipse.ui.genericeditor.tests.contributions.LongRunningBarContentAssistProcessor"
contentType="org.eclipse.ui.genericeditor.tests.specialized-content-type">
</contentAssistProcessor>
+ <contentAssistProcessor
+ class="org.eclipse.ui.genericeditor.tests.contributions.BarContentAssistProcessor"
+ contentType="org.eclipse.ui.genericeditor.tests.enabled-when-content-type">
+ <enabledWhen>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.ui.genericeditor.tests.contributions.enabled">
+ </test>
+ </enabledWhen>
+ </contentAssistProcessor>
</extension>
<extension
point="org.eclipse.ui.genericeditor.hoverProviders">
<hoverProvider
- class="org.eclipse.ui.genericeditor.tests.contributions.AlrightyHoverProvider"
- contentType="org.eclipse.ui.genericeditor.tests.content-type">
+ class="org.eclipse.ui.genericeditor.tests.contributions.AlrightyHoverProvider"
+ contentType="org.eclipse.ui.genericeditor.tests.enabled-when-content-type">
+ <enabledWhen>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.ui.genericeditor.tests.contributions.enabled">
+ </test>
+ </enabledWhen>
+ </hoverProvider>
+ <hoverProvider
+ class="org.eclipse.ui.genericeditor.tests.contributions.AlrightyHoverProvider"
+ contentType="org.eclipse.ui.genericeditor.tests.content-type">
</hoverProvider>
<hoverProvider
class="org.eclipse.ui.genericeditor.tests.contributions.WorldHoverProvider"
@@ -38,6 +58,18 @@
class="org.eclipse.ui.genericeditor.tests.contributions.HelloHoverProvider"
contentType="org.eclipse.ui.genericeditor.tests.specialized-content-type-bar">
</hoverProvider>
+ <hoverProvider
+ class="org.eclipse.ui.genericeditor.tests.contributions.WorldHoverProvider"
+ contentType="org.eclipse.ui.genericeditor.tests.enabled-when-content-type">
+ <enabledWhen>
+ <not>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.ui.genericeditor.tests.contributions.enabled">
+ </test>
+ </not>
+ </enabledWhen>
+ </hoverProvider>
</extension>
<extension
point="org.eclipse.ui.genericeditor.reconcilers">
@@ -53,6 +85,28 @@
class="org.eclipse.ui.genericeditor.tests.contributions.TheReconcilerFirst"
contentType="org.eclipse.ui.genericeditor.tests.content-type">
</reconciler>
+ <reconciler
+ class="org.eclipse.ui.genericeditor.tests.contributions.TheReconcilerFirst"
+ contentType="org.eclipse.ui.genericeditor.tests.enabled-when-content-type">
+ <enabledWhen>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.ui.genericeditor.tests.contributions.enabled">
+ </test>
+ </enabledWhen>
+ </reconciler>
+ <reconciler
+ class="org.eclipse.ui.genericeditor.tests.contributions.TheReconcilerSecond"
+ contentType="org.eclipse.ui.genericeditor.tests.enabled-when-content-type">
+ <enabledWhen>
+ <not>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.ui.genericeditor.tests.contributions.enabled">
+ </test>
+ </not>
+ </enabledWhen>
+ </reconciler>
</extension>
<extension
point="org.eclipse.ui.genericeditor.presentationReconcilers">
@@ -68,6 +122,16 @@
class="org.eclipse.ui.genericeditor.tests.contributions.ThePresentationReconcilerRed"
contentType="org.eclipse.ui.genericeditor.tests.sub-specialized-content-type">
</presentationReconciler>
+ <presentationReconciler
+ class="org.eclipse.ui.genericeditor.tests.contributions.ThePresentationReconcilerBlue"
+ contentType="org.eclipse.ui.genericeditor.tests.enabled-when-content-type">
+ <enabledWhen>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.ui.genericeditor.tests.contributions.enabled">
+ </test>
+ </enabledWhen>
+ </presentationReconciler>
</extension>
<extension
point="org.eclipse.ui.ide.markerResolution">
@@ -120,6 +184,13 @@
name="Specialized Generic Editor content-type for &apos;bar.txt&apos;"
priority="normal">
</content-type>
+ <content-type
+ base-type="org.eclipse.core.runtime.text"
+ file-names="enabledWhen.txt"
+ id="org.eclipse.ui.genericeditor.tests.enabled-when-content-type"
+ name="enabledWhen content-type for &apos;enabledWhen.txt&apos;"
+ priority="normal">
+ </content-type>
</extension>
<extension
point="org.eclipse.ui.genericeditor.autoEditStrategies">
@@ -135,6 +206,16 @@
class="org.eclipse.ui.genericeditor.tests.contributions.TheAutoEditStrategyThird"
contentType="org.eclipse.ui.genericeditor.tests.sub-specialized-content-type">
</autoEditStrategy>
+ <autoEditStrategy
+ class="org.eclipse.ui.genericeditor.tests.contributions.TheAutoEditStrategyFirst"
+ contentType="org.eclipse.ui.genericeditor.tests.enabled-when-content-type">
+ <enabledWhen>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.ui.genericeditor.tests.contributions.enabled">
+ </test>
+ </enabledWhen>
+ </autoEditStrategy>
</extension>
<extension
point="org.eclipse.ui.genericeditor.highlightReconcilers">
@@ -142,5 +223,25 @@
class="org.eclipse.ui.genericeditor.tests.contributions.HighlightReconciler"
contentType="org.eclipse.ui.genericeditor.tests.content-type-bar">
</highlightReconciler>
- </extension>
+ <highlightReconciler
+ class="org.eclipse.ui.genericeditor.tests.contributions.HighlightReconciler"
+ contentType="org.eclipse.ui.genericeditor.tests.enabled-when-content-type">
+ <enabledWhen>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.ui.genericeditor.tests.contributions.enabled">
+ </test>
+ </enabledWhen>
+ </highlightReconciler>
+ </extension>
+ <extension
+ point="org.eclipse.core.expressions.propertyTesters">
+ <propertyTester
+ class="org.eclipse.ui.genericeditor.tests.contributions.EnabledPropertyTester"
+ id="org.eclipse.ui.genericeditor.tests.contributions.enabled"
+ namespace="org.eclipse.ui.genericeditor.tests.contributions"
+ properties="enabled"
+ type="org.eclipse.ui.internal.genericeditor.ExtensionBasedTextEditor">
+ </propertyTester>
+ </extension>
</plugin>
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AutoEditTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AutoEditTest.java
index 1aa3a3e51..caddf69c8 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AutoEditTest.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AutoEditTest.java
@@ -18,6 +18,8 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.ui.genericeditor.tests.contributions.EnabledPropertyTester;
+
public class AutoEditTest extends AbstratGenericEditorTest {
@Test
@@ -29,4 +31,23 @@ public class AutoEditTest extends AbstratGenericEditorTest {
Assert.assertEquals("AutoAddedThird!AutoAddedSecond!AutoAddedFirst!", document.get());
}
+ @Test
+ public void testEnabledWhenAutoEdit() throws Exception {
+ EnabledPropertyTester.setEnabled(true);
+ createAndOpenFile("enabledWhen.txt", "bar 'bar'");
+ IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput());
+ StyledText control= (StyledText) editor.getAdapter(Control.class);
+ control.setText("");
+ // order of auto-edits from most specialized to least specialized
+ Assert.assertEquals("AutoAddedFirst!", document.get());
+ cleanFileAndEditor();
+
+ EnabledPropertyTester.setEnabled(false);
+ createAndOpenFile("enabledWhen.txt", "bar 'bar'");
+ document= editor.getDocumentProvider().getDocument(editor.getEditorInput());
+ control= (StyledText) editor.getAdapter(Control.class);
+ control.setText("");
+ // order of auto-edits from most specialized to least specialized
+ Assert.assertEquals("", document.get());
+ }
}
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 31b054395..91ec93ff0 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.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
@@ -36,6 +37,7 @@ import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.tests.util.DisplayHelper;
import org.eclipse.ui.genericeditor.tests.contributions.BarContentAssistProcessor;
+import org.eclipse.ui.genericeditor.tests.contributions.EnabledPropertyTester;
import org.eclipse.ui.genericeditor.tests.contributions.LongRunningBarContentAssistProcessor;
import org.eclipse.ui.texteditor.ContentAssistAction;
@@ -51,11 +53,7 @@ public class CompletionTest extends AbstratGenericEditorTest {
@Test
public void testCompletion() 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);
+ openConentAssist();
this.completionShell= findNewShell(beforeShells);
final Table completionProposalList = findCompletionSelectionControl(completionShell);
checkCompletionContent(completionProposalList);
@@ -63,6 +61,36 @@ public class CompletionTest extends AbstratGenericEditorTest {
// Assert.assertEquals("Completion didn't complete", "bars are good for a beer.", ((StyledText)editor.getAdapter(Control.class)).getText());
}
+ @Test
+ public void testEnabledWhenCompletion() throws Exception {
+ // Confirm that when disabled, a completion shell is present
+ EnabledPropertyTester.setEnabled(false);
+ createAndOpenFile("enabledWhen.txt", "bar 'bar'");
+ final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
+ openConentAssist();
+ Shell[] afterShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells())
+ .filter(Shell::isVisible)
+ .filter(shell -> !beforeShells.contains(shell))
+ .toArray(Shell[]::new);
+ assertEquals("A new shell was found", 0, afterShells.length);
+ cleanFileAndEditor();
+
+ // Confirm that when enabled, a completion shell is present
+ EnabledPropertyTester.setEnabled(true);
+ createAndOpenFile("enabledWhen.txt", "bar 'bar'");
+ final Set<Shell> beforeEnabledShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
+ openConentAssist();
+ assertNotNull(findNewShell(beforeEnabledShells));
+ }
+
+ private void openConentAssist() {
+ editor.selectAndReveal(3, 0);
+ ContentAssistAction action = (ContentAssistAction) editor.getAction(ITextEditorActionConstants.CONTENT_ASSIST);
+ action.update();
+ action.run();
+ waitAndDispatch(100);
+ }
+
/**
* Checks that completion behaves as expected:
* 1. Computing is shown instantaneously
@@ -111,11 +139,7 @@ public class CompletionTest extends AbstratGenericEditorTest {
@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);
+ openConentAssist();
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
@@ -134,7 +158,7 @@ public class CompletionTest extends AbstratGenericEditorTest {
emulatePressLeftArrowKey();
DisplayHelper.sleep(editor.getSite().getShell().getDisplay(), 200); //give time to process events
long processingDuration = System.currentTimeMillis() - timestamp;
- assertTrue("UI Thread frozen for " + processingDuration + "ms", processingDuration < LongRunningBarContentAssistProcessor.DELAY);
+ assertTrue("UI Thread frozen for " + processingDuration + "ms", processingDuration < LongRunningBarContentAssistProcessor.DELAY);
}
@Test
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HighlightTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HighlightTest.java
index 802640626..b80950c8b 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HighlightTest.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HighlightTest.java
@@ -27,6 +27,8 @@ import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.tests.util.DisplayHelper;
+import org.eclipse.ui.genericeditor.tests.contributions.EnabledPropertyTester;
+
import org.eclipse.ui.texteditor.IDocumentProvider;
public class HighlightTest extends AbstratGenericEditorTest {
@@ -50,6 +52,18 @@ public class HighlightTest extends AbstratGenericEditorTest {
}
@Test
+ public void testEnabledWhenCustomHighlightReconciler() throws Exception {
+ EnabledPropertyTester.setEnabled(true);
+ createAndOpenFile("enabledWhen.txt", "bar 'bar'");
+ checkHighlightForCaretOffset(0, "'bar'", 1);
+ cleanFileAndEditor();
+
+ EnabledPropertyTester.setEnabled(false);
+ createAndOpenFile("enabledWhen.txt", "bar 'bar'");
+ checkHighlightForCaretOffset(0, "'bar'", 0);
+ }
+
+ @Test
public void testHighlightWordAtDocumentStart() throws Exception {
createAndOpenFile("foo.txt", EDITOR_TEXT);
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 68a1f18cc..3f08862ab 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
@@ -48,6 +48,7 @@ import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.tests.util.DisplayHelper;
import org.eclipse.ui.genericeditor.tests.contributions.AlrightyHoverProvider;
+import org.eclipse.ui.genericeditor.tests.contributions.EnabledPropertyTester;
import org.eclipse.ui.genericeditor.tests.contributions.HelloHoverProvider;
import org.eclipse.ui.genericeditor.tests.contributions.MarkerResolutionGenerator;
import org.eclipse.ui.genericeditor.tests.contributions.WorldHoverProvider;
@@ -77,6 +78,22 @@ public class HoverTest extends AbstratGenericEditorTest {
assertNull(findControl(shell, StyledText.class, WorldHoverProvider.LABEL));
}
+ @Test
+ public void testEnabledWhenHover() throws Exception {
+ EnabledPropertyTester.setEnabled(true);
+ createAndOpenFile("enabledWhen.txt", "bar 'bar'");
+ Shell shell = getHoverShell(triggerCompletionAndRetrieveInformationControlManager());
+ assertNotNull(findControl(shell, StyledText.class, AlrightyHoverProvider.LABEL));
+ assertNull(findControl(shell, StyledText.class, WorldHoverProvider.LABEL));
+ cleanFileAndEditor();
+
+ EnabledPropertyTester.setEnabled(false);
+ createAndOpenFile("enabledWhen.txt", "bar 'bar'");
+ shell = getHoverShell(triggerCompletionAndRetrieveInformationControlManager());
+ assertNull(findControl(shell, StyledText.class, AlrightyHoverProvider.LABEL));
+ assertNotNull(findControl(shell, StyledText.class, WorldHoverProvider.LABEL));
+ }
+
/**
* @throws Exception ex
* @since 1.1
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/ReconcilerTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/ReconcilerTest.java
index 0f5470814..f84a42715 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/ReconcilerTest.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/ReconcilerTest.java
@@ -28,6 +28,7 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.tests.util.DisplayHelper;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.genericeditor.tests.contributions.EnabledPropertyTester;
import org.eclipse.ui.genericeditor.tests.contributions.ReconcilerStrategyFirst;
import org.eclipse.ui.genericeditor.tests.contributions.ReconcilerStrategySecond;
import org.eclipse.ui.internal.genericeditor.ExtensionBasedTextEditor;
@@ -47,6 +48,18 @@ public class ReconcilerTest extends AbstratGenericEditorTest {
}
@Test
+ public void testEnabledWhenReconciler() throws Exception {
+ EnabledPropertyTester.setEnabled(true);
+ createAndOpenFile("enabledWhen.txt", "");
+ performTestOnEditor(ReconcilerStrategyFirst.SEARCH_TERM, editor, ReconcilerStrategyFirst.REPLACEMENT);
+ cleanFileAndEditor();
+
+ EnabledPropertyTester.setEnabled(false);
+ createAndOpenFile("enabledWhen.txt", "");
+ performTestOnEditor(ReconcilerStrategySecond.SEARCH_TERM, editor, ReconcilerStrategySecond.REPLACEMENT);
+ }
+
+ @Test
public void testMultipleEditors() throws Exception {
secondProject= ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.currentTimeMillis());
secondProject.create(null);
@@ -57,7 +70,7 @@ public class ReconcilerTest extends AbstratGenericEditorTest {
.getActivePage().openEditor(new FileEditorInput(secondFile), "org.eclipse.ui.genericeditor.GenericEditor");
performTestOnEditor(ReconcilerStrategyFirst.SEARCH_TERM, editor, ReconcilerStrategyFirst.REPLACEMENT);
}
-
+
@Test
public void testMultipleReconcilers() throws Exception {
secondFile = project.getFile("bar.txt");
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/StylingTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/StylingTest.java
index 04d1e02dc..cb664bceb 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/StylingTest.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/StylingTest.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.ui.genericeditor.tests;
+import static org.junit.Assert.assertNull;
+
import org.junit.Assert;
import org.junit.Test;
@@ -18,6 +20,8 @@ import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.genericeditor.tests.contributions.EnabledPropertyTester;
+
public class StylingTest extends AbstratGenericEditorTest {
@Test
@@ -29,4 +33,22 @@ public class StylingTest extends AbstratGenericEditorTest {
Assert.assertTrue("Token is not of expected color", isRed);
}
+ @Test
+ public void testEnabledWhenStyle() throws Exception {
+ EnabledPropertyTester.setEnabled(true);
+ createAndOpenFile("enabledWhen.txt", "bar 'bar'");
+ editor.selectAndReveal(4, 8);
+ StyledText widget = (StyledText) editor.getAdapter(Control.class);
+ StyleRange style= widget.getStyleRangeAtOffset(4);//get the style of first token
+ boolean isBlue= style.foreground.getRGB().equals(new RGB(0, 0, 255));//is it Blue?
+ Assert.assertTrue("Token is not of expected color", isBlue);
+ cleanFileAndEditor();
+
+ EnabledPropertyTester.setEnabled(false);
+ createAndOpenFile("enabledWhen.txt", "bar 'bar'");
+ editor.selectAndReveal(4, 8);
+ widget = (StyledText) editor.getAdapter(Control.class);
+ assertNull(widget.getStyleRangeAtOffset(4));
+ }
+
}
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/EnabledPropertyTester.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/EnabledPropertyTester.java
new file mode 100644
index 000000000..65ba1ca1f
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/EnabledPropertyTester.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2018 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:
+ * - Lucas Bullen (Red Hat Inc.)
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.tests.contributions;
+
+import org.eclipse.core.expressions.PropertyTester;
+
+public class EnabledPropertyTester extends PropertyTester {
+
+ private static final String PROPERTY_NAME = "enabled";
+ private static boolean isEnabled = true;
+
+ @Override
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (property.equals(PROPERTY_NAME)) {
+ return isEnabled;
+ }
+ return false;
+ }
+
+ public static void setEnabled(boolean isEnabled) {
+ EnabledPropertyTester.isEnabled = isEnabled;
+ }
+
+}

Back to the top