• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "third_party/skia/include/core/SkBitmap.h"
7 #include "webkit/glue/webkit_glue.h"
8 
9 namespace {
10 
TEST(WebkitGlueTest,DecodeImageFail)11 TEST(WebkitGlueTest, DecodeImageFail) {
12   std::string data("not an image");
13   SkBitmap image;
14   EXPECT_FALSE(webkit_glue::DecodeImage(data, &image));
15   EXPECT_TRUE(image.isNull());
16 }
17 
TEST(WebkitGlueTest,DecodeImage)18 TEST(WebkitGlueTest, DecodeImage) {
19   std::string data("GIF87a\x02\x00\x02\x00\xa1\x04\x00\x00\x00\x00\x00\x00\xff"
20                    "\xff\x00\x00\x00\xff\x00,\x00\x00\x00\x00\x02\x00\x02\x00"
21                    "\x00\x02\x03\x84\x16\x05\x00;", 42);
22   EXPECT_EQ(42u, data.size());
23   SkBitmap image;
24   EXPECT_TRUE(webkit_glue::DecodeImage(data, &image));
25   EXPECT_FALSE(image.isNull());
26   EXPECT_EQ(2, image.width());
27   EXPECT_EQ(2, image.height());
28   EXPECT_EQ(SkBitmap::kARGB_8888_Config, image.config());
29   image.lockPixels();
30   EXPECT_EQ(SK_ColorBLACK, *image.getAddr32(0, 0));
31   EXPECT_EQ(SK_ColorRED, *image.getAddr32(1, 0));
32   EXPECT_EQ(SK_ColorGREEN, *image.getAddr32(0, 1));
33   EXPECT_EQ(SK_ColorBLUE, *image.getAddr32(1, 1));
34   image.unlockPixels();
35 }
36 
37 }  // namespace
38