swtbot: Stabilize FilterColorEditorTest
authorPatrick Tasse <patrick.tasse@gmail.com>
Tue, 22 Mar 2016 19:53:15 +0000 (15:53 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Tue, 29 Mar 2016 21:37:04 +0000 (17:37 -0400)
A condition is added that waits for the image at the specified bounds
to have changed when compared to a specified current image. This ensures
that the cell has painted with required changes following user input.

ImageHelper now implements hashCode() and equals().

Change-Id: I444ab78f074ebd5c28f8b4aea4927b1c01558486
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/69076
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/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ImageHelper.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/FilterColorEditorTest.java

index 102625f41517f8262be3a9393630fd3473126796..3e16284de021a7d7e3b05cc02ac5f570019f452c 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2015 Ericsson
+ * Copyright (c) 2015, 2016 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -222,6 +222,40 @@ public final class ImageHelper {
         return new RGB(((pixel >> 16) & 0xff), ((pixel >> 8) & 0xff), ((pixel) & 0xff));
     }
 
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((fBounds == null) ? 0 : fBounds.hashCode());
+        result = prime * result + Arrays.hashCode(fPixels);
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        ImageHelper other = (ImageHelper) obj;
+        if (fBounds == null) {
+            if (other.fBounds != null) {
+                return false;
+            }
+        } else if (!fBounds.equals(other.fBounds)) {
+            return false;
+        }
+        if (!Arrays.equals(fPixels, other.fPixels)) {
+            return false;
+        }
+        return true;
+    }
+
     /**
      * On Mac, RGB values that are captured with ImageHelper are affected by
      * monitor color profiles. To account for this, we can draw the expected
index e24c65d292f729fe41f4f76d54ea49f7b18802d2..5ce5f348ee788ea65198af23e5cb86b1d492d1ff 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2015 Ericsson
+ * Copyright (c) 2015, 2016 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -38,9 +38,12 @@ import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
 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.SWTBotTable;
 import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
@@ -169,13 +172,14 @@ public class FilterColorEditorTest {
     public void testHighlight() {
         final Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, SOURCE_COLUMN);
 
-        Multiset<RGB> colorBefore = ImageHelper.grabImage(cellBounds).getHistogram();
+        ImageHelper before = ImageHelper.grabImage(cellBounds);
+        Multiset<RGB> colorBefore = before.getHistogram();
         // Select source column and enter regex
         fTableBot.click(0, SOURCE_COLUMN);
         fBot.text().typeText("HostF\n", 100);
         // make sure selected row is not matching row
         fTableBot.select(ROW - 1);
-        Multiset<RGB> colorAfter = ImageHelper.grabImage(cellBounds).getHistogram();
+        Multiset<RGB> colorAfter = waitForNewImage(cellBounds, before).getHistogram();
 
         assertTrue(colorBefore.contains(fBackground));
         assertTrue(colorBefore.contains(fForeground));
@@ -205,7 +209,7 @@ public class FilterColorEditorTest {
         fBot.text().typeText("e\n", 100);
         // make sure matching item is not selected
         fTableBot.select(ROW - 1);
-        ImageHelper after = ImageHelper.grabImage(cellBounds);
+        ImageHelper after = waitForNewImage(cellBounds, before);
 
         Multiset<RGB> colorBefore = before.getHistogram();
         Multiset<RGB> colorAfter = after.getHistogram();
@@ -246,23 +250,25 @@ public class FilterColorEditorTest {
     public void testSwitchToFilter() {
         Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, TIMESTAMP_COLUMN);
         ImageHelper before = ImageHelper.grabImage(cellBounds);
+
         // enter regex in Timestamp column
         fTableBot.click(0, TIMESTAMP_COLUMN);
         fBot.text().typeText("00\n", 100);
         // make sure matching column is not selected
         fTableBot.select(ROW - 1);
-        ImageHelper afterSearch = ImageHelper.grabImage(cellBounds);
+        ImageHelper afterSearch = waitForNewImage(cellBounds, before);
+
         // click Add as Filter
         fTableBot.click(0, 0);
         fBot.waitUntil(ConditionHelpers.isTableCellFilled(fTableBot, "<srch>", 0, TIMESTAMP_COLUMN));
-        //TODO: We need a better way to make sure that the table is done updating
-        SWTBotUtils.delay(2000);
+        fBot.waitUntil(ConditionHelpers.isTableCellFilled(fTableBot, "22/22", 1, TIMESTAMP_COLUMN));
         // the bounds have changed after applying the filter
         cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, TIMESTAMP_COLUMN);
         ImageHelper afterFilter = ImageHelper.grabImage(cellBounds);
+
         // press DEL to clear highlighting
         fTableBot.pressShortcut(Keystrokes.DELETE);
-        ImageHelper afterClear = ImageHelper.grabImage(cellBounds);
+        ImageHelper afterClear = waitForNewImage(cellBounds, afterFilter);
 
         List<RGB> beforeLine = before.getPixelRow(2);
         List<RGB> afterSearchLine = afterSearch.getPixelRow(2);
@@ -303,13 +309,14 @@ public class FilterColorEditorTest {
 
         final Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, SOURCE_COLUMN);
 
-        Multiset<RGB> colorBefore = ImageHelper.grabImage(cellBounds).getHistogram();
+        ImageHelper before = ImageHelper.grabImage(cellBounds);
+        Multiset<RGB> colorBefore = before.getHistogram();
         // Select source column and enter regex
         fTableBot.click(0, SOURCE_COLUMN);
         fBot.text().typeText("HostF\n", 100);
         // make sure selected row is not matching row
         fTableBot.select(ROW - 1);
-        Multiset<RGB> colorAfter = ImageHelper.grabImage(cellBounds).getHistogram();
+        Multiset<RGB> colorAfter = waitForNewImage(cellBounds, before).getHistogram();
 
         assertTrue(colorBefore.contains(fBackground));
         assertTrue(colorBefore.contains(fForeground));
@@ -330,4 +337,26 @@ public class FilterColorEditorTest {
         // reset the highlight color preference
         colorRegistry.put(HIGHLIGHT_COLOR_DEFINITION_ID, fHighlight);
     }
+
+    private static ImageHelper waitForNewImage(Rectangle bounds, ImageHelper currentImage) {
+        ImageHelper[] newImage = new ImageHelper[1];
+        fBot.waitUntil(new DefaultCondition() {
+            @Override
+            public boolean test() throws Exception {
+                return UIThreadRunnable.syncExec(new Result<Boolean> () {
+                    @Override
+                    public Boolean run() {
+                        newImage[0] = ImageHelper.grabImage(bounds);
+                        return !newImage[0].equals(currentImage);
+                    }
+                });
+            }
+
+            @Override
+            public String getFailureMessage() {
+                return "Image at bounds " + bounds + " did not change";
+            }
+        });
+        return newImage[0];
+    }
 }
This page took 0.029297 seconds and 5 git commands to generate.