Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / ui / gfx / icon_util_unittest.cc
index 641422a..f0f2cde 100644 (file)
@@ -2,18 +2,19 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/file_util.h"
+#include "ui/gfx/icon_util.h"
+
+#include "base/files/file_util.h"
 #include "base/files/scoped_temp_dir.h"
 #include "base/memory/scoped_ptr.h"
 #include "base/path_service.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "third_party/skia/include/core/SkBitmap.h"
 #include "ui/gfx/gfx_paths.h"
-#include "ui/gfx/icon_util.h"
+#include "ui/gfx/icon_util_unittests_resource.h"
 #include "ui/gfx/image/image.h"
 #include "ui/gfx/image/image_family.h"
 #include "ui/gfx/size.h"
-#include "ui/test/ui_unittests_resource.h"
 
 namespace {
 
@@ -26,7 +27,8 @@ static const char kTempIconFilename[] = "temp_test_icon.ico";
 class IconUtilTest : public testing::Test {
  public:
   virtual void SetUp() OVERRIDE {
-    PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_);
+    gfx::RegisterPathProvider();
+    ASSERT_TRUE(PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_));
     temp_directory_.CreateUniqueTempDir();
   }
 
@@ -50,9 +52,8 @@ class IconUtilTest : public testing::Test {
 
   SkBitmap CreateBlackSkBitmap(int width, int height) {
     SkBitmap bitmap;
-    bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
-    bitmap.allocPixels();
-    // Setting the pixels to black.
+    bitmap.allocN32Pixels(width, height);
+    // Setting the pixels to transparent-black.
     memset(bitmap.getPixels(), 0, width * height * 4);
     return bitmap;
   }
@@ -172,23 +173,22 @@ TEST_F(IconUtilTest, TestBitmapToIconInvalidParameters) {
   // Wrong bitmap format.
   bitmap.reset(new SkBitmap);
   ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
-  bitmap->setConfig(SkBitmap::kA8_Config, kSmallIconWidth, kSmallIconHeight);
+  bitmap->setInfo(SkImageInfo::MakeA8(kSmallIconWidth, kSmallIconHeight));
   icon = IconUtil::CreateHICONFromSkBitmap(*bitmap);
   EXPECT_EQ(icon, static_cast<HICON>(NULL));
 
   // Invalid bitmap size.
   bitmap.reset(new SkBitmap);
   ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
-  bitmap->setConfig(SkBitmap::kARGB_8888_Config, 0, 0);
+  bitmap->setInfo(SkImageInfo::MakeN32Premul(0, 0));
   icon = IconUtil::CreateHICONFromSkBitmap(*bitmap);
   EXPECT_EQ(icon, static_cast<HICON>(NULL));
 
   // Valid bitmap configuration but no pixels allocated.
   bitmap.reset(new SkBitmap);
   ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
-  bitmap->setConfig(SkBitmap::kARGB_8888_Config,
-                    kSmallIconWidth,
-                    kSmallIconHeight);
+  bitmap->setInfo(SkImageInfo::MakeN32Premul(kSmallIconWidth,
+                                             kSmallIconHeight));
   icon = IconUtil::CreateHICONFromSkBitmap(*bitmap);
   EXPECT_TRUE(icon == NULL);
 }
@@ -206,10 +206,9 @@ TEST_F(IconUtilTest, TestCreateIconFileInvalidParameters) {
   // Wrong bitmap format.
   bitmap.reset(new SkBitmap);
   ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
-  bitmap->setConfig(SkBitmap::kA8_Config, kSmallIconWidth, kSmallIconHeight);
   // Must allocate pixels or else ImageSkia will ignore the bitmap and just
   // return an empty image.
-  bitmap->allocPixels();
+  bitmap->allocPixels(SkImageInfo::MakeA8(kSmallIconWidth, kSmallIconHeight));
   memset(bitmap->getPixels(), 0, bitmap->width() * bitmap->height());
   image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap));
   EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family,
@@ -220,8 +219,7 @@ TEST_F(IconUtilTest, TestCreateIconFileInvalidParameters) {
   image_family.clear();
   bitmap.reset(new SkBitmap);
   ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
-  bitmap->setConfig(SkBitmap::kARGB_8888_Config, 0, 0);
-  bitmap->allocPixels();
+  bitmap->allocPixels(SkImageInfo::MakeN32Premul(0, 0));
   image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap));
   EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family,
                                                        valid_icon_filename));
@@ -231,9 +229,8 @@ TEST_F(IconUtilTest, TestCreateIconFileInvalidParameters) {
   image_family.clear();
   bitmap.reset(new SkBitmap);
   ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
-  bitmap->setConfig(SkBitmap::kARGB_8888_Config,
-                    kSmallIconWidth,
-                    kSmallIconHeight);
+  bitmap->setInfo(SkImageInfo::MakeN32Premul(kSmallIconWidth,
+                                             kSmallIconHeight));
   image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap));
   EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family,
                                                        valid_icon_filename));
@@ -284,7 +281,7 @@ TEST_F(IconUtilTest, TestCreateSkBitmapFromHICON) {
   ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
   EXPECT_EQ(bitmap->width(), small_icon_size.width());
   EXPECT_EQ(bitmap->height(), small_icon_size.height());
-  EXPECT_EQ(bitmap->config(), SkBitmap::kARGB_8888_Config);
+  EXPECT_EQ(bitmap->colorType(), kN32_SkColorType);
   ::DestroyIcon(small_icon);
 
   base::FilePath large_icon_filename = test_data_directory_.AppendASCII(
@@ -298,7 +295,7 @@ TEST_F(IconUtilTest, TestCreateSkBitmapFromHICON) {
   ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
   EXPECT_EQ(bitmap->width(), large_icon_size.width());
   EXPECT_EQ(bitmap->height(), large_icon_size.height());
-  EXPECT_EQ(bitmap->config(), SkBitmap::kARGB_8888_Config);
+  EXPECT_EQ(bitmap->colorType(), kN32_SkColorType);
   ::DestroyIcon(large_icon);
 }