Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: ui/gfx/icon_util_unittest.cc

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/gfx_paths.cc ('k') | webkit/browser/appcache/appcache_database.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 10 #include "third_party/skia/include/core/SkBitmap.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 protected: 66 protected:
67 // The root directory for test files. This should be treated as read-only. 67 // The root directory for test files. This should be treated as read-only.
68 base::FilePath test_data_directory_; 68 base::FilePath test_data_directory_;
69 69
70 // Directory for creating files by this test. 70 // Directory for creating files by this test.
71 base::ScopedTempDir temp_directory_; 71 base::ScopedTempDir temp_directory_;
72 }; 72 };
73 73
74 void IconUtilTest::CheckAllIconSizes(const base::FilePath& icon_filename, 74 void IconUtilTest::CheckAllIconSizes(const base::FilePath& icon_filename,
75 int max_icon_size) { 75 int max_icon_size) {
76 ASSERT_TRUE(file_util::PathExists(icon_filename)); 76 ASSERT_TRUE(base::PathExists(icon_filename));
77 77
78 // Determine how many icons to expect, based on |max_icon_size|. 78 // Determine how many icons to expect, based on |max_icon_size|.
79 int expected_num_icons = 0; 79 int expected_num_icons = 0;
80 for (size_t i = 0; i < IconUtil::kNumIconDimensions; ++i) { 80 for (size_t i = 0; i < IconUtil::kNumIconDimensions; ++i) {
81 if (IconUtil::kIconDimensions[i] > max_icon_size) 81 if (IconUtil::kIconDimensions[i] > max_icon_size)
82 break; 82 break;
83 ++expected_num_icons; 83 ++expected_num_icons;
84 } 84 }
85 85
86 // First, use the Windows API to load the icon, a basic validity test. 86 // First, use the Windows API to load the icon, a basic validity test.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 bitmap.reset(new SkBitmap); 207 bitmap.reset(new SkBitmap);
208 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL)); 208 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
209 bitmap->setConfig(SkBitmap::kA8_Config, kSmallIconWidth, kSmallIconHeight); 209 bitmap->setConfig(SkBitmap::kA8_Config, kSmallIconWidth, kSmallIconHeight);
210 // Must allocate pixels or else ImageSkia will ignore the bitmap and just 210 // Must allocate pixels or else ImageSkia will ignore the bitmap and just
211 // return an empty image. 211 // return an empty image.
212 bitmap->allocPixels(); 212 bitmap->allocPixels();
213 memset(bitmap->getPixels(), 0, bitmap->width() * bitmap->height()); 213 memset(bitmap->getPixels(), 0, bitmap->width() * bitmap->height());
214 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap)); 214 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap));
215 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family, 215 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family,
216 valid_icon_filename)); 216 valid_icon_filename));
217 EXPECT_FALSE(file_util::PathExists(valid_icon_filename)); 217 EXPECT_FALSE(base::PathExists(valid_icon_filename));
218 218
219 // Invalid bitmap size. 219 // Invalid bitmap size.
220 image_family.clear(); 220 image_family.clear();
221 bitmap.reset(new SkBitmap); 221 bitmap.reset(new SkBitmap);
222 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL)); 222 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
223 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 0, 0); 223 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 0, 0);
224 bitmap->allocPixels(); 224 bitmap->allocPixels();
225 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap)); 225 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap));
226 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family, 226 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family,
227 valid_icon_filename)); 227 valid_icon_filename));
228 EXPECT_FALSE(file_util::PathExists(valid_icon_filename)); 228 EXPECT_FALSE(base::PathExists(valid_icon_filename));
229 229
230 // Bitmap with no allocated pixels. 230 // Bitmap with no allocated pixels.
231 image_family.clear(); 231 image_family.clear();
232 bitmap.reset(new SkBitmap); 232 bitmap.reset(new SkBitmap);
233 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL)); 233 ASSERT_NE(bitmap.get(), static_cast<SkBitmap*>(NULL));
234 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 234 bitmap->setConfig(SkBitmap::kARGB_8888_Config,
235 kSmallIconWidth, 235 kSmallIconWidth,
236 kSmallIconHeight); 236 kSmallIconHeight);
237 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap)); 237 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap));
238 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family, 238 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family,
239 valid_icon_filename)); 239 valid_icon_filename));
240 EXPECT_FALSE(file_util::PathExists(valid_icon_filename)); 240 EXPECT_FALSE(base::PathExists(valid_icon_filename));
241 241
242 // Invalid file name. 242 // Invalid file name.
243 image_family.clear(); 243 image_family.clear();
244 bitmap->allocPixels(); 244 bitmap->allocPixels();
245 // Setting the pixels to black. 245 // Setting the pixels to black.
246 memset(bitmap->getPixels(), 0, bitmap->width() * bitmap->height() * 4); 246 memset(bitmap->getPixels(), 0, bitmap->width() * bitmap->height() * 4);
247 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap)); 247 image_family.Add(gfx::Image::CreateFrom1xBitmap(*bitmap));
248 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family, 248 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family,
249 invalid_icon_filename)); 249 invalid_icon_filename));
250 EXPECT_FALSE(file_util::PathExists(invalid_icon_filename)); 250 EXPECT_FALSE(base::PathExists(invalid_icon_filename));
251 } 251 }
252 252
253 // This test case makes sure IconUtil::CreateIconFileFromImageFamily fails if 253 // This test case makes sure IconUtil::CreateIconFileFromImageFamily fails if
254 // the image family is empty or invalid. 254 // the image family is empty or invalid.
255 TEST_F(IconUtilTest, TestCreateIconFileEmptyImageFamily) { 255 TEST_F(IconUtilTest, TestCreateIconFileEmptyImageFamily) {
256 base::FilePath icon_filename = temp_directory_.path().AppendASCII( 256 base::FilePath icon_filename = temp_directory_.path().AppendASCII(
257 kTempIconFilename); 257 kTempIconFilename);
258 258
259 // Empty image family. 259 // Empty image family.
260 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(gfx::ImageFamily(), 260 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(gfx::ImageFamily(),
261 icon_filename)); 261 icon_filename));
262 EXPECT_FALSE(file_util::PathExists(icon_filename)); 262 EXPECT_FALSE(base::PathExists(icon_filename));
263 263
264 // Image family with only an empty image. 264 // Image family with only an empty image.
265 gfx::ImageFamily image_family; 265 gfx::ImageFamily image_family;
266 image_family.Add(gfx::Image()); 266 image_family.Add(gfx::Image());
267 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family, 267 EXPECT_FALSE(IconUtil::CreateIconFileFromImageFamily(image_family,
268 icon_filename)); 268 icon_filename));
269 EXPECT_FALSE(file_util::PathExists(icon_filename)); 269 EXPECT_FALSE(base::PathExists(icon_filename));
270 } 270 }
271 271
272 // This test case makes sure that when we load an icon from disk and convert 272 // This test case makes sure that when we load an icon from disk and convert
273 // the HICON into a bitmap, the bitmap has the expected format and dimensions. 273 // the HICON into a bitmap, the bitmap has the expected format and dimensions.
274 TEST_F(IconUtilTest, TestCreateSkBitmapFromHICON) { 274 TEST_F(IconUtilTest, TestCreateSkBitmapFromHICON) {
275 scoped_ptr<SkBitmap> bitmap; 275 scoped_ptr<SkBitmap> bitmap;
276 base::FilePath small_icon_filename = test_data_directory_.AppendASCII( 276 base::FilePath small_icon_filename = test_data_directory_.AppendASCII(
277 kSmallIconName); 277 kSmallIconName);
278 gfx::Size small_icon_size(kSmallIconWidth, kSmallIconHeight); 278 gfx::Size small_icon_size(kSmallIconWidth, kSmallIconHeight);
279 HICON small_icon = LoadIconFromFile(small_icon_filename, 279 HICON small_icon = LoadIconFromFile(small_icon_filename,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 } 426 }
427 427
428 // This tests that kNumIconDimensionsUpToMediumSize has the correct value. 428 // This tests that kNumIconDimensionsUpToMediumSize has the correct value.
429 TEST_F(IconUtilTest, TestNumIconDimensionsUpToMediumSize) { 429 TEST_F(IconUtilTest, TestNumIconDimensionsUpToMediumSize) {
430 ASSERT_LE(IconUtil::kNumIconDimensionsUpToMediumSize, 430 ASSERT_LE(IconUtil::kNumIconDimensionsUpToMediumSize,
431 IconUtil::kNumIconDimensions); 431 IconUtil::kNumIconDimensions);
432 EXPECT_EQ(IconUtil::kMediumIconSize, 432 EXPECT_EQ(IconUtil::kMediumIconSize,
433 IconUtil::kIconDimensions[ 433 IconUtil::kIconDimensions[
434 IconUtil::kNumIconDimensionsUpToMediumSize - 1]); 434 IconUtil::kNumIconDimensionsUpToMediumSize - 1]);
435 } 435 }
OLDNEW
« no previous file with comments | « ui/gfx/gfx_paths.cc ('k') | webkit/browser/appcache/appcache_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698