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

Unified Diff: ui/base/resource/resource_bundle_unittest.cc

Issue 24175004: Remove dependency on ui::ScaleFactor from ui/gfx (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix new usage of scale in FastShowPickler Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/resource/resource_bundle_ios.mm ('k') | ui/base/resource/resource_bundle_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6a7b2b7db9c15e0b2a5f40ee8b864b9ed822b2b1..e50d6b457023574f2a7355200728f6028c18c528 100644
--- a/ui/base/resource/resource_bundle_unittest.cc
+++ b/ui/base/resource/resource_bundle_unittest.cc
@@ -433,6 +433,10 @@ TEST_F(ResourceBundleImageTest, GetRawDataResource) {
// Test requesting image reps at various scale factors from the image returned
// via ResourceBundle::GetImageNamed().
TEST_F(ResourceBundleImageTest, GetImageNamed) {
+ std::vector<ScaleFactor> supported_factors;
+ supported_factors.push_back(SCALE_FACTOR_100P);
+ supported_factors.push_back(SCALE_FACTOR_200P);
+ test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
base::FilePath data_1x_path = dir_path().AppendASCII("sample_1x.pak");
base::FilePath data_2x_path = dir_path().AppendASCII("sample_2x.pak");
@@ -445,35 +449,44 @@ TEST_F(ResourceBundleImageTest, GetImageNamed) {
resource_bundle->AddDataPackFromPath(data_1x_path, SCALE_FACTOR_100P);
resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P);
- EXPECT_EQ(SCALE_FACTOR_200P, resource_bundle->max_scale_factor());
+ EXPECT_EQ(SCALE_FACTOR_200P, resource_bundle->GetMaxScaleFactor());
gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
#if defined(OS_CHROMEOS)
// ChromeOS loads highest scale factor first.
- EXPECT_EQ(ui::SCALE_FACTOR_200P, image_skia->image_reps()[0].scale_factor());
+ EXPECT_EQ(ui::SCALE_FACTOR_200P,
+ GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
#else
- EXPECT_EQ(ui::SCALE_FACTOR_100P, image_skia->image_reps()[0].scale_factor());
+ EXPECT_EQ(ui::SCALE_FACTOR_100P,
+ GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
#endif
// 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());
+ image_skia->GetRepresentation(GetImageScale(ui::SCALE_FACTOR_100P));
+ EXPECT_EQ(ui::SCALE_FACTOR_100P, GetSupportedScaleFactor(image_rep.scale()));
+ image_rep =
+ image_skia->GetRepresentation(GetImageScale(ui::SCALE_FACTOR_200P));
+ EXPECT_EQ(ui::SCALE_FACTOR_200P, GetSupportedScaleFactor(image_rep.scale()));
// 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);
+ image_rep = image_skia->GetRepresentation(
+ ui::GetImageScale(ui::SCALE_FACTOR_140P));
+ ui::ScaleFactor scale_factor = GetSupportedScaleFactor(image_rep.scale());
+ EXPECT_TRUE(scale_factor == ui::SCALE_FACTOR_100P ||
+ scale_factor == ui::SCALE_FACTOR_200P);
}
// Test that GetImageNamed() behaves properly for images which GRIT has
// annotated as having fallen back to 1x.
TEST_F(ResourceBundleImageTest, GetImageNamedFallback1x) {
+ std::vector<ScaleFactor> supported_factors;
+ supported_factors.push_back(SCALE_FACTOR_100P);
+ supported_factors.push_back(SCALE_FACTOR_200P);
+ test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
base::FilePath data_path = dir_path().AppendASCII("sample.pak");
base::FilePath data_2x_path = dir_path().AppendASCII("sample_2x.pak");
@@ -495,8 +508,8 @@ TEST_F(ResourceBundleImageTest, GetImageNamedFallback1x) {
// The image rep for 2x should be available. It should be resized to the
// proper 2x size.
gfx::ImageSkiaRep image_rep =
- image_skia->GetRepresentation(ui::SCALE_FACTOR_200P);
- EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor());
+ image_skia->GetRepresentation(GetImageScale(ui::SCALE_FACTOR_200P));
+ EXPECT_EQ(ui::SCALE_FACTOR_200P, GetSupportedScaleFactor(image_rep.scale()));
EXPECT_EQ(20, image_rep.pixel_width());
EXPECT_EQ(20, image_rep.pixel_height());
}
@@ -506,6 +519,12 @@ TEST_F(ResourceBundleImageTest, GetImageNamedFallback1x) {
// requires rounding as a result of using a non-integer scale factor.
// Scale factors of 140 and 1805 are Windows specific.
TEST_F(ResourceBundleImageTest, GetImageNamedFallback1xRounding) {
+ std::vector<ScaleFactor> supported_factors;
+ supported_factors.push_back(SCALE_FACTOR_100P);
+ supported_factors.push_back(SCALE_FACTOR_140P);
+ supported_factors.push_back(SCALE_FACTOR_180P);
+ test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
+
base::FilePath data_path = dir_path().AppendASCII("sample.pak");
base::FilePath data_140P_path = dir_path().AppendASCII("sample_140P.pak");
base::FilePath data_180P_path = dir_path().AppendASCII("sample_180P.pak");
@@ -527,9 +546,11 @@ TEST_F(ResourceBundleImageTest, GetImageNamedFallback1xRounding) {
// Non-integer dimensions should be rounded up.
gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
gfx::ImageSkiaRep image_rep =
- image_skia->GetRepresentation(ui::SCALE_FACTOR_140P);
+ image_skia->GetRepresentation(
+ GetImageScale(ui::SCALE_FACTOR_140P));
EXPECT_EQ(12, image_rep.pixel_width());
- image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_180P);
+ image_rep = image_skia->GetRepresentation(
+ GetImageScale(ui::SCALE_FACTOR_180P));
EXPECT_EQ(15, image_rep.pixel_width());
}
#endif
@@ -547,7 +568,7 @@ TEST_F(ResourceBundleImageTest, FallbackToNone) {
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());
+ GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
}
} // namespace ui
« no previous file with comments | « ui/base/resource/resource_bundle_ios.mm ('k') | ui/base/resource/resource_bundle_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698