lttng.swtbot: remove fViewBot from ResourcesViewTest
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Mon, 21 Nov 2016 18:39:11 +0000 (13:39 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Mon, 21 Nov 2016 20:59:27 +0000 (15:59 -0500)
This allows getViewBot to work even if the view was closed
and re-opened.

Change-Id: I7b999f83dfea74785244e282748ed7975ef67d34
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/85428
Reviewed-by: Hudson CI
Reviewed-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Tested-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/ResourcesViewTest.java

index fdfb05c7ff03dd87952edb90c452b495bf833b48..c99e1ab93646826caa511c779519ae0207abc983 100644 (file)
@@ -33,6 +33,7 @@ import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
 import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
 import org.eclipse.swtbot.swt.finder.results.Result;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotCanvas;
+import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.resources.ResourcesView;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
 import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
@@ -81,11 +82,10 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
     private static final Point TOGGLE_SIZE = new Point(7, 8);
     private static final Point HIDE_SIZE = new Point(16, 16);
 
-    private SWTBotView fViewBot;
 
     @Override
     protected SWTBotView getViewBot() {
-        return fViewBot;
+        return fBot.viewById(ResourcesView.ID);
     }
 
     @Override
@@ -107,10 +107,10 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
     @Override
     @Before
     public void before() {
-        fViewBot = fBot.viewByTitle("Resources");
-        fViewBot.show();
+        SWTBotView viewBot = getViewBot();
+        viewBot.show();
         super.before();
-        fViewBot.setFocus();
+        viewBot.setFocus();
     }
 
     /**
@@ -130,11 +130,12 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
      */
     @Test
     public void testToolBarSelectNextPreviousMarker() {
+        SWTBotView viewBot = getViewBot();
         testNextPreviousMarker(
-                () -> fViewBot.toolbarButton(NEXT_MARKER).click(),
-                () -> fViewBot.toolbarButton(NEXT_MARKER).click(SWT.SHIFT),
-                () -> fViewBot.toolbarButton(PREVIOUS_MARKER).click(),
-                () -> fViewBot.toolbarButton(PREVIOUS_MARKER).click(SWT.SHIFT));
+                () -> viewBot.toolbarButton(NEXT_MARKER).click(),
+                () -> viewBot.toolbarButton(NEXT_MARKER).click(SWT.SHIFT),
+                () -> viewBot.toolbarButton(PREVIOUS_MARKER).click(),
+                () -> viewBot.toolbarButton(PREVIOUS_MARKER).click(SWT.SHIFT));
     }
 
     private void testNextPreviousMarker(Runnable nextMarker, Runnable shiftNextMarker, Runnable previousMarker, Runnable shiftPreviousMarker) {
@@ -183,6 +184,7 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
      */
     @Test
     public void testShowMarkers() {
+        SWTBotView viewBot = getViewBot();
         /* set selection to trace start time */
         TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
         timeGraphIsReadyCondition(new TmfTimeRange(START_TIME, START_TIME), START_TIME);
@@ -191,22 +193,22 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
         KEYBOARD.pressShortcut(Keystrokes.HOME);
 
         /* check that "Next Marker" and "Previous Marker" are enabled */
-        assertTrue(fViewBot.toolbarButton(NEXT_MARKER).isEnabled());
-        assertTrue(fViewBot.toolbarButton(PREVIOUS_MARKER).isEnabled());
+        assertTrue(viewBot.toolbarButton(NEXT_MARKER).isEnabled());
+        assertTrue(viewBot.toolbarButton(PREVIOUS_MARKER).isEnabled());
 
         /* disable Lost Events markers */
-        fViewBot.viewMenu(LOST_EVENTS).click();
+        viewBot.viewMenu(LOST_EVENTS).click();
 
         /* check that "Next Marker" and "Previous Marker" are disabled */
-        assertFalse(fViewBot.toolbarButton(NEXT_MARKER).isEnabled());
-        assertFalse(fViewBot.toolbarButton(PREVIOUS_MARKER).isEnabled());
+        assertFalse(viewBot.toolbarButton(NEXT_MARKER).isEnabled());
+        assertFalse(viewBot.toolbarButton(PREVIOUS_MARKER).isEnabled());
 
         /* enable Lost Events markers */
-        fViewBot.viewMenu(LOST_EVENTS).click();
+        viewBot.viewMenu(LOST_EVENTS).click();
 
         /* check that "Next Marker" and "Previous Marker" are enabled */
-        assertTrue(fViewBot.toolbarButton(NEXT_MARKER).isEnabled());
-        assertTrue(fViewBot.toolbarButton(PREVIOUS_MARKER).isEnabled());
+        assertTrue(viewBot.toolbarButton(NEXT_MARKER).isEnabled());
+        assertTrue(viewBot.toolbarButton(PREVIOUS_MARKER).isEnabled());
     }
 
     /**
@@ -216,6 +218,7 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
     @Ignore
     @Test
     public void testMarkerNavigationSubMenu() {
+        SWTBotView viewBot = getViewBot();
         /* set selection to trace start time */
         TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
         timeGraphIsReadyCondition(new TmfTimeRange(START_TIME, START_TIME), START_TIME);
@@ -224,17 +227,17 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
         KEYBOARD.pressShortcut(Keystrokes.HOME);
 
         /* disable Lost Events navigation */
-        fViewBot.toolbarDropDownButton(NEXT_MARKER).menuItem(LOST_EVENTS).click();
+        viewBot.toolbarDropDownButton(NEXT_MARKER).menuItem(LOST_EVENTS).click();
 
         /* click "Next Marker" */
-        fViewBot.toolbarButton(NEXT_MARKER).click();
+        viewBot.toolbarButton(NEXT_MARKER).click();
         timeGraphIsReadyCondition(new TmfTimeRange(START_TIME, START_TIME), START_TIME);
 
         /* enable Lost Events navigation */
-        fViewBot.toolbarDropDownButton(NEXT_MARKER).menuItem(LOST_EVENTS).click();
+        viewBot.toolbarDropDownButton(NEXT_MARKER).menuItem(LOST_EVENTS).click();
 
         /* click "Next Marker" */
-        fViewBot.toolbarButton(NEXT_MARKER).click();
+        viewBot.toolbarButton(NEXT_MARKER).click();
         timeGraphIsReadyCondition(new TmfTimeRange(LOST_EVENT_TIME1, LOST_EVENT_END1), LOST_EVENT_TIME1);
     }
 
@@ -243,6 +246,7 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
      */
     @Test
     public void testAddRemoveBookmark() {
+        SWTBotView viewBot = getViewBot();
         /* change window range to 10 ms */
         TmfTimeRange range = new TmfTimeRange(START_TIME, START_TIME.normalize(10000000L, ITmfTimestamp.NANOSECOND_SCALE));
         TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range));
@@ -257,13 +261,13 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
         KEYBOARD.pressShortcut(Keystrokes.DOWN);
 
         /* click "Select Next State Change" 2 times */
-        fViewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click();
+        viewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click();
         timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME1, CPU0_TIME1), CPU0_TIME1);
-        fViewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click();
+        viewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click();
         timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME2, CPU0_TIME2), CPU0_TIME2);
 
         /* click "Add Bookmark..." and fill Add Bookmark dialog */
-        fViewBot.toolbarButton(ADD_BOOKMARK).click();
+        viewBot.toolbarButton(ADD_BOOKMARK).click();
         SWTBot dialogBot = fBot.shell(ADD_BOOKMARK_DIALOG).bot();
         dialogBot.text().setText("B1");
         dialogBot.button(OK).click();
@@ -272,39 +276,39 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
          * click "Select Next State Change" 2 times and shift-click "Select Next
          * State Change
          */
-        fViewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click();
+        viewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click();
         timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME3, CPU0_TIME3), CPU0_TIME3);
-        fViewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click();
+        viewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click();
         timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4, CPU0_TIME4), CPU0_TIME4);
-        fViewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click(SWT.SHIFT);
+        viewBot.toolbarButton(SELECT_NEXT_STATE_CHANGE).click(SWT.SHIFT);
         timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4, CPU0_TIME5), CPU0_TIME5);
 
         /* click "Add Bookmark..." and fill Add Bookmark dialog */
-        fViewBot.toolbarButton(ADD_BOOKMARK).click();
+        viewBot.toolbarButton(ADD_BOOKMARK).click();
         dialogBot = fBot.shell(ADD_BOOKMARK_DIALOG).bot();
         dialogBot.text().setText("B2");
         dialogBot.button(OK).click();
 
         /* click "Previous Marker" */
-        fViewBot.toolbarButton(PREVIOUS_MARKER).click();
+        viewBot.toolbarButton(PREVIOUS_MARKER).click();
         timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME2, CPU0_TIME2), CPU0_TIME2);
 
         /* click "Remove Bookmark" */
-        fViewBot.toolbarButton(REMOVE_BOOKMARK).click();
+        viewBot.toolbarButton(REMOVE_BOOKMARK).click();
 
         /* click "Next Marker" */
-        fViewBot.toolbarButton(NEXT_MARKER).click();
+        viewBot.toolbarButton(NEXT_MARKER).click();
         timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4, CPU0_TIME5), CPU0_TIME5);
 
         /* click "Remove Bookmark" */
-        fViewBot.toolbarButton(REMOVE_BOOKMARK).click();
+        viewBot.toolbarButton(REMOVE_BOOKMARK).click();
 
         /* click "Previous Marker" */
-        fViewBot.toolbarButton(PREVIOUS_MARKER).click();
+        viewBot.toolbarButton(PREVIOUS_MARKER).click();
         timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4, CPU0_TIME5), CPU0_TIME5);
 
         /* click "Select Previous State Change" */
-        fViewBot.toolbarButton(SELECT_PREVIOUS_STATE_CHANGE).click();
+        viewBot.toolbarButton(SELECT_PREVIOUS_STATE_CHANGE).click();
         timeGraphIsReadyCondition(new TmfTimeRange(CPU0_TIME4, CPU0_TIME4), CPU0_TIME4);
     }
 
@@ -313,6 +317,7 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
      */
     @Test
     public void testMarkerAxis() {
+        SWTBotView viewBot = getViewBot();
         /* center window range of first lost event range */
         ITmfTimestamp startTime = LOST_EVENT_TIME1.normalize(-10000000L, ITmfTimestamp.NANOSECOND_SCALE);
         ITmfTimestamp endTime = LOST_EVENT_END1.normalize(10000000L, ITmfTimestamp.NANOSECOND_SCALE);
@@ -325,11 +330,11 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
         timeGraphIsReadyCondition(new TmfTimeRange(startTime, startTime), startTime);
 
         /* get marker axis size with one category */
-        final TimeGraphMarkerAxis markerAxis = fViewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphMarkerAxis.class));
+        final TimeGraphMarkerAxis markerAxis = viewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphMarkerAxis.class));
         final Point size1 = getSize(markerAxis);
 
         /* add bookmark at window start time */
-        fViewBot.toolbarButton(ADD_BOOKMARK).click();
+        viewBot.toolbarButton(ADD_BOOKMARK).click();
         SWTBot dialogBot = fBot.shell(ADD_BOOKMARK_DIALOG).bot();
         dialogBot.text().setText("B");
         dialogBot.button(OK).click();
@@ -341,7 +346,7 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
         /*
          * get the state area bounds, since we don't know the name space width
          */
-        final TimeGraphControl timeGraph = fViewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class));
+        final TimeGraphControl timeGraph = viewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class));
         int x0 = getXForTime(timeGraph, startTime.toNanos());
         int x1 = getXForTime(timeGraph, endTime.toNanos());
 
@@ -361,7 +366,7 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
         fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(startTime, startTime)));
 
         /* click "Remove Bookmark" */
-        fViewBot.toolbarButton(REMOVE_BOOKMARK).click();
+        viewBot.toolbarButton(REMOVE_BOOKMARK).click();
         assertEquals(size1, getSize(markerAxis));
 
         /* click the 'expanded' icon to collapse */
@@ -377,12 +382,12 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
         assertEquals(0, getSize(markerAxis).y);
 
         /* show Lost Events markers */
-        fViewBot.viewMenu(LOST_EVENTS).click();
+        viewBot.viewMenu(LOST_EVENTS).click();
         assertEquals(size1, getSize(markerAxis));
     }
 
     private void timeGraphIsReadyCondition(@NonNull TmfTimeRange selectionRange, @NonNull ITmfTimestamp visibleTime) {
-        IWorkbenchPart part = fViewBot.getViewReference().getPart(false);
+        IWorkbenchPart part = getViewBot().getViewReference().getPart(false);
         fBot.waitUntil(ConditionHelpers.timeGraphIsReadyCondition((AbstractTimeGraphView) part, selectionRange, visibleTime));
     }
 
This page took 0.030526 seconds and 5 git commands to generate.