Index: trunk/src/ui/gfx/image/image_skia_unittest.cc |
=================================================================== |
--- trunk/src/ui/gfx/image/image_skia_unittest.cc (revision 224498) |
+++ trunk/src/ui/gfx/image/image_skia_unittest.cc (working copy) |
@@ -8,6 +8,7 @@ |
#include "base/threading/simple_thread.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
+#include "ui/base/layout.h" |
#include "ui/gfx/image/image_skia_rep.h" |
#include "ui/gfx/image/image_skia_source.h" |
#include "ui/gfx/size.h" |
@@ -31,7 +32,7 @@ |
virtual ~FixedSource() { |
} |
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
return image_; |
} |
@@ -48,8 +49,8 @@ |
virtual ~DynamicSource() { |
} |
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
- return gfx::ImageSkiaRep(size_, scale); |
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
+ return gfx::ImageSkiaRep(size_, scale_factor); |
} |
private: |
@@ -66,7 +67,7 @@ |
virtual ~NullSource() { |
} |
- virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
return gfx::ImageSkiaRep(); |
} |
@@ -114,55 +115,58 @@ |
} // namespace test |
TEST(ImageSkiaTest, FixedSource) { |
- ImageSkiaRep image(Size(100, 200), 1.0f); |
+ ImageSkiaRep image(Size(100, 200), ui::SCALE_FACTOR_100P); |
ImageSkia image_skia(new FixedSource(image), Size(100, 200)); |
EXPECT_EQ(0U, image_skia.image_reps().size()); |
- const ImageSkiaRep& result_100p = image_skia.GetRepresentation(1.0f); |
+ const ImageSkiaRep& result_100p = |
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_100P); |
EXPECT_EQ(100, result_100p.GetWidth()); |
EXPECT_EQ(200, result_100p.GetHeight()); |
- EXPECT_EQ(1.0f, result_100p.scale()); |
+ EXPECT_EQ(ui::SCALE_FACTOR_100P, result_100p.scale_factor()); |
EXPECT_EQ(1U, image_skia.image_reps().size()); |
- const ImageSkiaRep& result_200p = image_skia.GetRepresentation(2.0f); |
+ const ImageSkiaRep& result_200p = |
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_200P); |
EXPECT_EQ(100, result_200p.GetWidth()); |
EXPECT_EQ(200, result_200p.GetHeight()); |
EXPECT_EQ(100, result_200p.pixel_width()); |
EXPECT_EQ(200, result_200p.pixel_height()); |
- EXPECT_EQ(1.0f, result_200p.scale()); |
+ EXPECT_EQ(ui::SCALE_FACTOR_100P, result_200p.scale_factor()); |
EXPECT_EQ(1U, image_skia.image_reps().size()); |
// Get the representation again and make sure it doesn't |
// generate new image skia rep. |
- image_skia.GetRepresentation(1.0f); |
- image_skia.GetRepresentation(2.0f); |
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_100P); |
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_200P); |
EXPECT_EQ(1U, image_skia.image_reps().size()); |
} |
TEST(ImageSkiaTest, DynamicSource) { |
ImageSkia image_skia(new DynamicSource(Size(100, 200)), Size(100, 200)); |
EXPECT_EQ(0U, image_skia.image_reps().size()); |
- const ImageSkiaRep& result_100p = image_skia.GetRepresentation(1.0f); |
+ const ImageSkiaRep& result_100p = |
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_100P); |
EXPECT_EQ(100, result_100p.GetWidth()); |
EXPECT_EQ(200, result_100p.GetHeight()); |
- EXPECT_EQ(1.0f, result_100p.scale()); |
+ EXPECT_EQ(ui::SCALE_FACTOR_100P, result_100p.scale_factor()); |
EXPECT_EQ(1U, image_skia.image_reps().size()); |
const ImageSkiaRep& result_200p = |
- image_skia.GetRepresentation(2.0f); |
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_200P); |
EXPECT_EQ(100, result_200p.GetWidth()); |
EXPECT_EQ(200, result_200p.GetHeight()); |
EXPECT_EQ(200, result_200p.pixel_width()); |
EXPECT_EQ(400, result_200p.pixel_height()); |
- EXPECT_EQ(2.0f, result_200p.scale()); |
+ EXPECT_EQ(ui::SCALE_FACTOR_200P, result_200p.scale_factor()); |
EXPECT_EQ(2U, image_skia.image_reps().size()); |
// Get the representation again and make sure it doesn't |
// generate new image skia rep. |
- image_skia.GetRepresentation(1.0f); |
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_100P); |
EXPECT_EQ(2U, image_skia.image_reps().size()); |
- image_skia.GetRepresentation(2.0f); |
+ image_skia.GetRepresentation(ui::SCALE_FACTOR_200P); |
EXPECT_EQ(2U, image_skia.image_reps().size()); |
} |
@@ -178,16 +182,16 @@ |
// Simulate a source which loads images on a delay. Upon |
// GetImageForScaleFactor, it immediately returns null and starts loading |
// image reps slowly. |
- image.GetRepresentation(1.0f); |
- image.GetRepresentation(2.0f); |
+ image.GetRepresentation(ui::SCALE_FACTOR_100P); |
+ image.GetRepresentation(ui::SCALE_FACTOR_200P); |
// After a lengthy amount of simulated time, finally loaded image reps. |
image.AddRepresentation(ImageSkiaRep( |
- gfx::Size(kSmallIcon1x, kSmallIcon1x), 1.0f)); |
+ gfx::Size(kSmallIcon1x, kSmallIcon1x), ui::SCALE_FACTOR_100P)); |
image.AddRepresentation(ImageSkiaRep( |
- gfx::Size(kSmallIcon2x, kSmallIcon2x), 2.0f)); |
+ gfx::Size(kSmallIcon2x, kSmallIcon2x), ui::SCALE_FACTOR_200P)); |
image.AddRepresentation(ImageSkiaRep( |
- gfx::Size(kLargeIcon1x, kLargeIcon1x), 1.0f)); |
+ gfx::Size(kLargeIcon1x, kLargeIcon1x), ui::SCALE_FACTOR_100P)); |
std::vector<ImageSkiaRep> image_reps = image.image_reps(); |
EXPECT_EQ(3u, image_reps.size()); |
@@ -195,9 +199,9 @@ |
int num_1x = 0; |
int num_2x = 0; |
for (size_t i = 0; i < image_reps.size(); ++i) { |
- if (image_reps[i].scale() == 1.0f) |
+ if (image_reps[i].scale_factor() == ui::SCALE_FACTOR_100P) |
num_1x++; |
- else if (image_reps[i].scale() == 2.0f) |
+ else if (image_reps[i].scale_factor() == ui::SCALE_FACTOR_200P) |
num_2x++; |
} |
EXPECT_EQ(2, num_1x); |
@@ -214,9 +218,9 @@ |
TEST(ImageSkiaTest, GetBitmapFromEmpty) { |
// Create an image with 1 representation and remove it so the ImageSkiaStorage |
// is left with no representations. |
- ImageSkia empty_image(ImageSkiaRep(Size(100, 200), 1.0f)); |
+ ImageSkia empty_image(ImageSkiaRep(Size(100, 200), ui::SCALE_FACTOR_100P)); |
ImageSkia empty_image_copy(empty_image); |
- empty_image.RemoveRepresentation(1.0f); |
+ empty_image.RemoveRepresentation(ui::SCALE_FACTOR_100P); |
// Check that ImageSkia::bitmap() still returns a valid SkBitmap pointer for |
// the image and all its copies. |
@@ -233,12 +237,12 @@ |
EXPECT_TRUE(image.BackedBySameObjectAs(unrelated)); |
image.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10), |
- 1.0f)); |
+ ui::SCALE_FACTOR_100P)); |
ImageSkia copy = image; |
copy.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10), |
- 2.0f)); |
+ ui::SCALE_FACTOR_200P)); |
unrelated.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10), |
- 1.0f)); |
+ ui::SCALE_FACTOR_100P)); |
EXPECT_TRUE(image.BackedBySameObjectAs(copy)); |
EXPECT_FALSE(image.BackedBySameObjectAs(unrelated)); |
EXPECT_FALSE(copy.BackedBySameObjectAs(unrelated)); |
@@ -255,7 +259,7 @@ |
} |
TEST(ImageSkiaTest, StaticOnThreadTest) { |
- ImageSkia image(ImageSkiaRep(Size(100, 200), 1.0f)); |
+ ImageSkia image(ImageSkiaRep(Size(100, 200), ui::SCALE_FACTOR_100P)); |
EXPECT_FALSE(image.IsThreadSafe()); |
test::TestOnThread image_on_thread(&image); |
@@ -361,8 +365,8 @@ |
image.MakeThreadSafe(); |
EXPECT_TRUE(image.IsThreadSafe()); |
// Check if image reps are generated for supported scale factors. |
- EXPECT_EQ(ImageSkia::GetSupportedScales().size(), |
- image.image_reps().size()); |
+ EXPECT_EQ(ui::GetSupportedScaleFactors().size(), |
+ image.image_reps().size()); |
test::TestOnThread threadsafe_on_thread(&image); |
threadsafe_on_thread.StartAndJoin(); |
EXPECT_TRUE(threadsafe_on_thread.can_read()); |