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

Unified Diff: trunk/src/ui/gfx/image/image_unittest.cc

Issue 24262008: Revert 224473 "Remove dependency on ui::ScaleFactor from ui/gfx" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 | « trunk/src/ui/gfx/image/image_skia_util_mac.mm ('k') | trunk/src/ui/gfx/image/image_unittest_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trunk/src/ui/gfx/image/image_unittest.cc
===================================================================
--- trunk/src/ui/gfx/image/image_unittest.cc (revision 224498)
+++ trunk/src/ui/gfx/image/image_unittest.cc (working copy)
@@ -5,6 +5,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPaint.h"
+#include "ui/base/layout.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_png_rep.h"
#include "ui/gfx/image/image_skia.h"
@@ -30,15 +31,6 @@
#endif
class ImageTest : public testing::Test {
- public:
- ImageTest() {
- std::vector<float> scales;
- scales.push_back(1.0f);
-#if !defined(OS_IOS)
- scales.push_back(2.0f);
-#endif
- gfx::ImageSkia::SetSupportedScales(scales);
- }
};
namespace gt = gfx::test;
@@ -103,14 +95,14 @@
// invalid data.
TEST_F(ImageTest, EmptyImageFromObviouslyInvalidPNGImage) {
std::vector<gfx::ImagePNGRep> image_png_reps1;
- image_png_reps1.push_back(gfx::ImagePNGRep(NULL, 1.0f));
+ image_png_reps1.push_back(gfx::ImagePNGRep(NULL, ui::SCALE_FACTOR_100P));
gfx::Image image1(image_png_reps1);
EXPECT_TRUE(image1.IsEmpty());
EXPECT_EQ(0U, image1.RepresentationCount());
std::vector<gfx::ImagePNGRep> image_png_reps2;
image_png_reps2.push_back(gfx::ImagePNGRep(
- new base::RefCountedBytes(), 1.0f));
+ new base::RefCountedBytes(), ui::SCALE_FACTOR_100P));
gfx::Image image2(image_png_reps2);
EXPECT_TRUE(image2.IsEmpty());
EXPECT_EQ(0U, image2.RepresentationCount());
@@ -174,7 +166,7 @@
const int kSize2x = 50;
gfx::ImageSkia image_skia;
image_skia.AddRepresentation(gfx::ImageSkiaRep(gt::CreateBitmap(
- kSize2x, kSize2x), 2.0f));
+ kSize2x, kSize2x), ui::SCALE_FACTOR_200P));
gfx::Image image1(image_skia);
scoped_refptr<base::RefCountedMemory> png_bytes1 = image1.As1xPNGBytes();
EXPECT_TRUE(png_bytes1.get());
@@ -182,7 +174,7 @@
std::vector<gfx::ImagePNGRep> image_png_reps;
image_png_reps.push_back(gfx::ImagePNGRep(
- gt::CreatePNGBytes(kSize2x), 2.0f));
+ gt::CreatePNGBytes(kSize2x), ui::SCALE_FACTOR_200P));
gfx::Image image2(image_png_reps);
EXPECT_FALSE(image2.IsEmpty());
EXPECT_EQ(0, image2.Width());
@@ -200,9 +192,9 @@
scoped_refptr<base::RefCountedMemory> bytes1x = gt::CreatePNGBytes(kSize1x);
std::vector<gfx::ImagePNGRep> image_png_reps;
- image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, 1.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(bytes1x, ui::SCALE_FACTOR_100P));
image_png_reps.push_back(gfx::ImagePNGRep(
- gt::CreatePNGBytes(kSize2x), 2.0f));
+ gt::CreatePNGBytes(kSize2x), ui::SCALE_FACTOR_200P));
gfx::Image image(image_png_reps);
EXPECT_FALSE(image.IsEmpty());
@@ -220,9 +212,9 @@
SkBitmap bitmap_1x = gt::CreateBitmap(kSize1x, kSize1x);
gfx::ImageSkia image_skia;
image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap_1x,
- 1.0f));
+ ui::SCALE_FACTOR_100P));
image_skia.AddRepresentation(gfx::ImageSkiaRep(gt::CreateBitmap(
- kSize2x, kSize2x), 2.0f));
+ kSize2x, kSize2x), ui::SCALE_FACTOR_200P));
gfx::Image image(image_skia);
EXPECT_TRUE(gt::IsEqual(image.As1xPNGBytes(), bitmap_1x));
@@ -237,20 +229,20 @@
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);
- 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);
gfx::ImageSkia image_skia = image.AsImageSkia();
EXPECT_TRUE(gt::ImageSkiaStructureMatches(image_skia, kSize1x, kSize1x,
- scales));
+ scale_factors));
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()));
}
TEST_F(ImageTest, MultiResolutionPNGToPlatform) {
@@ -260,18 +252,18 @@
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 from_png(image_png_reps);
gfx::Image from_platform(gt::CopyPlatformType(from_png));
#if defined(OS_IOS)
// On iOS the platform type (UIImage) only supports one resolution.
- std::vector<float> scales = gfx::ImageSkia::GetSupportedScales();
- EXPECT_EQ(scales.size(), 1U);
- if (scales[0] == 1.0f)
+ std::vector<ui::ScaleFactor> scale_factors = ui::GetSupportedScaleFactors();
+ EXPECT_EQ(scale_factors.size(), 1U);
+ if (scale_factors[0] == ui::SCALE_FACTOR_100P)
EXPECT_TRUE(gt::IsEqual(bytes1x, from_platform.AsBitmap()));
- else if (scales[0] == 2.0f)
+ else if (scale_factors[0] == ui::SCALE_FACTOR_200P)
EXPECT_TRUE(gt::IsEqual(bytes2x, from_platform.AsBitmap()));
else
ADD_FAILURE() << "Unexpected platform scale factor.";
@@ -289,7 +281,7 @@
EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG));
std::vector<gfx::ImagePNGRep> image_png_reps;
- image_png_reps.push_back(gfx::ImagePNGRep(png_data, 1.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(png_data, ui::SCALE_FACTOR_100P));
gfx::Image from_png(image_png_reps);
EXPECT_TRUE(from_png.HasRepresentation(gfx::Image::kImageRepPNG));
@@ -300,13 +292,15 @@
// sure these work with the Skia Encode/Decode.
TEST_F(ImageTest, PNGEncodeFromSkiaDecodeToPlatform) {
// Force the conversion sequence skia to png to platform_type.
+ ui::ScaleFactor ideal_scale_factor = ui::GetScaleFactorFromScale(1.0f);
+
gfx::Image from_bitmap = gfx::Image::CreateFrom1xBitmap(
gt::CreateBitmap(25, 25));
scoped_refptr<base::RefCountedMemory> png_bytes =
from_bitmap.As1xPNGBytes();
std::vector<gfx::ImagePNGRep> image_png_reps;
- image_png_reps.push_back(gfx::ImagePNGRep(png_bytes, 1.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(png_bytes, ideal_scale_factor));
gfx::Image from_png(image_png_reps);
gfx::Image from_platform(gt::CopyPlatformType(from_png));
@@ -321,7 +315,7 @@
scoped_refptr<base::RefCountedMemory> png_bytes =
from_platform.As1xPNGBytes();
std::vector<gfx::ImagePNGRep> image_png_reps;
- image_png_reps.push_back(gfx::ImagePNGRep(png_bytes, 1.0f));
+ image_png_reps.push_back(gfx::ImagePNGRep(png_bytes, ui::SCALE_FACTOR_100P));
gfx::Image from_png(image_png_reps);
EXPECT_TRUE(gt::IsEqual(from_platform.AsBitmap(), from_png.AsBitmap()));
@@ -333,7 +327,7 @@
invalid_bytes->data().push_back('0');
std::vector<gfx::ImagePNGRep> image_png_reps;
image_png_reps.push_back(gfx::ImagePNGRep(
- invalid_bytes, 1.0f));
+ invalid_bytes, ui::SCALE_FACTOR_100P));
gfx::Image image(image_png_reps);
gt::CheckImageIndicatesPNGDecodeFailure(image);
}
@@ -344,7 +338,7 @@
invalid_bytes->data().push_back('0');
std::vector<gfx::ImagePNGRep> image_png_reps;
image_png_reps.push_back(gfx::ImagePNGRep(
- invalid_bytes, 1.0f));
+ invalid_bytes, ui::SCALE_FACTOR_100P));
gfx::Image from_png(image_png_reps);
gfx::Image from_platform(gt::CopyPlatformType(from_png));
gt::CheckImageIndicatesPNGDecodeFailure(from_platform);
@@ -642,16 +636,16 @@
gfx::ImageSkia image_skia;
image_skia.AddRepresentation(gfx::ImageSkiaRep(
gt::CreateBitmap(kWidth1x, kHeight1x),
- 1.0f));
+ ui::SCALE_FACTOR_100P));
image_skia.AddRepresentation(gfx::ImageSkiaRep(
gt::CreateBitmap(kWidth2x, kHeight2x),
- 2.0f));
+ ui::SCALE_FACTOR_200P));
- 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));
// Check that the image has a single representation.
gfx::Image image(image_skia);
@@ -667,13 +661,13 @@
gfx::ImageSkia image_skia;
image_skia.AddRepresentation(gfx::ImageSkiaRep(
- gt::CreateBitmap(kWidth2x, kHeight2x), 2.0f));
+ gt::CreateBitmap(kWidth2x, kHeight2x), ui::SCALE_FACTOR_200P));
EXPECT_EQ(1u, image_skia.image_reps().size());
- image_skia.RemoveRepresentation(1.0f);
+ image_skia.RemoveRepresentation(ui::SCALE_FACTOR_100P);
EXPECT_EQ(1u, image_skia.image_reps().size());
- image_skia.RemoveRepresentation(2.0f);
+ image_skia.RemoveRepresentation(ui::SCALE_FACTOR_200P);
EXPECT_EQ(0u, image_skia.image_reps().size());
}
@@ -685,7 +679,7 @@
SkBitmap bitmap(gt::CreateBitmap(10, 10));
EXPECT_TRUE(!bitmap.isNull());
image = gfx::Image(gfx::ImageSkia(
- gfx::ImageSkiaRep(bitmap, 1.0f)));
+ gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)));
}
EXPECT_TRUE(!image.ToSkBitmap()->isNull());
}
« no previous file with comments | « trunk/src/ui/gfx/image/image_skia_util_mac.mm ('k') | trunk/src/ui/gfx/image/image_unittest_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698