summaryrefslogtreecommitdiffstats
path: root/cc/test
diff options
context:
space:
mode:
Diffstat (limited to 'cc/test')
-rw-r--r--cc/test/layer_tree_pixel_test.cc37
-rw-r--r--cc/test/layer_tree_pixel_test.h10
-rw-r--r--cc/test/pixel_comparator.h9
3 files changed, 50 insertions, 6 deletions
diff --git a/cc/test/layer_tree_pixel_test.cc b/cc/test/layer_tree_pixel_test.cc
index 86e3f30..6e7b137 100644
--- a/cc/test/layer_tree_pixel_test.cc
+++ b/cc/test/layer_tree_pixel_test.cc
@@ -6,6 +6,7 @@
#include "base/path_service.h"
#include "cc/test/paths.h"
+#include "cc/test/pixel_comparator.h"
#include "cc/test/pixel_test_utils.h"
#include "cc/trees/layer_tree_impl.h"
#include "ui/gl/gl_implementation.h"
@@ -14,7 +15,8 @@
namespace cc {
-LayerTreePixelTest::LayerTreePixelTest() {}
+LayerTreePixelTest::LayerTreePixelTest()
+ : pixel_comparator_(new ExactPixelComparator(true)) {}
LayerTreePixelTest::~LayerTreePixelTest() {}
@@ -66,8 +68,9 @@ void LayerTreePixelTest::SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
// To rebaseline:
// EXPECT_TRUE(WritePNGFile(bitmap, test_data_dir.Append(ref_file_)));
- EXPECT_TRUE(MatchesPNGFile(bitmap, test_data_dir.Append(ref_file_),
- ExactPixelComparator(true)));
+ EXPECT_TRUE(MatchesPNGFile(bitmap,
+ test_data_dir.Append(ref_file_),
+ *pixel_comparator_));
EndTest();
}
@@ -89,6 +92,34 @@ scoped_refptr<SolidColorLayer> LayerTreePixelTest::CreateSolidColorLayer(
return layer;
}
+scoped_refptr<SolidColorLayer> LayerTreePixelTest::
+ CreateSolidColorLayerWithBorder(
+ gfx::Rect rect, SkColor color, int border_width, SkColor border_color) {
+ scoped_refptr<SolidColorLayer> layer = CreateSolidColorLayer(rect, color);
+ scoped_refptr<SolidColorLayer> border_top = CreateSolidColorLayer(
+ gfx::Rect(0, 0, rect.width(), border_width), border_color);
+ scoped_refptr<SolidColorLayer> border_left = CreateSolidColorLayer(
+ gfx::Rect(0,
+ border_width,
+ border_width,
+ rect.height() - border_width * 2),
+ border_color);
+ scoped_refptr<SolidColorLayer> border_right = CreateSolidColorLayer(
+ gfx::Rect(rect.width() - border_width,
+ border_width,
+ border_width,
+ rect.height() - border_width * 2),
+ border_color);
+ scoped_refptr<SolidColorLayer> border_bottom = CreateSolidColorLayer(
+ gfx::Rect(0, rect.height() - border_width, rect.width(), border_width),
+ border_color);
+ layer->AddChild(border_top);
+ layer->AddChild(border_left);
+ layer->AddChild(border_right);
+ layer->AddChild(border_bottom);
+ return layer;
+}
+
void LayerTreePixelTest::RunPixelTest(
scoped_refptr<Layer> content_root,
base::FilePath file_name) {
diff --git a/cc/test/layer_tree_pixel_test.h b/cc/test/layer_tree_pixel_test.h
index e5f049a..ceddfab 100644
--- a/cc/test/layer_tree_pixel_test.h
+++ b/cc/test/layer_tree_pixel_test.h
@@ -3,6 +3,8 @@
// found in the LICENSE file.
#include "base/files/file_path.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "cc/layers/solid_color_layer.h"
#include "cc/test/layer_tree_test.h"
@@ -11,6 +13,7 @@
namespace cc {
class LayerTreeHost;
+class PixelComparator;
class LayerTreePixelTest : public LayerTreeTest {
protected:
@@ -31,6 +34,11 @@ class LayerTreePixelTest : public LayerTreeTest {
scoped_refptr<SolidColorLayer> CreateSolidColorLayer(gfx::Rect rect,
SkColor color);
+ scoped_refptr<SolidColorLayer> CreateSolidColorLayerWithBorder(
+ gfx::Rect rect,
+ SkColor color,
+ int border_width,
+ SkColor border_color);
void RunPixelTest(scoped_refptr<Layer> content_root,
base::FilePath file_name);
@@ -42,6 +50,8 @@ class LayerTreePixelTest : public LayerTreeTest {
kCSSGreen = 0xff008000,
};
+ scoped_ptr<PixelComparator> pixel_comparator_;
+
private:
scoped_refptr<Layer> content_root_;
base::FilePath ref_file_;
diff --git a/cc/test/pixel_comparator.h b/cc/test/pixel_comparator.h
index 9c12c21..d51eff0 100644
--- a/cc/test/pixel_comparator.h
+++ b/cc/test/pixel_comparator.h
@@ -13,17 +13,18 @@ namespace cc {
// Interface for pixel comparators.
class PixelComparator {
public:
+ virtual ~PixelComparator() {}
+
virtual bool Compare(const SkBitmap& actual_bmp,
const SkBitmap& expected_bmp) const = 0;
-
- protected:
- virtual ~PixelComparator() {}
};
// Exact pixel comparator. Counts the number of pixel with an error.
class ExactPixelComparator : public PixelComparator {
public:
explicit ExactPixelComparator(const bool discard_alpha);
+ virtual ~ExactPixelComparator() {}
+
// Returns true if the two bitmaps are identical. Otherwise, returns false
// and report the number of pixels with an error on LOG(ERROR). Differences
// in the alpha channel are ignored.
@@ -45,6 +46,8 @@ class FuzzyPixelComparator : public PixelComparator {
const float avg_abs_error_limit,
const int max_abs_error_limit,
const int small_error_threshold);
+ virtual ~FuzzyPixelComparator() {}
+
// Computes error metrics and returns true if the errors don't exceed the
// specified limits. Otherwise, returns false and reports the error metrics on
// LOG(ERROR). Differences in the alpha channel are ignored.