Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/WebKit/Source/platform/DragImageTest.cpp

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 25 matching lines...) Expand all
36 #include "platform/graphics/BitmapImage.h" 36 #include "platform/graphics/BitmapImage.h"
37 #include "platform/graphics/Image.h" 37 #include "platform/graphics/Image.h"
38 #include "platform/graphics/skia/SkiaUtils.h" 38 #include "platform/graphics/skia/SkiaUtils.h"
39 #include "platform/weborigin/KURL.h" 39 #include "platform/weborigin/KURL.h"
40 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
41 #include "third_party/skia/include/core/SkCanvas.h" 41 #include "third_party/skia/include/core/SkCanvas.h"
42 #include "third_party/skia/include/core/SkColor.h" 42 #include "third_party/skia/include/core/SkColor.h"
43 #include "third_party/skia/include/core/SkImage.h" 43 #include "third_party/skia/include/core/SkImage.h"
44 #include "third_party/skia/include/core/SkPixelRef.h" 44 #include "third_party/skia/include/core/SkPixelRef.h"
45 #include "third_party/skia/include/core/SkSurface.h" 45 #include "third_party/skia/include/core/SkSurface.h"
46 #include "wtf/OwnPtr.h"
47 #include "wtf/PassOwnPtr.h"
46 #include "wtf/PassRefPtr.h" 48 #include "wtf/PassRefPtr.h"
47 #include "wtf/RefPtr.h" 49 #include "wtf/RefPtr.h"
48 #include <memory>
49 50
50 namespace blink { 51 namespace blink {
51 52
52 class TestImage : public Image { 53 class TestImage : public Image {
53 public: 54 public:
54 static PassRefPtr<TestImage> create(PassRefPtr<SkImage> image) 55 static PassRefPtr<TestImage> create(PassRefPtr<SkImage> image)
55 { 56 {
56 return adoptRef(new TestImage(image)); 57 return adoptRef(new TestImage(image));
57 } 58 }
58 59
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 { 118 {
118 EXPECT_FALSE(DragImage::create(0)); 119 EXPECT_FALSE(DragImage::create(0));
119 120
120 RefPtr<TestImage> nullTestImage(TestImage::create(IntSize())); 121 RefPtr<TestImage> nullTestImage(TestImage::create(IntSize()));
121 EXPECT_FALSE(DragImage::create(nullTestImage.get())); 122 EXPECT_FALSE(DragImage::create(nullTestImage.get()));
122 } 123 }
123 124
124 TEST(DragImageTest, NonNullHandling) 125 TEST(DragImageTest, NonNullHandling)
125 { 126 {
126 RefPtr<TestImage> testImage(TestImage::create(IntSize(2, 2))); 127 RefPtr<TestImage> testImage(TestImage::create(IntSize(2, 2)));
127 std::unique_ptr<DragImage> dragImage = DragImage::create(testImage.get()); 128 OwnPtr<DragImage> dragImage = DragImage::create(testImage.get());
128 ASSERT_TRUE(dragImage); 129 ASSERT_TRUE(dragImage);
129 130
130 dragImage->scale(0.5, 0.5); 131 dragImage->scale(0.5, 0.5);
131 IntSize size = dragImage->size(); 132 IntSize size = dragImage->size();
132 EXPECT_EQ(1, size.width()); 133 EXPECT_EQ(1, size.width());
133 EXPECT_EQ(1, size.height()); 134 EXPECT_EQ(1, size.height());
134 } 135 }
135 136
136 TEST(DragImageTest, CreateDragImage) 137 TEST(DragImageTest, CreateDragImage)
137 { 138 {
(...skipping 12 matching lines...) Expand all
150 float deviceScaleFactor = 1.0f; 151 float deviceScaleFactor = 1.0f;
151 152
152 FontDescription fontDescription; 153 FontDescription fontDescription;
153 fontDescription.firstFamily().setFamily("Arial"); 154 fontDescription.firstFamily().setFamily("Arial");
154 fontDescription.setSpecifiedSize(16); 155 fontDescription.setSpecifiedSize(16);
155 fontDescription.setIsAbsoluteSize(true); 156 fontDescription.setIsAbsoluteSize(true);
156 fontDescription.setGenericFamily(FontDescription::NoFamily); 157 fontDescription.setGenericFamily(FontDescription::NoFamily);
157 fontDescription.setWeight(FontWeightNormal); 158 fontDescription.setWeight(FontWeightNormal);
158 fontDescription.setStyle(FontStyleNormal); 159 fontDescription.setStyle(FontStyleNormal);
159 160
160 std::unique_ptr<DragImage> testImage = 161 OwnPtr<DragImage> testImage =
161 DragImage::create(url, testLabel, fontDescription, deviceScaleFactor); 162 DragImage::create(url, testLabel, fontDescription, deviceScaleFactor);
162 std::unique_ptr<DragImage> expectedImage = 163 OwnPtr<DragImage> expectedImage =
163 DragImage::create(url, expectedLabel, fontDescription, deviceScaleFactor ); 164 DragImage::create(url, expectedLabel, fontDescription, deviceScaleFactor );
164 165
165 EXPECT_EQ(testImage->size().width(), expectedImage->size().width()); 166 EXPECT_EQ(testImage->size().width(), expectedImage->size().width());
166 } 167 }
167 168
168 // SkPixelRef which fails to lock, as a lazy pixel ref might if its pixels 169 // SkPixelRef which fails to lock, as a lazy pixel ref might if its pixels
169 // cannot be generated. 170 // cannot be generated.
170 class InvalidPixelRef : public SkPixelRef { 171 class InvalidPixelRef : public SkPixelRef {
171 public: 172 public:
172 InvalidPixelRef(const SkImageInfo& info) : SkPixelRef(info) { } 173 InvalidPixelRef(const SkImageInfo& info) : SkPixelRef(info) { }
(...skipping 12 matching lines...) Expand all
185 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); 186 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
186 RefPtr<SkPixelRef> pixelRef = adoptRef(new InvalidPixelRef(info)); 187 RefPtr<SkPixelRef> pixelRef = adoptRef(new InvalidPixelRef(info));
187 SkBitmap invalidBitmap; 188 SkBitmap invalidBitmap;
188 invalidBitmap.setInfo(info); 189 invalidBitmap.setInfo(info);
189 invalidBitmap.setPixelRef(pixelRef.get()); 190 invalidBitmap.setPixelRef(pixelRef.get());
190 RefPtr<BitmapImage> image = BitmapImage::createWithOrientationForTesting(inv alidBitmap, OriginRightTop); 191 RefPtr<BitmapImage> image = BitmapImage::createWithOrientationForTesting(inv alidBitmap, OriginRightTop);
191 192
192 // Create a DragImage from it. In MSAN builds, this will cause a failure if 193 // Create a DragImage from it. In MSAN builds, this will cause a failure if
193 // the pixel memory is not initialized, if we have to respect non-default 194 // the pixel memory is not initialized, if we have to respect non-default
194 // orientation. 195 // orientation.
195 std::unique_ptr<DragImage> dragImage = DragImage::create(image.get(), Respec tImageOrientation); 196 OwnPtr<DragImage> dragImage = DragImage::create(image.get(), RespectImageOri entation);
196 197
197 // With an invalid pixel ref, BitmapImage should have no backing SkImage => we don't allocate 198 // With an invalid pixel ref, BitmapImage should have no backing SkImage => we don't allocate
198 // a DragImage. 199 // a DragImage.
199 ASSERT_FALSE(dragImage); 200 ASSERT_FALSE(dragImage);
200 } 201 }
201 202
202 TEST(DragImageTest, InterpolationNone) 203 TEST(DragImageTest, InterpolationNone)
203 { 204 {
204 SkBitmap expectedBitmap; 205 SkBitmap expectedBitmap;
205 expectedBitmap.allocN32Pixels(4, 4); 206 expectedBitmap.allocN32Pixels(4, 4);
206 { 207 {
207 SkAutoLockPixels lock(expectedBitmap); 208 SkAutoLockPixels lock(expectedBitmap);
208 expectedBitmap.eraseArea(SkIRect::MakeXYWH(0, 0, 2, 2), 0xFFFFFFFF); 209 expectedBitmap.eraseArea(SkIRect::MakeXYWH(0, 0, 2, 2), 0xFFFFFFFF);
209 expectedBitmap.eraseArea(SkIRect::MakeXYWH(0, 2, 2, 2), 0xFF000000); 210 expectedBitmap.eraseArea(SkIRect::MakeXYWH(0, 2, 2, 2), 0xFF000000);
210 expectedBitmap.eraseArea(SkIRect::MakeXYWH(2, 0, 2, 2), 0xFF000000); 211 expectedBitmap.eraseArea(SkIRect::MakeXYWH(2, 0, 2, 2), 0xFF000000);
211 expectedBitmap.eraseArea(SkIRect::MakeXYWH(2, 2, 2, 2), 0xFFFFFFFF); 212 expectedBitmap.eraseArea(SkIRect::MakeXYWH(2, 2, 2, 2), 0xFFFFFFFF);
212 } 213 }
213 214
214 SkBitmap testBitmap; 215 SkBitmap testBitmap;
215 testBitmap.allocN32Pixels(2, 2); 216 testBitmap.allocN32Pixels(2, 2);
216 { 217 {
217 SkAutoLockPixels lock(testBitmap); 218 SkAutoLockPixels lock(testBitmap);
218 testBitmap.eraseArea(SkIRect::MakeXYWH(0, 0, 1, 1), 0xFFFFFFFF); 219 testBitmap.eraseArea(SkIRect::MakeXYWH(0, 0, 1, 1), 0xFFFFFFFF);
219 testBitmap.eraseArea(SkIRect::MakeXYWH(0, 1, 1, 1), 0xFF000000); 220 testBitmap.eraseArea(SkIRect::MakeXYWH(0, 1, 1, 1), 0xFF000000);
220 testBitmap.eraseArea(SkIRect::MakeXYWH(1, 0, 1, 1), 0xFF000000); 221 testBitmap.eraseArea(SkIRect::MakeXYWH(1, 0, 1, 1), 0xFF000000);
221 testBitmap.eraseArea(SkIRect::MakeXYWH(1, 1, 1, 1), 0xFFFFFFFF); 222 testBitmap.eraseArea(SkIRect::MakeXYWH(1, 1, 1, 1), 0xFFFFFFFF);
222 } 223 }
223 224
224 RefPtr<TestImage> testImage = TestImage::create(fromSkSp(SkImage::MakeFromBi tmap(testBitmap))); 225 RefPtr<TestImage> testImage = TestImage::create(fromSkSp(SkImage::MakeFromBi tmap(testBitmap)));
225 std::unique_ptr<DragImage> dragImage = DragImage::create(testImage.get(), Do NotRespectImageOrientation, 1, InterpolationNone); 226 OwnPtr<DragImage> dragImage = DragImage::create(testImage.get(), DoNotRespec tImageOrientation, 1, InterpolationNone);
226 ASSERT_TRUE(dragImage); 227 ASSERT_TRUE(dragImage);
227 dragImage->scale(2, 2); 228 dragImage->scale(2, 2);
228 const SkBitmap& dragBitmap = dragImage->bitmap(); 229 const SkBitmap& dragBitmap = dragImage->bitmap();
229 { 230 {
230 SkAutoLockPixels lock1(dragBitmap); 231 SkAutoLockPixels lock1(dragBitmap);
231 SkAutoLockPixels lock2(expectedBitmap); 232 SkAutoLockPixels lock2(expectedBitmap);
232 for (int x = 0; x < dragBitmap.width(); ++x) 233 for (int x = 0; x < dragBitmap.width(); ++x)
233 for (int y = 0; y < dragBitmap.height(); ++y) 234 for (int y = 0; y < dragBitmap.height(); ++y)
234 EXPECT_EQ(expectedBitmap.getColor(x, y), dragBitmap.getColor(x, y)); 235 EXPECT_EQ(expectedBitmap.getColor(x, y), dragBitmap.getColor(x, y));
235 } 236 }
236 } 237 }
237 238
238 } // namespace blink 239 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/DragImage.cpp ('k') | third_party/WebKit/Source/platform/EventTracer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698