Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2017-02-22 06:36:38 -0500
committerAlexander Kurtakov2017-03-16 03:34:56 -0400
commitc07ac490577295e392ac81a6694b5629182694b2 (patch)
tree4370b807fa570051daaa240b3bde40c65e2d2658 /org.eclipse.ui.genericeditor.tests
parenta6082e6cac4837a7484cb5b4272bd7d1ce2813a4 (diff)
downloadeclipse.platform.text-c07ac490577295e392ac81a6694b5629182694b2.tar.gz
eclipse.platform.text-c07ac490577295e392ac81a6694b5629182694b2.tar.xz
eclipse.platform.text-c07ac490577295e392ac81a6694b5629182694b2.zip
Bug 512525 - Editor actions in menus and Generic Editor
* Add menus so commands are accessible via shortcut and quick-assist * Add images to commands so they look nice in menus * Test enablement of wordwrap, whitesplaces, block selection in Generic Editor... Bug: 512525 Bug: 512571 Change-Id: I95345a8eae45bec98f835614156d4037e7df4431 Signed-off-by: Mickael Istria <mistria@redhat.com>
Diffstat (limited to 'org.eclipse.ui.genericeditor.tests')
-rw-r--r--org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AbstratGenericEditorTest.java (renamed from org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestUtils.java)46
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java41
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/EditorTest.java73
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestSuite.java8
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java40
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/StylingTest.java38
7 files changed, 122 insertions, 128 deletions
diff --git a/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF b/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF
index 123f4c261..a563c469f 100644
--- a/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF
@@ -19,7 +19,9 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)",
org.eclipse.ui.ide;bundle-version="3.11.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.workbench.texteditor.tests;bundle-version="3.11.100",
+ org.eclipse.ui.tests.harness,
+ org.eclipse.ui.editors;bundle-version="3.11.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Eclipse-BundleShape: dir
Bundle-ActivationPolicy: lazy
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/AbstratGenericEditorTest.java
index 9d0562613..6d12a6f54 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/AbstratGenericEditorTest.java
@@ -12,6 +12,9 @@ package org.eclipse.ui.genericeditor.tests;
import java.io.ByteArrayInputStream;
+import org.junit.After;
+import org.junit.Before;
+
import org.eclipse.swt.widgets.Display;
import org.eclipse.core.resources.IFile;
@@ -19,37 +22,54 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.genericeditor.ExtensionBasedTextEditor;
import org.eclipse.ui.intro.IIntroPart;
+import org.eclipse.ui.part.FileEditorInput;
-public class GenericEditorTestUtils {
+/**
+ * Closes intro, create {@link #project}, create {@link #file} and open {@link #editor}; and clean up.
+ * Also contains additional utility methods
+ * @since 1.0
+ */
+public class AbstratGenericEditorTest {
- private static IProject project;
- private static IFile file;
+ protected IProject project;
+ protected IFile file;
+ protected ExtensionBasedTextEditor editor;
- public static void setUpBeforeClass() throws Exception {
- project = ResourcesPlugin.getWorkspace().getRoot().getProject("genericEditorTest");
+ /**
+ * Closes intro, create {@link #project}, create {@link #file} and open {@link #editor}
+ * @throws Exception ex
+ */
+ @Before
+ public void setUp() throws Exception {
+ closeIntro();
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.currentTimeMillis());
project.create(null);
project.open(null);
file = project.getFile("foo.txt");
file.create(new ByteArrayInputStream("bar 'bar'".getBytes()), true, null);
+ editor = (ExtensionBasedTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage().openEditor(new FileEditorInput(this.file), "org.eclipse.ui.genericeditor.GenericEditor");
}
- public static void tearDownAfterClass() throws Exception {
- file.delete(true, null);
- project.delete(true, null);
+ @After
+ public void tearDown() throws Exception {
+ if (file != null) {
+ file.delete(true, null);
+ }
+ if (project != null) {
+ project.delete(true, null);
+ }
}
- public static void closeIntro() {
+ private static void closeIntro() {
IIntroPart intro = PlatformUI.getWorkbench().getIntroManager().getIntro();
if (intro != null) {
PlatformUI.getWorkbench().getIntroManager().closeIntro(intro);
}
}
- public static IFile getFile(){
- return file;
- }
-
public static void waitAndDispatch(long milliseconds) {
long timeout = milliseconds; //ms
long start = System.currentTimeMillis();
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 46e5bf4ed..0347d308a 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
@@ -17,10 +17,6 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.eclipse.swt.widgets.Composite;
@@ -32,45 +28,16 @@ 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;
import org.eclipse.ui.texteditor.ContentAssistAction;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
/**
- * @since 3.11
- *
+ * @since 1.0
*/
-public class CompletionTest {
-
- private AbstractTextEditor editor;
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- GenericEditorTestUtils.setUpBeforeClass();
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- GenericEditorTestUtils.tearDownAfterClass();
- }
-
- @Before
- public void setUp() throws Exception {
- GenericEditorTestUtils.closeIntro();
- editor = (AbstractTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
- .getActivePage().openEditor(new FileEditorInput(GenericEditorTestUtils.getFile()), "org.eclipse.ui.genericeditor.GenericEditor");
- }
-
- @After
- public void tearDown() throws Exception {
- editor.getSite().getPage().closeEditor(editor, false);
- editor= null;
- }
+public class CompletionTest extends AbstratGenericEditorTest {
@Test
public void testCompletion() throws Exception {
@@ -79,7 +46,7 @@ public class CompletionTest {
ContentAssistAction action = (ContentAssistAction) editor.getAction(ITextEditorActionConstants.CONTENT_ASSIST);
action.update();
action.run();
- GenericEditorTestUtils.waitAndDispatch(100);
+ waitAndDispatch(100);
Set<Shell> afterShell = new HashSet<>(Arrays.asList(Display.getDefault().getShells()));
afterShell.removeAll(beforeShell);
assertEquals("No completion", 1, afterShell.size());
@@ -93,7 +60,7 @@ public class CompletionTest {
ICompletionProposal completionProposal = (ICompletionProposal)completionProposalItem.getData();
assertEquals(BarContentAssistProcessor.PROPOSAL, completionProposal .getDisplayString());
completionProposalList.setSelection(completionProposalItem);
- GenericEditorTestUtils.waitAndDispatch(LongRunningBarContentAssistProcessor.DELAY + 100);
+ waitAndDispatch(LongRunningBarContentAssistProcessor.DELAY + 100);
// asynchronous
assertEquals(2, completionProposalList.getItemCount());
completionProposalItem = completionProposalList.getItem(0);
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/EditorTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/EditorTest.java
new file mode 100644
index 000000000..814547f55
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/EditorTest.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2017 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;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.widgets.Control;
+
+import org.eclipse.core.commands.Command;
+
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.IHandlerService;
+
+import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
+
+public class EditorTest extends AbstratGenericEditorTest{
+
+ @Test
+ public void testGenericEditorHasWordWrap() throws Exception {
+ this.editor.setFocus();
+ final StyledText editorTextWidget = (StyledText) this.editor.getAdapter(Control.class);
+ Assert.assertFalse(editorTextWidget.getWordWrap());
+ Assert.assertFalse(this.editor.isWordWrapEnabled());
+ // Toggle word wrap
+ ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
+ Command wordWrapCommand = commandService.getCommand(ITextEditorActionDefinitionIds.WORD_WRAP);
+ Assert.assertTrue(wordWrapCommand.isDefined());
+ Assert.assertTrue(wordWrapCommand.isEnabled());
+ Assert.assertTrue(wordWrapCommand.isHandled());
+ PlatformUI.getWorkbench().getService(IHandlerService.class).executeCommand(wordWrapCommand.getId(), null);
+ //
+ Assert.assertTrue(editorTextWidget.getWordWrap());
+ Assert.assertTrue(this.editor.isWordWrapEnabled());
+ }
+
+ @Test
+ public void testGenericEditorCanShowWhitespaceCharacters() throws Exception {
+ this.editor.setFocus();
+ // Toggle word wrap
+ ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
+ Command wordWrapCommand = commandService.getCommand(ITextEditorActionDefinitionIds.SHOW_WHITESPACE_CHARACTERS);
+ Assert.assertTrue(wordWrapCommand.isDefined());
+ Assert.assertTrue(wordWrapCommand.isEnabled());
+ Assert.assertTrue(wordWrapCommand.isHandled());
+ PlatformUI.getWorkbench().getService(IHandlerService.class).executeCommand(wordWrapCommand.getId(), null);
+ }
+
+ @Test
+ public void testGenericEditorCanUseBlockSelection() throws Exception {
+ this.editor.setFocus();
+ Assert.assertFalse(this.editor.isBlockSelectionModeEnabled());
+ // Toggle word wrap
+ ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
+ Command wordWrapCommand = commandService.getCommand(ITextEditorActionDefinitionIds.BLOCK_SELECTION_MODE);
+ Assert.assertTrue(wordWrapCommand.isDefined());
+ Assert.assertTrue(wordWrapCommand.isEnabled());
+ Assert.assertTrue(wordWrapCommand.isHandled());
+ PlatformUI.getWorkbench().getService(IHandlerService.class).executeCommand(wordWrapCommand.getId(), null);
+ //
+ Assert.assertTrue(this.editor.isBlockSelectionModeEnabled());
+ }
+}
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 115f6005e..e349652f2 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
@@ -1,13 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2016-2017 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:
- * IBM Corporation - initial API and implementation
- * Mickael Istria (Red Hat Inc.) - [484157] Add zoom test
+ * Mickael Istria, Sopot Cela (Red Hat Inc.)
*******************************************************************************/
package org.eclipse.ui.genericeditor.tests;
@@ -19,7 +18,8 @@ import org.junit.runners.Suite.SuiteClasses;
@SuiteClasses({
CompletionTest.class,
StylingTest.class,
- HoverTest.class
+ HoverTest.class,
+ EditorTest.class
})
public class GenericEditorTestSuite {
// see @SuiteClasses
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 f130f4d23..a330a309d 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
@@ -18,10 +18,6 @@ import static org.junit.Assert.fail;
import java.util.Collections;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
@@ -46,61 +42,33 @@ import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.tests.util.DisplayHelper;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.genericeditor.tests.contributions.MagicHoverProvider;
import org.eclipse.ui.genericeditor.tests.contributions.MarkerResolutionGenerator;
-import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.workbench.texteditor.tests.ScreenshotTest;
import org.eclipse.ui.texteditor.AbstractTextEditor;
/**
- * @since 3.11
- *
+ * @since 1.0
*/
-public class HoverTest {
+public class HoverTest extends AbstratGenericEditorTest {
@Rule
public TestName testName = new TestName();
- private AbstractTextEditor editor;
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- GenericEditorTestUtils.setUpBeforeClass();
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- GenericEditorTestUtils.tearDownAfterClass();
- }
-
- @Before
- public void setUp() throws Exception {
- GenericEditorTestUtils.closeIntro();
- editor = (AbstractTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
- .getActivePage().openEditor(new FileEditorInput(GenericEditorTestUtils.getFile()), "org.eclipse.ui.genericeditor.GenericEditor");
- }
-
- @After
- public void tearDown() throws Exception {
- editor.getSite().getPage().closeEditor(editor, false);
- editor= null;
- }
-
@Test
public void testHover() throws Exception {
Shell shell = getHoverShell(triggerCompletionAndRetrieveInformationControlManager());
assertNotNull(findControl(shell, StyledText.class, MagicHoverProvider.LABEL));
}
-
+
@Test
public void testProblemHover() throws Exception {
String problemMessage = "Huston...";
IMarker marker = null;
try {
- marker = GenericEditorTestUtils.getFile().createMarker(IMarker.PROBLEM);
+ 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);
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 4a5fa8b93..04d1e02dc 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,11 +10,7 @@
*******************************************************************************/
package org.eclipse.ui.genericeditor.tests;
-import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.eclipse.swt.custom.StyleRange;
@@ -22,42 +18,10 @@ import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.FileEditorInput;
-
-import org.eclipse.ui.texteditor.AbstractTextEditor;
-
-public class StylingTest {
-
- private AbstractTextEditor editor;
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- GenericEditorTestUtils.setUpBeforeClass();
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- GenericEditorTestUtils.tearDownAfterClass();
- }
-
- @Before
- public void setUp() throws Exception {
- GenericEditorTestUtils.closeIntro();
-
- editor = (AbstractTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
- .getActivePage().openEditor(new FileEditorInput(GenericEditorTestUtils.getFile()), "org.eclipse.ui.genericeditor.GenericEditor");
- }
-
- @After
- public void tearDown() throws Exception {
- editor.getSite().getPage().closeEditor(editor, false);
- editor= null;
- }
+public class StylingTest extends AbstratGenericEditorTest {
@Test
public void testStyle() throws Exception {
-
editor.selectAndReveal(4, 8);
StyledText widget = (StyledText) editor.getAdapter(Control.class);
StyleRange style= widget.getStyleRangeAtOffset(4);//get the style of first token

Back to the top