Bug 1120023 - Fix some bugs in MockMediaResource. r=cpearce
authorBobby Holley <bobbyholley@gmail.com>
Sat, 10 Jan 2015 02:05:28 -0800
changeset 248939 677f21c77f7e092f4187342f43694c55463c164d
parent 248938 8ce96306c2d339d94a49a442d5c56320b13b8169
child 248940 9de247dc316174bd7c35d1e7449a82a5318cc153
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1120023
milestone37.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 1120023 - Fix some bugs in MockMediaResource. r=cpearce 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) MOZ_OVERRIDE
   {
-    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;
   }