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
.assertFalse
;
16 import static org
.junit
.Assert
.assertTrue
;
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
;
40 * SWTBot tests for Resources view
42 * @author Patrick Tasse
44 public class ResourcesViewTest
extends KernelTestBase
{
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);
69 private SWTBotView fViewBot
;
76 public void before() {
77 fViewBot
= fBot
.viewByTitle("Resources");
84 * Test keyboard marker navigation using '.' and ','
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(',')));
96 * Test tool bar buttons "Next Marker" and "Previous Marker"
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
));
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
);
112 /* select first item */
113 KEYBOARD
.pressShortcut(Keystrokes
.HOME
);
115 /* click "Next Marker" 3 times */
117 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME1
, LOST_EVENT_END1
), LOST_EVENT_TIME1
);
119 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME2
, LOST_EVENT_END2
), LOST_EVENT_TIME2
);
121 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME3
, LOST_EVENT_END3
), LOST_EVENT_TIME3
);
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
);
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
);
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
);
149 * Test "Show Markers" view menu
151 /* SWTBot doesn't support dynamic view menus yet */
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
);
159 /* select first item */
160 KEYBOARD
.pressShortcut(Keystrokes
.HOME
);
162 /* check that "Next Marker" and "Previous Marker" are enabled */
163 assertTrue(fViewBot
.toolbarButton(NEXT_MARKER
).isEnabled());
164 assertTrue(fViewBot
.toolbarButton(PREVIOUS_MARKER
).isEnabled());
166 /* disable Lost Events markers */
167 fViewBot
.viewMenu(LOST_EVENTS
).click();
169 /* check that "Next Marker" and "Previous Marker" are disabled */
170 assertFalse(fViewBot
.toolbarButton(NEXT_MARKER
).isEnabled());
171 assertFalse(fViewBot
.toolbarButton(PREVIOUS_MARKER
).isEnabled());
173 /* enable Lost Events markers */
174 fViewBot
.viewMenu(LOST_EVENTS
).click();
176 /* check that "Next Marker" and "Previous Marker" are enabled */
177 assertTrue(fViewBot
.toolbarButton(NEXT_MARKER
).isEnabled());
178 assertTrue(fViewBot
.toolbarButton(PREVIOUS_MARKER
).isEnabled());
182 * Test "Next Event" tool bar button sub-menu
184 /* SWTBot doesn't support clicking the same tool bar sub-menu twice */
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
);
192 /* select first item */
193 KEYBOARD
.pressShortcut(Keystrokes
.HOME
);
195 /* disable Lost Events navigation */
196 fViewBot
.toolbarDropDownButton(NEXT_MARKER
).menuItem(LOST_EVENTS
).click();
198 /* click "Next Marker" */
199 fViewBot
.toolbarButton(NEXT_MARKER
).click();
200 timeGraphIsReadyCondition(new TmfTimeRange(START_TIME
, START_TIME
), START_TIME
);
202 /* enable Lost Events navigation */
203 fViewBot
.toolbarDropDownButton(NEXT_MARKER
).menuItem(LOST_EVENTS
).click();
205 /* click "Next Marker" */
206 fViewBot
.toolbarButton(NEXT_MARKER
).click();
207 timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME1
, LOST_EVENT_END1
), LOST_EVENT_TIME1
);
211 * Test tool bar button "Add Bookmark..." and "Remove Bookmark"
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
));
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
);
224 /* select first CPU resource */
225 KEYBOARD
.pressShortcut(Keystrokes
.HOME
);
226 KEYBOARD
.pressShortcut(Keystrokes
.DOWN
);
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
);
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();
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
);
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();
254 /* click "Previous Marker" */
255 fViewBot
.toolbarButton(PREVIOUS_MARKER
).click();
256 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME2
, CPU0_TIME2
), CPU0_TIME2
);
258 /* click "Remove Bookmark" */
259 fViewBot
.toolbarButton(REMOVE_BOOKMARK
).click();
261 /* click "Next Marker" */
262 fViewBot
.toolbarButton(NEXT_MARKER
).click();
263 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4
, CPU0_TIME5
), CPU0_TIME5
);
265 /* click "Remove Bookmark" */
266 fViewBot
.toolbarButton(REMOVE_BOOKMARK
).click();
268 /* click "Previous Marker" */
269 fViewBot
.toolbarButton(PREVIOUS_MARKER
).click();
270 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4
, CPU0_TIME5
), CPU0_TIME5
);
272 /* click "Select Previous Event" */
273 fViewBot
.toolbarButton(SELECT_PREVIOUS_EVENT
).click();
274 timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4
, CPU0_TIME4
), CPU0_TIME4
);
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
));