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;
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;
+ }
+ });
+ }
}
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;
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
/* 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);
}
/**
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);
}
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);
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);