| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "platform/DragImage.h" | 31 #include "platform/DragImage.h" |
| 32 | 32 |
| 33 #include "platform/fonts/FontDescription.h" | 33 #include "platform/fonts/FontDescription.h" |
| 34 #include "platform/fonts/FontTraits.h" | 34 #include "platform/fonts/FontTraits.h" |
| 35 #include "platform/geometry/IntSize.h" | 35 #include "platform/geometry/IntSize.h" |
| 36 #include "platform/graphics/BitmapImage.h" | 36 #include "platform/graphics/BitmapImage.h" |
| 37 #include "platform/graphics/GraphicsScreen.h" |
| 37 #include "platform/graphics/Image.h" | 38 #include "platform/graphics/Image.h" |
| 38 #include "platform/weborigin/KURL.h" | 39 #include "platform/weborigin/KURL.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
| 40 #include "third_party/skia/include/core/SkColor.h" | 41 #include "third_party/skia/include/core/SkColor.h" |
| 41 #include "third_party/skia/include/core/SkImage.h" | 42 #include "third_party/skia/include/core/SkImage.h" |
| 42 #include "third_party/skia/include/core/SkPixelRef.h" | 43 #include "third_party/skia/include/core/SkPixelRef.h" |
| 43 #include "third_party/skia/include/core/SkSurface.h" | 44 #include "third_party/skia/include/core/SkSurface.h" |
| 44 #include "wtf/OwnPtr.h" | 45 #include "wtf/OwnPtr.h" |
| 45 #include "wtf/PassOwnPtr.h" | 46 #include "wtf/PassOwnPtr.h" |
| 46 #include "wtf/PassRefPtr.h" | 47 #include "wtf/PassRefPtr.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 static SkSurface* createSkSurface(IntSize size) | 108 static SkSurface* createSkSurface(IntSize size) |
| 108 { | 109 { |
| 109 return SkSurface::NewRaster(SkImageInfo::MakeN32(size.width(), size.heig
ht(), kPremul_SkAlphaType)); | 110 return SkSurface::NewRaster(SkImageInfo::MakeN32(size.width(), size.heig
ht(), kPremul_SkAlphaType)); |
| 110 } | 111 } |
| 111 | 112 |
| 112 RefPtr<SkImage> m_image; | 113 RefPtr<SkImage> m_image; |
| 113 }; | 114 }; |
| 114 | 115 |
| 115 TEST(DragImageTest, NullHandling) | 116 TEST(DragImageTest, NullHandling) |
| 116 { | 117 { |
| 118 WillPaintForDevice device(ScreenDevice::sRGBTest); |
| 119 |
| 117 EXPECT_FALSE(DragImage::create(0)); | 120 EXPECT_FALSE(DragImage::create(0)); |
| 118 | 121 |
| 119 RefPtr<TestImage> nullTestImage(TestImage::create(IntSize())); | 122 RefPtr<TestImage> nullTestImage(TestImage::create(IntSize())); |
| 120 EXPECT_FALSE(DragImage::create(nullTestImage.get())); | 123 EXPECT_FALSE(DragImage::create(nullTestImage.get())); |
| 121 } | 124 } |
| 122 | 125 |
| 123 TEST(DragImageTest, NonNullHandling) | 126 TEST(DragImageTest, NonNullHandling) |
| 124 { | 127 { |
| 128 WillPaintForDevice device(ScreenDevice::sRGBTest); |
| 129 |
| 125 RefPtr<TestImage> testImage(TestImage::create(IntSize(2, 2))); | 130 RefPtr<TestImage> testImage(TestImage::create(IntSize(2, 2))); |
| 126 OwnPtr<DragImage> dragImage = DragImage::create(testImage.get()); | 131 OwnPtr<DragImage> dragImage = DragImage::create(testImage.get()); |
| 127 ASSERT_TRUE(dragImage); | 132 ASSERT_TRUE(dragImage); |
| 128 | 133 |
| 129 dragImage->scale(0.5, 0.5); | 134 dragImage->scale(0.5, 0.5); |
| 130 IntSize size = dragImage->size(); | 135 IntSize size = dragImage->size(); |
| 131 EXPECT_EQ(1, size.width()); | 136 EXPECT_EQ(1, size.width()); |
| 132 EXPECT_EQ(1, size.height()); | 137 EXPECT_EQ(1, size.height()); |
| 133 } | 138 } |
| 134 | 139 |
| 135 TEST(DragImageTest, CreateDragImage) | 140 TEST(DragImageTest, CreateDragImage) |
| 136 { | 141 { |
| 142 WillPaintForDevice device(ScreenDevice::sRGBTest); |
| 143 |
| 137 // Tests that the DrageImage implementation doesn't choke on null values | 144 // Tests that the DrageImage implementation doesn't choke on null values |
| 138 // of imageForCurrentFrame(). | 145 // of imageForCurrentFrame(). |
| 139 // FIXME: how is this test any different from test NullHandling? | 146 // FIXME: how is this test any different from test NullHandling? |
| 140 RefPtr<TestImage> testImage(TestImage::create(IntSize())); | 147 RefPtr<TestImage> testImage(TestImage::create(IntSize())); |
| 141 EXPECT_FALSE(DragImage::create(testImage.get())); | 148 EXPECT_FALSE(DragImage::create(testImage.get())); |
| 142 } | 149 } |
| 143 | 150 |
| 144 TEST(DragImageTest, TrimWhitespace) | 151 TEST(DragImageTest, TrimWhitespace) |
| 145 { | 152 { |
| 153 WillPaintForDevice device(ScreenDevice::sRGBTest); |
| 154 |
| 146 KURL url(ParsedURLString, "http://www.example.com/"); | 155 KURL url(ParsedURLString, "http://www.example.com/"); |
| 147 String testLabel = " Example Example Example \n "; | 156 String testLabel = " Example Example Example \n "; |
| 148 String expectedLabel = "Example Example Example"; | 157 String expectedLabel = "Example Example Example"; |
| 149 float deviceScaleFactor = 1.0f; | 158 float deviceScaleFactor = 1.0f; |
| 150 | 159 |
| 151 FontDescription fontDescription; | 160 FontDescription fontDescription; |
| 152 fontDescription.firstFamily().setFamily("Arial"); | 161 fontDescription.firstFamily().setFamily("Arial"); |
| 153 fontDescription.setSpecifiedSize(16); | 162 fontDescription.setSpecifiedSize(16); |
| 154 fontDescription.setIsAbsoluteSize(true); | 163 fontDescription.setIsAbsoluteSize(true); |
| 155 fontDescription.setGenericFamily(FontDescription::NoFamily); | 164 fontDescription.setGenericFamily(FontDescription::NoFamily); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 169 class InvalidPixelRef : public SkPixelRef { | 178 class InvalidPixelRef : public SkPixelRef { |
| 170 public: | 179 public: |
| 171 InvalidPixelRef(const SkImageInfo& info) : SkPixelRef(info) { } | 180 InvalidPixelRef(const SkImageInfo& info) : SkPixelRef(info) { } |
| 172 private: | 181 private: |
| 173 bool onNewLockPixels(LockRec*) override { return false; } | 182 bool onNewLockPixels(LockRec*) override { return false; } |
| 174 void onUnlockPixels() override { ASSERT_NOT_REACHED(); } | 183 void onUnlockPixels() override { ASSERT_NOT_REACHED(); } |
| 175 }; | 184 }; |
| 176 | 185 |
| 177 TEST(DragImageTest, InvalidRotatedBitmapImage) | 186 TEST(DragImageTest, InvalidRotatedBitmapImage) |
| 178 { | 187 { |
| 188 WillPaintForDevice device(ScreenDevice::sRGBTest); |
| 189 |
| 179 // This test is mostly useful with MSAN builds, which can actually detect | 190 // This test is mostly useful with MSAN builds, which can actually detect |
| 180 // the use of uninitialized memory. | 191 // the use of uninitialized memory. |
| 181 | 192 |
| 182 // Create a BitmapImage which will fail to produce pixels, and hence not | 193 // Create a BitmapImage which will fail to produce pixels, and hence not |
| 183 // draw. | 194 // draw. |
| 184 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 195 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
| 185 RefPtr<SkPixelRef> pixelRef = adoptRef(new InvalidPixelRef(info)); | 196 RefPtr<SkPixelRef> pixelRef = adoptRef(new InvalidPixelRef(info)); |
| 186 SkBitmap invalidBitmap; | 197 SkBitmap invalidBitmap; |
| 187 invalidBitmap.setInfo(info); | 198 invalidBitmap.setInfo(info); |
| 188 invalidBitmap.setPixelRef(pixelRef.get()); | 199 invalidBitmap.setPixelRef(pixelRef.get()); |
| 189 RefPtr<BitmapImage> image = BitmapImage::createWithOrientationForTesting(inv
alidBitmap, OriginRightTop); | 200 RefPtr<BitmapImage> image = BitmapImage::createWithOrientationForTesting(inv
alidBitmap, OriginRightTop); |
| 190 | 201 |
| 191 // Create a DragImage from it. In MSAN builds, this will cause a failure if | 202 // Create a DragImage from it. In MSAN builds, this will cause a failure if |
| 192 // the pixel memory is not initialized, if we have to respect non-default | 203 // the pixel memory is not initialized, if we have to respect non-default |
| 193 // orientation. | 204 // orientation. |
| 194 OwnPtr<DragImage> dragImage = DragImage::create(image.get(), RespectImageOri
entation); | 205 OwnPtr<DragImage> dragImage = DragImage::create(image.get(), RespectImageOri
entation); |
| 195 | 206 |
| 196 // With an invalid pixel ref, BitmapImage should have no backing SkImage =>
we don't allocate | 207 // With an invalid pixel ref, BitmapImage should have no backing SkImage =>
we don't allocate |
| 197 // a DragImage. | 208 // a DragImage. |
| 198 ASSERT_FALSE(dragImage); | 209 ASSERT_FALSE(dragImage); |
| 199 } | 210 } |
| 200 | 211 |
| 201 TEST(DragImageTest, InterpolationNone) | 212 TEST(DragImageTest, InterpolationNone) |
| 202 { | 213 { |
| 214 WillPaintForDevice device(ScreenDevice::sRGBTest); |
| 215 |
| 203 SkBitmap expectedBitmap; | 216 SkBitmap expectedBitmap; |
| 204 expectedBitmap.allocN32Pixels(4, 4); | 217 expectedBitmap.allocN32Pixels(4, 4); |
| 205 { | 218 { |
| 206 SkAutoLockPixels lock(expectedBitmap); | 219 SkAutoLockPixels lock(expectedBitmap); |
| 207 expectedBitmap.eraseArea(SkIRect::MakeXYWH(0, 0, 2, 2), 0xFFFFFFFF); | 220 expectedBitmap.eraseArea(SkIRect::MakeXYWH(0, 0, 2, 2), 0xFFFFFFFF); |
| 208 expectedBitmap.eraseArea(SkIRect::MakeXYWH(0, 2, 2, 2), 0xFF000000); | 221 expectedBitmap.eraseArea(SkIRect::MakeXYWH(0, 2, 2, 2), 0xFF000000); |
| 209 expectedBitmap.eraseArea(SkIRect::MakeXYWH(2, 0, 2, 2), 0xFF000000); | 222 expectedBitmap.eraseArea(SkIRect::MakeXYWH(2, 0, 2, 2), 0xFF000000); |
| 210 expectedBitmap.eraseArea(SkIRect::MakeXYWH(2, 2, 2, 2), 0xFFFFFFFF); | 223 expectedBitmap.eraseArea(SkIRect::MakeXYWH(2, 2, 2, 2), 0xFFFFFFFF); |
| 211 } | 224 } |
| 212 | 225 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 228 { | 241 { |
| 229 SkAutoLockPixels lock1(dragBitmap); | 242 SkAutoLockPixels lock1(dragBitmap); |
| 230 SkAutoLockPixels lock2(expectedBitmap); | 243 SkAutoLockPixels lock2(expectedBitmap); |
| 231 for (int x = 0; x < dragBitmap.width(); ++x) | 244 for (int x = 0; x < dragBitmap.width(); ++x) |
| 232 for (int y = 0; y < dragBitmap.height(); ++y) | 245 for (int y = 0; y < dragBitmap.height(); ++y) |
| 233 EXPECT_EQ(expectedBitmap.getColor(x, y), dragBitmap.getColor(x,
y)); | 246 EXPECT_EQ(expectedBitmap.getColor(x, y), dragBitmap.getColor(x,
y)); |
| 234 } | 247 } |
| 235 } | 248 } |
| 236 | 249 |
| 237 } // namespace blink | 250 } // namespace blink |
| OLD | NEW |