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

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

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