Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 123909 Details for
Bug 262615
[Commands] Add test for TextActionHandler
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
TextActionHandler tests v01
texthandler-v01.txt (text/plain), 10.17 KB, created by
Paul Webster
on 2009-01-27 13:12:01 EST
(
hide
)
Description:
TextActionHandler tests v01
Filename:
MIME Type:
Creator:
Paul Webster
Created:
2009-01-27 13:12:01 EST
Size:
10.17 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.tests >Index: Eclipse UI Tests/org/eclipse/ui/tests/internal/InternalTestSuite.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/InternalTestSuite.java,v >retrieving revision 1.29 >diff -u -r1.29 InternalTestSuite.java >--- Eclipse UI Tests/org/eclipse/ui/tests/internal/InternalTestSuite.java 23 Oct 2008 14:57:41 -0000 1.29 >+++ Eclipse UI Tests/org/eclipse/ui/tests/internal/InternalTestSuite.java 27 Jan 2009 18:11:38 -0000 >@@ -55,5 +55,6 @@ > addTest(new TestSuite(ReopenMenuTest.class)); > addTest(new TestSuite(UtilTest.class)); > addTest(new TestSuite(MarkerTesterTest.class)); >+ addTest(new TestSuite(TextHandlerTest.class)); > } > } >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/plugin.xml,v >retrieving revision 1.268 >diff -u -r1.268 plugin.xml >--- plugin.xml 21 Jan 2009 19:25:22 -0000 1.268 >+++ plugin.xml 27 Jan 2009 18:11:38 -0000 >@@ -465,6 +465,12 @@ > name="NonRestorableView" > restorable="false"> > </view> >+ <view >+ class="org.eclipse.ui.tests.internal.TextControlView" >+ id="org.eclipse.ui.tests.textHandlerView" >+ name="Text Control view" >+ restorable="true"> >+ </view> > > </extension> > <extension >Index: Eclipse UI Tests/org/eclipse/ui/tests/internal/TextControlView.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/internal/TextControlView.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/internal/TextControlView.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/internal/TextControlView.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,115 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation 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 >+ ******************************************************************************/ >+ >+package org.eclipse.ui.tests.internal; >+ >+import java.lang.reflect.Field; >+import java.lang.reflect.Method; >+ >+import org.eclipse.jface.action.Action; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Text; >+import org.eclipse.ui.actions.TextActionHandler; >+import org.eclipse.ui.part.ViewPart; >+ >+/** >+ * @since 3.5 >+ * >+ */ >+public class TextControlView extends ViewPart { >+ public static final String ID = "org.eclipse.ui.tests.textHandlerView"; >+ public Action cutAction; >+ public Action copyAction; >+ public Action selectAllAction; >+ public Action pasteAction; >+ public Action cutDummyAction; >+ public Action copyDummyAction; >+ public Action selectDummyAllAction; >+ public Action pasteDummyAction; >+ public Text editableText; >+ public Text nonEditableText; >+ private TextActionHandler delegator; >+ >+ public TextControlView() { >+ cutDummyAction = new Action("Cut") { >+ }; >+ copyDummyAction = new Action("Copy") { >+ }; >+ selectDummyAllAction = new Action("Select All") { >+ }; >+ pasteDummyAction = new Action("Paste") { >+ }; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets >+ * .Composite) >+ */ >+ public void createPartControl(Composite parent) { >+ Composite c = new Composite(parent, SWT.NONE); >+ c.setLayout(new GridLayout(3, true)); >+ editableText = new Text(c, SWT.MULTI); >+ editableText.setLayoutData(new GridData()); >+ nonEditableText = new Text(c, SWT.MULTI | SWT.READ_ONLY); >+ nonEditableText.setLayoutData(new GridData()); >+ delegator = new TextActionHandler(getViewSite().getActionBars()); >+ delegator.addText(editableText); >+ delegator.addText(nonEditableText); >+ delegator.setCutAction(cutDummyAction); >+ delegator.setCopyAction(copyDummyAction); >+ delegator.setSelectAllAction(selectDummyAllAction); >+ delegator.setPasteAction(pasteDummyAction); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.ui.part.WorkbenchPart#setFocus() >+ */ >+ public void setFocus() { >+ editableText.setFocus(); >+ } >+ >+ public Action getPasteAction() throws Exception { >+ return getAction("textPasteAction"); >+ } >+ >+ public Action getCopyAction() throws Exception { >+ return getAction("textCopyAction"); >+ } >+ >+ public Action getCutAction() throws Exception { >+ return getAction("textCutAction"); >+ } >+ >+ public Action getSelectAllAction() throws Exception { >+ return getAction("textSelectAllAction"); >+ } >+ >+ public void updateEnabledState() throws Exception { >+ Method method = TextActionHandler.class.getDeclaredMethod( >+ "updateActionsEnableState", null); >+ method.setAccessible(true); >+ method.invoke(delegator, null); >+ } >+ >+ private Action getAction(String fieldName) throws Exception { >+ Field field = TextActionHandler.class.getDeclaredField(fieldName); >+ field.setAccessible(true); >+ return (Action) field.get(delegator); >+ } >+} >Index: Eclipse UI Tests/org/eclipse/ui/tests/internal/TextHandlerTest.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/internal/TextHandlerTest.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/internal/TextHandlerTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/internal/TextHandlerTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,126 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation 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 >+ ******************************************************************************/ >+ >+package org.eclipse.ui.tests.internal; >+ >+import org.eclipse.swt.dnd.Clipboard; >+import org.eclipse.swt.dnd.TextTransfer; >+import org.eclipse.swt.dnd.Transfer; >+import org.eclipse.swt.dnd.URLTransfer; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.tests.harness.util.UITestCase; >+ >+/** >+ * @since 3.5 >+ * >+ */ >+public class TextHandlerTest extends UITestCase { >+ >+ public TextHandlerTest(String testName) { >+ super(testName); >+ } >+ >+ public void testEditableText() throws Exception { >+ IWorkbenchWindow window = openTestWindow(); >+ TextControlView view = (TextControlView) window.getActivePage() >+ .showView(TextControlView.ID); >+ >+ Clipboard clipboard = new Clipboard(window.getWorkbench().getDisplay()); >+ try { >+ clipboard.setContents(new Object[] { "http://www.google.ca" }, >+ new Transfer[] { URLTransfer.getInstance() }); >+ processEvents(); >+ view.updateEnabledState(); >+ >+ assertFalse(view.getCopyAction().isEnabled()); >+ assertFalse(view.getCutAction().isEnabled()); >+ assertFalse(view.getPasteAction().isEnabled()); >+ assertFalse(view.getSelectAllAction().isEnabled()); >+ >+ view.editableText.setText("Hello"); >+ processEvents(); >+ view.updateEnabledState(); >+ assertFalse(view.getCopyAction().isEnabled()); >+ assertFalse(view.getCutAction().isEnabled()); >+ assertFalse(view.getPasteAction().isEnabled()); >+ assertTrue(view.getSelectAllAction().isEnabled()); >+ >+ view.editableText.setSelection(0, 3); >+ processEvents(); >+ view.updateEnabledState(); >+ assertTrue(view.getCopyAction().isEnabled()); >+ assertTrue(view.getCutAction().isEnabled()); >+ assertFalse(view.getPasteAction().isEnabled()); >+ assertTrue(view.getSelectAllAction().isEnabled()); >+ >+ clipboard.setContents(new Object[] { "http://www.google.ca" }, >+ new Transfer[] { TextTransfer.getInstance() }); >+ processEvents(); >+ view.updateEnabledState(); >+ >+ assertTrue(view.getCopyAction().isEnabled()); >+ assertTrue(view.getCutAction().isEnabled()); >+ assertTrue(view.getPasteAction().isEnabled()); >+ assertTrue(view.getSelectAllAction().isEnabled()); >+ >+ } finally { >+ clipboard.dispose(); >+ } >+ } >+ >+ public void testNonEditableText() throws Exception { >+ IWorkbenchWindow window = openTestWindow(); >+ TextControlView view = (TextControlView) window.getActivePage() >+ .showView(TextControlView.ID); >+ >+ Clipboard clipboard = new Clipboard(window.getWorkbench().getDisplay()); >+ try { >+ clipboard.setContents(new Object[] { "http://www.google.ca" }, >+ new Transfer[] { URLTransfer.getInstance() }); >+ view.nonEditableText.setFocus(); >+ processEvents(); >+ view.updateEnabledState(); >+ >+ assertFalse(view.getCopyAction().isEnabled()); >+ assertFalse(view.getCutAction().isEnabled()); >+ assertFalse(view.getPasteAction().isEnabled()); >+ assertFalse(view.getSelectAllAction().isEnabled()); >+ >+ view.nonEditableText.setText("Hello"); >+ processEvents(); >+ view.updateEnabledState(); >+ assertFalse(view.getCopyAction().isEnabled()); >+ assertFalse(view.getCutAction().isEnabled()); >+ assertFalse(view.getPasteAction().isEnabled()); >+ assertTrue(view.getSelectAllAction().isEnabled()); >+ >+ view.nonEditableText.setSelection(0, 3); >+ processEvents(); >+ view.updateEnabledState(); >+ assertTrue(view.getCopyAction().isEnabled()); >+ assertFalse(view.getCutAction().isEnabled()); >+ assertFalse(view.getPasteAction().isEnabled()); >+ assertTrue(view.getSelectAllAction().isEnabled()); >+ >+ clipboard.setContents(new Object[] { "http://www.google.ca" }, >+ new Transfer[] { TextTransfer.getInstance() }); >+ processEvents(); >+ view.updateEnabledState(); >+ >+ assertTrue(view.getCopyAction().isEnabled()); >+ assertFalse(view.getCutAction().isEnabled()); >+ assertFalse(view.getPasteAction().isEnabled()); >+ assertTrue(view.getSelectAllAction().isEnabled()); >+ } finally { >+ clipboard.dispose(); >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 262615
: 123909