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

Unified Diff: Source/platform/DragImageTest.cpp

Issue 877553011: Unit test for non-default orientation images which don't produce pixels. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/platform/graphics/BitmapImage.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/DragImageTest.cpp
diff --git a/Source/platform/DragImageTest.cpp b/Source/platform/DragImageTest.cpp
index 2bb96e4291ef468e8d1b5915bbba34cabea97d7d..825134f1b6d2b981bcb84a509430b2717345ea03 100644
--- a/Source/platform/DragImageTest.cpp
+++ b/Source/platform/DragImageTest.cpp
@@ -35,11 +35,13 @@
#include "platform/fonts/FontDescription.h"
#include "platform/fonts/FontTraits.h"
#include "platform/geometry/IntSize.h"
+#include "platform/graphics/BitmapImage.h"
#include "platform/graphics/Image.h"
#include "platform/graphics/skia/NativeImageSkia.h"
#include "platform/weborigin/KURL.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
+#include "third_party/skia/include/core/SkPixelRef.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/PassRefPtr.h"
@@ -167,4 +169,46 @@ TEST(DragImageTest, TrimWhitespace)
EXPECT_EQ(testImage->size().width(), expectedImage->size().width());
}
+// SkPixelRef which fails to lock, as a lazy pixel ref might if its pixels
+// cannot be generated.
+class InvalidPixelRef : public SkPixelRef {
+public:
+ InvalidPixelRef(const SkImageInfo& info) : SkPixelRef(info) { }
+private:
+ bool onNewLockPixels(LockRec*) override { return false; }
+ void onUnlockPixels() override { ASSERT_NOT_REACHED(); }
+};
+
+TEST(DragImageTest, InvalidRotatedBitmapImage)
+{
+ // This test is mostly useful with MSAN builds, which can actually detect
+ // the use of uninitialized memory.
+
+ // Create a BitmapImage which will fail to produce pixels, and hence not
+ // draw.
+ SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
+ RefPtr<SkPixelRef> pixelRef = adoptRef(new InvalidPixelRef(info));
+ SkBitmap invalidBitmap;
+ invalidBitmap.setInfo(info);
+ invalidBitmap.setPixelRef(pixelRef.get());
+ RefPtr<NativeImageSkia> nativeImage = NativeImageSkia::create(invalidBitmap);
+ RefPtr<BitmapImage> image = BitmapImage::createWithOrientationForTesting(nativeImage, OriginRightTop);
+
+ // Create a DragImage from it. In MSAN builds, this will cause a failure if
+ // the pixel memory is not initialized, if we have to respect non-default
+ // orientation.
+ OwnPtr<DragImage> dragImage = DragImage::create(image.get(), RespectImageOrientation);
+
+ // The DragImage should be fully transparent.
+ SkBitmap dragImageBitmap = dragImage->bitmap();
+ SkAutoLockPixels lock(dragImageBitmap);
+ ASSERT_NE(nullptr, dragImageBitmap.getPixels());
+ for (int x = 0; x < dragImageBitmap.width(); x++) {
+ for (int y = 0; y < dragImageBitmap.height(); y++) {
+ int alpha = SkColorGetA(dragImageBitmap.getColor(x, y));
+ ASSERT_EQ(0, alpha);
+ }
+ }
+}
+
} // anonymous namespace
« no previous file with comments | « no previous file | Source/platform/graphics/BitmapImage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698