swtbot: Fix ControlFlowViewTest
authorPatrick Tasse <patrick.tasse@gmail.com>
Tue, 2 Jun 2015 21:26:02 +0000 (17:26 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Thu, 4 Jun 2015 15:32:15 +0000 (11:32 -0400)
If the test host burps for a minimum of 400 ms between the 5th and the
6th click of the "Follow CPU Fwd" button, the test will fail because the
wait condition for the time range returns immediately since the 6th
selected event is a change of process that has the same timestamp as the
5th selected event and the listener notifier has timed out due to the
host delay, updating the trace manager with the selection time of the
5th selected event, and then the following assert on the tree selection
fails because the selected entry change event is still stuck in the new
listener notifier for another 400 ms.

A new condition is created to wait until the tree selection equals the
expected value, instead of using an assertion.

Additionally, the tests are updated to use the new click(int) with
modifier methods in SWTBot, allowing the test of range selection using
tool bar buttons while the SHIFT key is pressed.

Change-Id: Ic607d063b13248bd5ab91a87861ce3dad8a2b286
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/49259
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/ControlFlowViewTest.java
org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java

index a0a56e95f62f3865c79062a1b8e5685ec6a532d5..a84ad87c27dedf1626350f8214a26a301c04d590 100644 (file)
 
 package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
 
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import java.util.List;
 
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.swt.SWT;
 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
 import org.eclipse.swtbot.swt.finder.keyboard.Keyboard;
@@ -191,30 +191,19 @@ public class ControlFlowViewTest extends KernelTest {
         fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME3)));
         assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME3));
 
-//        /* shift-click "Select Next Event" 3 times */
-//        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
-//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME6)));
-        /* click "Select Next Event" 3 times */
-        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
-        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
-        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
-        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME6, TID1_TIME6)));
+        /* shift-click "Select Next Event" 3 times */
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME6)));
         assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME6));
 
-//        /* shift-click "Select Previous Event" 4 times */
-//        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
-//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME2)));
-        /* click "Select Previous Event" 4 times */
-        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
-        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
-        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
-        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
-        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME2, TID1_TIME2)));
+        /* shift-click "Select Previous Event" 4 times */
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME3, TID1_TIME2)));
         assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME2));
 
         /* click "Select Next Event" 2 times */
@@ -223,30 +212,19 @@ public class ControlFlowViewTest extends KernelTest {
         fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME4)));
         assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME4));
 
-//        /* shift-click "Select Previous Event" 3 times */
-//        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
-//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME1)));
-        /* click "Select Previous Event" 3 times */
-        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
-        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
-        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click();
-        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME1, TID1_TIME1)));
+        /* shift-click "Select Previous Event" 3 times */
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+        fViewBot.toolbarButton(SELECT_PREVIOUS_EVENT).click(SWT.SHIFT);
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME1)));
         assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME1));
 
-//        /* shift-click "Select Next Event" 4 times */
-//        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
-//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME5)));
-        /* click "Select Next Event" 4 times */
-        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
-        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
-        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
-        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click();
-        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME5, TID1_TIME5)));
+        /* shift-click "Select Next Event" 4 times */
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+        fViewBot.toolbarButton(SELECT_NEXT_EVENT).click(SWT.SHIFT);
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME4, TID1_TIME5)));
         assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME5));
 
         /* click "Select Previous Event" 5 times */
@@ -307,70 +285,48 @@ public class ControlFlowViewTest extends KernelTest {
         fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
         fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
         fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME2, TID2_TIME2)));
-        assertEquals("2", tree.selection().get(0, 1));
+        fBot.waitUntil(ConditionHelpers.treeSelectionContains(tree, 1, "2"));
         assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME2));
 
-//        /* shift-click "Follow CPU Forward" 3 times */
-//        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
-//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME2, TID5_TIME1)));
-        /* click "Follow CPU Forward" 3 times */
-        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
-        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
-        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
-        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID5_TIME1, TID5_TIME1)));
-        assertEquals("5", tree.selection().get(0, 1));
+        /* shift-click "Follow CPU Forward" 3 times */
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME2, TID5_TIME1)));
+        fBot.waitUntil(ConditionHelpers.treeSelectionContains(tree, 1, "5"));
         assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID5_TIME1));
 
-//        /* shift-click "Follow CPU Backward" 4 times */
-//        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
-//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME2, TID2_TIME1)));
-        /* click "Follow CPU Backward" 4 times */
-        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
-        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
-        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
-        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
-        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME1, TID2_TIME1)));
-        assertEquals("2", tree.selection().get(0, 1));
+        /* shift-click "Follow CPU Backward" 4 times */
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME2, TID2_TIME1)));
+        fBot.waitUntil(ConditionHelpers.treeSelectionContains(tree, 1, "2"));
         assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME1));
 
         /* click "Follow CPU Forward" 2 times */
         fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
         fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
         fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME3, TID2_TIME3)));
-        assertEquals("2", tree.selection().get(0, 1));
+        fBot.waitUntil(ConditionHelpers.treeSelectionContains(tree, 1, "2"));
         assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME3));
 
-//        /* shift-click "Follow CPU Backward" 3 times */
-//        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
-//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME3, TID1_TIME1)));
-        /* click "Follow CPU Backward" 3 times */
-        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
-        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
-        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click();
-        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID1_TIME1, TID1_TIME1)));
-        assertEquals("1", tree.selection().get(0, 1));
+        /* shift-click "Follow CPU Backward" 3 times */
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+        fViewBot.toolbarButton(FOLLOW_CPU_BACKWARD).click(SWT.SHIFT);
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME3, TID1_TIME1)));
+        fBot.waitUntil(ConditionHelpers.treeSelectionContains(tree, 1, "1"));
         assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID1_TIME1));
 
-//        /* shift-click "Follow CPU Forward" 4 times */
-//        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
-//        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
-//        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME3, TID2_TIME4)));
-        /* click "Follow CPU Forward" 4 times */
-        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
-        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
-        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
-        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click();
-        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME4, TID2_TIME4)));
-        assertEquals("2", tree.selection().get(0, 1));
+        /* shift-click "Follow CPU Forward" 4 times */
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+        fViewBot.toolbarButton(FOLLOW_CPU_FORWARD).click(SWT.SHIFT);
+        fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(TID2_TIME3, TID2_TIME4)));
+        fBot.waitUntil(ConditionHelpers.treeSelectionContains(tree, 1, "2"));
         assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(TID2_TIME4));
 
         /* click "Follow CPU Backward" 5 times */
index ef7d191334d253b9bc696e7f92af4c0b5df38e38..26f944d7fb89183a58412c24cbb200a9ddf9b051 100644 (file)
@@ -24,6 +24,7 @@ import org.eclipse.osgi.util.NLS;
 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
 import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.utils.TableCollection;
 import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
 import org.eclipse.swtbot.swt.finder.waits.ICondition;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
@@ -341,4 +342,37 @@ public final class ConditionHelpers {
             }
         };
     }
+
+    /**
+     * Condition to check if the selection contains the specified text at the
+     * specified column. The text is checked in any item of the tree selection.
+     *
+     * @param tree
+     *            the SWTBot tree
+     * @param column
+     *            the column index
+     * @param text
+     *            the expected text
+     * @return ICondition for verification
+     */
+    public static ICondition treeSelectionContains(final SWTBotTree tree, final int column, final String text) {
+        return new SWTBotTestCondition() {
+            @Override
+            public boolean test() throws Exception {
+                TableCollection selection = tree.selection();
+                for (int row = 0; row < selection.rowCount(); row++) {
+                    if (selection.get(row, column).equals(text)) {
+                        return true;
+                    }
+                }
+                return false;
+            }
+
+            @Override
+            public String getFailureMessage() {
+                return NLS.bind("Tree selection [0,{0}]: {1} expected: {2}",
+                        new Object[] { column, tree.selection().get(0, column), text});
+            }
+        };
+    }
 }
This page took 0.028956 seconds and 5 git commands to generate.