Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b8ebe47ecf46c299f7142fd9e7453f114de07131 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*******************************************************************************
 * Copyright (c) 2009, 2012 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 ******************************************************************************/

package org.eclipse.ui.tests.menus;

import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.internal.PartSite;
import org.eclipse.ui.internal.PopupMenuExtender;
import org.eclipse.ui.tests.api.ListElement;
import org.eclipse.ui.tests.api.ListView;
import org.eclipse.ui.tests.harness.util.UITestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
 * @since 3.5
 * @author Prakash G.R.
 *
 */
@RunWith(JUnit4.class)
public class Bug264804Test extends UITestCase {

	public Bug264804Test() {
		super(Bug264804Test.class.getSimpleName());
	}

	@Test
	public void testPopup() throws Exception {
		IWorkbenchWindow window = openTestWindow();

		ListView part = (ListView) window.getActivePage().showView(
				"org.eclipse.ui.tests.api.IActionFilterTest1");
		ListElement red = new ListElement("red");
		ListElement blue = new ListElement("blue");
		ListElement redTrue = new ListElement("red", true);
		part.addElement(red);
		part.addElement(blue);
		part.addElement(redTrue);

		assertNotNull(part);
		MenuManager manager = new MenuManager();

		final ISelectionProvider prov = part.getSelectionProvider();
		prov.setSelection(new StructuredSelection(blue));
		PopupMenuExtender popupMenuExtender = null;
		try {
			popupMenuExtender = new PopupMenuExtender(
					"org.eclipse.ui.tests.Bug264804", manager, prov, part,
					((PartSite)part.getSite()).getContext(), false);

			Menu contextMenu = manager.createContextMenu(window.getShell());
			// contextMenu.setVisible(true);
			Event e = new Event();
			e.widget = contextMenu;
			processEvents();
			contextMenu.notifyListeners(SWT.Show, e);

			find("org.eclipse.ui.file.close", manager.getItems());

			// This is our error case, we process the Hide event and then
			// process the Show event, and then the async execs are allowed
			// to run
			contextMenu.notifyListeners(SWT.Hide, e);
			contextMenu.notifyListeners(SWT.Show, e);
			processEvents();

			find("org.eclipse.ui.file.close", manager.getItems());
		} finally {
			popupMenuExtender.dispose();
		}
	}

	/**
	 * @param id
	 * @param items
	 */
	private void find(String id, IContributionItem[] items) throws Exception {
		for (IContributionItem item : items) {
			if (id.equals(item.getId())) {
				assertTrue("Should be visible", item.isVisible());
				return;
			}
		}
		fail("Could not find " + id);
	}

}

Back to the top