c95118373405dbeb43243f3dd14595a0f418dbc4
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / kernel / ui / swtbot / tests / ResourcesViewTest.java
1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
14
15 import static org.junit.Assert.assertFalse;
16 import static org.junit.Assert.assertTrue;
17
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.eclipse.jface.bindings.keys.KeyStroke;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
22 import org.eclipse.swtbot.swt.finder.SWTBot;
23 import org.eclipse.swtbot.swt.finder.keyboard.Keyboard;
24 import org.eclipse.swtbot.swt.finder.keyboard.KeyboardFactory;
25 import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
26 import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
27 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
28 import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
29 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
30 import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
31 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
32 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
33 import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView;
34 import org.eclipse.ui.IWorkbenchPart;
35 import org.junit.Before;
36 import org.junit.Ignore;
37 import org.junit.Test;
38
39 /**
40 * SWTBot tests for Resources view
41 *
42 * @author Patrick Tasse
43 */
44 public class ResourcesViewTest extends KernelTestBase {
45
46 private static final String NEXT_MARKER = "Next Marker";
47 private static final String PREVIOUS_MARKER = "Previous Marker";
48 private static final String SELECT_NEXT_EVENT = "Select Next Event";
49 private static final String SELECT_PREVIOUS_EVENT = "Select Previous Event";
50 private static final String ADD_BOOKMARK = "Add Bookmark...";
51 private static final String REMOVE_BOOKMARK = "Remove Bookmark";
52 private static final String ADD_BOOKMARK_DIALOG = "Add Bookmark";
53 private static final String LOST_EVENTS = "Lost Events";
54 private static final String OK = "OK";
55 private static final Keyboard KEYBOARD = KeyboardFactory.getSWTKeyboard();
56 private static final @NonNull ITmfTimestamp START_TIME = new TmfNanoTimestamp(1368000272650993664L);
57 private static final @NonNull ITmfTimestamp LOST_EVENT_TIME1 = new TmfNanoTimestamp(1368000272681793477L);
58 private static final @NonNull ITmfTimestamp LOST_EVENT_END1 = new TmfNanoTimestamp(1368000272681793477L + 7425331L);
59 private static final @NonNull ITmfTimestamp LOST_EVENT_TIME2 = new TmfNanoTimestamp(1368000272820875850L);
60 private static final @NonNull ITmfTimestamp LOST_EVENT_END2 = new TmfNanoTimestamp(1368000272820875850L + 6640670L);
61 private static final @NonNull ITmfTimestamp LOST_EVENT_TIME3 = new TmfNanoTimestamp(1368000272882715015L);
62 private static final @NonNull ITmfTimestamp LOST_EVENT_END3 = new TmfNanoTimestamp(1368000272882715015L + 11373385L);
63 private static final @NonNull ITmfTimestamp CPU0_TIME1 = new TmfNanoTimestamp(1368000272651208412L);
64 private static final @NonNull ITmfTimestamp CPU0_TIME2 = new TmfNanoTimestamp(1368000272651852656L);
65 private static final @NonNull ITmfTimestamp CPU0_TIME3 = new TmfNanoTimestamp(1368000272652067404L);
66 private static final @NonNull ITmfTimestamp CPU0_TIME4 = new TmfNanoTimestamp(1368000272652282152L);
67 private static final @NonNull ITmfTimestamp CPU0_TIME5 = new TmfNanoTimestamp(1368000272653141144L);
68
69 private SWTBotView fViewBot;
70
71 /**
72 * Before Test
73 */
74 @Override
75 @Before
76 public void before() {
77 fViewBot = fBot.viewByTitle("Resources");
78 fViewBot.show();
79 super.before();
80 fViewBot.setFocus();
81 }
82
83 /**
84 * Test keyboard marker navigation using '.' and ','
85 */
86 @Test
87 public void testKeyboardSelectNextPreviousMarker() {
88 testNextPreviousMarker(
89 () -> KEYBOARD.pressShortcut(KeyStroke.getInstance('.')),
90 () -> KEYBOARD.pressShortcut(Keystrokes.SHIFT, KeyStroke.getInstance('.')),
91 () -> KEYBOARD.pressShortcut(KeyStroke.getInstance(',')),
92 () -> KEYBOARD.pressShortcut(Keystrokes.SHIFT, KeyStroke.getInstance(',')));
93 }
94
95 /**
96 * Test tool bar buttons "Next Marker" and "Previous Marker"
97 */
98 @Test
99 public void testToolBarSelectNextPreviousMarker() {
100 testNextPreviousMarker(
101 () -> fViewBot.toolbarButton(NEXT_MARKER).click(),
102 () -> fViewBot.toolbarButton(NEXT_MARKER).click(SWT.SHIFT),
103 () -> fViewBot.toolbarButton(PREVIOUS_MARKER).click(),
104 () -> fViewBot.toolbarButton(PREVIOUS_MARKER).click(SWT.SHIFT));
105 }
106
107 private void testNextPreviousMarker(Runnable nextMarker, Runnable shiftNextMarker, Runnable previousMarker, Runnable shiftPreviousMarker) {
108 /* set selection to trace start time */
109 TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
110 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME, START_TIME), START_TIME);
111
112 /* select first item */
113 KEYBOARD.pressShortcut(Keystrokes.HOME);
114
115 /* click "Next Marker" 3 times */
116 nextMarker.run();
117 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME1, LOST_EVENT_END1), LOST_EVENT_TIME1);
118 nextMarker.run();
119 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME2, LOST_EVENT_END2), LOST_EVENT_TIME2);
120 nextMarker.run();
121 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3, LOST_EVENT_END3), LOST_EVENT_TIME3);
122
123 /* shift-click "Previous Marker" 3 times */
124 shiftPreviousMarker.run();
125 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3, LOST_EVENT_TIME3), LOST_EVENT_TIME3);
126 shiftPreviousMarker.run();
127 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3, LOST_EVENT_TIME2), LOST_EVENT_TIME2);
128 shiftPreviousMarker.run();
129 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3, LOST_EVENT_TIME1), LOST_EVENT_TIME1);
130
131 /* shift-click "Next Marker" 3 times */
132 shiftNextMarker.run();
133 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3, LOST_EVENT_END1), LOST_EVENT_END1);
134 shiftNextMarker.run();
135 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3, LOST_EVENT_END2), LOST_EVENT_END2);
136 shiftNextMarker.run();
137 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3, LOST_EVENT_END3), LOST_EVENT_END3);
138
139 /* click "Previous Marker" 3 times */
140 previousMarker.run();
141 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME2, LOST_EVENT_END2), LOST_EVENT_TIME2);
142 previousMarker.run();
143 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME1, LOST_EVENT_END1), LOST_EVENT_TIME1);
144 previousMarker.run();
145 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME1, LOST_EVENT_END1), LOST_EVENT_TIME1);
146 }
147
148 /**
149 * Test "Show Markers" view menu
150 */
151 /* SWTBot doesn't support dynamic view menus yet */
152 @Ignore
153 @Test
154 public void testShowMarkers() {
155 /* set selection to trace start time */
156 TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
157 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME, START_TIME), START_TIME);
158
159 /* select first item */
160 KEYBOARD.pressShortcut(Keystrokes.HOME);
161
162 /* check that "Next Marker" and "Previous Marker" are enabled */
163 assertTrue(fViewBot.toolbarButton(NEXT_MARKER).isEnabled());
164 assertTrue(fViewBot.toolbarButton(PREVIOUS_MARKER).isEnabled());
165
166 /* disable Lost Events markers */
167 fViewBot.menu(LOST_EVENTS).click();
168
169 /* check that "Next Marker" and "Previous Marker" are disabled */
170 assertFalse(fViewBot.toolbarButton(NEXT_MARKER).isEnabled());
171 assertFalse(fViewBot.toolbarButton(PREVIOUS_MARKER).isEnabled());
172
173 /* enable Lost Events markers */
174 fViewBot.menu(LOST_EVENTS).click();
175
176 /* check that "Next Marker" and "Previous Marker" are enabled */
177 assertTrue(fViewBot.toolbarButton(NEXT_MARKER).isEnabled());
178 assertTrue(fViewBot.toolbarButton(PREVIOUS_MARKER).isEnabled());
179 }
180
181 /**
182 * Test "Next Event" tool bar button sub-menu
183 */
184 /* SWTBot doesn't support clicking the same tool bar sub-menu twice */
185 @Ignore
186 @Test
187 public void testMarkerNavigationSubMenu() {
188 /* set selection to trace start time */
189 TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
190 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME, START_TIME), START_TIME);
191
192 /* select first item */
193 KEYBOARD.pressShortcut(Keystrokes.HOME);
194
195 /* disable Lost Events navigation */
196 fViewBot.toolbarDropDownButton(NEXT_MARKER).menuItem(LOST_EVENTS).click();
197
198 /* click "Next Marker" */
199 fViewBot.toolbarButton(NEXT_MARKER).click();
200 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME, START_TIME), START_TIME);
201
202 /* enable Lost Events navigation */
203 fViewBot.toolbarDropDownButton(NEXT_MARKER).menuItem(LOST_EVENTS).click();
204
205 /* click "Next Marker" */
206 fViewBot.toolbarButton(NEXT_MARKER).click();
207 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME1, LOST_EVENT_END1), LOST_EVENT_TIME1);
208 }
209
210 /**
211 * Test tool bar button "Add Bookmark..." and "Remove Bookmark"
212 */
213 @Test
214 public void testAddRemoveBookmark() {
215 /* change window range to 10 ms */
216 TmfTimeRange range = new TmfTimeRange(START_TIME, START_TIME.normalize(10000000L, ITmfTimestamp.NANOSECOND_SCALE));
217 TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range));
218 fBot.waitUntil(ConditionHelpers.windowRange(range));
219
220 /* set selection to trace start time */
221 TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
222 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME, START_TIME), START_TIME);
223
224 /* select first CPU resource */
225 KEYBOARD.pressShortcut(Keystrokes.HOME);
226 KEYBOARD.pressShortcut(Keystrokes.DOWN);
227
228 /* click "Select Next Event" 2 times */
229 fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
230 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME1, CPU0_TIME1), CPU0_TIME1);
231 fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
232 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME2, CPU0_TIME2), CPU0_TIME2);
233
234 /* click "Add Bookmark..." and fill Add Bookmark dialog */
235 fViewBot.toolbarButton(ADD_BOOKMARK).click();
236 SWTBot dialogBot = fBot.shell(ADD_BOOKMARK_DIALOG).bot();
237 dialogBot.text().setText("B1");
238 dialogBot.button(OK).click();
239
240 /* click "Select Next Event" 2 times and shift-click "Select Next Event*/
241 fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
242 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME3, CPU0_TIME3), CPU0_TIME3);
243 fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
244 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4, CPU0_TIME4), CPU0_TIME4);
245 fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
246 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4, CPU0_TIME5), CPU0_TIME5);
247
248 /* click "Add Bookmark..." and fill Add Bookmark dialog */
249 fViewBot.toolbarButton(ADD_BOOKMARK).click();
250 dialogBot = fBot.shell(ADD_BOOKMARK_DIALOG).bot();
251 dialogBot.text().setText("B2");
252 dialogBot.button(OK).click();
253
254 /* click "Previous Marker" */
255 fViewBot.toolbarButton(PREVIOUS_MARKER).click();
256 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME2, CPU0_TIME2), CPU0_TIME2);
257
258 /* click "Remove Bookmark" */
259 fViewBot.toolbarButton(REMOVE_BOOKMARK).click();
260
261 /* click "Next Marker" */
262 fViewBot.toolbarButton(NEXT_MARKER).click();
263 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4, CPU0_TIME5), CPU0_TIME5);
264
265 /* click "Remove Bookmark" */
266 fViewBot.toolbarButton(REMOVE_BOOKMARK).click();
267
268 /* click "Previous Marker" */
269 fViewBot.toolbarButton(PREVIOUS_MARKER).click();
270 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4, CPU0_TIME5), CPU0_TIME5);
271
272 /* click "Select Previous Event" */
273 fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
274 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4, CPU0_TIME4), CPU0_TIME4);
275 }
276
277 private void timeGraphIsReadyCondition(@NonNull TmfTimeRange selectionRange, @NonNull ITmfTimestamp visibleTime) {
278 IWorkbenchPart part = fViewBot.getViewReference().getPart(false);
279 fBot.waitUntil(ConditionHelpers.timeGraphIsReadyCondition((AbstractTimeGraphView) part, selectionRange, visibleTime));
280 }
281 }
This page took 0.043765 seconds and 4 git commands to generate.