tmf: FilterColorEditorTest on Mac
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Mon, 14 Dec 2015 03:03:48 +0000 (22:03 -0500)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tue, 15 Dec 2015 04:31:37 +0000 (23:31 -0500)
On Mac, RGB values that are captured with ImageHelper are affected by
monitor color profiles. To account for this, we can draw the expected
color in a simple shell and use that color as expected value instead.

Also, switching to the Filter mode in the table is not instantaneous,
we need to wait until it's done before capturing the next image.

Change-Id: I930570027ba53f3dbdcecb5925a8e67c24c239b2
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/62573
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@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 33763d0484fabbb01c65a91feb0d80f4d294f8c2..102625f41517f8262be3a9393630fd3473126796 100644 (file)
@@ -20,11 +20,19 @@ import java.util.List;
 
 import javax.imageio.ImageIO;
 
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swtbot.swt.finder.SWTBot;
 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
 import org.eclipse.swtbot.swt.finder.results.Result;
+import org.eclipse.swtbot.swt.finder.utils.SWTUtils;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
 
 import com.google.common.collect.HashMultiset;
 import com.google.common.collect.Multiset;
@@ -213,4 +221,64 @@ public final class ImageHelper {
     private static RGB getRgbFromRGBPixel(int pixel) {
         return new RGB(((pixel >> 16) & 0xff), ((pixel >> 8) & 0xff), ((pixel) & 0xff));
     }
+
+    /**
+     * On Mac, RGB values that are captured with ImageHelper are affected by
+     * monitor color profiles. To account for this, we can draw the expected
+     * color in a simple shell and use that color as expected value instead.
+     *
+     * @param original
+     *            original color to adjust
+     * @return adjusted color
+     */
+    public static RGB adjustExpectedColor(RGB original) {
+        if (!SWTUtils.isMac()) {
+            return original;
+        }
+
+        /* Create shell with desired color as background */
+        boolean painted[] = new boolean[1];
+        final Shell shell = UIThreadRunnable.syncExec(new Result<Shell>() {
+            @Override
+            public Shell run() {
+                Shell s = new Shell(Display.getDefault());
+                s.setSize(100, 100);
+                Color color = new Color(Display.getDefault(), original);
+                s.setBackground(color);
+                s.addPaintListener(new PaintListener() {
+                    @Override
+                    public void paintControl(PaintEvent e) {
+                        painted[0] = true;
+                    }
+                });
+                s.open();
+                return s;
+            }
+        });
+
+        /* Make sure the shell has been painted before getting the color */
+        new SWTBot().waitUntil(new DefaultCondition() {
+
+            @Override
+            public boolean test() throws Exception {
+                return painted[0];
+            }
+
+            @Override
+            public String getFailureMessage() {
+                return "Shell was not painted";
+            }
+        });
+
+        /* Get the color  */
+        return UIThreadRunnable.syncExec(new Result<RGB>() {
+            @Override
+            public RGB run() {
+                shell.update();
+                RGB rgb = ImageHelper.grabImage(shell.getBounds()).getPixel(50, 50);
+                shell.close();
+                return rgb;
+            }
+        });
+    }
 }
index e57e998a46a39702ea4ad5c2dd71f1335df78331..08eb62c902045725fba345c59b5c7a1815bd7773 100644 (file)
@@ -42,6 +42,7 @@ import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
 import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
 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;
 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper;
 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
 import org.eclipse.ui.PlatformUI;
@@ -78,9 +79,11 @@ public class FilterColorEditorTest {
     private static final Logger fLogger = Logger.getRootLogger();
     private SWTBotTable fTableBot;
     private static final int ROW = 8;
+    /** Expected color values */
     private RGB fForeground;
     private RGB fBackground;
-    private RGB fHighlight;
+    private static RGB fHighlight;
+    private static RGB EXPECTED_GREEN;
 
     /**
      * Test Class setup
@@ -117,6 +120,10 @@ public class FilterColorEditorTest {
 
         /* Finish waiting for eclipse to load */
         SWTBotUtils.waitForJobs();
+
+        ColorRegistry colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
+        fHighlight = ImageHelper.adjustExpectedColor(colorRegistry.get(HIGHLIGHT_COLOR_DEFINITION_ID).getRGB());
+        EXPECTED_GREEN = ImageHelper.adjustExpectedColor(GREEN);
     }
 
     /**
@@ -141,8 +148,6 @@ public class FilterColorEditorTest {
         fTableBot = editorBot.bot().table();
         fBackground = fTableBot.backgroundColor().getRGB();
         fForeground = fTableBot.foregroundColor().getRGB();
-        ColorRegistry colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
-        fHighlight = colorRegistry.get(HIGHLIGHT_COLOR_DEFINITION_ID).getRGB();
 
         SWTBotUtils.maximizeTable(fTableBot);
     }
@@ -248,6 +253,9 @@ public class FilterColorEditorTest {
         ImageHelper after = ImageHelper.grabImage(cellBounds);
         // toggle filter mode
         fTableBot.click(0, 0);
+        fBot.waitUntil(ConditionHelpers.isTableCellFilled(fTableBot, "<filter>", 0, 1));
+        //TODO: We need a better way to make sure that the table is done updating
+        SWTBotUtils.delay(2000);
         ImageHelper afterFilter = ImageHelper.grabImage(cellBounds);
 
         List<RGB> beforeLine = before.getPixelRow(2);
@@ -295,18 +303,18 @@ public class FilterColorEditorTest {
         assertTrue(colorBefore.contains(fBackground));
         assertTrue(colorBefore.contains(fForeground));
         assertFalse(colorBefore.contains(fHighlight));
-        assertFalse(colorBefore.contains(GREEN));
+        assertFalse(colorBefore.contains(EXPECTED_GREEN));
 
         assertTrue(colorAfter.contains(fBackground));
         assertTrue(colorAfter.contains(fForeground));
         assertFalse(colorAfter.contains(fHighlight));
-        assertTrue(colorAfter.contains(GREEN));
+        assertTrue(colorAfter.contains(EXPECTED_GREEN));
 
         /*
          * Check that some background became green.
          */
         assertTrue(colorAfter.count(fBackground) < colorBefore.count(fBackground));
-        assertTrue(colorAfter.count(GREEN) > colorBefore.count(GREEN));
+        assertTrue(colorAfter.count(EXPECTED_GREEN) > colorBefore.count(EXPECTED_GREEN));
 
         // reset the highlight color preference
         colorRegistry.put(HIGHLIGHT_COLOR_DEFINITION_ID, fHighlight);
This page took 0.032682 seconds and 5 git commands to generate.