OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/picture_layer_tiling.h" | 5 #include "cc/picture_layer_tiling.h" |
6 | 6 |
7 #include "cc/test/fake_picture_layer_tiling_client.h" | 7 #include "cc/test/fake_picture_layer_tiling_client.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/gfx/size_conversions.h" | 9 #include "ui/gfx/size_conversions.h" |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 EXPECT_TRUE(remaining.IsEmpty()); | 57 EXPECT_TRUE(remaining.IsEmpty()); |
58 } | 58 } |
59 | 59 |
60 protected: | 60 protected: |
61 FakePictureLayerTilingClient client_; | 61 FakePictureLayerTilingClient client_; |
62 scoped_ptr<PictureLayerTiling> tiling_; | 62 scoped_ptr<PictureLayerTiling> tiling_; |
63 | 63 |
64 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); | 64 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); |
65 }; | 65 }; |
66 | 66 |
| 67 class PictureLayerTilingTest : public testing::Test { |
| 68 public: |
| 69 PictureLayerTilingTest() { |
| 70 tiling_ = PictureLayerTiling::Create(0, gfx::Size(0, 0)); |
| 71 } |
| 72 |
| 73 void VerifyTimeForBoundsToIntersect(gfx::Rect previous, |
| 74 gfx::Rect current, |
| 75 gfx::Rect target, |
| 76 double time) { |
| 77 EXPECT_EQ(tiling_->TimeForBoundsToIntersect(previous, current, 1, target), |
| 78 time); |
| 79 } |
| 80 protected: |
| 81 scoped_ptr<PictureLayerTiling> tiling_; |
| 82 }; |
| 83 |
67 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsNoScale) { | 84 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsNoScale) { |
68 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); | 85 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); |
69 VerifyTilesExactlyCoverRect(1, gfx::Rect()); | 86 VerifyTilesExactlyCoverRect(1, gfx::Rect()); |
70 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801)); | 87 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801)); |
71 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412)); | 88 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412)); |
72 | 89 |
73 // With borders, a size of 3x3 = 1 pixel of content. | 90 // With borders, a size of 3x3 = 1 pixel of content. |
74 Initialize(gfx::Size(3, 3), 1, gfx::Size(10, 10)); | 91 Initialize(gfx::Size(3, 3), 1, gfx::Size(10, 10)); |
75 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1)); | 92 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1)); |
76 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2)); | 93 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 VerifyTilesExactlyCoverRect(2.0f, gfx::Rect(512, 365, 253, 182)); | 128 VerifyTilesExactlyCoverRect(2.0f, gfx::Rect(512, 365, 253, 182)); |
112 | 129 |
113 float scale = 6.7f; | 130 float scale = 6.7f; |
114 gfx::Size bounds(800, 600); | 131 gfx::Size bounds(800, 600); |
115 gfx::Rect full_rect(gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale))); | 132 gfx::Rect full_rect(gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale))); |
116 Initialize(gfx::Size(256, 512), 5.2f, bounds); | 133 Initialize(gfx::Size(256, 512), 5.2f, bounds); |
117 VerifyTilesExactlyCoverRect(scale, full_rect); | 134 VerifyTilesExactlyCoverRect(scale, full_rect); |
118 VerifyTilesExactlyCoverRect(scale, gfx::Rect(2014, 1579, 867, 1033)); | 135 VerifyTilesExactlyCoverRect(scale, gfx::Rect(2014, 1579, 867, 1033)); |
119 } | 136 } |
120 | 137 |
| 138 TEST_F(PictureLayerTilingTest, TimeForBoundsToIntersectWithScroll) { |
| 139 gfx::Rect target(0, 0, 800, 600); |
| 140 gfx::Rect current(100, 100, 100, 100); |
| 141 VerifyTimeForBoundsToIntersect( |
| 142 gfx::Rect(-200, 0, 100, 100), current, target, 0); |
| 143 VerifyTimeForBoundsToIntersect( |
| 144 gfx::Rect(-100, 0, 100, 100), current, target, 0); |
| 145 VerifyTimeForBoundsToIntersect( |
| 146 gfx::Rect(400, 400, 100, 100), current, target, 0); |
| 147 |
| 148 current = gfx::Rect(-300, -300, 100, 100); |
| 149 VerifyTimeForBoundsToIntersect( |
| 150 gfx::Rect(0, 0, 100, 100), current, target, 1000); |
| 151 VerifyTimeForBoundsToIntersect( |
| 152 gfx::Rect(-200, -200, 100, 100), current, target, 1000); |
| 153 VerifyTimeForBoundsToIntersect( |
| 154 gfx::Rect(-400, -400, 100, 100), current, target, 2); |
| 155 } |
| 156 |
| 157 TEST_F(PictureLayerTilingTest, TimeForBoundsToIntersectWithScale) { |
| 158 gfx::Rect target(0, 0, 800, 600); |
| 159 gfx::Rect current(100, 100, 100, 100); |
| 160 VerifyTimeForBoundsToIntersect( |
| 161 gfx::Rect(-200, 0, 200, 200), current, target, 0); |
| 162 VerifyTimeForBoundsToIntersect( |
| 163 gfx::Rect(-100, 0, 50, 50), current, target, 0); |
| 164 VerifyTimeForBoundsToIntersect( |
| 165 gfx::Rect(400, 400, 400, 400), current, target, 0); |
| 166 |
| 167 current = gfx::Rect(-300, -300, 100, 100); |
| 168 VerifyTimeForBoundsToIntersect( |
| 169 gfx::Rect(-400, -400, 300, 300), current, target, 1000); |
| 170 VerifyTimeForBoundsToIntersect( |
| 171 gfx::Rect(-275, -275, 50, 50), current, target, 8); |
| 172 VerifyTimeForBoundsToIntersect( |
| 173 gfx::Rect(-450, -450, 50, 50), current, target, 1); |
| 174 } |
| 175 |
121 } // namespace cc | 176 } // namespace cc |
OLD | NEW |