summaryrefslogtreecommitdiffstats
path: root/ui/gfx/scoped_image_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ui/gfx/scoped_image_unittest.cc')
-rw-r--r--ui/gfx/scoped_image_unittest.cc98
1 files changed, 98 insertions, 0 deletions
diff --git a/ui/gfx/scoped_image_unittest.cc b/ui/gfx/scoped_image_unittest.cc
new file mode 100644
index 0000000..8e8b312
--- /dev/null
+++ b/ui/gfx/scoped_image_unittest.cc
@@ -0,0 +1,98 @@
+// 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 "base/scoped_ptr.h"
+#include "gfx/scoped_image.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+#if defined(OS_LINUX)
+#include "gfx/gtk_util.h"
+#elif defined(OS_MACOSX)
+#include "base/mac/mac_util.h"
+#include "skia/ext/skia_utils_mac.h"
+#endif
+
+namespace {
+
+class ScopedImageTest : public testing::Test {
+ public:
+ SkBitmap* CreateBitmap() {
+ SkBitmap* bitmap = new SkBitmap();
+ bitmap->setConfig(SkBitmap::kARGB_8888_Config, 25, 25);
+ bitmap->allocPixels();
+ bitmap->eraseRGB(255, 0, 0);
+ return bitmap;
+ }
+
+ gfx::NativeImage CreateNativeImage() {
+ scoped_ptr<SkBitmap> bitmap(CreateBitmap());
+#if defined(OS_MACOSX)
+ NSImage* image = gfx::SkBitmapToNSImage(*(bitmap.get()));
+ base::mac::NSObjectRetain(image);
+ return image;
+#elif defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
+ return gfx::GdkPixbufFromSkBitmap(bitmap.get());
+#else
+ return bitmap.release();
+#endif
+ }
+};
+
+TEST_F(ScopedImageTest, Initialize) {
+ gfx::ScopedImage<SkBitmap> image(CreateBitmap());
+ EXPECT_TRUE(image.Get());
+}
+
+TEST_F(ScopedImageTest, Free) {
+ gfx::ScopedImage<SkBitmap> image(CreateBitmap());
+ EXPECT_TRUE(image.Get());
+ image.Free();
+ EXPECT_FALSE(image.Get());
+}
+
+TEST_F(ScopedImageTest, Release) {
+ gfx::ScopedImage<SkBitmap> image(CreateBitmap());
+ EXPECT_TRUE(image.Get());
+ scoped_ptr<SkBitmap> bitmap(image.Release());
+ EXPECT_FALSE(image.Get());
+}
+
+TEST_F(ScopedImageTest, Set) {
+ gfx::ScopedImage<SkBitmap> image(CreateBitmap());
+ EXPECT_TRUE(image.Get());
+ SkBitmap* image2 = CreateBitmap();
+ image.Set(image2);
+ EXPECT_EQ(image2, image.Get());
+}
+
+TEST_F(ScopedImageTest, NativeInitialize) {
+ gfx::ScopedNativeImage image(CreateNativeImage());
+ EXPECT_TRUE(image.Get());
+}
+
+TEST_F(ScopedImageTest, NativeFree) {
+ gfx::ScopedNativeImage image(CreateNativeImage());
+ EXPECT_TRUE(image.Get());
+ image.Free();
+ EXPECT_FALSE(image.Get());
+}
+
+TEST_F(ScopedImageTest, NativeRelease) {
+ gfx::ScopedNativeImage image(CreateNativeImage());
+ EXPECT_TRUE(image.Get());
+ gfx::ScopedNativeImage image2(image.Release());
+ EXPECT_FALSE(image.Get());
+ EXPECT_TRUE(image2.Get());
+}
+
+TEST_F(ScopedImageTest, NativeSet) {
+ gfx::ScopedNativeImage image(CreateNativeImage());
+ EXPECT_TRUE(image.Get());
+ gfx::NativeImage image2 = CreateNativeImage();
+ image.Set(image2);
+ EXPECT_EQ(image2, image.Get());
+}
+
+} // namespace