Bug 1120023 - Fix some bugs in MockMediaResource. r=cpearce, a=sledru
authorBobby Holley <bobbyholley@gmail.com>
Sat, 10 Jan 2015 02:05:28 -0800
changeset 242862 e5cc2f8f3f7e
parent 242861 60f6890d84cf
child 242863 423cb20b5f43
push id4322
push userryanvm@gmail.com
push date2015-01-14 15:18 +0000
treeherdermozilla-beta@82cce51fb174 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, sledru
bugs1120023
milestone36.0
Bug 1120023 - Fix some bugs in MockMediaResource. r=cpearce, a=sledru If we don't do this, the subsequent changes to DataSourceAdapter will cause gtest failures in TestMP4Demuxer.
dom/media/gtest/MockMediaResource.cpp
dom/media/gtest/MockMediaResource.h
--- a/dom/media/gtest/MockMediaResource.cpp
+++ b/dom/media/gtest/MockMediaResource.cpp
@@ -44,17 +44,18 @@ MockMediaResource::ReadAt(int64_t aOffse
 
   // Make it fail if we're re-entrant
   if (mEntry++) {
     MOZ_ASSERT(false);
     return NS_ERROR_FAILURE;
   }
 
   fseek(mFileHandle, aOffset, SEEK_SET);
-  *aBytes = (uint32_t) fread(aBuffer, aCount, 1, mFileHandle);
+  size_t objectsRead = fread(aBuffer, aCount, 1, mFileHandle);
+  *aBytes = objectsRead == 1 ? aCount : 0;
 
   mEntry--;
 
   return ferror(mFileHandle) ? NS_ERROR_FAILURE : NS_OK;
 }
 
 int64_t
 MockMediaResource::GetLength()
--- a/dom/media/gtest/MockMediaResource.h
+++ b/dom/media/gtest/MockMediaResource.h
@@ -54,18 +54,22 @@ public:
   {
     return false;
   }
   virtual bool IsSuspendedByCache() MOZ_OVERRIDE { return false; }
   virtual bool IsSuspended() MOZ_OVERRIDE { return false; }
   virtual nsresult ReadFromCache(char* aBuffer, int64_t aOffset,
                                  uint32_t aCount)
   {
-    return NS_OK;
+    uint32_t bytesRead = 0;
+    nsresult rv = ReadAt(aOffset, aBuffer, aCount, &bytesRead);
+    NS_ENSURE_SUCCESS(rv, rv);
+    return bytesRead == aCount ? NS_OK : NS_ERROR_FAILURE;
   }
+
   virtual bool IsTransportSeekable() MOZ_OVERRIDE { return true; }
   virtual nsresult Open(nsIStreamListener** aStreamListener) MOZ_OVERRIDE;
   virtual nsresult GetCachedRanges(nsTArray<MediaByteRange>& aRanges)
     MOZ_OVERRIDE;
   virtual const nsCString& GetContentType() const MOZ_OVERRIDE
   {
     return mContentType;
   }