1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.lttng2
.kernel
.ui
.swtbot
.tests
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertFalse
;
17 import static org
.junit
.Assert
.assertTrue
;
19 import org
.eclipse
.jdt
.annotation
.NonNull
;
20 import org
.eclipse
.jface
.bindings
.keys
.KeyStroke
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.graphics
.Point
;
23 import org
.eclipse
.swt
.widgets
.Control
;
24 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
25 import org
.eclipse
.swtbot
.swt
.finder
.SWTBot
;
26 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
27 import org
.eclipse
.swtbot
.swt
.finder
.keyboard
.Keyboard
;
28 import org
.eclipse
.swtbot
.swt
.finder
.keyboard
.KeyboardFactory
;
29 import org
.eclipse
.swtbot
.swt
.finder
.keyboard
.Keystrokes
;
30 import org
.eclipse
.swtbot
.swt
.finder
.matchers
.WidgetOfType
;
31 import org
.eclipse
.swtbot
.swt
.finder
.results
.Result
;
32 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotCanvas
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalManager
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfWindowRangeUpdatedSignal
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
38 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
39 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
40 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.timegraph
.AbstractTimeGraphView
;
41 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
42 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphMarkerAxis
;
43 import org
.eclipse
.ui
.IWorkbenchPart
;
44 import org
.junit
.Before
;
45 import org
.junit
.Ignore
;
46 import org
.junit
.Test
;
49 * SWTBot tests for Resources view
51 * @author Patrick Tasse
53 public class ResourcesViewTest
extends KernelTestBase
{
55 private static final String NEXT_MARKER
= "Next Marker";
56 private static final String PREVIOUS_MARKER
= "Previous Marker";
57 private static final String SELECT_NEXT_EVENT
= "Select Next Event";
58 private static final String SELECT_PREVIOUS_EVENT
= "Select Previous Event";
59 private static final String ADD_BOOKMARK
= "Add Bookmark...";
60 private static final String REMOVE_BOOKMARK
= "Remove Bookmark";
61 private static final String ADD_BOOKMARK_DIALOG
= "Add Bookmark";
62 private static final String LOST_EVENTS
= "Lost Events";
63 private static final String OK
= "OK";
64 private static final Keyboard KEYBOARD
= KeyboardFactory
.getSWTKeyboard();
65 private static final @NonNull ITmfTimestamp START_TIME
= new TmfNanoTimestamp(1368000272650993664L);
66 private static final @NonNull ITmfTimestamp LOST_EVENT_TIME1
= new TmfNanoTimestamp(1368000272681793477L);
67 private static final @NonNull ITmfTimestamp LOST_EVENT_END1
= new TmfNanoTimestamp(1368000272681793477L + 7425331L);
68 private static final @NonNull ITmfTimestamp LOST_EVENT_TIME2
= new TmfNanoTimestamp(1368000272820875850L);
69 private static final @NonNull ITmfTimestamp LOST_EVENT_END2
= new TmfNanoTimestamp(1368000272820875850L + 6640670L);
70 private static final @NonNull ITmfTimestamp LOST_EVENT_TIME3
= new TmfNanoTimestamp(1368000272882715015L);
71 private static final @NonNull ITmfTimestamp LOST_EVENT_END3
= new TmfNanoTimestamp(1368000272882715015L + 11373385L);
72 private static final @NonNull ITmfTimestamp CPU0_TIME1
= new TmfNanoTimestamp(1368000272651208412L);
73 private static final @NonNull ITmfTimestamp CPU0_TIME2
= new TmfNanoTimestamp(1368000272651852656L);
74 private static final @NonNull ITmfTimestamp CPU0_TIME3
= new TmfNanoTimestamp(1368000272652067404L);
75 private static final @NonNull ITmfTimestamp CPU0_TIME4
= new TmfNanoTimestamp(1368000272652282152L);
76 private static final @NonNull ITmfTimestamp CPU0_TIME5
= new TmfNanoTimestamp(1368000272653141144L);
77 private static final int TOP_MARGIN
= 1;
78 private static final Point TOGGLE_SIZE
= new Point(7, 8);
79 private static final Point HIDE_SIZE
= new Point(16, 16);
81 private SWTBotView fViewBot
;
88 public void before() {
89 fViewBot
= fBot
.viewByTitle("Resources");
96 * Test keyboard marker navigation using '.' and ','
99 public void testKeyboardSelectNextPreviousMarker() {
100 testNextPreviousMarker(
101 () -> KEYBOARD
.pressShortcut(KeyStroke
.getInstance('.')),
102 () -> KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, KeyStroke
.getInstance('.')),
103 () -> KEYBOARD
.pressShortcut(KeyStroke
.getInstance(',')),
104 () -> KEYBOARD
.pressShortcut(Keystrokes
.SHIFT
, KeyStroke
.getInstance(',')));
108 * Test tool bar buttons "Next Marker" and "Previous Marker"
111 public void testToolBarSelectNextPreviousMarker() {
112 testNextPreviousMarker(
113 () -> fViewBot
.toolbarButton(NEXT_MARKER
).click(),
114 () -> fViewBot
.toolbarButton(NEXT_MARKER
).click(SWT
.SHIFT
),
115 () -> fViewBot
.toolbarButton(PREVIOUS_MARKER
).click(),
116 () -> fViewBot
.toolbarButton(PREVIOUS_MARKER
).click(SWT
.SHIFT
));
119 private void testNextPreviousMarker(Runnable nextMarker
, Runnable shiftNextMarker
, Runnable previousMarker
, Runnable shiftPreviousMarker
) {
120 /* set selection to trace start time */
121 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME
));
122 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME
, START_TIME
), START_TIME
);
124 /* select first item */
125 KEYBOARD
.pressShortcut(Keystrokes
.HOME
);
127 /* click "Next Marker" 3 times */
129 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME1
, LOST_EVENT_END1
), LOST_EVENT_TIME1
);
131 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME2
, LOST_EVENT_END2
), LOST_EVENT_TIME2
);
133 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3
, LOST_EVENT_END3
), LOST_EVENT_TIME3
);
135 /* shift-click "Previous Marker" 3 times */
136 shiftPreviousMarker
.run();
137 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3
, LOST_EVENT_TIME3
), LOST_EVENT_TIME3
);
138 shiftPreviousMarker
.run();
139 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3
, LOST_EVENT_TIME2
), LOST_EVENT_TIME2
);
140 shiftPreviousMarker
.run();
141 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3
, LOST_EVENT_TIME1
), LOST_EVENT_TIME1
);
143 /* shift-click "Next Marker" 3 times */
144 shiftNextMarker
.run();
145 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3
, LOST_EVENT_END1
), LOST_EVENT_END1
);
146 shiftNextMarker
.run();
147 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3
, LOST_EVENT_END2
), LOST_EVENT_END2
);
148 shiftNextMarker
.run();
149 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3
, LOST_EVENT_END3
), LOST_EVENT_END3
);
151 /* click "Previous Marker" 3 times */
152 previousMarker
.run();
153 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME2
, LOST_EVENT_END2
), LOST_EVENT_TIME2
);
154 previousMarker
.run();
155 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME1
, LOST_EVENT_END1
), LOST_EVENT_TIME1
);
156 previousMarker
.run();
157 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME1
, LOST_EVENT_END1
), LOST_EVENT_TIME1
);
161 * Test "Show Markers" view menu
164 public void testShowMarkers() {
165 /* set selection to trace start time */
166 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME
));
167 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME
, START_TIME
), START_TIME
);
169 /* select first item */
170 KEYBOARD
.pressShortcut(Keystrokes
.HOME
);
172 /* check that "Next Marker" and "Previous Marker" are enabled */
173 assertTrue(fViewBot
.toolbarButton(NEXT_MARKER
).isEnabled());
174 assertTrue(fViewBot
.toolbarButton(PREVIOUS_MARKER
).isEnabled());
176 /* disable Lost Events markers */
177 fViewBot
.viewMenu(LOST_EVENTS
).click();
179 /* check that "Next Marker" and "Previous Marker" are disabled */
180 assertFalse(fViewBot
.toolbarButton(NEXT_MARKER
).isEnabled());
181 assertFalse(fViewBot
.toolbarButton(PREVIOUS_MARKER
).isEnabled());
183 /* enable Lost Events markers */
184 fViewBot
.viewMenu(LOST_EVENTS
).click();
186 /* check that "Next Marker" and "Previous Marker" are enabled */
187 assertTrue(fViewBot
.toolbarButton(NEXT_MARKER
).isEnabled());
188 assertTrue(fViewBot
.toolbarButton(PREVIOUS_MARKER
).isEnabled());
192 * Test "Next Event" tool bar button sub-menu
194 /* SWTBot doesn't support clicking the same tool bar sub-menu twice */
197 public void testMarkerNavigationSubMenu() {
198 /* set selection to trace start time */
199 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME
));
200 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME
, START_TIME
), START_TIME
);
202 /* select first item */
203 KEYBOARD
.pressShortcut(Keystrokes
.HOME
);
205 /* disable Lost Events navigation */
206 fViewBot
.toolbarDropDownButton(NEXT_MARKER
).menuItem(LOST_EVENTS
).click();
208 /* click "Next Marker" */
209 fViewBot
.toolbarButton(NEXT_MARKER
).click();
210 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME
, START_TIME
), START_TIME
);
212 /* enable Lost Events navigation */
213 fViewBot
.toolbarDropDownButton(NEXT_MARKER
).menuItem(LOST_EVENTS
).click();
215 /* click "Next Marker" */
216 fViewBot
.toolbarButton(NEXT_MARKER
).click();
217 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME1
, LOST_EVENT_END1
), LOST_EVENT_TIME1
);
221 * Test tool bar button "Add Bookmark..." and "Remove Bookmark"
224 public void testAddRemoveBookmark() {
225 /* change window range to 10 ms */
226 TmfTimeRange range
= new TmfTimeRange(START_TIME
, START_TIME
.normalize(10000000L, ITmfTimestamp
.NANOSECOND_SCALE
));
227 TmfSignalManager
.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range
));
228 fBot
.waitUntil(ConditionHelpers
.windowRange(range
));
230 /* set selection to trace start time */
231 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME
));
232 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME
, START_TIME
), START_TIME
);
234 /* select first CPU resource */
235 KEYBOARD
.pressShortcut(Keystrokes
.HOME
);
236 KEYBOARD
.pressShortcut(Keystrokes
.DOWN
);
238 /* click "Select Next Event" 2 times */
239 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click();
240 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME1
, CPU0_TIME1
), CPU0_TIME1
);
241 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click();
242 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME2
, CPU0_TIME2
), CPU0_TIME2
);
244 /* click "Add Bookmark..." and fill Add Bookmark dialog */
245 fViewBot
.toolbarButton(ADD_BOOKMARK
).click();
246 SWTBot dialogBot
= fBot
.shell(ADD_BOOKMARK_DIALOG
).bot();
247 dialogBot
.text().setText("B1");
248 dialogBot
.button(OK
).click();
250 /* click "Select Next Event" 2 times and shift-click "Select Next Event*/
251 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click();
252 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME3
, CPU0_TIME3
), CPU0_TIME3
);
253 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click();
254 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4
, CPU0_TIME4
), CPU0_TIME4
);
255 fViewBot
.toolbarButton(SELECT_NEXT_EVENT
).click(SWT
.SHIFT
);
256 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4
, CPU0_TIME5
), CPU0_TIME5
);
258 /* click "Add Bookmark..." and fill Add Bookmark dialog */
259 fViewBot
.toolbarButton(ADD_BOOKMARK
).click();
260 dialogBot
= fBot
.shell(ADD_BOOKMARK_DIALOG
).bot();
261 dialogBot
.text().setText("B2");
262 dialogBot
.button(OK
).click();
264 /* click "Previous Marker" */
265 fViewBot
.toolbarButton(PREVIOUS_MARKER
).click();
266 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME2
, CPU0_TIME2
), CPU0_TIME2
);
268 /* click "Remove Bookmark" */
269 fViewBot
.toolbarButton(REMOVE_BOOKMARK
).click();
271 /* click "Next Marker" */
272 fViewBot
.toolbarButton(NEXT_MARKER
).click();
273 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4
, CPU0_TIME5
), CPU0_TIME5
);
275 /* click "Remove Bookmark" */
276 fViewBot
.toolbarButton(REMOVE_BOOKMARK
).click();
278 /* click "Previous Marker" */
279 fViewBot
.toolbarButton(PREVIOUS_MARKER
).click();
280 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4
, CPU0_TIME5
), CPU0_TIME5
);
282 /* click "Select Previous Event" */
283 fViewBot
.toolbarButton(SELECT_PREVIOUS_EVENT
).click();
284 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4
, CPU0_TIME4
), CPU0_TIME4
);
288 * Test the marker axis
291 public void testMarkerAxis() {
292 /* center window range of first lost event range */
293 ITmfTimestamp startTime
= LOST_EVENT_TIME1
.normalize(-10000000L, ITmfTimestamp
.NANOSECOND_SCALE
);
294 ITmfTimestamp endTime
= LOST_EVENT_END1
.normalize(10000000L, ITmfTimestamp
.NANOSECOND_SCALE
);
295 TmfTimeRange range
= new TmfTimeRange(startTime
, endTime
);
296 TmfSignalManager
.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range
));
297 fBot
.waitUntil(ConditionHelpers
.windowRange(range
));
299 /* set selection to window start time */
300 TmfSignalManager
.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, startTime
));
301 timeGraphIsReadyCondition(new TmfTimeRange(startTime
, startTime
), startTime
);
303 /* get marker axis size with one category */
304 final TimeGraphMarkerAxis markerAxis
= fViewBot
.bot().widget(WidgetOfType
.widgetOfType(TimeGraphMarkerAxis
.class));
305 final Point size1
= getSize(markerAxis
);
307 /* add bookmark at window start time */
308 fViewBot
.toolbarButton(ADD_BOOKMARK
).click();
309 SWTBot dialogBot
= fBot
.shell(ADD_BOOKMARK_DIALOG
).bot();
310 dialogBot
.text().setText("B");
311 dialogBot
.button(OK
).click();
313 /* get marker axis size with two categories */
314 final Point size2
= getSize(markerAxis
);
315 final int rowHeight
= size2
.y
- size1
.y
;
317 /* get the state area bounds, since we don't know the name space width */
318 final TimeGraphControl timeGraph
= fViewBot
.bot().widget(WidgetOfType
.widgetOfType(TimeGraphControl
.class));
319 int x0
= getXForTime(timeGraph
, startTime
.toNanos());
320 int x1
= getXForTime(timeGraph
, endTime
.toNanos());
322 /* click at the center of the marker axis width and first row height, it should be within the lost event range */
323 final SWTBotCanvas markerAxisCanvas
= new SWTBotCanvas(markerAxis
);
324 markerAxisCanvas
.click((x0
+ x1
) / 2, TOP_MARGIN
+ rowHeight
/ 2);
325 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(LOST_EVENT_TIME1
, LOST_EVENT_END1
)));
327 /* click near the left of the marker axis width and center of second row height, it should be on the bookmark label */
328 markerAxisCanvas
.click(x0
+ 2, TOP_MARGIN
+ rowHeight
+ rowHeight
/ 2);
329 fBot
.waitUntil(ConditionHelpers
.selectionRange(new TmfTimeRange(startTime
, startTime
)));
331 /* click "Remove Bookmark" */
332 fViewBot
.toolbarButton(REMOVE_BOOKMARK
).click();
333 assertEquals(size1
, getSize(markerAxis
));
335 /* click the 'expanded' icon to collapse */
336 markerAxisCanvas
.click(TOGGLE_SIZE
.x
/ 2, TOGGLE_SIZE
.y
/ 2);
337 assertEquals(TOGGLE_SIZE
.y
, getSize(markerAxis
).y
);
339 /* click the 'collapsed' icon to expand */
340 markerAxisCanvas
.click(TOGGLE_SIZE
.x
/ 2, TOGGLE_SIZE
.y
/ 2);
341 assertEquals(size1
, getSize(markerAxis
));
343 /* click on the 'X' icon to hide the 'Lost Events' marker category */
344 markerAxisCanvas
.click(TOGGLE_SIZE
.x
+ HIDE_SIZE
.x
/ 2, TOP_MARGIN
+ HIDE_SIZE
.y
/ 2);
345 assertEquals(0, getSize(markerAxis
).y
);
347 /* show Lost Events markers */
348 fViewBot
.viewMenu(LOST_EVENTS
).click();
349 assertEquals(size1
, getSize(markerAxis
));
352 private void timeGraphIsReadyCondition(@NonNull TmfTimeRange selectionRange
, @NonNull ITmfTimestamp visibleTime
) {
353 IWorkbenchPart part
= fViewBot
.getViewReference().getPart(false);
354 fBot
.waitUntil(ConditionHelpers
.timeGraphIsReadyCondition((AbstractTimeGraphView
) part
, selectionRange
, visibleTime
));
357 private static int getXForTime(TimeGraphControl timeGraph
, long time
) {
358 return UIThreadRunnable
.syncExec(new Result
<Integer
>() {
360 public Integer
run() {
361 return timeGraph
.getXForTime(time
);
366 private static Point
getSize(Control control
) {
367 return UIThreadRunnable
.syncExec(new Result
<Point
>() {
370 return control
.getSize();