aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamilo Bernal2013-05-22 13:24:05 (EDT)
committerAlexander Kurtakov2013-05-24 08:21:36 (EDT)
commitc86ec565724aa283ff0f5d3779131213ec0d5a97 (patch)
tree80c71a2b8c4d75f33494293661bf6f30aca7cfe4
parentfb8fe6c1a5f167fecf38f2a24c4e4e2bd71daf2b (diff)
downloadorg.eclipse.linuxtools-c86ec565724aa283ff0f5d3779131213ec0d5a97.zip
org.eclipse.linuxtools-c86ec565724aa283ff0f5d3779131213ec0d5a97.tar.gz
org.eclipse.linuxtools-c86ec565724aa283ff0f5d3779131213ec0d5a97.tar.bz2
Remove ContextMenuHelper from PreferencesTest.refs/changes/53/13053/3
SWTBot now provides the workaround for selecting context menus. Change-Id: Ia3a4565c754f10813a55c06eb634bc0071c30590 Reviewed-on: https://git.eclipse.org/r/13053 Tested-by: Hudson CI Reviewed-by: Alexander Kurtakov <akurtako@redhat.com> IP-Clean: Alexander Kurtakov <akurtako@redhat.com> Tested-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.provider.tests/src/org/eclipse/linuxtools/profiling/provider/tests/ContextMenuHelper.java139
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.provider.tests/src/org/eclipse/linuxtools/profiling/provider/tests/PreferencesTest.java26
2 files changed, 25 insertions, 140 deletions
diff --git a/profiling/org.eclipse.linuxtools.profiling.provider.tests/src/org/eclipse/linuxtools/profiling/provider/tests/ContextMenuHelper.java b/profiling/org.eclipse.linuxtools.profiling.provider.tests/src/org/eclipse/linuxtools/profiling/provider/tests/ContextMenuHelper.java
deleted file mode 100644
index 254178f..0000000
--- a/profiling/org.eclipse.linuxtools.profiling.provider.tests/src/org/eclipse/linuxtools/profiling/provider/tests/ContextMenuHelper.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Red Hat, Inc.
- * 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:
- * Red Hat initial API and implementation
- * Adapted from http://www.eclipse.org/forums/index.php?t=msg&th=11863&start=2
- *******************************************************************************/
-package org.eclipse.linuxtools.profiling.provider.tests;
-
-import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withMnemonic;
-import static org.hamcrest.core.AllOf.allOf;
-import static org.hamcrest.core.IsInstanceOf.instanceOf;
-
-import java.util.Arrays;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
-import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
-import org.eclipse.swtbot.swt.finder.results.VoidResult;
-import org.eclipse.swtbot.swt.finder.results.WidgetResult;
-import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot;
-import org.hamcrest.Matcher;
-
-/**
- * Adapted from http://www.eclipse.org/forums/index.php?t=msg&th=11863&start=2
- */
-public class ContextMenuHelper {
-
- /**
- * Clicks the context menu matching the text.
- *
- * @param bot
- *
- * @param texts
- * the text on the context menu.
- * @throws WidgetNotFoundException
- * if the widget is not found.
- * @throws SWTException
- * if the menu item is disabled (the root cause being an
- * {@link IllegalStateException})
- */
- public static void clickContextMenu(final AbstractSWTBot<?> bot,
- final String... texts) {
-
- // show
- final MenuItem menuItem = UIThreadRunnable
- .syncExec(new WidgetResult<MenuItem>() {
- public MenuItem run() {
- MenuItem theItem = getMenuItem(bot, texts);
- if (theItem != null && !theItem.isEnabled())
- throw new IllegalStateException(
- "Menu item is diabled"); //$NON-NLS-1$
-
- return theItem;
- }
- });
- if (menuItem == null) {
- throw new WidgetNotFoundException("Could not find menu: " //$NON-NLS-1$
- + Arrays.asList(texts));
- }
-
- // click
- click(menuItem);
-
- // hide
- UIThreadRunnable.syncExec(new VoidResult() {
- public void run() {
- if (menuItem.isDisposed())
- return; // menu already gone
- hide(menuItem.getParent());
- }
- });
- }
-
- private static MenuItem getMenuItem(final AbstractSWTBot<?> bot,
- final String... texts) {
- MenuItem theItem = null;
- Control control = (Control) bot.widget;
- // for dynamic menus, we need to issue this event
- control.notifyListeners(SWT.MenuDetect, new Event());
- Menu menu = control.getMenu();
- for (String text : texts) {
- // Use regex to ensure tests pass if items are reordered.
- Matcher<?> matcher = allOf(instanceOf(MenuItem.class),
- withMnemonic(text));
- theItem = show(menu, matcher);
- if (theItem != null) {
- menu = theItem.getMenu();
- } else {
- hide(menu);
- break;
- }
- }
- return theItem;
- }
-
- private static MenuItem show(final Menu menu, final Matcher<?> matcher) {
- if (menu != null) {
- menu.notifyListeners(SWT.Show, new Event());
- MenuItem[] items = menu.getItems();
- for (final MenuItem menuItem : items) {
- if (matcher.matches(menuItem)) {
- return menuItem;
- }
- }
- menu.notifyListeners(SWT.Hide, new Event());
- }
- return null;
- }
-
- private static void click(final MenuItem menuItem) {
- final Event event = new Event();
- event.time = (int) System.currentTimeMillis();
- event.widget = menuItem;
- event.display = menuItem.getDisplay();
- event.type = SWT.Selection;
-
- UIThreadRunnable.asyncExec(menuItem.getDisplay(), new VoidResult() {
- public void run() {
- menuItem.notifyListeners(SWT.Selection, event);
- }
- });
- }
-
- private static void hide(final Menu menu) {
- menu.notifyListeners(SWT.Hide, new Event());
- if (menu.getParentMenu() != null) {
- hide(menu.getParentMenu());
- }
- }
-}
diff --git a/profiling/org.eclipse.linuxtools.profiling.provider.tests/src/org/eclipse/linuxtools/profiling/provider/tests/PreferencesTest.java b/profiling/org.eclipse.linuxtools.profiling.provider.tests/src/org/eclipse/linuxtools/profiling/provider/tests/PreferencesTest.java
index 2a1264f..992665d 100644
--- a/profiling/org.eclipse.linuxtools.profiling.provider.tests/src/org/eclipse/linuxtools/profiling/provider/tests/PreferencesTest.java
+++ b/profiling/org.eclipse.linuxtools.profiling.provider.tests/src/org/eclipse/linuxtools/profiling/provider/tests/PreferencesTest.java
@@ -27,9 +27,12 @@ import org.eclipse.linuxtools.internal.profiling.launch.provider.launch.Provider
import org.eclipse.linuxtools.profiling.tests.AbstractTest;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.finders.ContextMenuHelper;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
@@ -160,7 +163,8 @@ public class PreferencesTest extends AbstractTest{
String subMenuItem = "3 Profile Timing"; //$NON-NLS-1$
// Click on "Profiling Tools -> 3 Profiling Timing" context menu to execute shortcut.
- ContextMenuHelper.clickContextMenu(treeBot, menuItem, subMenuItem);
+ MenuItem menu = ContextMenuHelper.contextMenu(treeBot, menuItem, subMenuItem);
+ click(menu);
// Assert that the expected tool is running.
SWTBotShell profileShell = bot.shell("Successful profile launch").activate(); //$NON-NLS-1$
@@ -237,4 +241,24 @@ public class PreferencesTest extends AbstractTest{
}
});
}
+
+ /**
+ * Click specfied menu item.
+ *
+ * @param menuItem
+ * menu item to click
+ */
+ public static void click(final MenuItem menuItem) {
+ final Event event = new Event();
+ event.time = (int) System.currentTimeMillis();
+ event.widget = menuItem;
+ event.display = menuItem.getDisplay();
+ event.type = SWT.Selection;
+
+ UIThreadRunnable.asyncExec(menuItem.getDisplay(), new VoidResult() {
+ public void run() {
+ menuItem.notifyListeners(SWT.Selection, event);
+ }
+ });
+ }
} \ No newline at end of file