Index: cc/nine_patch_layer_impl_unittest.cc |
diff --git a/cc/nine_patch_layer_impl_unittest.cc b/cc/nine_patch_layer_impl_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..90210562de42dc269713c4f3d7f079bdf9288cc2 |
--- /dev/null |
+++ b/cc/nine_patch_layer_impl_unittest.cc |
@@ -0,0 +1,84 @@ |
+// Copyright 2012 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 "config.h" |
+ |
+#include "cc/nine_patch_layer_impl.h" |
+ |
+#include "cc/append_quads_data.h" |
+#include "cc/test/geometry_test_utils.h" |
+#include "cc/test/layer_test_common.h" |
+#include "cc/test/mock_quad_culler.h" |
+#include "cc/texture_draw_quad.h" |
+#include "ui/gfx/rect_conversions.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include <public/WebTransformationMatrix.h> |
+ |
+using namespace cc; |
+ |
+namespace { |
+ |
+TEST(NinePatchLayerImplTest, verifyDrawQuads) |
+{ |
+ // Input is a 100x100 bitmap with a 20x20 aperture at x=20, y=20. |
+ // The bounds of the layer are set to 400x400, so the draw quads |
+ // generated should leave the border width (20) intact. |
+ MockQuadCuller quadCuller; |
+ gfx::Size bitmapSize(100, 100); |
+ gfx::Size layerSize(400, 400); |
+ gfx::Rect visibleContentRect(gfx::Point(), layerSize); |
+ gfx::Rect apertureRect(20, 20, 20, 20); |
jamesr
2012/11/05 23:10:53
would you mind making these values not equal to ea
aelias_OOO_until_Jul13
2012/11/06 01:15:00
Done.
|
+ gfx::Rect scaledApertureNonUniform(20, 20, 320, 320); |
+ |
+ scoped_ptr<NinePatchLayerImpl> layer = NinePatchLayerImpl::create(1); |
+ layer->setVisibleContentRect(visibleContentRect); |
+ layer->setBounds(layerSize); |
+ layer->setContentBounds(layerSize); |
+ layer->createRenderSurface(); |
+ layer->setRenderTarget(layer.get()); |
+ layer->setLayout(bitmapSize, apertureRect); |
+ layer->setResourceId(1); |
+ |
+ // This scale should not affect the generated quad geometry, but only |
+ // the shared draw transform. |
+ WebKit::WebTransformationMatrix transform; |
+ transform.scale(10); |
+ layer->setDrawTransform(transform); |
+ |
+ AppendQuadsData data; |
+ layer->appendQuads(quadCuller, data); |
+ |
+ // Verify quad rects |
+ const QuadList& quads = quadCuller.quadList(); |
+ EXPECT_EQ(quads.size(), 8); |
+ Region remaining(visibleContentRect); |
+ for (size_t i = 0; i < quads.size(); ++i) { |
+ DrawQuad* quad = quads[i]; |
+ gfx::Rect quadRect = quad->quadRect(); |
+ |
+ EXPECT_TRUE(visibleContentRect.Contains(quadRect)) << i; |
+ EXPECT_TRUE(remaining.Contains(quadRect)) << i; |
+ EXPECT_EQ(quad->sharedQuadState()->quadTransform, transform) << i; |
+ remaining.Subtract(Region(quadRect)); |
+ } |
+ EXPECT_EQ(remaining.rects().size(), 1); |
+ EXPECT_RECT_EQ(remaining.bounds(), scaledApertureNonUniform); |
+ |
+ // Verify UV rects |
+ gfx::Rect bitmapRect(gfx::Point(), bitmapSize); |
+ Region texRemaining(bitmapRect); |
+ for (size_t i = 0; i < quads.size(); ++i) { |
+ DrawQuad* quad = quads[i]; |
+ ASSERT_EQ(quad->material(), DrawQuad::TextureContent); |
+ TextureDrawQuad* texQuad = static_cast<TextureDrawQuad*>(quad); |
+ gfx::RectF texRect = texQuad->uvRect(); |
+ texRect.Scale(bitmapSize.width(), bitmapSize.height()); |
+ texRemaining.Subtract(Region(gfx::ToEnclosingRect(texRect))); |
+ } |
+ EXPECT_EQ(texRemaining.rects().size(), 1); |
+ EXPECT_RECT_EQ(texRemaining.bounds(), apertureRect); |
+} |
+ |
+} |