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 134971 Details for
Bug 275393
[FieldAssist] Automate the manual test cases
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]
Generalize field assist tests patch v1
bug275393-patch-v1.txt (text/plain), 38.73 KB, created by
Remy Suen
on 2009-05-08 10:18:54 EDT
(
hide
)
Description:
Generalize field assist tests patch v1
Filename:
MIME Type:
Creator:
Remy Suen
Created:
2009-05-08 10:18:54 EDT
Size:
38.73 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.tests >Index: Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/FieldAssistTestSuite.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/FieldAssistTestSuite.java,v >retrieving revision 1.1 >diff -u -r1.1 FieldAssistTestSuite.java >--- Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/FieldAssistTestSuite.java 10 Oct 2006 18:39:47 -0000 1.1 >+++ Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/FieldAssistTestSuite.java 8 May 2009 14:04:25 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2006 IBM Corporation and others. >+ * Copyright (c) 2005, 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 >@@ -30,5 +30,7 @@ > */ > public FieldAssistTestSuite() { > addTest(new TestSuite(FieldAssistAPITest.class)); >+ addTest(new TestSuite(ComboContentAssistCommandAdapterTest.class)); >+ addTest(new TestSuite(TextContentAssistCommandAdapterTest.class)); > } > } >Index: Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/FieldAssistAPITest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/FieldAssistAPITest.java,v >retrieving revision 1.2 >diff -u -r1.2 FieldAssistAPITest.java >--- Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/FieldAssistAPITest.java 7 May 2009 23:10:49 -0000 1.2 >+++ Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/FieldAssistAPITest.java 8 May 2009 14:04:25 -0000 >@@ -15,28 +15,8 @@ > > import junit.framework.TestCase; > >-import org.eclipse.jface.dialogs.Dialog; >-import org.eclipse.jface.dialogs.MessageDialog; >-import org.eclipse.jface.fieldassist.ContentProposalAdapter; > import org.eclipse.jface.fieldassist.FieldDecorationRegistry; >-import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; >-import org.eclipse.jface.fieldassist.TextContentAdapter; >-import org.eclipse.jface.layout.GridDataFactory; >-import org.eclipse.jface.layout.GridLayoutFactory; >-import org.eclipse.swt.SWT; > import org.eclipse.swt.graphics.Image; >-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.Label; >-import org.eclipse.swt.widgets.Shell; >-import org.eclipse.swt.widgets.Text; >-import org.eclipse.ui.IWorkbench; >-import org.eclipse.ui.IWorkbenchCommandConstants; >-import org.eclipse.ui.PlatformUI; >-import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter; >-import org.eclipse.ui.handlers.IHandlerService; > import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages; > > /** >@@ -46,8 +26,6 @@ > */ > public class FieldAssistAPITest extends TestCase { > >- private Dialog dialog; >- > public FieldAssistAPITest() { > super(); > } >@@ -59,17 +37,6 @@ > super(name); > } > >- protected void setUp() throws Exception { >- super.setUp(); >- } >- >- protected void tearDown() throws Exception { >- if (dialog != null) { >- dialog.close(); >- } >- super.tearDown(); >- } >- > public void testFieldDecorationRegistry() { > int originalMaxHeight = FieldDecorationRegistry.getDefault() > .getMaximumDecorationHeight(); >@@ -123,318 +90,5 @@ > .getMaximumDecorationHeight() == originalMaxHeight); > assertTrue(FieldDecorationRegistry.getDefault() > .getMaximumDecorationWidth() == originalMaxWidth); >- >- } >- >- /** >- * Tests that a ContentAssistCommandAdapter that has no autoactivation >- * characters set will not have its proposals disappear when a user invokes >- * content assist and then subsequently inserts a character that matches the >- * first character of a suggested proposal. >- * <p> >- * <ol> >- * <li>User invokes content assist</li> >- * <li>"one", "two", "three"...shows up</li> >- * <li>User hits the 'O' key</li> >- * <li>The list shows up (the bug was reporting that the list disappeared)</li> >- * </ol> >- * >- * @see org.eclipse.jface.tests.fieldassist.FieldAssistAPITest >- */ >- public void testBug271339EmptyAutoActivationCharacters() throws Exception { >- IWorkbench workbench = PlatformUI.getWorkbench(); >- Shell shell = workbench.getActiveWorkbenchWindow().getShell(); >- Display display = shell.getDisplay(); >- >- // record the number of shells we have up and active >- int shellCount = display.getShells().length; >- >- // the text control of our dialog >- final Text[] textField = { null }; >- >- dialog = new MessageDialog(shell, null, null, null, >- MessageDialog.INFORMATION, new String[] { "OK" }, 0) { >- protected Control createCustomArea(Composite parent) { >- String[] proposals = new String[] { "one", "two", "three", >- "four", "five", "six", "seven", "eight", "nine", "ten" }; >- >- Composite container = new Composite(parent, SWT.NULL); >- GridDataFactory.fillDefaults().grab(true, true).applyTo( >- container); >- GridLayoutFactory.swtDefaults().numColumns(2) >- .applyTo(container); >- >- Label label = new Label(container, SWT.NULL); >- label.setText("Test Content Assist bug 271339"); >- >- textField[0] = new Text(container, SWT.FLAT); >- SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider( >- proposals); >- proposalProvider.setFiltering(true); >- >- // use an empty character array because no characters should >- // prompt for autoactivation >- ContentAssistCommandAdapter adapter = new ContentAssistCommandAdapter( >- textField[0], new TextContentAdapter(), >- proposalProvider, null, new char[0], true); >- adapter >- .setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); >- >- GridDataFactory.fillDefaults().grab(true, false).applyTo( >- textField[0]); >- >- return container; >- } >- }; >- >- // we don't want to block the tests >- dialog.setBlockOnOpen(false); >- dialog.open(); >- >- // grant the text field focus >- textField[0].setFocus(); >- // spin the event loop to make sure the text field gets focus >- while (display.readAndDispatch()) >- ; >- >- // retrieve the content assist handler and run it >- IHandlerService handlerService = (IHandlerService) workbench >- .getService(IHandlerService.class); >- handlerService.executeCommand( >- IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST, null); >- >- assertEquals( >- "There should be two more shells up, the dialog and the proposals dialog", >- shellCount + 2, display.getShells().length); >- >- // fake a KeyDown event >- Event event = new Event(); >- event.type = SWT.KeyDown; >- event.character = 'o'; >- textField[0].notifyListeners(SWT.KeyDown, event); >- >- // now we insert the character 'o', this will send out a Modify event >- textField[0].insert("o"); //$NON-NLS-1$ >- >- assertEquals( >- "There should still be two more shells up, the dialog and the proposals dialog", >- shellCount + 2, display.getShells().length); >- >- // spin the event loop again because we have some asyncExec calls in the >- // ContentProposalAdapter class >- while (display.readAndDispatch()) >- ; >- >- // clean-up >- dialog.close(); >- } >- >- /** >- * Tests that a ContentAssistCommandAdapter that has no autoactivation >- * characters set will not have its proposals appear when a user inserts a >- * character that matches the first character of a suggested proposal. >- * <p> >- * <ol> >- * <li>User hits the 'O' key</li> >- * <li>While "one" matches, the proposals should not appear as no >- * autoactivation characters have been set</li> >- * </ol> >- * >- * @see org.eclipse.jface.tests.fieldassist.FieldAssistAPITest >- */ >- public void testBug271339EmptyAutoActivationCharacters2() throws Exception { >- IWorkbench workbench = PlatformUI.getWorkbench(); >- Shell shell = workbench.getActiveWorkbenchWindow().getShell(); >- Display display = shell.getDisplay(); >- >- // record the number of shells we have up and active >- int shellCount = display.getShells().length; >- >- // the text control of our dialog >- final Text[] textField = { null }; >- >- dialog = new MessageDialog(shell, null, null, null, >- MessageDialog.INFORMATION, new String[] { "OK" }, 0) { >- protected Control createCustomArea(Composite parent) { >- String[] proposals = new String[] { "one", "two", "three", >- "four", "five", "six", "seven", "eight", "nine", "ten" }; >- >- Composite container = new Composite(parent, SWT.NULL); >- GridDataFactory.fillDefaults().grab(true, true).applyTo( >- container); >- GridLayoutFactory.swtDefaults().numColumns(2) >- .applyTo(container); >- >- Label label = new Label(container, SWT.NULL); >- label.setText("Test Content Assist bug 271339"); >- >- textField[0] = new Text(container, SWT.FLAT); >- SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider( >- proposals); >- proposalProvider.setFiltering(true); >- >- // use an empty character array because no characters should >- // prompt for autoactivation >- ContentAssistCommandAdapter adapter = new ContentAssistCommandAdapter( >- textField[0], new TextContentAdapter(), >- proposalProvider, null, new char[0], true); >- adapter >- .setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); >- >- GridDataFactory.fillDefaults().grab(true, false).applyTo( >- textField[0]); >- >- return container; >- } >- }; >- >- // we don't want to block the tests >- dialog.setBlockOnOpen(false); >- dialog.open(); >- >- // grant the text field focus >- textField[0].setFocus(); >- // spin the event loop to make sure the text field gets focus >- while (display.readAndDispatch()) >- ; >- >- // fake a KeyDown event >- Event event = new Event(); >- event.type = SWT.KeyDown; >- event.character = 'o'; >- textField[0].notifyListeners(SWT.KeyDown, event); >- >- // now we insert the character 'o', this will send out a Modify event >- textField[0].insert("o"); //$NON-NLS-1$ >- >- // we have no autoactivation characters, the proposals should not appear >- assertEquals( >- "There should only be one more extra shell, the dialog itself", >- shellCount + 1, display.getShells().length); >- >- // spin the event loop again because we have some asyncExec calls in the >- // ContentProposalAdapter class >- while (display.readAndDispatch()) >- ; >- >- // clean-up >- dialog.close(); >- } >- >- /** >- * Tests that a ContentAssistCommandAdapter that has no autoactivation >- * characters set will stay open if the user backspaces over a narrowing >- * proposal character. >- * <p> >- * <ol> >- * <li>User invokes content assist</li> >- * <li>"one", "two", "three"...shows up</li> >- * <li>User hits the 'O' key</li> >- * <li>The list narrows</li> >- * <li>user hits backspace</li> >- * <li>the popup should remain open</li> >- * </ol> >- * >- * @see org.eclipse.jface.tests.fieldassist.FieldAssistAPITest >- */ >- public void testBug271339EmptyAutoActivationCharacters3() throws Exception { >- IWorkbench workbench = PlatformUI.getWorkbench(); >- Shell shell = workbench.getActiveWorkbenchWindow().getShell(); >- Display display = shell.getDisplay(); >- >- // record the number of shells we have up and active >- int shellCount = display.getShells().length; >- >- // the text control of our dialog >- final Text[] textField = { null }; >- >- dialog = new MessageDialog(shell, null, null, null, >- MessageDialog.INFORMATION, new String[] { "OK" }, 0) { >- protected Control createCustomArea(Composite parent) { >- String[] proposals = new String[] { "one", "two", "three", >- "four", "five", "six", "seven", "eight", "nine", "ten" }; >- >- Composite container = new Composite(parent, SWT.NULL); >- GridDataFactory.fillDefaults().grab(true, true).applyTo( >- container); >- GridLayoutFactory.swtDefaults().numColumns(2) >- .applyTo(container); >- >- Label label = new Label(container, SWT.NULL); >- label.setText("Test Content Assist bug 271339"); >- >- textField[0] = new Text(container, SWT.FLAT); >- SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider( >- proposals); >- proposalProvider.setFiltering(true); >- >- // use an empty character array because no characters should >- // prompt for autoactivation >- ContentAssistCommandAdapter adapter = new ContentAssistCommandAdapter( >- textField[0], new TextContentAdapter(), >- proposalProvider, null, new char[0], true); >- adapter >- .setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); >- >- GridDataFactory.fillDefaults().grab(true, false).applyTo( >- textField[0]); >- >- return container; >- } >- }; >- >- // we don't want to block the tests >- dialog.setBlockOnOpen(false); >- dialog.open(); >- >- // grant the text field focus >- textField[0].setFocus(); >- // spin the event loop to make sure the text field gets focus >- while (display.readAndDispatch()) >- ; >- >- // retrieve the content assist handler and run it >- IHandlerService handlerService = (IHandlerService) workbench >- .getService(IHandlerService.class); >- handlerService.executeCommand( >- IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST, null); >- >- assertEquals( >- "There should be two more shells up, the dialog and the proposals dialog", >- shellCount + 2, display.getShells().length); >- >- // fake a KeyDown event >- Event event = new Event(); >- event.type = SWT.KeyDown; >- event.character = 'o'; >- textField[0].notifyListeners(SWT.KeyDown, event); >- >- // now we insert the character 'o', this will send out a Modify event >- textField[0].insert("o"); //$NON-NLS-1$ >- >- assertEquals( >- "There should still be two more shells up, the dialog and the proposals dialog", >- shellCount + 2, display.getShells().length); >- >- // fake a Backspace >- event = new Event(); >- event.type = SWT.KeyDown; >- event.character = SWT.BS; >- textField[0].notifyListeners(SWT.KeyDown, event); >- >- // now we remove the o, this will trigger a modify >- textField[0].setText(""); //$NON-NLS-1$ >- >- assertEquals( >- "There should still be two more shells up, the dialog and the proposals dialog", >- shellCount + 2, display.getShells().length); >- >- // spin the event loop again because we have some asyncExec calls in the >- // ContentProposalAdapter class >- while (display.readAndDispatch()) >- ; >- >- // clean-up >- dialog.close(); > } > } >Index: Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/ComboFieldAssistWindow.java >=================================================================== >RCS file: Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/ComboFieldAssistWindow.java >diff -N Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/ComboFieldAssistWindow.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/ComboFieldAssistWindow.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,36 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Remy Chi Jian Suen 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: >+ * Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.jface.tests.fieldassist; >+ >+import org.eclipse.jface.fieldassist.ComboContentAdapter; >+import org.eclipse.jface.fieldassist.IControlContentAdapter; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Combo; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+ >+public class ComboFieldAssistWindow extends AbstractFieldAssistWindow { >+ >+ protected IControlContentAdapter getControlContentAdapter() { >+ return new ComboContentAdapter(); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @seeorg.eclipse.jface.tests.fieldassist.AbstractFieldAssistWindow# >+ * createFieldAssistControl(org.eclipse.swt.widgets.Composite) >+ */ >+ protected Control createFieldAssistControl(Composite parent) { >+ return new Combo(parent, SWT.DROP_DOWN); >+ } >+ >+} >Index: Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/TextCommandFieldAssistWindow.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/TextCommandFieldAssistWindow.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/TextCommandFieldAssistWindow.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/TextCommandFieldAssistWindow.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,27 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Remy Chi Jian Suen 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: >+ * Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.ui.tests.fieldassist; >+ >+import org.eclipse.jface.fieldassist.ContentProposalAdapter; >+import org.eclipse.jface.tests.fieldassist.TextFieldAssistWindow; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter; >+ >+public class TextCommandFieldAssistWindow extends TextFieldAssistWindow { >+ >+ protected ContentProposalAdapter createContentProposalAdapter( >+ Control control) { >+ return new ContentAssistCommandAdapter(control, >+ getControlContentAdapter(), getContentProposalProvider(), null, >+ getAutoActivationCharacters()); >+ } >+ >+} >Index: Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/TextContentAssistCommandAdapterTest.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/TextContentAssistCommandAdapterTest.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/TextContentAssistCommandAdapterTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/TextContentAssistCommandAdapterTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,22 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Remy Chi Jian Suen 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: >+ * Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.ui.tests.fieldassist; >+ >+import org.eclipse.jface.tests.fieldassist.AbstractFieldAssistWindow; >+ >+public class TextContentAssistCommandAdapterTest extends >+ AbstractContentAssistCommandAdapterTest { >+ >+ protected AbstractFieldAssistWindow createFieldAssistWindow() { >+ return new TextCommandFieldAssistWindow(); >+ } >+ >+} >Index: Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/AbstractFieldAssistTestCase.java >=================================================================== >RCS file: Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/AbstractFieldAssistTestCase.java >diff -N Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/AbstractFieldAssistTestCase.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/AbstractFieldAssistTestCase.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,144 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Remy Chi Jian Suen 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: >+ * Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.jface.tests.fieldassist; >+ >+import junit.framework.TestCase; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Combo; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Text; >+ >+public abstract class AbstractFieldAssistTestCase extends TestCase { >+ >+ /** >+ * The window that is being tested. >+ */ >+ private AbstractFieldAssistWindow window; >+ >+ /** >+ * The original number of shells at the beginning of the test. >+ */ >+ private int originalShellCount; >+ >+ /** >+ * Sets up this field assist test case. Subclasses should extend but not >+ * override. >+ */ >+ protected void setUp() throws Exception { >+ super.setUp(); >+ originalShellCount = Display.getDefault().getShells().length; >+ window = createFieldAssistWindow(); >+ assertNotNull(window); >+ } >+ >+ /** >+ * Tears down this field assist test case. Subclasses should extend but not >+ * override. >+ */ >+ protected void tearDown() throws Exception { >+ if (window != null) { >+ spinEventLoop(); >+ >+ // clean-up >+ window.close(); >+ window = null; >+ } >+ >+ super.tearDown(); >+ } >+ >+ /** >+ * Creates the field assist window that is to be tested. >+ */ >+ protected abstract AbstractFieldAssistWindow createFieldAssistWindow(); >+ >+ /** >+ * Returns the created field assist window. May be null if >+ * {@link #createFieldAssistWindow()} has not been called yet or if the test >+ * is being torn down. >+ */ >+ protected AbstractFieldAssistWindow getFieldAssistWindow() { >+ return window; >+ } >+ >+ protected void spinEventLoop() { >+ // spin the event loop again because we have some asyncExec calls in the >+ // ContentProposalAdapter class >+ while (window.getDisplay().readAndDispatch()) >+ ; >+ } >+ >+ protected void ensurePopupIsUp() { >+ // if our autoactivation delay is zero, we use an asyncExec to get the >+ // popup up, hence, we need to spin the event loop >+ if (window.getAutoActivationDelay() == 0) { >+ spinEventLoop(); >+ } >+ } >+ >+ /** >+ * Sends an SWT FocisIn event to the field assist control. >+ */ >+ protected void sendFocusInToControl() { >+ Event event = new Event(); >+ event.type = SWT.FocusIn; >+ window.getFieldAssistControl().notifyListeners(SWT.FocusIn, event); >+ } >+ >+ /** >+ * Sends an SWT KeyDown event for the specified character to the field >+ * assist control. >+ * >+ * @param character >+ * the character that has been pressed >+ */ >+ protected void sendKeyDownToControl(char character) { >+ // fake a KeyDown event >+ Event event = new Event(); >+ event.type = SWT.KeyDown; >+ event.character = character; >+ window.getFieldAssistControl().notifyListeners(SWT.KeyDown, event); >+ } >+ >+ /** >+ * Sets the text of the field assist control. >+ */ >+ protected void setText(String string) { >+ Control control = window.getFieldAssistControl(); >+ if (control instanceof Combo) { >+ ((Combo) control).setText(string); >+ } else if (control instanceof Text) { >+ ((Text) control).setText(string); >+ } >+ } >+ >+ /** >+ * Checks that there is only one shell up, the original field assist window. >+ */ >+ protected void assertOneShellUp() { >+ assertEquals("There should only be one shell up, the dialog", >+ originalShellCount + 1, window.getDisplay().getShells().length); >+ } >+ >+ /** >+ * Checks that there are two shells up, the original field assist window and >+ * the proposals popup. >+ */ >+ protected void assertTwoShellsUp() { >+ assertEquals( >+ "There should two shells up, the dialog and the proposals dialog", >+ originalShellCount + 2, window.getDisplay().getShells().length); >+ } >+ >+} >Index: Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/AbstractFieldAssistWindow.java >=================================================================== >RCS file: Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/AbstractFieldAssistWindow.java >diff -N Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/AbstractFieldAssistWindow.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/AbstractFieldAssistWindow.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,147 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Remy Chi Jian Suen 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: >+ * Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.jface.tests.fieldassist; >+ >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.jface.bindings.keys.KeyStroke; >+import org.eclipse.jface.fieldassist.ContentProposalAdapter; >+import org.eclipse.jface.fieldassist.IContentProposalProvider; >+import org.eclipse.jface.fieldassist.IControlContentAdapter; >+import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; >+import org.eclipse.jface.window.Window; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+ >+public abstract class AbstractFieldAssistWindow extends Window { >+ >+ private Control fieldAssistControl; >+ >+ private IContentProposalProvider proposalProvider; >+ private KeyStroke keyStroke = null; >+ private char[] autoActivationCharacters = null; >+ private int filterStyle = ContentProposalAdapter.FILTER_NONE; >+ private boolean propagateKeys = true; >+ private int acceptance = ContentProposalAdapter.PROPOSAL_INSERT; >+ private int autoActivationDelay = 0; >+ >+ public AbstractFieldAssistWindow() { >+ super((Shell) null); >+ } >+ >+ public Display getDisplay() { >+ return getShell().getDisplay(); >+ } >+ >+ protected Control createContents(Composite parent) { >+ Composite content = (Composite) super.createContents(parent); >+ content.setLayout(new FillLayout()); >+ >+ fieldAssistControl = createFieldAssistControl(parent); >+ Assert.isNotNull(fieldAssistControl); >+ >+ ContentProposalAdapter adapter = createContentProposalAdapter(fieldAssistControl); >+ adapter.setAutoActivationDelay(autoActivationDelay); >+ adapter.setFilterStyle(filterStyle); >+ adapter.setPropagateKeys(propagateKeys); >+ adapter.setProposalAcceptanceStyle(acceptance); >+ >+ return content; >+ } >+ >+ /** >+ * Create and return the content proposal adapter that will be used by this >+ * field assist window. >+ * >+ * @param control >+ * the SWT control to provide field assist for >+ */ >+ protected ContentProposalAdapter createContentProposalAdapter( >+ Control control) { >+ return new ContentProposalAdapter(control, getControlContentAdapter(), >+ getContentProposalProvider(), getKeyStroke(), >+ getAutoActivationCharacters()); >+ } >+ >+ protected abstract IControlContentAdapter getControlContentAdapter(); >+ >+ public Control getFieldAssistControl() { >+ return fieldAssistControl; >+ } >+ >+ protected abstract Control createFieldAssistControl(Composite parent); >+ >+ public void setAutoActivationDelay(int autoActivationDelay) { >+ this.autoActivationDelay = autoActivationDelay; >+ } >+ >+ public final int getAutoActivationDelay() { >+ return autoActivationDelay; >+ } >+ >+ protected boolean shouldFilterProposals() { >+ return true; >+ } >+ >+ protected String[] getProposals() { >+ return new String[] { "one", "two", "three", "four", "five", "six", >+ "seven", "eight", "nine", "ten" }; >+ } >+ >+ protected char[] getAutoActivationCharacters() { >+ return autoActivationCharacters; >+ } >+ >+ public void setAutoActivationCharacters(char[] autoActivationCharacters) { >+ this.autoActivationCharacters = autoActivationCharacters; >+ } >+ >+ protected IContentProposalProvider createContentProposalProvider() { >+ SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider( >+ getProposals()); >+ proposalProvider.setFiltering(shouldFilterProposals()); >+ return proposalProvider; >+ } >+ >+ protected IContentProposalProvider getContentProposalProvider() { >+ if (proposalProvider == null) { >+ proposalProvider = createContentProposalProvider(); >+ } >+ return proposalProvider; >+ } >+ >+ public void setContentProposalProvider( >+ IContentProposalProvider proposalProvider) { >+ this.proposalProvider = proposalProvider; >+ } >+ >+ public void setFilterStyle(int filterStyle) { >+ this.filterStyle = filterStyle; >+ } >+ >+ public void setPropagateKeys(boolean propagateKeys) { >+ this.propagateKeys = propagateKeys; >+ } >+ >+ public void setProposalAcceptanceStyle(int acceptance) { >+ this.acceptance = acceptance; >+ } >+ >+ protected KeyStroke getKeyStroke() { >+ return keyStroke; >+ } >+ >+ public void setKeyStroke(KeyStroke keyStroke) { >+ this.keyStroke = keyStroke; >+ } >+} >Index: Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/AbstractContentAssistCommandAdapterTest.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/AbstractContentAssistCommandAdapterTest.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/AbstractContentAssistCommandAdapterTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/AbstractContentAssistCommandAdapterTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,143 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Remy Chi Jian Suen 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: >+ * Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.ui.tests.fieldassist; >+ >+import org.eclipse.jface.tests.fieldassist.AbstractFieldAssistTestCase; >+import org.eclipse.swt.SWT; >+import org.eclipse.ui.IWorkbenchCommandConstants; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.handlers.IHandlerService; >+ >+public abstract class AbstractContentAssistCommandAdapterTest extends >+ AbstractFieldAssistTestCase { >+ >+ protected void executeContentAssistHandler() throws Exception { >+ // retrieve the content assist handler and run it >+ IHandlerService handlerService = (IHandlerService) PlatformUI >+ .getWorkbench().getService(IHandlerService.class); >+ handlerService.executeCommand( >+ IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST, null); >+ } >+ >+ public void testHandlerPromptsPopup() throws Exception { >+ getFieldAssistWindow().open(); >+ >+ sendFocusInToControl(); >+ executeContentAssistHandler(); >+ >+ assertTwoShellsUp(); >+ } >+ >+ /** >+ * Tests that a ContentAssistCommandAdapter that has no autoactivation >+ * characters set will not have its proposals disappear when a user invokes >+ * content assist and then subsequently inserts a character that matches the >+ * first character of a suggested proposal. >+ * <p> >+ * <ol> >+ * <li>User invokes content assist</li> >+ * <li>"one", "two", "three"...shows up</li> >+ * <li>User hits the 'O' key</li> >+ * <li>The list shows up (the bug was reporting that the list disappeared)</li> >+ * </ol> >+ */ >+ public void testBug271339EmptyAutoActivationCharacters() throws Exception { >+ getFieldAssistWindow().open(); >+ >+ sendFocusInToControl(); >+ executeContentAssistHandler(); >+ >+ assertTwoShellsUp(); >+ >+ sendKeyDownToControl('o'); >+ setText("o"); //$NON-NLS-1$ >+ >+ assertTwoShellsUp(); >+ } >+ >+ /** >+ * Tests that a ContentAssistCommandAdapter that has no autoactivation >+ * characters set will not have its proposals appear when a user inserts a >+ * character that matches the first character of a suggested proposal. >+ * <p> >+ * <ol> >+ * <li>User hits the 'O' key</li> >+ * <li>While "one" matches, the proposals should not appear as no >+ * autoactivation characters have been set</li> >+ * </ol> >+ */ >+ public void testBug271339EmptyAutoActivationCharacters2() throws Exception { >+ getFieldAssistWindow().open(); >+ >+ sendFocusInToControl(); >+ >+ sendKeyDownToControl('o'); >+ setText("o"); //$NON-NLS-1$ >+ >+ assertOneShellUp(); >+ } >+ >+ /** >+ * Tests that a ContentAssistCommandAdapter that has no autoactivation >+ * characters set will stay open if the user backspaces over a narrowing >+ * proposal character. >+ * <p> >+ * <ol> >+ * <li>User invokes content assist</li> >+ * <li>"one", "two", "three"...shows up</li> >+ * <li>User hits the 'O' key</li> >+ * <li>The list narrows</li> >+ * <li>user hits backspace</li> >+ * <li>the popup should remain open</li> >+ * </ol> >+ */ >+ public void testBug271339EmptyAutoActivationCharacters3() throws Exception { >+ getFieldAssistWindow().open(); >+ >+ sendFocusInToControl(); >+ executeContentAssistHandler(); >+ >+ assertTwoShellsUp(); >+ >+ sendKeyDownToControl('o'); >+ setText("o"); //$NON-NLS-1$ >+ >+ assertTwoShellsUp(); >+ >+ sendKeyDownToControl(SWT.BS); >+ setText(""); >+ >+ assertTwoShellsUp(); >+ } >+ >+// public void testX() throws Exception { >+// getFieldAssistWindow().setAutoActivationCharacters(new char[] { 'o', 't' }); >+// getFieldAssistWindow().open(); >+// >+// setFocusToControl(); >+// >+// sendKeyDownToControl('o'); >+// setText("o"); //$NON-NLS-1$ >+// >+// assertOneShellUp(); >+// >+// executeContentAssistHandler(); >+// >+// assertTwoShellsUp(); >+// >+// sendKeyDownToControl(SWT.BS); >+// setText(""); >+// >+// assertTwoShellsUp(); >+// } >+ >+} >Index: Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/ComboContentAssistCommandAdapterTest.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/ComboContentAssistCommandAdapterTest.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/ComboContentAssistCommandAdapterTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/ComboContentAssistCommandAdapterTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,22 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Remy Chi Jian Suen 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: >+ * Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.ui.tests.fieldassist; >+ >+import org.eclipse.jface.tests.fieldassist.AbstractFieldAssistWindow; >+ >+public class ComboContentAssistCommandAdapterTest extends >+ AbstractContentAssistCommandAdapterTest { >+ >+ protected AbstractFieldAssistWindow createFieldAssistWindow() { >+ return new ComboCommandFieldAssistWindow(); >+ } >+ >+} >Index: Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/ComboCommandFieldAssistWindow.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/ComboCommandFieldAssistWindow.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/ComboCommandFieldAssistWindow.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/fieldassist/ComboCommandFieldAssistWindow.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,27 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Remy Chi Jian Suen 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: >+ * Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.ui.tests.fieldassist; >+ >+import org.eclipse.jface.fieldassist.ContentProposalAdapter; >+import org.eclipse.jface.tests.fieldassist.ComboFieldAssistWindow; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter; >+ >+public class ComboCommandFieldAssistWindow extends ComboFieldAssistWindow { >+ >+ protected ContentProposalAdapter createContentProposalAdapter( >+ Control control) { >+ return new ContentAssistCommandAdapter(control, >+ getControlContentAdapter(), getContentProposalProvider(), null, >+ getAutoActivationCharacters()); >+ } >+ >+} >Index: Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/TextFieldAssistWindow.java >=================================================================== >RCS file: Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/TextFieldAssistWindow.java >diff -N Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/TextFieldAssistWindow.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/TextFieldAssistWindow.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,39 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Remy Chi Jian Suen 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: >+ * Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.jface.tests.fieldassist; >+ >+import org.eclipse.jface.fieldassist.IControlContentAdapter; >+import org.eclipse.jface.fieldassist.TextContentAdapter; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Text; >+ >+public class TextFieldAssistWindow extends AbstractFieldAssistWindow { >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @seeorg.eclipse.jface.tests.fieldassist.AbstractFieldAssistWindow# >+ * createFieldAssistControl(org.eclipse.swt.widgets.Composite) >+ */ >+ protected Control createFieldAssistControl(Composite parent) { >+ return new Text(parent, SWT.SINGLE); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.tests.fieldassist.AbstractFieldAssistWindow#getControlContentAdapter() >+ */ >+ protected IControlContentAdapter getControlContentAdapter() { >+ return new TextContentAdapter(); >+ } >+ >+}
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 275393
: 134971