Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2003 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Common Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/cpl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
|
12 |
package org.eclipse.ui.tests.keys; |
13 |
|
14 |
|
15 |
import org.eclipse.core.resources.IProject; |
16 |
import org.eclipse.core.resources.IWorkspace; |
17 |
import org.eclipse.core.resources.ResourcesPlugin; |
18 |
import org.eclipse.core.runtime.CoreException; |
19 |
import org.eclipse.jface.action.IAction; |
20 |
import org.eclipse.swt.widgets.Display; |
21 |
import org.eclipse.swt.widgets.Event; |
22 |
import org.eclipse.swt.widgets.MenuItem; |
23 |
import org.eclipse.swt.widgets.Shell; |
24 |
import org.eclipse.ui.IWorkbenchActionConstants; |
25 |
import org.eclipse.ui.IWorkbenchWindow; |
26 |
import org.eclipse.ui.internal.Workbench; |
27 |
import org.eclipse.ui.keys.KeyStroke; |
28 |
import org.eclipse.ui.keys.ParseException; |
29 |
import org.eclipse.ui.tests.util.UITestCase; |
30 |
import org.eclipse.ui.texteditor.AbstractTextEditor; |
31 |
|
32 |
/** |
33 |
* Tests Bug 43321 |
34 |
* |
35 |
* @since 3.0 |
36 |
*/ |
37 |
public class Bug43321Test extends UITestCase { |
38 |
|
39 |
private static final String NAVIGATOR_VIEW_ID = "org.eclipse.ui.views.ResourceNavigator"; |
40 |
|
41 |
/* |
42 |
* @see TestCase#setUp() |
43 |
*/ |
44 |
protected void setUp() throws Exception { |
45 |
super.setUp(); |
46 |
} |
47 |
|
48 |
/* |
49 |
* @see TestCase#tearDown() |
50 |
*/ |
51 |
protected void tearDown() throws Exception { |
52 |
super.tearDown(); |
53 |
} |
54 |
|
55 |
/** |
56 |
* Constructor for Bug43321Test. |
57 |
* |
58 |
* @param name |
59 |
* The name of the test |
60 |
*/ |
61 |
public Bug43321Test(String name) { |
62 |
super(name); |
63 |
} |
64 |
|
65 |
/** |
66 |
* Tests that non-check box items on the menu are not checked when activated |
67 |
* from the keyboard. |
68 |
* @throws ParseException If "CTRL+C" isn't a valid key stroke. |
69 |
*/ |
70 |
public void testNoCheckOnNonCheckbox() throws CoreException, ParseException { |
71 |
IWorkbenchWindow window = openTestWindow(); |
72 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
73 |
IProject testProject = workspace.getRoot().getProject("TestProject"); //$NON-NLS-1$ |
74 |
testProject.create(null); |
75 |
testProject.open(null); |
76 |
AbstractTextEditor editor = (AbstractTextEditor) window.getActivePage().openEditor(testProject.getFile(".project")); //$NON-NLS-1$ |
77 |
editor.selectAndReveal(0, 1); |
78 |
|
79 |
// Update the display. |
80 |
Shell shell = window.getShell(); |
81 |
Display display = shell.getDisplay(); |
82 |
while (display.readAndDispatch()); |
83 |
|
84 |
// Press "Ctrl+C" to perform a copy. |
85 |
KeyStroke[] keyStrokes = { KeyStroke.getInstance("CTRL+C") }; //$NON-NLS-1$ |
86 |
Event event = new Event(); |
87 |
((Workbench) window.getWorkbench()).press(keyStrokes, event); |
88 |
|
89 |
// Get the menu item we've just selected. |
90 |
IAction action = editor.getEditorSite().getActionBars().getGlobalActionHandler(IWorkbenchActionConstants.COPY); |
91 |
assertTrue("Non-checkbox menu item is checked.", !action.isChecked()); //$NON-NLS-1$ |
92 |
} |
93 |
|
94 |
public static MenuItem getMenuItem(MenuItem[] menuItems, String text) { |
95 |
for (int i = 0; i < menuItems.length; i++) { |
96 |
if (menuItems[i].getText().equals(text)) { |
97 |
return menuItems[i]; |
98 |
} |
99 |
} |
100 |
|
101 |
return null; |
102 |
} |
103 |
} |