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/big_endian.h" | 8 #include "base/big_endian.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); | 179 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); |
180 | 180 |
181 base::FilePath pack_path(FILE_PATH_LITERAL("/path/to/test_path.pak")); | 181 base::FilePath pack_path(FILE_PATH_LITERAL("/path/to/test_path.pak")); |
182 ui::ScaleFactor pack_scale_factor = ui::SCALE_FACTOR_200P; | 182 ui::ScaleFactor pack_scale_factor = ui::SCALE_FACTOR_200P; |
183 | 183 |
184 EXPECT_CALL(delegate, | 184 EXPECT_CALL(delegate, |
185 GetPathForResourcePack( | 185 GetPathForResourcePack( |
186 Property(&base::FilePath::value, pack_path.value()), | 186 Property(&base::FilePath::value, pack_path.value()), |
187 pack_scale_factor)) | 187 pack_scale_factor)) |
188 .Times(1) | 188 .Times(1) |
189 .WillOnce(Return(pack_path)); | 189 .WillOnce(Return(base::FilePath())); |
190 | 190 |
191 resource_bundle->AddDataPackFromPath(pack_path, pack_scale_factor); | 191 resource_bundle->AddDataPackFromPath(pack_path, pack_scale_factor); |
192 } | 192 } |
193 | 193 |
194 #if defined(OS_LINUX) | 194 #if defined(OS_LINUX) |
195 // Fails consistently on Linux: crbug.com/161902 | 195 // Fails consistently on Linux: crbug.com/161902 |
196 #define MAYBE_DelegateGetPathForLocalePack DISABLED_DelegateGetPathForLocalePack | 196 #define MAYBE_DelegateGetPathForLocalePack DISABLED_DelegateGetPathForLocalePack |
197 #else | 197 #else |
198 #define MAYBE_DelegateGetPathForLocalePack DelegateGetPathForLocalePack | 198 #define MAYBE_DelegateGetPathForLocalePack DelegateGetPathForLocalePack |
199 #endif | 199 #endif |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 const base::FilePath& dir_path() { return dir_.path(); } | 407 const base::FilePath& dir_path() { return dir_.path(); } |
408 | 408 |
409 private: | 409 private: |
410 scoped_ptr<DataPack> locale_pack_; | 410 scoped_ptr<DataPack> locale_pack_; |
411 base::ScopedTempDir dir_; | 411 base::ScopedTempDir dir_; |
412 | 412 |
413 DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageTest); | 413 DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageTest); |
414 }; | 414 }; |
415 | 415 |
416 // Verify that we don't crash when trying to load a resource that is not found. | 416 // Verify that we don't crash when trying to load a resource that is not found. |
417 // In some cases, we fail to mmap resources.pak, but try to keep going anyway. | |
418 TEST_F(ResourceBundleImageTest, LoadDataResourceBytes) { | 417 TEST_F(ResourceBundleImageTest, LoadDataResourceBytes) { |
419 base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); | 418 base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); |
420 | 419 |
421 // Dump contents into the pak files. | 420 // Dump contents into the pak files. |
422 ASSERT_EQ(base::WriteFile(data_path, kEmptyPakContents, | 421 ASSERT_EQ(base::WriteFile(data_path, kEmptyPakContents, |
423 kEmptyPakSize), static_cast<int>(kEmptyPakSize)); | 422 kEmptyPakSize), static_cast<int>(kEmptyPakSize)); |
424 | 423 |
425 // Create a resource bundle from the file. | 424 // Create a resource bundle from the file. |
426 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); | 425 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); |
427 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); | 426 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); |
428 | 427 |
429 const int kUnfoundResourceId = 10000; | 428 const int kUnfoundResourceId = 10000; |
430 EXPECT_EQ(NULL, resource_bundle->LoadDataResourceBytes( | 429 EXPECT_EQ(NULL, resource_bundle->LoadDataResourceBytes( |
431 kUnfoundResourceId)); | 430 kUnfoundResourceId)); |
432 | |
433 // Give a .pak file that doesn't exist so we will fail to load it. | |
434 resource_bundle->AddDataPackFromPath( | |
435 base::FilePath(FILE_PATH_LITERAL("non-existant-file.pak")), | |
436 ui::SCALE_FACTOR_NONE); | |
437 EXPECT_EQ(NULL, resource_bundle->LoadDataResourceBytes( | |
438 kUnfoundResourceId)); | |
439 } | 431 } |
440 | 432 |
441 TEST_F(ResourceBundleImageTest, GetRawDataResource) { | 433 TEST_F(ResourceBundleImageTest, GetRawDataResource) { |
442 base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); | 434 base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); |
443 base::FilePath data_2x_path = | 435 base::FilePath data_2x_path = |
444 dir_path().Append(FILE_PATH_LITERAL("sample_2x.pak")); | 436 dir_path().Append(FILE_PATH_LITERAL("sample_2x.pak")); |
445 | 437 |
446 // Dump contents into the pak files. | 438 // Dump contents into the pak files. |
447 ASSERT_EQ(base::WriteFile(data_path, kSamplePakContents, | 439 ASSERT_EQ(base::WriteFile(data_path, kSamplePakContents, |
448 kSamplePakSize), static_cast<int>(kSamplePakSize)); | 440 kSamplePakSize), static_cast<int>(kSamplePakSize)); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); | 613 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); |
622 | 614 |
623 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); | 615 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); |
624 EXPECT_EQ(1u, image_skia->image_reps().size()); | 616 EXPECT_EQ(1u, image_skia->image_reps().size()); |
625 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); | 617 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); |
626 EXPECT_EQ(ui::SCALE_FACTOR_100P, | 618 EXPECT_EQ(ui::SCALE_FACTOR_100P, |
627 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); | 619 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); |
628 } | 620 } |
629 | 621 |
630 } // namespace ui | 622 } // namespace ui |
OLD | NEW |