| 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 "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
| 9 #include "ui/base/layout.h" | 9 #include "ui/base/layout.h" |
| 10 #include "ui/gfx/image/image_skia_rep.h" | 10 #include "ui/gfx/image/image_skia_rep.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 empty_image.RemoveRepresentation(ui::SCALE_FACTOR_100P); | 181 empty_image.RemoveRepresentation(ui::SCALE_FACTOR_100P); |
| 182 | 182 |
| 183 // Check that ImageSkia::bitmap() still returns a valid SkBitmap pointer for | 183 // Check that ImageSkia::bitmap() still returns a valid SkBitmap pointer for |
| 184 // the image and all its copies. | 184 // the image and all its copies. |
| 185 const SkBitmap* bitmap = empty_image_copy.bitmap(); | 185 const SkBitmap* bitmap = empty_image_copy.bitmap(); |
| 186 ASSERT_NE(static_cast<SkBitmap*>(NULL), bitmap); | 186 ASSERT_NE(static_cast<SkBitmap*>(NULL), bitmap); |
| 187 EXPECT_TRUE(bitmap->isNull()); | 187 EXPECT_TRUE(bitmap->isNull()); |
| 188 EXPECT_TRUE(bitmap->empty()); | 188 EXPECT_TRUE(bitmap->empty()); |
| 189 } | 189 } |
| 190 | 190 |
| 191 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 191 TEST(ImageSkiaTest, OperatorBitmapFromSource) { | 192 TEST(ImageSkiaTest, OperatorBitmapFromSource) { |
| 192 ImageSkia image_skia(new DynamicSource(Size(100, 200)), Size(100, 200)); | 193 ImageSkia image_skia(new DynamicSource(Size(100, 200)), Size(100, 200)); |
| 193 // ImageSkia should use the source to create the bitmap. | 194 // ImageSkia should use the source to create the bitmap. |
| 194 const SkBitmap& bitmap = image_skia; | 195 const SkBitmap& bitmap = image_skia; |
| 195 ASSERT_NE(static_cast<SkBitmap*>(NULL), &bitmap); | 196 ASSERT_NE(static_cast<SkBitmap*>(NULL), &bitmap); |
| 196 EXPECT_FALSE(bitmap.isNull()); | 197 EXPECT_FALSE(bitmap.isNull()); |
| 197 } | 198 } |
| 199 #endif |
| 198 | 200 |
| 199 TEST(ImageSkiaTest, BackedBySameObjectAs) { | 201 TEST(ImageSkiaTest, BackedBySameObjectAs) { |
| 200 // Null images should all be backed by the same object (NULL). | 202 // Null images should all be backed by the same object (NULL). |
| 201 ImageSkia image; | 203 ImageSkia image; |
| 202 ImageSkia unrelated; | 204 ImageSkia unrelated; |
| 203 EXPECT_TRUE(image.BackedBySameObjectAs(unrelated)); | 205 EXPECT_TRUE(image.BackedBySameObjectAs(unrelated)); |
| 204 | 206 |
| 205 image.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10), | 207 image.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10), |
| 206 ui::SCALE_FACTOR_100P)); | 208 ui::SCALE_FACTOR_100P)); |
| 207 ImageSkia copy = image; | 209 ImageSkia copy = image; |
| 208 copy.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10), | 210 copy.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10), |
| 209 ui::SCALE_FACTOR_200P)); | 211 ui::SCALE_FACTOR_200P)); |
| 210 unrelated.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10), | 212 unrelated.AddRepresentation(gfx::ImageSkiaRep(gfx::Size(10, 10), |
| 211 ui::SCALE_FACTOR_100P)); | 213 ui::SCALE_FACTOR_100P)); |
| 212 EXPECT_TRUE(image.BackedBySameObjectAs(copy)); | 214 EXPECT_TRUE(image.BackedBySameObjectAs(copy)); |
| 213 EXPECT_FALSE(image.BackedBySameObjectAs(unrelated)); | 215 EXPECT_FALSE(image.BackedBySameObjectAs(unrelated)); |
| 214 EXPECT_FALSE(copy.BackedBySameObjectAs(unrelated)); | 216 EXPECT_FALSE(copy.BackedBySameObjectAs(unrelated)); |
| 215 } | 217 } |
| 216 | 218 |
| 217 } // namespace gfx | 219 } // namespace gfx |
| OLD | NEW |