summaryrefslogtreecommitdiffstats
path: root/webkit/glue/webkit_glue_unittest.cc
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 21:40:31 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 21:40:31 +0000
commit99432806a06b73301e4723de2d4b6b12aad63a21 (patch)
treee5a3acd4e58c9fae254f7b7ea496e4ce6e8fd0df /webkit/glue/webkit_glue_unittest.cc
parentefbb6048973339847cc5b8dbcd373702995b887a (diff)
downloadchromium_src-99432806a06b73301e4723de2d4b6b12aad63a21.zip
chromium_src-99432806a06b73301e4723de2d4b6b12aad63a21.tar.gz
chromium_src-99432806a06b73301e4723de2d4b6b12aad63a21.tar.bz2
Coverity: Fix leaking NativeImageSkia in webkit_glue::DecodeImage.
CID=5406 BUG=none TEST=tools/valgrind/chrome_tests.sh -t test_shell --gtest_filter=WebkitGlueTest.\* Review URL: http://codereview.chromium.org/391026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31833 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/webkit_glue_unittest.cc')
-rw-r--r--webkit/glue/webkit_glue_unittest.cc37
1 files changed, 37 insertions, 0 deletions
diff --git a/webkit/glue/webkit_glue_unittest.cc b/webkit/glue/webkit_glue_unittest.cc
new file mode 100644
index 0000000..9ba56e3
--- /dev/null
+++ b/webkit/glue/webkit_glue_unittest.cc
@@ -0,0 +1,37 @@
+// Copyright (c) 2009 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 "testing/gtest/include/gtest/gtest.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "webkit/glue/webkit_glue.h"
+
+namespace {
+
+TEST(WebkitGlueTest, DecodeImageFail) {
+ std::string data("not an image");
+ SkBitmap image;
+ EXPECT_FALSE(webkit_glue::DecodeImage(data, &image));
+ EXPECT_TRUE(image.isNull());
+}
+
+TEST(WebkitGlueTest, DecodeImage) {
+ std::string data("GIF87a\x02\x00\x02\x00\xa1\x04\x00\x00\x00\x00\x00\x00\xff"
+ "\xff\x00\x00\x00\xff\x00,\x00\x00\x00\x00\x02\x00\x02\x00"
+ "\x00\x02\x03\x84\x16\x05\x00;", 42);
+ EXPECT_EQ(42u, data.size());
+ SkBitmap image;
+ EXPECT_TRUE(webkit_glue::DecodeImage(data, &image));
+ EXPECT_FALSE(image.isNull());
+ EXPECT_EQ(2, image.width());
+ EXPECT_EQ(2, image.height());
+ EXPECT_EQ(SkBitmap::kARGB_8888_Config, image.config());
+ image.lockPixels();
+ EXPECT_EQ(SK_ColorBLACK, *image.getAddr32(0, 0));
+ EXPECT_EQ(SK_ColorRED, *image.getAddr32(1, 0));
+ EXPECT_EQ(SK_ColorGREEN, *image.getAddr32(0, 1));
+ EXPECT_EQ(SK_ColorBLUE, *image.getAddr32(1, 1));
+ image.unlockPixels();
+}
+
+} // namespace