swtbot: Add SWTBot tests for collapsible event table header bar
authorPatrick Tasse <patrick.tasse@gmail.com>
Wed, 16 Mar 2016 20:51:18 +0000 (16:51 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Thu, 31 Mar 2016 15:56:19 +0000 (11:56 -0400)
Change-Id: I53e6d536b8995ed02190c22a4b9fa7d1eb59a32b
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/68583
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/FilterColorEditorTest.java

index 5ce5f348ee788ea65198af23e5cb86b1d492d1ff..7233b9595680492df8d17950fac1a2c2fa81a030 100644 (file)
@@ -44,6 +44,8 @@ import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
 import org.eclipse.swtbot.swt.finder.results.Result;
 import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
 import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotCLabel;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotCanvas;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
 import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
@@ -338,6 +340,57 @@ public class FilterColorEditorTest {
         colorRegistry.put(HIGHLIGHT_COLOR_DEFINITION_ID, fHighlight);
     }
 
+    /**
+     * Test the header bar
+     */
+    @Test
+    public void testHeaderBar() {
+        // Add search filter on Timestamp column
+        fTableBot.click(0, TIMESTAMP_COLUMN);
+        fBot.text().typeText("2");
+        fBot.text().pressShortcut(Keystrokes.CR);
+        // Add search filter on Message column and Add as Filter
+        fTableBot.click(0, MESSAGE_COLUMN);
+        fBot.text().typeText("F");
+        fBot.text().pressShortcut(Keystrokes.CTRL, Keystrokes.CR);
+        fBot.waitUntil(ConditionHelpers.isTableCellFilled(fTableBot, "2/22", 1, 1));
+        fBot.waitUntil(ConditionHelpers.isTableCellFilled(fTableBot, "Message F", 3, MESSAGE_COLUMN));
+        fBot.clabel("Timestamp matches \"2\"");
+        fBot.clabel("Message matches \"F\"");
+        waitForHighlightState(3, TIMESTAMP_COLUMN, true);
+        waitForHighlightState(3, MESSAGE_COLUMN, true);
+        // Clear all filter highlighting
+        fTableBot.pressShortcut(Keystrokes.DELETE);
+        waitForHighlightState(3, TIMESTAMP_COLUMN, false);
+        waitForHighlightState(3, MESSAGE_COLUMN, false);
+        // Click filter label to set the filter highlighting on Message filter
+        SWTBotCLabel filterCLabel = fBot.clabel("Message matches \"F\"");
+        SWTBotCanvas filterCanvas = new SWTBotCanvas(filterCLabel.widget);
+        filterCanvas.click();
+        waitForHighlightState(3, TIMESTAMP_COLUMN, false);
+        waitForHighlightState(3, MESSAGE_COLUMN, true);
+        // Click filter icon to remove the Message filter
+        Rectangle imageBounds = filterCLabel.image().getBounds();
+        filterCanvas.click(filterCLabel.widget.getLeftMargin() + imageBounds.width / 2, filterCLabel.widget.getTopMargin() + imageBounds.height / 2);
+        fBot.waitUntil(ConditionHelpers.isTableCellFilled(fTableBot, "5/22", 1, 1));
+    }
+
+    private void waitForHighlightState(int row, int column, boolean highlight) {
+        fBot.waitUntil(new DefaultCondition() {
+            @Override
+            public boolean test() throws Exception {
+                Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, row, column);
+                ImageHelper imageHelper = ImageHelper.grabImage(cellBounds);
+                return imageHelper.getHistogram().contains(fHighlight) == highlight;
+            }
+
+            @Override
+            public String getFailureMessage() {
+                return String.format("Cell (%d, %d) did not have highlight state: %s", row, column, Boolean.toString(highlight));
+            }
+        });
+    }
+
     private static ImageHelper waitForNewImage(Rectangle bounds, ImageHelper currentImage) {
         ImageHelper[] newImage = new ImageHelper[1];
         fBot.waitUntil(new DefaultCondition() {
This page took 0.026246 seconds and 5 git commands to generate.