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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 166 |
167 #endif // OS_MACOSX | 167 #endif // OS_MACOSX |
168 | 168 |
169 TEST(ImageSkiaTest, GetBitmap) { | 169 TEST(ImageSkiaTest, GetBitmap) { |
170 ImageSkia image_skia(new DynamicSource(Size(100, 200)), Size(100, 200)); | 170 ImageSkia image_skia(new DynamicSource(Size(100, 200)), Size(100, 200)); |
171 const SkBitmap* bitmap = image_skia.bitmap(); | 171 const SkBitmap* bitmap = image_skia.bitmap(); |
172 EXPECT_NE(static_cast<SkBitmap*>(NULL), bitmap); | 172 EXPECT_NE(static_cast<SkBitmap*>(NULL), bitmap); |
173 EXPECT_FALSE(bitmap->isNull()); | 173 EXPECT_FALSE(bitmap->isNull()); |
174 } | 174 } |
175 | 175 |
| 176 TEST(ImageSkiaTest, GetBitmapFromEmpty) { |
| 177 // Create an image with 1 representation and remove it so the ImageSkiaStorage |
| 178 // is left with no representations. |
| 179 ImageSkia empty_image(ImageSkiaRep(Size(100, 200), ui::SCALE_FACTOR_100P)); |
| 180 ImageSkia empty_image_copy(empty_image); |
| 181 empty_image.RemoveRepresentation(ui::SCALE_FACTOR_100P); |
| 182 |
| 183 // Check that ImageSkia::bitmap() still returns a valid SkBitmap pointer for |
| 184 // the image and all its copies. |
| 185 const SkBitmap* bitmap = empty_image_copy.bitmap(); |
| 186 ASSERT_NE(static_cast<SkBitmap*>(NULL), bitmap); |
| 187 EXPECT_TRUE(bitmap->isNull()); |
| 188 EXPECT_TRUE(bitmap->empty()); |
| 189 } |
| 190 |
| 191 TEST(ImageSkiaTest, OperatorBitmapFromSource) { |
| 192 ImageSkia image_skia(new DynamicSource(Size(100, 200)), Size(100, 200)); |
| 193 // ImageSkia should use the source to create the bitmap. |
| 194 const SkBitmap& bitmap = image_skia; |
| 195 ASSERT_NE(static_cast<SkBitmap*>(NULL), &bitmap); |
| 196 EXPECT_FALSE(bitmap.isNull()); |
| 197 } |
| 198 |
176 } // namespace gfx | 199 } // namespace gfx |
OLD | NEW |