summaryrefslogtreecommitdiffstats
path: root/cc/nine_patch_layer_impl_unittest.cc
diff options
context:
space:
mode:
authoraelias@chromium.org <aelias@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-06 05:53:00 +0000
committeraelias@chromium.org <aelias@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-06 05:53:00 +0000
commit35680c0ca726980e1a380e668bf7565b39eb7ce9 (patch)
treef6c147c60ca4beae0d663efc9d211f55325a6854 /cc/nine_patch_layer_impl_unittest.cc
parentae8be5cadd06887ae263a9e906afe297e8cffb8b (diff)
downloadchromium_src-35680c0ca726980e1a380e668bf7565b39eb7ce9.zip
chromium_src-35680c0ca726980e1a380e668bf7565b39eb7ce9.tar.gz
chromium_src-35680c0ca726980e1a380e668bf7565b39eb7ce9.tar.bz2
cc: Nine patch layer.
Review URL: https://chromiumcodereview.appspot.com/11304020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166154 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/nine_patch_layer_impl_unittest.cc')
-rw-r--r--cc/nine_patch_layer_impl_unittest.cc94
1 files changed, 94 insertions, 0 deletions
diff --git a/cc/nine_patch_layer_impl_unittest.cc b/cc/nine_patch_layer_impl_unittest.cc
new file mode 100644
index 0000000..55f0c10
--- /dev/null
+++ b/cc/nine_patch_layer_impl_unittest.cc
@@ -0,0 +1,94 @@
+// 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/single_thread_proxy.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 "ui/gfx/safe_integer_conversions.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include <public/WebTransformationMatrix.h>
+
+using namespace cc;
+
+namespace {
+
+gfx::Rect ToRoundedIntRect(gfx::RectF rect_f) {
+ return gfx::Rect(gfx::ToRoundedInt(rect_f.x()), gfx::ToRoundedInt(rect_f.y()), gfx::ToRoundedInt(rect_f.width()), gfx::ToRoundedInt(rect_f.height()));
+}
+
+TEST(NinePatchLayerImplTest, verifyDrawQuads)
+{
+ DebugScopedSetImplThread implThread;
+
+ // Input is a 100x100 bitmap with a 40x50 aperture at x=20, y=30.
+ // The bounds of the layer are set to 400x400, so the draw quads
+ // generated should leave the border width (40) intact.
+ MockQuadCuller quadCuller;
+ gfx::Size bitmapSize(100, 100);
+ gfx::Size layerSize(400, 400);
+ gfx::Rect visibleContentRect(gfx::Point(), layerSize);
+ gfx::Rect apertureRect(20, 30, 40, 50);
+ gfx::Rect scaledApertureNonUniform(20, 30, 340, 350);
+
+ 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_RECT_EQ(remaining.bounds(), scaledApertureNonUniform);
+ Region scaledApertureRegion(scaledApertureNonUniform);
+ EXPECT_EQ(remaining, scaledApertureRegion);
+
+ // 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(ToRoundedIntRect(texRect)));
+ }
+ EXPECT_RECT_EQ(texRemaining.bounds(), apertureRect);
+ Region apertureRegion(apertureRect);
+ EXPECT_EQ(texRemaining, apertureRegion);
+}
+
+}