| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/image/image_skia.h" | 5 #include "ui/gfx/image/image_skia.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/threading/simple_thread.h" | 9 #include "base/threading/simple_thread.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 ImageSkia::SetSupportedScales(supported_scales); | 151 ImageSkia::SetSupportedScales(supported_scales); |
| 152 } | 152 } |
| 153 ~ImageSkiaTest() override { ImageSkia::SetSupportedScales(old_scales_); } | 153 ~ImageSkiaTest() override { ImageSkia::SetSupportedScales(old_scales_); } |
| 154 | 154 |
| 155 private: | 155 private: |
| 156 std::vector<float> old_scales_; | 156 std::vector<float> old_scales_; |
| 157 DISALLOW_COPY_AND_ASSIGN(ImageSkiaTest); | 157 DISALLOW_COPY_AND_ASSIGN(ImageSkiaTest); |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 TEST_F(ImageSkiaTest, FixedSource) { | 160 TEST_F(ImageSkiaTest, FixedSource) { |
| 161 ImageSkiaRep image(Size(100, 200), 1.0f); | 161 ImageSkiaRep image(Size(100, 200), 0.0f); |
| 162 ImageSkia image_skia(new FixedSource(image), Size(100, 200)); | 162 ImageSkia image_skia(new FixedSource(image), Size(100, 200)); |
| 163 EXPECT_EQ(0U, image_skia.image_reps().size()); | 163 EXPECT_EQ(0U, image_skia.image_reps().size()); |
| 164 | 164 |
| 165 const ImageSkiaRep& result_100p = image_skia.GetRepresentation(1.0f); | 165 const ImageSkiaRep& result_100p = image_skia.GetRepresentation(1.0f); |
| 166 EXPECT_EQ(100, result_100p.GetWidth()); | 166 EXPECT_EQ(100, result_100p.GetWidth()); |
| 167 EXPECT_EQ(200, result_100p.GetHeight()); | 167 EXPECT_EQ(200, result_100p.GetHeight()); |
| 168 EXPECT_EQ(1.0f, result_100p.scale()); | 168 EXPECT_EQ(1.0f, result_100p.scale()); |
| 169 EXPECT_EQ(1U, image_skia.image_reps().size()); | 169 EXPECT_EQ(1U, image_skia.image_reps().size()); |
| 170 | 170 |
| 171 const ImageSkiaRep& result_200p = image_skia.GetRepresentation(2.0f); | 171 const ImageSkiaRep& result_200p = image_skia.GetRepresentation(2.0f); |
| 172 | 172 |
| 173 EXPECT_EQ(100, result_200p.GetWidth()); | 173 EXPECT_EQ(100, result_200p.GetWidth()); |
| 174 EXPECT_EQ(200, result_200p.GetHeight()); | 174 EXPECT_EQ(200, result_200p.GetHeight()); |
| 175 EXPECT_EQ(100, result_200p.pixel_width()); | 175 EXPECT_EQ(100, result_200p.pixel_width()); |
| 176 EXPECT_EQ(200, result_200p.pixel_height()); | 176 EXPECT_EQ(200, result_200p.pixel_height()); |
| 177 EXPECT_EQ(1.0f, result_200p.scale()); | 177 EXPECT_EQ(1.0f, result_200p.scale()); |
| 178 EXPECT_EQ(1U, image_skia.image_reps().size()); | 178 EXPECT_EQ(1U, image_skia.image_reps().size()); |
| 179 | 179 |
| 180 const ImageSkiaRep& result_300p = image_skia.GetRepresentation(3.0f); |
| 181 |
| 182 EXPECT_EQ(100, result_300p.GetWidth()); |
| 183 EXPECT_EQ(200, result_300p.GetHeight()); |
| 184 EXPECT_EQ(100, result_300p.pixel_width()); |
| 185 EXPECT_EQ(200, result_300p.pixel_height()); |
| 186 EXPECT_EQ(1.0f, result_300p.scale()); |
| 187 EXPECT_EQ(1U, image_skia.image_reps().size()); |
| 188 |
| 180 // Get the representation again and make sure it doesn't | 189 // Get the representation again and make sure it doesn't |
| 181 // generate new image skia rep. | 190 // generate new image skia rep. |
| 182 image_skia.GetRepresentation(1.0f); | 191 image_skia.GetRepresentation(1.0f); |
| 183 image_skia.GetRepresentation(2.0f); | 192 image_skia.GetRepresentation(2.0f); |
| 193 image_skia.GetRepresentation(3.0f); |
| 184 EXPECT_EQ(1U, image_skia.image_reps().size()); | 194 EXPECT_EQ(1U, image_skia.image_reps().size()); |
| 185 } | 195 } |
| 186 | 196 |
| 187 TEST_F(ImageSkiaTest, FixedScaledSource) { | 197 TEST_F(ImageSkiaTest, FixedScaledSource) { |
| 188 ImageSkiaRep image(Size(100, 200), 1.0f); | 198 ImageSkiaRep image(Size(100, 200), 1.0f); |
| 189 ImageSkia image_skia(new FixedScaleSource(image), Size(100, 200)); | 199 ImageSkia image_skia(new FixedScaleSource(image), Size(100, 200)); |
| 190 EXPECT_EQ(0U, image_skia.image_reps().size()); | 200 EXPECT_EQ(0U, image_skia.image_reps().size()); |
| 191 | 201 |
| 192 const ImageSkiaRep& result_100p = image_skia.GetRepresentation(1.0f); | 202 const ImageSkiaRep& result_100p = image_skia.GetRepresentation(1.0f); |
| 193 EXPECT_EQ(100, result_100p.GetWidth()); | 203 EXPECT_EQ(100, result_100p.GetWidth()); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 EXPECT_EQ(1U, image.image_reps().size()); | 620 EXPECT_EQ(1U, image.image_reps().size()); |
| 611 | 621 |
| 612 const ImageSkiaRep& rep12 = image.GetRepresentation(1.2f); | 622 const ImageSkiaRep& rep12 = image.GetRepresentation(1.2f); |
| 613 EXPECT_EQ(1.0f, rep12.scale()); | 623 EXPECT_EQ(1.0f, rep12.scale()); |
| 614 EXPECT_EQ("100x200", rep12.pixel_size().ToString()); | 624 EXPECT_EQ("100x200", rep12.pixel_size().ToString()); |
| 615 EXPECT_TRUE(rep12.unscaled()); | 625 EXPECT_TRUE(rep12.unscaled()); |
| 616 EXPECT_EQ(1U, image.image_reps().size()); | 626 EXPECT_EQ(1U, image.image_reps().size()); |
| 617 } | 627 } |
| 618 | 628 |
| 619 } // namespace gfx | 629 } // namespace gfx |
| OLD | NEW |