Bug 1194059 (Part 3) - Ensure the nsIInputStream LoadImage() returns is always buffered. r=tn
authorSeth Fowler <mark.seth.fowler@gmail.com>
Fri, 14 Aug 2015 00:37:16 -0700
changeset 257778 c263278045e2aa6214149359b18c9bd97df522bb
parent 257777 167ceb9650797d3281a4940450604893dc6bad26
child 257779 c035b63e1b816877cfdfcedfc7b530e1a0ad4308
push id29226
push userryanvm@gmail.com
push dateFri, 14 Aug 2015 13:01:14 +0000
treeherdermozilla-central@1b2402247429 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn
bugs1194059
milestone43.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 1194059 (Part 3) - Ensure the nsIInputStream LoadImage() returns is always buffered. r=tn
image/test/gtest/Common.cpp
image/test/gtest/TestMetadata.cpp
--- a/image/test/gtest/Common.cpp
+++ b/image/test/gtest/Common.cpp
@@ -10,16 +10,17 @@
 
 #include "nsDirectoryServiceDefs.h"
 #include "nsIDirectoryService.h"
 #include "nsIFile.h"
 #include "nsIInputStream.h"
 #include "nsIProperties.h"
 #include "nsNetUtil.h"
 #include "mozilla/nsRefPtr.h"
+#include "nsStreamUtils.h"
 #include "nsString.h"
 
 namespace mozilla {
 
 using namespace gfx;
 
 using std::abs;
 
@@ -66,16 +67,25 @@ LoadFile(const char* aRelativePath)
   // working directory.
   file->AppendNative(nsAutoCString(aRelativePath));
 
   // Construct an input stream for the requested file.
   nsCOMPtr<nsIInputStream> inputStream;
   rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream), file);
   ASSERT_TRUE_OR_RETURN(NS_SUCCEEDED(rv), nullptr);
 
+  // Ensure the resulting input stream is buffered.
+  if (!NS_InputStreamIsBuffered(inputStream)) {
+    nsCOMPtr<nsIInputStream> bufStream;
+    rv = NS_NewBufferedInputStream(getter_AddRefs(bufStream),
+                                   inputStream, 1024);
+    ASSERT_TRUE_OR_RETURN(NS_SUCCEEDED(rv), nullptr);
+    inputStream = bufStream;
+  }
+
   return inputStream.forget();
 }
 
 bool
 IsSolidColor(SourceSurface* aSurface, BGRAColor aColor, bool aFuzzy)
 {
   nsRefPtr<DataSourceSurface> dataSurface = aSurface->GetDataSurface();
   ASSERT_TRUE_OR_RETURN(dataSurface != nullptr, false);
--- a/image/test/gtest/TestMetadata.cpp
+++ b/image/test/gtest/TestMetadata.cpp
@@ -38,30 +38,19 @@ TEST(ImageMetadata, ImageModuleAvailable
 }
 
 static void
 CheckMetadata(const ImageTestCase& aTestCase, bool aEnableBMPAlpha = false)
 {
   nsCOMPtr<nsIInputStream> inputStream = LoadFile(aTestCase.mPath);
   ASSERT_TRUE(inputStream != nullptr);
 
-  // Prepare the input stream.
-  nsresult rv;
-  if (!NS_InputStreamIsBuffered(inputStream)) {
-    nsCOMPtr<nsIInputStream> bufStream;
-    rv = NS_NewBufferedInputStream(getter_AddRefs(bufStream),
-                                   inputStream, 1024);
-    if (NS_SUCCEEDED(rv)) {
-      inputStream = bufStream;
-    }
-  }
-
   // Figure out how much data we have.
   uint64_t length;
-  rv = inputStream->Available(&length);
+  nsresult rv = inputStream->Available(&length);
   ASSERT_TRUE(NS_SUCCEEDED(rv));
 
   // Write the data into a SourceBuffer.
   nsRefPtr<SourceBuffer> sourceBuffer = new SourceBuffer();
   sourceBuffer->ExpectLength(length);
   rv = sourceBuffer->AppendFromInputStream(inputStream, length);
   ASSERT_TRUE(NS_SUCCEEDED(rv));
   sourceBuffer->Complete(NS_OK);