Chromium Code Reviews| Index: webkit/compositor_bindings/web_layer_impl_fixed_bounds_unittest.cc |
| diff --git a/webkit/compositor_bindings/web_layer_impl_fixed_bounds_unittest.cc b/webkit/compositor_bindings/web_layer_impl_fixed_bounds_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ae23de7ad6ffd3079234d4db07af12e6ebb16a35 |
| --- /dev/null |
| +++ b/webkit/compositor_bindings/web_layer_impl_fixed_bounds_unittest.cc |
| @@ -0,0 +1,127 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/layer.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h" |
| +#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
| +#include "third_party/WebKit/Source/Platform/chromium/public/WebTransformationMatrix.h" |
| +#include "third_party/skia/include/utils/SkMatrix44.h" |
| +#include "ui/gfx/point3_f.h" |
| +#include "webkit/compositor_bindings/web_layer_impl_fixed_bounds.h" |
| + |
| +using namespace WebKit; |
| + |
| +TEST(WebLayerImplFixedBoundsTest, IdentityBounds) |
|
enne (OOO)
2013/02/22 00:10:49
Thanks for these tests. It's hard to tell from lo
Xianzhu
2013/02/22 00:53:30
Agreed. Will change the tests.
|
| +{ |
| + scoped_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds()); |
| + layer->setAnchorPoint(WebFloatPoint(0, 0)); |
| + layer->setFixedBounds(gfx::Size(100, 100)); |
| + layer->setBounds(WebSize(100, 100)); |
| + EXPECT_EQ(WebSize(100, 100), layer->bounds()); |
| + EXPECT_EQ(gfx::Size(100, 100), layer->layer()->bounds()); |
| + EXPECT_EQ(gfx::Transform(), layer->layer()->transform()); |
| +} |
| + |
| +gfx::Point3F transformPoint(const gfx::Transform& transform, const gfx::Point3F& point) |
| +{ |
| + gfx::Point3F result = point; |
| + transform.TransformPoint(result); |
| + return result; |
| +} |
| + |
| +#define EXPECT_POINT3F_EQ(p1, p2) \ |
| + EXPECT_FLOAT_EQ((p1).x(), (p2).x()); \ |
| + EXPECT_FLOAT_EQ((p1).y(), (p2).y()); \ |
| + EXPECT_FLOAT_EQ((p1).z(), (p2).z()); |
| + |
| +TEST(WebLayerImplFixedBoundsTest, NonIdentityBounds) |
| +{ |
| + scoped_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds()); |
| + layer->setAnchorPoint(WebFloatPoint(0, 0)); |
| + layer->setFixedBounds(gfx::Size(100, 50)); |
| + layer->setBounds(WebSize(250, 200)); |
| + EXPECT_EQ(WebSize(250, 200), layer->bounds()); |
| + EXPECT_EQ(gfx::Size(100, 50), layer->layer()->bounds()); |
| + EXPECT_POINT3F_EQ(gfx::Point3F(25, 80, 1), transformPoint(layer->layer()->transform(), gfx::Point3F(10, 20, 1))); |
| + EXPECT_POINT3F_EQ(gfx::Point3F(4, 5, 1), transformPoint(layer->layer()->sublayerTransform(), gfx::Point3F(10, 20, 1))); |
| + EXPECT_TRUE(layer->transform().isIdentity()); |
| + |
| + layer->setBounds(gfx::Size(75, 100)); |
| + EXPECT_EQ(WebSize(75, 100), layer->bounds()); |
| + EXPECT_EQ(gfx::Size(100, 50), layer->layer()->bounds()); |
| + EXPECT_POINT3F_EQ(gfx::Point3F(7.5f, 40, 1), transformPoint(layer->layer()->transform(), gfx::Point3F(10, 20, 1))); |
| + EXPECT_POINT3F_EQ(gfx::Point3F(10, 20, 1), transformPoint(layer->layer()->sublayerTransform(), gfx::Point3F(7.5f, 40, 1))); |
| + EXPECT_TRUE(layer->transform().isIdentity()); |
| + |
| + layer->setFixedBounds(gfx::Size(200, 100)); |
| + EXPECT_EQ(WebSize(75, 100), layer->bounds()); |
| + EXPECT_EQ(gfx::Size(200, 100), layer->layer()->bounds()); |
| + EXPECT_POINT3F_EQ(gfx::Point3F(3.75f, 20, 1), transformPoint(layer->layer()->transform(), gfx::Point3F(10, 20, 1))); |
| + EXPECT_POINT3F_EQ(gfx::Point3F(10, 20, 1), transformPoint(layer->layer()->sublayerTransform(), gfx::Point3F(3.75f, 20, 1))); |
| + EXPECT_TRUE(layer->transform().isIdentity()); |
| +} |
| + |
| +TEST(WebLayerImplFixedBoundsTest, WithOriginalTransform) |
| +{ |
| + gfx::Transform originalTransform; |
| + originalTransform.Translate3d(50, 60, 70); |
| + originalTransform.Scale3d(1.5, 2.5, 3.5); |
| + |
| + scoped_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds()); |
| + layer->setAnchorPoint(WebFloatPoint(0, 0)); |
| + layer->setTransform(originalTransform.matrix()); |
| + layer->setFixedBounds(gfx::Size(100, 200)); |
| + layer->setBounds(gfx::Size(150, 50)); |
| + EXPECT_EQ(WebSize(150, 50), layer->bounds()); |
| + EXPECT_EQ(gfx::Size(100, 200), layer->layer()->bounds()); |
| + EXPECT_POINT3F_EQ(transformPoint(originalTransform, gfx::Point3F(15, 5, 1)), transformPoint(layer->layer()->transform(), gfx::Point3F(10, 20, 1))); |
| + |
| + originalTransform.RotateAbout(gfx::Vector3dF(1.8, 2.8, 3.8), 100); |
| + layer->setTransform(originalTransform.matrix()); |
| + EXPECT_EQ(WebSize(150, 50), layer->bounds()); |
| + EXPECT_EQ(gfx::Size(100, 200), layer->layer()->bounds()); |
| + EXPECT_POINT3F_EQ(transformPoint(originalTransform, gfx::Point3F(15, 5, 1)), transformPoint(layer->layer()->transform(), gfx::Point3F(10, 20, 1))); |
| +} |
| + |
| +TEST(WebLayerImplFixedBoundsTest, WithAnchorPoint) |
| +{ |
| + scoped_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds()); |
| + layer->setAnchorPoint(WebFloatPoint(0.4, 0.6)); |
| + layer->setFixedBounds(gfx::Size(100, 200)); |
| + layer->setBounds(WebSize(150, 250)); |
| + EXPECT_EQ(WebSize(150, 250), layer->bounds()); |
| + EXPECT_EQ(gfx::Size(100, 200), layer->layer()->bounds()); |
| + float left = -40.f; |
| + float top = -120.f; |
| + EXPECT_POINT3F_EQ(gfx::Point3F(left, top, 0), transformPoint(layer->layer()->transform(), gfx::Point3F(left, top, 0))); |
| + EXPECT_POINT3F_EQ(gfx::Point3F(left + 75, top + 125, 0), transformPoint(layer->layer()->transform(), gfx::Point3F(left + 50, top + 100, 0))); |
| +} |
| + |
| +TEST(WebLayerImplFixedBoundsTest, WithOriginalTransformAndSublayerTransformAndAnchorPoint) |
| +{ |
| + gfx::Transform originalTransform; |
| + originalTransform.Translate3d(50, 60, 70); |
| + originalTransform.Scale3d(1.5, 2.5, 3.5); |
| + |
| + gfx::Transform sublayerTransform; |
| + sublayerTransform.Scale3d(1.1, 2.2, 3.3); |
| + sublayerTransform.Translate3d(11, 22, 33); |
| + sublayerTransform.RotateAbout(gfx::Vector3dF(3.3, 2.2, 1.1), 99); |
| + |
| + scoped_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds()); |
| + layer->setAnchorPoint(WebFloatPoint(0.3, 0.7)); |
| + layer->setTransform(originalTransform.matrix()); |
| + layer->setSublayerTransform(sublayerTransform.matrix()); |
| + layer->setFixedBounds(gfx::Size(100, 100)); |
| + layer->setBounds(gfx::Size(150, 150)); |
| + float left = -30.f; |
| + float top = -70.f; |
| + EXPECT_EQ(WebSize(150, 150), layer->bounds()); |
| + EXPECT_EQ(gfx::Size(100, 100), layer->layer()->bounds()); |
| + EXPECT_POINT3F_EQ(transformPoint(originalTransform, gfx::Point3F(left + 15, top + 15, 1)), |
| + transformPoint(layer->layer()->transform(), gfx::Point3F(left + 10, top + 10, 1))); |
| + EXPECT_POINT3F_EQ(transformPoint(sublayerTransform, gfx::Point3F(left + 10, top + 10, 1)), |
| + transformPoint(layer->layer()->sublayerTransform(), gfx::Point3F(left + 15, top + 15, 1))); |
| +} |