Bug 1276413 (Part 2) - Add tests for expected state when initializing a SurfaceSink. r=njn
authorSeth Fowler <mark.seth.fowler@gmail.com>
Wed, 01 Jun 2016 11:59:47 -0700
changeset 341007 9cef1a1fa8a2d158bcd53c946462dbb62f871ee9
parent 341006 817695430906243ef1f46f3c8df49f2b86f489ef
child 341008 3e54b910e5a24d011c41cddb1b25f408bf1ea87f
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1276413
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1276413 (Part 2) - Add tests for expected state when initializing a SurfaceSink. r=njn
image/test/gtest/TestSurfaceSink.cpp
--- a/image/test/gtest/TestSurfaceSink.cpp
+++ b/image/test/gtest/TestSurfaceSink.cpp
@@ -89,16 +89,33 @@ TEST(ImageSurfaceSink, NullSurfaceSink)
 
   // Attempt to advance to the next pass and make sure nothing changes.
   sink.ResetToFirstRow();
   EXPECT_TRUE(sink.IsSurfaceFinished());
   invalidRect = sink.TakeInvalidRect();
   EXPECT_TRUE(invalidRect.isNothing());
 }
 
+TEST(ImageSurfaceSink, SurfaceSinkInitialization)
+{
+  WithSurfaceSink<Orient::NORMAL>([](Decoder* aDecoder, SurfaceSink* aSink) {
+    // Check initial state.
+    EXPECT_FALSE(aSink->IsSurfaceFinished());
+    Maybe<SurfaceInvalidRect> invalidRect = aSink->TakeInvalidRect();
+    EXPECT_TRUE(invalidRect.isNothing());
+
+    // Check that the surface is zero-initialized. We verify this by calling
+    // CheckGeneratedImage() and telling it that we didn't write to the surface
+    // anyway (i.e., we wrote to the empty rect); it will then expect the entire
+    // surface to be transparent, which is what it should be if it was
+    // zero-initialied.
+    CheckGeneratedImage(aDecoder, IntRect(0, 0, 0, 0));
+  });
+}
+
 TEST(ImageSurfaceSink, SurfaceSinkWritePixels)
 {
   WithSurfaceSink<Orient::NORMAL>([](Decoder* aDecoder, SurfaceSink* aSink) {
     CheckWritePixels(aDecoder, aSink);
   });
 }
 
 TEST(ImageSurfaceSink, SurfaceSinkWriteRows)
@@ -436,16 +453,38 @@ TEST(ImageSurfaceSink, SurfaceSinkFlipVe
       // Check that the generated image is correct.
       RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef();
       RefPtr<SourceSurface> surface = currentFrame->GetSurface();
       EXPECT_TRUE(IsSolidColor(surface, BGRAColor::Green()));
     }
   });
 }
 
+TEST(ImageSurfaceSink, PalettedSurfaceSinkInitialization)
+{
+  WithPalettedSurfaceSink(IntRect(0, 0, 100, 100),
+                          [](Decoder* aDecoder, PalettedSurfaceSink* aSink) {
+    // Check initial state.
+    EXPECT_FALSE(aSink->IsSurfaceFinished());
+    Maybe<SurfaceInvalidRect> invalidRect = aSink->TakeInvalidRect();
+    EXPECT_TRUE(invalidRect.isNothing());
+
+    // Check that the paletted image data is zero-initialized.
+    RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef();
+    uint8_t* imageData = nullptr;
+    uint32_t imageLength = 0;
+    currentFrame->GetImageData(&imageData, &imageLength);
+    ASSERT_TRUE(imageData != nullptr);
+    ASSERT_EQ(100u * 100u, imageLength);
+    for (uint32_t i = 0; i < imageLength; ++i) {
+      ASSERT_EQ(uint8_t(0), imageData[i]);
+    }
+  });
+}
+
 TEST(ImageSurfaceSink, PalettedSurfaceSinkWritePixelsFor0_0_100_100)
 {
   WithPalettedSurfaceSink(IntRect(0, 0, 100, 100),
                           [](Decoder* aDecoder, PalettedSurfaceSink* aSink) {
     CheckPalettedWritePixels(aDecoder, aSink);
   });
 }