| Index: trunk/src/ui/gfx/image/image_mac_unittest.mm
|
| ===================================================================
|
| --- trunk/src/ui/gfx/image/image_mac_unittest.mm (revision 224498)
|
| +++ trunk/src/ui/gfx/image/image_mac_unittest.mm (working copy)
|
| @@ -16,26 +16,26 @@
|
| namespace {
|
|
|
| // Returns true if the structure of |ns_image| matches the structure
|
| -// described by |width|, |height|, and |scales|.
|
| +// described by |width|, |height|, and |scale_factors|.
|
| // The structure matches if:
|
| // - |ns_image| is not nil.
|
| -// - |ns_image| has NSImageReps of |scales|.
|
| +// - |ns_image| has NSImageReps of |scale_factors|.
|
| // - Each of the NSImageReps has a pixel size of [|ns_image| size] *
|
| -// scale.
|
| +// scale_factor.
|
| bool NSImageStructureMatches(
|
| NSImage* ns_image,
|
| int width,
|
| int height,
|
| - const std::vector<float>& scales) {
|
| + const std::vector<ui::ScaleFactor>& scale_factors) {
|
| if (!ns_image ||
|
| [ns_image size].width != width ||
|
| [ns_image size].height != height ||
|
| - [ns_image representations].count != scales.size()) {
|
| + [ns_image representations].count != scale_factors.size()) {
|
| return false;
|
| }
|
|
|
| - for (size_t i = 0; i < scales.size(); ++i) {
|
| - float scale = scales[i];
|
| + for (size_t i = 0; i < scale_factors.size(); ++i) {
|
| + float scale = ui::GetScaleFactorScale(scale_factors[i]);
|
| bool found_match = false;
|
| for (size_t j = 0; j < [ns_image representations].count; ++j) {
|
| NSImageRep* ns_image_rep = [[ns_image representations] objectAtIndex:j];
|
| @@ -74,14 +74,16 @@
|
|
|
| class ImageMacTest : public testing::Test {
|
| public:
|
| - ImageMacTest() {
|
| - gfx::ImageSkia::SetSupportedScales(gfx::test::Get1xAnd2xScales());
|
| + ImageMacTest()
|
| + : supported_scale_factors_(gfx::test::Get1xAnd2xScaleFactors()) {
|
| }
|
|
|
| virtual ~ImageMacTest() {
|
| }
|
|
|
| private:
|
| + ui::test::ScopedSetSupportedScaleFactors supported_scale_factors_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(ImageMacTest);
|
| };
|
|
|
| @@ -108,11 +110,11 @@
|
|
|
| const gfx::ImageSkia* image_skia = image.ToImageSkia();
|
|
|
| - std::vector<float> scales;
|
| - scales.push_back(1.0f);
|
| - scales.push_back(2.0f);
|
| + std::vector<ui::ScaleFactor> scale_factors;
|
| + scale_factors.push_back(ui::SCALE_FACTOR_100P);
|
| + scale_factors.push_back(ui::SCALE_FACTOR_200P);
|
| EXPECT_TRUE(gt::ImageSkiaStructureMatches(*image_skia, kWidth1x, kHeight1x,
|
| - scales));
|
| + scale_factors));
|
|
|
| // ToImageSkia should create a second representation.
|
| EXPECT_EQ(2u, image.RepresentationCount());
|
| @@ -139,11 +141,11 @@
|
|
|
| const gfx::ImageSkia* image_skia = image.ToImageSkia();
|
|
|
| - std::vector<float> scales;
|
| - scales.push_back(1.0f);
|
| - scales.push_back(2.0f);
|
| + std::vector<ui::ScaleFactor> scale_factors;
|
| + scale_factors.push_back(ui::SCALE_FACTOR_100P);
|
| + scale_factors.push_back(ui::SCALE_FACTOR_200P);
|
| EXPECT_TRUE(gt::ImageSkiaStructureMatches(*image_skia, kWidth1x, kHeight1x,
|
| - scales));
|
| + scale_factors));
|
|
|
| // ToImageSkia should create a second representation.
|
| EXPECT_EQ(2u, image.RepresentationCount());
|
| @@ -157,9 +159,9 @@
|
|
|
| gfx::ImageSkia image_skia;
|
| image_skia.AddRepresentation(gfx::ImageSkiaRep(
|
| - gt::CreateBitmap(kWidth1x, kHeight1x), 1.0f));
|
| + gt::CreateBitmap(kWidth1x, kHeight1x), ui::SCALE_FACTOR_100P));
|
| image_skia.AddRepresentation(gfx::ImageSkiaRep(
|
| - gt::CreateBitmap(kWidth2x, kHeight2x), 2.0f));
|
| + gt::CreateBitmap(kWidth2x, kHeight2x), ui::SCALE_FACTOR_200P));
|
|
|
| gfx::Image image(image_skia);
|
|
|
| @@ -168,10 +170,11 @@
|
|
|
| NSImage* ns_image = image.ToNSImage();
|
|
|
| - std::vector<float> scales;
|
| - scales.push_back(1.0f);
|
| - scales.push_back(2.0f);
|
| - EXPECT_TRUE(NSImageStructureMatches(ns_image, kWidth1x, kHeight1x, scales));
|
| + std::vector<ui::ScaleFactor> scale_factors;
|
| + scale_factors.push_back(ui::SCALE_FACTOR_100P);
|
| + scale_factors.push_back(ui::SCALE_FACTOR_200P);
|
| + EXPECT_TRUE(NSImageStructureMatches(ns_image, kWidth1x, kHeight1x,
|
| + scale_factors));
|
|
|
| // Request for NSImage* should create a second representation.
|
| EXPECT_EQ(2u, image.RepresentationCount());
|
| @@ -184,16 +187,17 @@
|
| scoped_refptr<base::RefCountedMemory> bytes1x = gt::CreatePNGBytes(kSize1x);
|
| scoped_refptr<base::RefCountedMemory> bytes2x = gt::CreatePNGBytes(kSize2x);
|
| std::vector<gfx::ImagePNGRep> image_png_reps;
|
| - image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f));
|
| - image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, 2.0f));
|
| + image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, ui::SCALE_FACTOR_100P));
|
| + image_png_reps.push_back(gfx::ImagePNGRep(bytes2x, ui::SCALE_FACTOR_200P));
|
|
|
| gfx::Image image(image_png_reps);
|
|
|
| NSImage* ns_image = image.ToNSImage();
|
| - std::vector<float> scales;
|
| - scales.push_back(1.0f);
|
| - scales.push_back(2.0f);
|
| - EXPECT_TRUE(NSImageStructureMatches(ns_image, kSize1x, kSize1x, scales));
|
| + std::vector<ui::ScaleFactor> scale_factors;
|
| + scale_factors.push_back(ui::SCALE_FACTOR_100P);
|
| + scale_factors.push_back(ui::SCALE_FACTOR_200P);
|
| + EXPECT_TRUE(NSImageStructureMatches(ns_image, kSize1x, kSize1x,
|
| + scale_factors));
|
|
|
| // Converting from PNG to NSImage should not go through ImageSkia.
|
| EXPECT_FALSE(image.HasRepresentation(gfx::Image::kImageRepSkia));
|
| @@ -201,9 +205,9 @@
|
| // Convert to ImageSkia to check pixel contents of NSImageReps.
|
| gfx::ImageSkia image_skia = gfx::ImageSkiaFromNSImage(ns_image);
|
| EXPECT_TRUE(gt::IsEqual(bytes1x,
|
| - image_skia.GetRepresentation(1.0f).sk_bitmap()));
|
| + image_skia.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap()));
|
| EXPECT_TRUE(gt::IsEqual(bytes2x,
|
| - image_skia.GetRepresentation(2.0f).sk_bitmap()));
|
| + image_skia.GetRepresentation(ui::SCALE_FACTOR_200P).sk_bitmap()));
|
| }
|
|
|
| } // namespace
|
|
|