OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/base/resource/resource_bundle.h" | 5 #include "ui/base/resource/resource_bundle.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 0xc1, 0x30, 0x60, 0x4d }; | 51 0xc1, 0x30, 0x60, 0x4d }; |
52 | 52 |
53 // Mock for the ResourceBundle::Delegate class. | 53 // Mock for the ResourceBundle::Delegate class. |
54 class MockResourceBundleDelegate : public ui::ResourceBundle::Delegate { | 54 class MockResourceBundleDelegate : public ui::ResourceBundle::Delegate { |
55 public: | 55 public: |
56 MockResourceBundleDelegate() { | 56 MockResourceBundleDelegate() { |
57 } | 57 } |
58 virtual ~MockResourceBundleDelegate() { | 58 virtual ~MockResourceBundleDelegate() { |
59 } | 59 } |
60 | 60 |
61 MOCK_METHOD2(GetPathForResourcePack, FilePath(const FilePath& pack_path, | 61 MOCK_METHOD2(GetPathForResourcePack, base::FilePath( |
62 ui::ScaleFactor scale_factor)); | 62 const base::FilePath& pack_path, ui::ScaleFactor scale_factor)); |
63 MOCK_METHOD2(GetPathForLocalePack, FilePath(const FilePath& pack_path, | 63 MOCK_METHOD2(GetPathForLocalePack, base::FilePath( |
64 const std::string& locale)); | 64 const base::FilePath& pack_path, const std::string& locale)); |
65 MOCK_METHOD1(GetImageNamed, gfx::Image(int resource_id)); | 65 MOCK_METHOD1(GetImageNamed, gfx::Image(int resource_id)); |
66 MOCK_METHOD2(GetNativeImageNamed, | 66 MOCK_METHOD2(GetNativeImageNamed, |
67 gfx::Image(int resource_id, | 67 gfx::Image(int resource_id, |
68 ui::ResourceBundle::ImageRTL rtl)); | 68 ui::ResourceBundle::ImageRTL rtl)); |
69 MOCK_METHOD2(LoadDataResourceBytes, | 69 MOCK_METHOD2(LoadDataResourceBytes, |
70 base::RefCountedStaticMemory*(int resource_id, | 70 base::RefCountedStaticMemory*(int resource_id, |
71 ui::ScaleFactor scale_factor)); | 71 ui::ScaleFactor scale_factor)); |
72 MOCK_METHOD2(GetRawDataResourceMock, base::StringPiece( | 72 MOCK_METHOD2(GetRawDataResourceMock, base::StringPiece( |
73 int resource_id, | 73 int resource_id, |
74 ui::ScaleFactor scale_factor)); | 74 ui::ScaleFactor scale_factor)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 kPngIHDRChunkType)); | 112 kPngIHDRChunkType)); |
113 | 113 |
114 bitmap_data->insert(ihdr_start + kPngChunkMetadataSize + ihdr_chunk_length, | 114 bitmap_data->insert(ihdr_start + kPngChunkMetadataSize + ihdr_chunk_length, |
115 custom_chunk.begin(), custom_chunk.end()); | 115 custom_chunk.begin(), custom_chunk.end()); |
116 } | 116 } |
117 | 117 |
118 // Creates datapack at |path| with a single bitmap at resource ID 3 | 118 // Creates datapack at |path| with a single bitmap at resource ID 3 |
119 // which is |edge_size|x|edge_size| pixels. | 119 // which is |edge_size|x|edge_size| pixels. |
120 // If |custom_chunk| is non empty, adds it after the IHDR chunk | 120 // If |custom_chunk| is non empty, adds it after the IHDR chunk |
121 // in the encoded bitmap data. | 121 // in the encoded bitmap data. |
122 void CreateDataPackWithSingleBitmap(const FilePath& path, | 122 void CreateDataPackWithSingleBitmap(const base::FilePath& path, |
123 int edge_size, | 123 int edge_size, |
124 const base::StringPiece& custom_chunk) { | 124 const base::StringPiece& custom_chunk) { |
125 SkBitmap bitmap; | 125 SkBitmap bitmap; |
126 bitmap.setConfig(SkBitmap::kARGB_8888_Config, edge_size, edge_size); | 126 bitmap.setConfig(SkBitmap::kARGB_8888_Config, edge_size, edge_size); |
127 bitmap.allocPixels(); | 127 bitmap.allocPixels(); |
128 bitmap.eraseColor(SK_ColorWHITE); | 128 bitmap.eraseColor(SK_ColorWHITE); |
129 std::vector<unsigned char> bitmap_data; | 129 std::vector<unsigned char> bitmap_data; |
130 EXPECT_TRUE(gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &bitmap_data)); | 130 EXPECT_TRUE(gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &bitmap_data)); |
131 | 131 |
132 if (custom_chunk.size() > 0) | 132 if (custom_chunk.size() > 0) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 ResourceBundle* resource_bundle_; | 167 ResourceBundle* resource_bundle_; |
168 | 168 |
169 private: | 169 private: |
170 DISALLOW_COPY_AND_ASSIGN(ResourceBundleTest); | 170 DISALLOW_COPY_AND_ASSIGN(ResourceBundleTest); |
171 }; | 171 }; |
172 | 172 |
173 TEST_F(ResourceBundleTest, DelegateGetPathForResourcePack) { | 173 TEST_F(ResourceBundleTest, DelegateGetPathForResourcePack) { |
174 MockResourceBundleDelegate delegate; | 174 MockResourceBundleDelegate delegate; |
175 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); | 175 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); |
176 | 176 |
177 FilePath pack_path(FILE_PATH_LITERAL("/path/to/test_path.pak")); | 177 base::FilePath pack_path(FILE_PATH_LITERAL("/path/to/test_path.pak")); |
178 ui::ScaleFactor pack_scale_factor = ui::SCALE_FACTOR_200P; | 178 ui::ScaleFactor pack_scale_factor = ui::SCALE_FACTOR_200P; |
179 | 179 |
180 EXPECT_CALL(delegate, | 180 EXPECT_CALL(delegate, |
181 GetPathForResourcePack( | 181 GetPathForResourcePack( |
182 Property(&FilePath::value, pack_path.value()), | 182 Property(&base::FilePath::value, pack_path.value()), |
183 pack_scale_factor)) | 183 pack_scale_factor)) |
184 .Times(1) | 184 .Times(1) |
185 .WillOnce(Return(pack_path)); | 185 .WillOnce(Return(pack_path)); |
186 | 186 |
187 resource_bundle->AddDataPackFromPath(pack_path, pack_scale_factor); | 187 resource_bundle->AddDataPackFromPath(pack_path, pack_scale_factor); |
188 } | 188 } |
189 | 189 |
190 #if defined(OS_LINUX) | 190 #if defined(OS_LINUX) |
191 // Fails consistently on Linux: crbug.com/161902 | 191 // Fails consistently on Linux: crbug.com/161902 |
192 #define MAYBE_DelegateGetPathForLocalePack DISABLED_DelegateGetPathForLocalePack | 192 #define MAYBE_DelegateGetPathForLocalePack DISABLED_DelegateGetPathForLocalePack |
193 #else | 193 #else |
194 #define MAYBE_DelegateGetPathForLocalePack DelegateGetPathForLocalePack | 194 #define MAYBE_DelegateGetPathForLocalePack DelegateGetPathForLocalePack |
195 #endif | 195 #endif |
196 TEST_F(ResourceBundleTest, MAYBE_DelegateGetPathForLocalePack) { | 196 TEST_F(ResourceBundleTest, MAYBE_DelegateGetPathForLocalePack) { |
197 MockResourceBundleDelegate delegate; | 197 MockResourceBundleDelegate delegate; |
198 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); | 198 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); |
199 | 199 |
200 std::string locale = "en-US"; | 200 std::string locale = "en-US"; |
201 | 201 |
202 // Cancel the load. | 202 // Cancel the load. |
203 EXPECT_CALL(delegate, GetPathForLocalePack(_, locale)) | 203 EXPECT_CALL(delegate, GetPathForLocalePack(_, locale)) |
204 .Times(2) | 204 .Times(2) |
205 .WillRepeatedly(Return(FilePath())) | 205 .WillRepeatedly(Return(base::FilePath())) |
206 .RetiresOnSaturation(); | 206 .RetiresOnSaturation(); |
207 | 207 |
208 EXPECT_FALSE(resource_bundle->LocaleDataPakExists(locale)); | 208 EXPECT_FALSE(resource_bundle->LocaleDataPakExists(locale)); |
209 EXPECT_EQ("", resource_bundle->LoadLocaleResources(locale)); | 209 EXPECT_EQ("", resource_bundle->LoadLocaleResources(locale)); |
210 | 210 |
211 // Allow the load to proceed. | 211 // Allow the load to proceed. |
212 EXPECT_CALL(delegate, GetPathForLocalePack(_, locale)) | 212 EXPECT_CALL(delegate, GetPathForLocalePack(_, locale)) |
213 .Times(2) | 213 .Times(2) |
214 .WillRepeatedly(ReturnArg<0>()); | 214 .WillRepeatedly(ReturnArg<0>()); |
215 | 215 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 341 } |
342 | 342 |
343 virtual void SetUp() OVERRIDE { | 343 virtual void SetUp() OVERRIDE { |
344 // Create a temporary directory to write test resource bundles to. | 344 // Create a temporary directory to write test resource bundles to. |
345 ASSERT_TRUE(dir_.CreateUniqueTempDir()); | 345 ASSERT_TRUE(dir_.CreateUniqueTempDir()); |
346 } | 346 } |
347 | 347 |
348 // Returns resource bundle which uses an empty data pak for locale data. | 348 // Returns resource bundle which uses an empty data pak for locale data. |
349 ui::ResourceBundle* CreateResourceBundleWithEmptyLocalePak() { | 349 ui::ResourceBundle* CreateResourceBundleWithEmptyLocalePak() { |
350 // Write an empty data pak for locale data. | 350 // Write an empty data pak for locale data. |
351 const FilePath& locale_path = dir_path().Append( | 351 const base::FilePath& locale_path = dir_path().Append( |
352 FILE_PATH_LITERAL("locale.pak")); | 352 FILE_PATH_LITERAL("locale.pak")); |
353 EXPECT_EQ(file_util::WriteFile(locale_path, kEmptyPakContents, | 353 EXPECT_EQ(file_util::WriteFile(locale_path, kEmptyPakContents, |
354 kEmptyPakSize), | 354 kEmptyPakSize), |
355 static_cast<int>(kEmptyPakSize)); | 355 static_cast<int>(kEmptyPakSize)); |
356 | 356 |
357 ui::ResourceBundle* resource_bundle = CreateResourceBundle(NULL); | 357 ui::ResourceBundle* resource_bundle = CreateResourceBundle(NULL); |
358 | 358 |
359 // Load the empty locale data pak. | 359 // Load the empty locale data pak. |
360 resource_bundle->LoadTestResources(FilePath(), locale_path); | 360 resource_bundle->LoadTestResources(base::FilePath(), locale_path); |
361 return resource_bundle; | 361 return resource_bundle; |
362 } | 362 } |
363 | 363 |
364 // Returns the path of temporary directory to write test data packs into. | 364 // Returns the path of temporary directory to write test data packs into. |
365 const FilePath& dir_path() { return dir_.path(); } | 365 const base::FilePath& dir_path() { return dir_.path(); } |
366 | 366 |
367 private: | 367 private: |
368 scoped_ptr<DataPack> locale_pack_; | 368 scoped_ptr<DataPack> locale_pack_; |
369 base::ScopedTempDir dir_; | 369 base::ScopedTempDir dir_; |
370 | 370 |
371 DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageTest); | 371 DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageTest); |
372 }; | 372 }; |
373 | 373 |
374 // Verify that we don't crash when trying to load a resource that is not found. | 374 // Verify that we don't crash when trying to load a resource that is not found. |
375 // In some cases, we fail to mmap resources.pak, but try to keep going anyway. | 375 // In some cases, we fail to mmap resources.pak, but try to keep going anyway. |
376 TEST_F(ResourceBundleImageTest, LoadDataResourceBytes) { | 376 TEST_F(ResourceBundleImageTest, LoadDataResourceBytes) { |
377 FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); | 377 base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); |
378 | 378 |
379 // Dump contents into the pak files. | 379 // Dump contents into the pak files. |
380 ASSERT_EQ(file_util::WriteFile(data_path, kEmptyPakContents, | 380 ASSERT_EQ(file_util::WriteFile(data_path, kEmptyPakContents, |
381 kEmptyPakSize), static_cast<int>(kEmptyPakSize)); | 381 kEmptyPakSize), static_cast<int>(kEmptyPakSize)); |
382 | 382 |
383 // Create a resource bundle from the file. | 383 // Create a resource bundle from the file. |
384 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); | 384 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); |
385 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); | 385 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); |
386 | 386 |
387 const int kUnfoundResourceId = 10000; | 387 const int kUnfoundResourceId = 10000; |
388 EXPECT_EQ(NULL, resource_bundle->LoadDataResourceBytes( | 388 EXPECT_EQ(NULL, resource_bundle->LoadDataResourceBytes( |
389 kUnfoundResourceId)); | 389 kUnfoundResourceId)); |
390 | 390 |
391 // Give a .pak file that doesn't exist so we will fail to load it. | 391 // Give a .pak file that doesn't exist so we will fail to load it. |
392 resource_bundle->AddDataPackFromPath( | 392 resource_bundle->AddDataPackFromPath( |
393 FilePath(FILE_PATH_LITERAL("non-existant-file.pak")), | 393 base::FilePath(FILE_PATH_LITERAL("non-existant-file.pak")), |
394 ui::SCALE_FACTOR_NONE); | 394 ui::SCALE_FACTOR_NONE); |
395 EXPECT_EQ(NULL, resource_bundle->LoadDataResourceBytes( | 395 EXPECT_EQ(NULL, resource_bundle->LoadDataResourceBytes( |
396 kUnfoundResourceId)); | 396 kUnfoundResourceId)); |
397 } | 397 } |
398 | 398 |
399 TEST_F(ResourceBundleImageTest, GetRawDataResource) { | 399 TEST_F(ResourceBundleImageTest, GetRawDataResource) { |
400 FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); | 400 base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); |
401 FilePath data_2x_path = dir_path().Append(FILE_PATH_LITERAL("sample_2x.pak")); | 401 base::FilePath data_2x_path = |
| 402 dir_path().Append(FILE_PATH_LITERAL("sample_2x.pak")); |
402 | 403 |
403 // Dump contents into the pak files. | 404 // Dump contents into the pak files. |
404 ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, | 405 ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, |
405 kSamplePakSize), static_cast<int>(kSamplePakSize)); | 406 kSamplePakSize), static_cast<int>(kSamplePakSize)); |
406 ASSERT_EQ(file_util::WriteFile(data_2x_path, kSamplePakContents2x, | 407 ASSERT_EQ(file_util::WriteFile(data_2x_path, kSamplePakContents2x, |
407 kSamplePakSize2x), static_cast<int>(kSamplePakSize2x)); | 408 kSamplePakSize2x), static_cast<int>(kSamplePakSize2x)); |
408 | 409 |
409 // Load the regular and 2x pak files. | 410 // Load the regular and 2x pak files. |
410 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); | 411 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); |
411 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); | 412 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); |
(...skipping 10 matching lines...) Expand all Loading... |
422 // for both scale factor requests. | 423 // for both scale factor requests. |
423 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6, | 424 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6, |
424 SCALE_FACTOR_100P)); | 425 SCALE_FACTOR_100P)); |
425 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6, | 426 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6, |
426 SCALE_FACTOR_200P)); | 427 SCALE_FACTOR_200P)); |
427 } | 428 } |
428 | 429 |
429 // Test requesting image reps at various scale factors from the image returned | 430 // Test requesting image reps at various scale factors from the image returned |
430 // via ResourceBundle::GetImageNamed(). | 431 // via ResourceBundle::GetImageNamed(). |
431 TEST_F(ResourceBundleImageTest, GetImageNamed) { | 432 TEST_F(ResourceBundleImageTest, GetImageNamed) { |
432 FilePath data_1x_path = dir_path().AppendASCII("sample_1x.pak"); | 433 base::FilePath data_1x_path = dir_path().AppendASCII("sample_1x.pak"); |
433 FilePath data_2x_path = dir_path().AppendASCII("sample_2x.pak"); | 434 base::FilePath data_2x_path = dir_path().AppendASCII("sample_2x.pak"); |
434 | 435 |
435 // Create the pak files. | 436 // Create the pak files. |
436 CreateDataPackWithSingleBitmap(data_1x_path, 10, base::StringPiece()); | 437 CreateDataPackWithSingleBitmap(data_1x_path, 10, base::StringPiece()); |
437 CreateDataPackWithSingleBitmap(data_2x_path, 20, base::StringPiece()); | 438 CreateDataPackWithSingleBitmap(data_2x_path, 20, base::StringPiece()); |
438 | 439 |
439 // Load the regular and 2x pak files. | 440 // Load the regular and 2x pak files. |
440 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); | 441 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); |
441 resource_bundle->AddDataPackFromPath(data_1x_path, SCALE_FACTOR_100P); | 442 resource_bundle->AddDataPackFromPath(data_1x_path, SCALE_FACTOR_100P); |
442 resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); | 443 resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); |
443 | 444 |
(...skipping 19 matching lines...) Expand all Loading... |
463 // The 1.4x pack was not loaded. Requesting the 1.4x resource should return | 464 // The 1.4x pack was not loaded. Requesting the 1.4x resource should return |
464 // either the 1x or the 2x resource. | 465 // either the 1x or the 2x resource. |
465 image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_140P); | 466 image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_140P); |
466 EXPECT_TRUE(image_rep.scale_factor() == ui::SCALE_FACTOR_100P || | 467 EXPECT_TRUE(image_rep.scale_factor() == ui::SCALE_FACTOR_100P || |
467 image_rep.scale_factor() == ui::SCALE_FACTOR_200P); | 468 image_rep.scale_factor() == ui::SCALE_FACTOR_200P); |
468 } | 469 } |
469 | 470 |
470 // Test that GetImageNamed() behaves properly for images which GRIT has | 471 // Test that GetImageNamed() behaves properly for images which GRIT has |
471 // annotated as having fallen back to 1x. | 472 // annotated as having fallen back to 1x. |
472 TEST_F(ResourceBundleImageTest, GetImageNamedFallback1x) { | 473 TEST_F(ResourceBundleImageTest, GetImageNamedFallback1x) { |
473 FilePath data_path = dir_path().AppendASCII("sample.pak"); | 474 base::FilePath data_path = dir_path().AppendASCII("sample.pak"); |
474 FilePath data_2x_path = dir_path().AppendASCII("sample_2x.pak"); | 475 base::FilePath data_2x_path = dir_path().AppendASCII("sample_2x.pak"); |
475 | 476 |
476 // Create the pak files. | 477 // Create the pak files. |
477 CreateDataPackWithSingleBitmap(data_path, 10, base::StringPiece()); | 478 CreateDataPackWithSingleBitmap(data_path, 10, base::StringPiece()); |
478 // 2x data pack bitmap has custom chunk to indicate that the 2x bitmap is not | 479 // 2x data pack bitmap has custom chunk to indicate that the 2x bitmap is not |
479 // available and that GRIT fell back to 1x. | 480 // available and that GRIT fell back to 1x. |
480 CreateDataPackWithSingleBitmap(data_2x_path, 10, base::StringPiece( | 481 CreateDataPackWithSingleBitmap(data_2x_path, 10, base::StringPiece( |
481 reinterpret_cast<const char*>(kPngScaleChunk), | 482 reinterpret_cast<const char*>(kPngScaleChunk), |
482 arraysize(kPngScaleChunk))); | 483 arraysize(kPngScaleChunk))); |
483 | 484 |
484 // Load the regular and 2x pak files. | 485 // Load the regular and 2x pak files. |
485 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); | 486 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); |
486 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); | 487 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); |
487 resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); | 488 resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); |
488 | 489 |
489 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); | 490 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); |
490 | 491 |
491 // The image rep for 2x should be available. It should be resized to the | 492 // The image rep for 2x should be available. It should be resized to the |
492 // proper 2x size. | 493 // proper 2x size. |
493 gfx::ImageSkiaRep image_rep = | 494 gfx::ImageSkiaRep image_rep = |
494 image_skia->GetRepresentation(ui::SCALE_FACTOR_200P); | 495 image_skia->GetRepresentation(ui::SCALE_FACTOR_200P); |
495 EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor()); | 496 EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor()); |
496 EXPECT_EQ(20, image_rep.pixel_width()); | 497 EXPECT_EQ(20, image_rep.pixel_width()); |
497 EXPECT_EQ(20, image_rep.pixel_height()); | 498 EXPECT_EQ(20, image_rep.pixel_height()); |
498 } | 499 } |
499 | 500 |
500 TEST_F(ResourceBundleImageTest, FallbackToNone) { | 501 TEST_F(ResourceBundleImageTest, FallbackToNone) { |
501 FilePath data_default_path = dir_path().AppendASCII("sample.pak"); | 502 base::FilePath data_default_path = dir_path().AppendASCII("sample.pak"); |
502 | 503 |
503 // Create the pak files. | 504 // Create the pak files. |
504 CreateDataPackWithSingleBitmap(data_default_path, 10, base::StringPiece()); | 505 CreateDataPackWithSingleBitmap(data_default_path, 10, base::StringPiece()); |
505 | 506 |
506 // Load the regular pak files only. | 507 // Load the regular pak files only. |
507 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); | 508 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); |
508 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); | 509 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); |
509 | 510 |
510 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); | 511 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); |
511 EXPECT_EQ(1u, image_skia->image_reps().size()); | 512 EXPECT_EQ(1u, image_skia->image_reps().size()); |
512 EXPECT_EQ(ui::SCALE_FACTOR_100P, | 513 EXPECT_EQ(ui::SCALE_FACTOR_100P, |
513 image_skia->image_reps()[0].scale_factor()); | 514 image_skia->image_reps()[0].scale_factor()); |
514 } | 515 } |
515 | 516 |
516 } // namespace ui | 517 } // namespace ui |
OLD | NEW |