Chromium Code Reviews| Index: ui/gfx/image/image_skia_unittest.cc |
| diff --git a/ui/gfx/image/image_skia_unittest.cc b/ui/gfx/image/image_skia_unittest.cc |
| index 15337a863a9d34dfffbd05bf44e6999065057a0d..f4f63cf7a5a393ecd8e5b0e15b832ae12c5144e3 100644 |
| --- a/ui/gfx/image/image_skia_unittest.cc |
| +++ b/ui/gfx/image/image_skia_unittest.cc |
| @@ -9,9 +9,11 @@ |
| #include "base/threading/simple_thread.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "third_party/skia/include/core/SkBitmap.h" |
| +#include "ui/gfx/canvas.h" |
| +#include "ui/gfx/geometry/rect.h" |
| +#include "ui/gfx/geometry/size.h" |
| #include "ui/gfx/image/image_skia_rep.h" |
| #include "ui/gfx/image/image_skia_source.h" |
| -#include "ui/gfx/size.h" |
| #include "ui/gfx/switches.h" |
| // Duplicated from base/threading/non_thread_safe.h so that we can be |
| @@ -54,7 +56,11 @@ class DynamicSource : public ImageSkiaSource { |
| virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
| last_requested_scale_ = scale; |
| - return gfx::ImageSkiaRep(size_, scale); |
|
oshima
2014/05/15 16:14:13
this constructor is used in other tests (and only
Jun Mukai
2014/05/16 01:57:33
Done.
|
| + // The returned image can be resized in ImageSkiaStorage, so |
| + // empty ImageSkiaRep could cause use-of-uninitialized-value. |
| + gfx::Canvas canvas(size_, scale, true); |
| + canvas.FillRect(Rect(size_), SK_ColorRED); |
| + return canvas.ExtractImageRep(); |
| } |
| float GetLastRequestedScaleAndReset() { |
| @@ -504,8 +510,9 @@ TEST_F(ImageSkiaTest, ArbitraryScaleFactorWithMissingResource) { |
| if (!ImageSkia::IsDSFScalingInImageSkiaEnabled()) |
| return; |
| - ImageSkia image(new FixedSource( |
| - ImageSkiaRep(Size(100, 200), 1.0f)), Size(100, 200)); |
| + Canvas canvas(Size(100, 200), 1.0f, false); |
| + canvas.FillRect(Rect(0, 0, 100, 200), SK_ColorRED); |
| + ImageSkia image(new FixedSource(canvas.ExtractImageRep()), Size(100, 200)); |
| // Requesting 1.5f -- falls back to 2.0f, but couldn't find. It should |
| // look up 1.0f and then rescale it. |
| @@ -525,8 +532,11 @@ TEST_F(ImageSkiaTest, UnscaledImageForArbitraryScaleFactor) { |
| return; |
| // 0.0f means unscaled. |
| + Canvas canvas(Size(100, 200), 1.0f, false); |
| + canvas.FillRect(Rect(0, 0, 100, 200), SK_ColorRED); |
| + ImageSkiaRep origin_rep = canvas.ExtractImageRep(); |
| ImageSkia image(new FixedSource( |
| - ImageSkiaRep(Size(100, 200), 0.0f)), Size(100, 200)); |
| + ImageSkiaRep(origin_rep.sk_bitmap(), 0.0f)), Size(100, 200)); |
| // Requesting 2.0f, which should return 1.0f unscaled image. |
| const ImageSkiaRep& rep = image.GetRepresentation(2.0f); |