Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / cc / resources / picture_pile_unittest.cc
index ee78c9c..87938fa 100644 (file)
@@ -39,13 +39,16 @@ class TestPicturePile : public PicturePile {
 class PicturePileTestBase {
  public:
   PicturePileTestBase()
-      : pile_(new TestPicturePile()),
-        background_color_(SK_ColorBLUE),
+      : background_color_(SK_ColorBLUE),
         min_scale_(0.125),
         frame_number_(0),
-        contents_opaque_(false) {
+        contents_opaque_(false) {}
+
+  void InitializeData() {
+    pile_ = make_scoped_refptr(new TestPicturePile());
     pile_->SetTileGridSize(gfx::Size(1000, 1000));
     pile_->SetMinContentsScale(min_scale_);
+    client_ = FakeContentLayerClient();
     SetTilingSize(pile_->tiling().max_texture_size());
   }
 
@@ -91,7 +94,10 @@ class PicturePileTestBase {
   bool contents_opaque_;
 };
 
-class PicturePileTest : public PicturePileTestBase, public testing::Test {};
+class PicturePileTest : public PicturePileTestBase, public testing::Test {
+ public:
+  virtual void SetUp() OVERRIDE { InitializeData(); }
+};
 
 TEST_F(PicturePileTest, SmallInvalidateInflated) {
   // Invalidate something inside a tile.
@@ -130,7 +136,7 @@ TEST_F(PicturePileTest, LargeInvalidateInflated) {
 
   int expected_inflation = pile_->buffer_pixels();
 
-  Picture* base_picture = picture_info.GetPicture();
+  const Picture* base_picture = picture_info.GetPicture();
   gfx::Rect base_picture_rect(pile_->tiling_size());
   base_picture_rect.Inset(-expected_inflation, -expected_inflation);
   EXPECT_EQ(base_picture_rect.ToString(),
@@ -396,6 +402,8 @@ enum Corner {
 class PicturePileResizeCornerTest : public PicturePileTestBase,
                                     public testing::TestWithParam<Corner> {
  protected:
+  virtual void SetUp() OVERRIDE { InitializeData(); }
+
   static gfx::Rect CornerSinglePixelRect(Corner corner, const gfx::Size& s) {
     switch (corner) {
       case TOP_LEFT:
@@ -1222,5 +1230,51 @@ TEST_F(PicturePileTest, SmallResizePileInsideInterestRect) {
   invalidation.Clear();
 }
 
+TEST_F(PicturePileTest, SolidRectangleIsSolid) {
+  // If the client has no contents, the solid state will be true.
+  Region invalidation1(tiling_rect());
+  UpdateAndExpandInvalidation(&invalidation1, tiling_size(), tiling_rect());
+  EXPECT_TRUE(pile_->is_solid_color());
+  EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), pile_->solid_color());
+
+  // If there is a single rect that covers the view, the solid
+  // state will be true.
+  SkPaint paint;
+  paint.setColor(SK_ColorCYAN);
+  client_.add_draw_rect(tiling_rect(), paint);
+  Region invalidation2(tiling_rect());
+  UpdateAndExpandInvalidation(&invalidation2, tiling_size(), tiling_rect());
+  EXPECT_TRUE(pile_->is_solid_color());
+  EXPECT_EQ(SK_ColorCYAN, pile_->solid_color());
+
+  // If a second smaller rect is draw that doesn't cover the viewport
+  // completely, the solid state will be false.
+  gfx::Rect smallRect = tiling_rect();
+  smallRect.Inset(10, 10, 10, 10);
+  client_.add_draw_rect(smallRect, paint);
+  Region invalidation3(tiling_rect());
+  UpdateAndExpandInvalidation(&invalidation3, tiling_size(), tiling_rect());
+  EXPECT_FALSE(pile_->is_solid_color());
+
+  // If a third rect is drawn over everything, we should be solid again.
+  paint.setColor(SK_ColorRED);
+  client_.add_draw_rect(tiling_rect(), paint);
+  Region invalidation4(tiling_rect());
+  UpdateAndExpandInvalidation(&invalidation4, tiling_size(), tiling_rect());
+  EXPECT_TRUE(pile_->is_solid_color());
+  EXPECT_EQ(SK_ColorRED, pile_->solid_color());
+
+  // If we draw too many, we don't bother doing the analysis and we should no
+  // longer be in a solid state.  There are 8 rects, two clips and a translate.
+  client_.add_draw_rect(tiling_rect(), paint);
+  client_.add_draw_rect(tiling_rect(), paint);
+  client_.add_draw_rect(tiling_rect(), paint);
+  client_.add_draw_rect(tiling_rect(), paint);
+  client_.add_draw_rect(tiling_rect(), paint);
+  Region invalidation5(tiling_rect());
+  UpdateAndExpandInvalidation(&invalidation5, tiling_size(), tiling_rect());
+  EXPECT_FALSE(pile_->is_solid_color());
+}
+
 }  // namespace
 }  // namespace cc