diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-19 15:22:05 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-19 15:22:05 +0000 |
commit | 5a585d4a59610e380b481f5f7fac850919c49816 (patch) | |
tree | c8e34141fc1dbba935d28b12d3d1614555a379c0 | |
parent | 38889cb24f897bf651601ab28810bb1c283253a5 (diff) | |
download | chromium_src-5a585d4a59610e380b481f5f7fac850919c49816.zip chromium_src-5a585d4a59610e380b481f5f7fac850919c49816.tar.gz chromium_src-5a585d4a59610e380b481f5f7fac850919c49816.tar.bz2 |
Mac: unit test for setting a clip rect with a scale transform
BUG=none
TEST=self
Review URL: http://codereview.chromium.org/3030003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52906 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | skia/ext/bitmap_platform_device_mac_unittest.cc | 66 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.gypi | 1 |
2 files changed, 67 insertions, 0 deletions
diff --git a/skia/ext/bitmap_platform_device_mac_unittest.cc b/skia/ext/bitmap_platform_device_mac_unittest.cc new file mode 100644 index 0000000..3330440 --- /dev/null +++ b/skia/ext/bitmap_platform_device_mac_unittest.cc @@ -0,0 +1,66 @@ +// Copyright (c) 2010 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 "skia/ext/bitmap_platform_device_mac.h" + +#include "base/scoped_ptr.h" +#include "skia/ext/skia_utils_mac.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/skia/include/core/SkMatrix.h" +#include "third_party/skia/include/core/SkRegion.h" + +namespace skia { + +const int kWidth = 400; +const int kHeight = 300; + +class BitmapPlatformDeviceMacTest : public testing::Test { + public: + BitmapPlatformDeviceMacTest() { + bitmap_.reset(BitmapPlatformDevice::Create( + NULL, kWidth, kHeight, /*is_opaque=*/true)); + } + + scoped_ptr<BitmapPlatformDevice> bitmap_; +}; + +TEST_F(BitmapPlatformDeviceMacTest, ClipRectTransformWithTranslate) { + SkMatrix transform; + transform.setTranslate(50, 140); + + SkRegion clip_region; + SkIRect rect; + rect.set(0, 0, kWidth, kHeight); + clip_region.setRect(rect); + bitmap_->setMatrixClip(transform, clip_region); + + CGContextRef context = bitmap_->GetBitmapContext(); + SkRect clip_rect = gfx::CGRectToSkRect(CGContextGetClipBoundingBox(context)); + transform.mapRect(&clip_rect); + EXPECT_EQ(0, clip_rect.fLeft); + EXPECT_EQ(0, clip_rect.fTop); + EXPECT_EQ(kWidth, clip_rect.width()); + EXPECT_EQ(kHeight, clip_rect.height()); +} + +TEST_F(BitmapPlatformDeviceMacTest, ClipRectTransformWithScale) { + SkMatrix transform; + transform.setScale(0.5, 0.5); + + SkRegion clip_region; + SkIRect rect; + rect.set(0, 0, kWidth, kHeight); + clip_region.setRect(rect); + bitmap_->setMatrixClip(transform, clip_region); + + CGContextRef context = bitmap_->GetBitmapContext(); + SkRect clip_rect = gfx::CGRectToSkRect(CGContextGetClipBoundingBox(context)); + transform.mapRect(&clip_rect); + EXPECT_EQ(0, clip_rect.fLeft); + EXPECT_EQ(0, clip_rect.fTop); + EXPECT_EQ(kWidth, clip_rect.width()); + EXPECT_EQ(kHeight, clip_rect.height()); +} + +} // namespace skia diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi index 2617692..f3e25ee 100644 --- a/webkit/tools/test_shell/test_shell.gypi +++ b/webkit/tools/test_shell/test_shell.gypi @@ -438,6 +438,7 @@ ], 'sources': [ '../../../skia/ext/skia_utils_mac_unittest.mm', + '../../../skia/ext/bitmap_platform_device_mac_unittest.cc', ], }], ['OS=="win"', { |