Chromium Code Reviews| Index: ui/base/resource/resource_bundle_unittest.cc |
| diff --git a/ui/base/resource/resource_bundle_unittest.cc b/ui/base/resource/resource_bundle_unittest.cc |
| index eadfd9e530032f9ffa506da688e0ef7d6b382948..1dd269e037a930d6f0aad3d94ccdeeec3a825de0 100644 |
| --- a/ui/base/resource/resource_bundle_unittest.cc |
| +++ b/ui/base/resource/resource_bundle_unittest.cc |
| @@ -247,7 +247,7 @@ TEST(ResourceBundle, LoadDataResourceBytes) { |
| // nothing. |
| ScopedTempDir dir; |
| ASSERT_TRUE(dir.CreateUniqueTempDir()); |
| - FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); |
| + FilePath data_path = dir.path().AppendASCII("sample.pak"); |
| // Put the ResourceBundle in a different scope so that it's destroyed before |
| // the ScopedTempDir. |
| @@ -284,9 +284,9 @@ TEST(ResourceBundle, GetRawDataResource) { |
| // nothing. |
| ScopedTempDir dir; |
| ASSERT_TRUE(dir.CreateUniqueTempDir()); |
| - FilePath locale_path = dir.path().Append(FILE_PATH_LITERAL("empty.pak")); |
| - FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); |
| - FilePath data_2x_path = dir.path().Append(FILE_PATH_LITERAL("sample_2x.pak")); |
| + FilePath locale_path = dir.path().AppendASCII("empty.pak"); |
| + FilePath data_path = dir.path().AppendASCII("sample.pak"); |
| + FilePath data_2x_path = dir.path().AppendASCII("sample_2x.pak"); |
| { |
| ResourceBundle resource_bundle(NULL); |
| @@ -334,38 +334,66 @@ TEST(ResourceBundle, GetImageNamed) { |
| ScopedTempDir dir; |
| ASSERT_TRUE(dir.CreateUniqueTempDir()); |
| - FilePath locale_path = dir.path().Append(FILE_PATH_LITERAL("empty.pak")); |
| - FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); |
| - FilePath data_2x_path = dir.path().Append(FILE_PATH_LITERAL("sample_2x.pak")); |
| + FilePath locale_path = dir.path().AppendASCII("empty.pak"); |
| + FilePath data_default_path = dir.path().AppendASCII("sample.pak"); |
| + FilePath data_1x_path = dir.path().AppendASCII("sample_1x.pak"); |
| + FilePath data_2x_path = dir.path().AppendASCII("sample_2x.pak"); |
| - { |
| - // Create the pak files. |
| - ASSERT_EQ(file_util::WriteFile(locale_path, kEmptyPakContents, |
| - kEmptyPakSize), static_cast<int>(kEmptyPakSize)); |
| - CreateDataPackWithSingleBitmap(data_path, 10); |
| - CreateDataPackWithSingleBitmap(data_2x_path, 20); |
| + // Create the pak files. |
| + ASSERT_EQ(file_util::WriteFile(locale_path, kEmptyPakContents, |
| + kEmptyPakSize), static_cast<int>(kEmptyPakSize)); |
| + CreateDataPackWithSingleBitmap(data_default_path, 10); |
| + CreateDataPackWithSingleBitmap(data_1x_path, 10); |
| + CreateDataPackWithSingleBitmap(data_2x_path, 20); |
| - // Load the regular and 2x pak files. |
| - ResourceBundle resource_bundle(NULL); |
| - resource_bundle.LoadTestResources(data_path, locale_path); |
| - resource_bundle.AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); |
| + // Load the regular and 2x pak files. |
| + ResourceBundle resource_bundle(NULL); |
| + resource_bundle.LoadTestResources(data_default_path, locale_path); |
| + resource_bundle.AddDataPackFromPath(data_1x_path, SCALE_FACTOR_100P); |
| + resource_bundle.AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); |
| + |
| + gfx::ImageSkia* image_skia = resource_bundle.GetImageSkiaNamed(3); |
| + |
| + EXPECT_EQ(ui::GetMaxScaleFactor(), |
| + image_skia->image_reps()[0].scale_factor()); |
|
pkotwicz
2012/11/07 06:40:44
Shouldn't you call ui::test::SetSupportedScaleFact
oshima
2012/11/07 22:35:30
Current code is a bit broken as we included 200P e
|
| + |
| + // Resource ID 3 exists in both 1x and 2x paks. Image reps should be |
| + // available for both scale factors in |image_skia|. |
| + gfx::ImageSkiaRep image_rep = |
| + image_skia->GetRepresentation(ui::SCALE_FACTOR_100P); |
| + EXPECT_EQ(ui::SCALE_FACTOR_100P, image_rep.scale_factor()); |
| + image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_200P); |
| + EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor()); |
| + |
| + // The 1.4x pack was not loaded. Requesting the 1.4x resource should return |
| + // either the 1x or the 2x resource. |
| + image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_140P); |
| + EXPECT_TRUE(image_rep.scale_factor() == ui::SCALE_FACTOR_100P || |
| + image_rep.scale_factor() == ui::SCALE_FACTOR_200P); |
| +} |
| - gfx::ImageSkia* image_skia = resource_bundle.GetImageSkiaNamed(3); |
| - |
| - // Resource ID 3 exists in both 1x and 2x paks. Image reps should be |
| - // available for both scale factors in |image_skia|. |
| - gfx::ImageSkiaRep image_rep = |
| - image_skia->GetRepresentation(ui::SCALE_FACTOR_100P); |
| - EXPECT_EQ(ui::SCALE_FACTOR_100P, image_rep.scale_factor()); |
| - image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_200P); |
| - EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor()); |
| - |
| - // The 1.4x pack was not loaded. Requesting the 1.4x resource should return |
| - // either the 1x or the 2x resource. |
| - image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_140P); |
| - EXPECT_TRUE(image_rep.scale_factor() == ui::SCALE_FACTOR_100P || |
| - image_rep.scale_factor() == ui::SCALE_FACTOR_200P); |
| - } |
| +TEST(ResourceBundle, FallbackToNone) { |
| + // On Windows, the default data is compiled into the binary so this does |
| + // nothing. |
| + ScopedTempDir dir; |
| + ASSERT_TRUE(dir.CreateUniqueTempDir()); |
| + |
| + FilePath locale_path = dir.path().AppendASCII("empty.pak"); |
| + FilePath data_default_path = dir.path().AppendASCII("sample.pak"); |
| + |
| + // Create the pak files. |
| + ASSERT_EQ(file_util::WriteFile(locale_path, kEmptyPakContents, |
| + kEmptyPakSize), static_cast<int>(kEmptyPakSize)); |
| + CreateDataPackWithSingleBitmap(data_default_path, 10); |
| + |
| + // Load the regular pak files only. |
| + ResourceBundle resource_bundle(NULL); |
| + resource_bundle.LoadTestResources(data_default_path, locale_path); |
| + |
| + gfx::ImageSkia* image_skia = resource_bundle.GetImageSkiaNamed(3); |
| + EXPECT_EQ(1u, image_skia->image_reps().size()); |
| + EXPECT_EQ(ui::SCALE_FACTOR_100P, |
| + image_skia->image_reps()[0].scale_factor()); |
| } |
| } // namespace ui |