Index: cc/trees/layer_tree_host_impl_unittest.cc |
diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc |
index 94ecb174c14ba231f2878b3986533fa04bbc50a7..2baede67c9562d45402ea40b0923ced7f849f795 100644 |
--- a/cc/trees/layer_tree_host_impl_unittest.cc |
+++ b/cc/trees/layer_tree_host_impl_unittest.cc |
@@ -196,15 +196,37 @@ class LayerTreeHostImplTest : public testing::Test, |
ExpectClearedScrollDeltasRecursive(layer->children()[i]); |
} |
+ // Some tests, e.g. ScrollAxisAlignedRotatedLayer generates float number |
+ // which is supposed to be 0 but actually a very small value e.g. 6.12323e-16, |
+ // that is exceeding our float equality test epsilon. In this case, we roll |
+ // our own version of float equality test. |
+ static void ExpectContainsFloat(const ScrollAndScaleSet& scroll_info, |
+ int id, |
+ const gfx::Vector2dF& scroll_delta) { |
+ int times_encountered = 0; |
+ |
+ for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { |
+ if (scroll_info.scrolls[i].layer_id != id) |
+ continue; |
+ float diff_x = scroll_delta.x() - scroll_info.scrolls[i].scroll_delta.x(); |
+ float diff_y = scroll_delta.y() - scroll_info.scrolls[i].scroll_delta.y(); |
+ EXPECT_TRUE(std::abs(diff_x) < 0.1e-10); |
danakj
2014/09/18 21:23:49
You can use EXPECT_FLOAT_EQ for this probably. Or
Yufeng Shen (Slow to review)
2014/09/18 22:47:55
Done.
|
+ EXPECT_TRUE(std::abs(diff_y) < 0.1e-10); |
+ times_encountered++; |
+ } |
+ |
+ ASSERT_EQ(1, times_encountered); |
+ } |
+ |
static void ExpectContains(const ScrollAndScaleSet& scroll_info, |
int id, |
- const gfx::Vector2d& scroll_delta) { |
+ const gfx::Vector2dF& scroll_delta) { |
int times_encountered = 0; |
for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { |
if (scroll_info.scrolls[i].layer_id != id) |
continue; |
- EXPECT_VECTOR_EQ(scroll_delta, scroll_info.scrolls[i].scroll_delta); |
+ EXPECT_VECTOR2DF_EQ(scroll_delta, scroll_info.scrolls[i].scroll_delta); |
danakj
2014/09/18 21:23:49
EXPECT_EQ?
Yufeng Shen (Slow to review)
2014/09/18 22:47:55
Done.
|
times_encountered++; |
} |
@@ -2955,7 +2977,7 @@ TEST_F(LayerTreeHostImplTest, ScrollAxisAlignedRotatedLayer) { |
DrawFrame(); |
// Scroll to the right in screen coordinates with a gesture. |
- gfx::Vector2d gesture_scroll_delta(10, 0); |
+ gfx::Vector2dF gesture_scroll_delta(10.0f, 0.0f); |
EXPECT_EQ(InputHandler::ScrollStarted, |
host_impl_->ScrollBegin(gfx::Point(), |
InputHandler::Gesture)); |
@@ -2964,13 +2986,13 @@ TEST_F(LayerTreeHostImplTest, ScrollAxisAlignedRotatedLayer) { |
// The layer should have scrolled down in its local coordinates. |
scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
- ExpectContains(*scroll_info.get(), |
- scroll_layer->id(), |
- gfx::Vector2d(0, gesture_scroll_delta.x())); |
+ ExpectContainsFloat(*scroll_info.get(), |
+ scroll_layer->id(), |
+ gfx::Vector2dF(0.0f, gesture_scroll_delta.x())); |
// Reset and scroll down with the wheel. |
scroll_layer->SetScrollDelta(gfx::Vector2dF()); |
- gfx::Vector2d wheel_scroll_delta(0, 10); |
+ gfx::Vector2dF wheel_scroll_delta(0.0f, 10.0f); |
EXPECT_EQ(InputHandler::ScrollStarted, |
host_impl_->ScrollBegin(gfx::Point(), |
InputHandler::Wheel)); |
@@ -3018,7 +3040,7 @@ TEST_F(LayerTreeHostImplTest, ScrollNonAxisAlignedRotatedLayer) { |
DrawFrame(); |
{ |
// Scroll down in screen coordinates with a gesture. |
- gfx::Vector2d gesture_scroll_delta(0, 10); |
+ gfx::Vector2dF gesture_scroll_delta(0.0f, 10.0f); |
EXPECT_EQ(InputHandler::ScrollStarted, |
host_impl_->ScrollBegin(gfx::Point(1, 1), |
InputHandler::Gesture)); |
@@ -3027,8 +3049,8 @@ TEST_F(LayerTreeHostImplTest, ScrollNonAxisAlignedRotatedLayer) { |
// The child layer should have scrolled down in its local coordinates an |
// amount proportional to the angle between it and the input scroll delta. |
- gfx::Vector2d expected_scroll_delta( |
- 0, |
+ gfx::Vector2dF expected_scroll_delta( |
+ 0.0f, |
gesture_scroll_delta.y() * |
std::cos(MathUtil::Deg2Rad(child_layer_angle))); |
scoped_ptr<ScrollAndScaleSet> scroll_info = |
@@ -3042,7 +3064,7 @@ TEST_F(LayerTreeHostImplTest, ScrollNonAxisAlignedRotatedLayer) { |
{ |
// Now reset and scroll the same amount horizontally. |
child_ptr->SetScrollDelta(gfx::Vector2dF()); |
- gfx::Vector2d gesture_scroll_delta(10, 0); |
+ gfx::Vector2dF gesture_scroll_delta(10.0f, 0.0f); |
EXPECT_EQ(InputHandler::ScrollStarted, |
host_impl_->ScrollBegin(gfx::Point(1, 1), |
InputHandler::Gesture)); |
@@ -3051,8 +3073,8 @@ TEST_F(LayerTreeHostImplTest, ScrollNonAxisAlignedRotatedLayer) { |
// The child layer should have scrolled down in its local coordinates an |
// amount proportional to the angle between it and the input scroll delta. |
- gfx::Vector2d expected_scroll_delta( |
- 0, |
+ gfx::Vector2dF expected_scroll_delta( |
+ 0.0f, |
-gesture_scroll_delta.x() * |
std::sin(MathUtil::Deg2Rad(child_layer_angle))); |
scoped_ptr<ScrollAndScaleSet> scroll_info = |
@@ -3061,10 +3083,10 @@ TEST_F(LayerTreeHostImplTest, ScrollNonAxisAlignedRotatedLayer) { |
// The root scroll layer should have scrolled more, since the input scroll |
// delta was mostly orthogonal to the child layer's vertical scroll axis. |
- gfx::Vector2d expected_root_scroll_delta( |
+ gfx::Vector2dF expected_root_scroll_delta( |
gesture_scroll_delta.x() * |
std::pow(std::cos(MathUtil::Deg2Rad(child_layer_angle)), 2), |
- 0); |
+ 0.0f); |
ExpectContains(*scroll_info.get(), |
scroll_layer->id(), |
expected_root_scroll_delta); |