blob: a64e3d792db7ce8f095b2c085af9cf6820ba9cd4 (
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
|
/*******************************************************************************
* Copyright (c) 2008 Ketan Padegaonkar 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:
* Ketan Padegaonkar - initial API and implementation
* Ketan Padegaonkar - http://swtbot.org/bugzilla/show_bug.cgi?id=88
*******************************************************************************/
package org.eclipse.swtbot.swt.finder.widgets;
import static org.eclipse.swtbot.swt.finder.SWTBotTestCase.assertNotSameWidget;
import static org.eclipse.swtbot.swt.finder.SWTBotTestCase.assertTextContains;
import static org.eclipse.swtbot.swt.finder.SWTBotTestCase.pass;
import static org.hamcrest.Matchers.any;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.List;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.finders.AbstractSWTTestCase;
import org.junit.Test;
/**
* @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
* @version $Id$
*/
public class SWTBotToolbarDropDownButtonTest extends AbstractSWTTestCase {
private SWTBot bot;
@Test
public void findsToolBarButtonWithIndex() throws Exception {
SWTBotToolbarDropDownButton button0 = bot.toolbarDropDownButton("Drop Down");
SWTBotToolbarDropDownButton button1 = bot.toolbarDropDownButton("Drop Down", 1);
assertNotSameWidget(button0.widget, button1.widget);
}
@Test
public void clicksToolBarButton() throws Exception {
try {
bot.checkBox("Listen").select();
SWTBotToolbarDropDownButton button = bot.toolbarDropDownButton("Drop Down");
button.click();
assertTextContains("Selection [13]: SelectionEvent{ToolItem ", bot.textInGroup("Listeners").widget);
} finally {
bot.checkBox("Listen").deselect();
}
}
@Test
public void getsAllMenuItems() throws Exception {
List<? extends SWTBotMenu> menuItems = bot.toolbarDropDownButton("Drop Down").menuItems(any(MenuItem.class));
menuItems.get(0).click();
assertEquals(7, menuItems.size());
}
@Test
public void clicksADropDownMenuItem() throws Exception {
SWTBotToolbarDropDownButton button = bot.toolbarDropDownButton("Drop Down");
try {
bot.menu("Kiwi");
fail("The menu item should not exist");
} catch (WidgetNotFoundException e) {
pass();
}
bot.shell("SWT Controls").activate();
button.menuItem("Kiwi").click();
}
public void setUp() throws Exception {
super.setUp();
bot = new SWTBot();
bot.tabItem("ToolBar").activate();
}
}
|