2014-06-02 19:38:04 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef MOCK_MEDIA_RESOURCE_H_
|
|
|
|
#define MOCK_MEDIA_RESOURCE_H_
|
|
|
|
|
|
|
|
#include "MediaResource.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "mozilla/Atomics.h"
|
|
|
|
|
|
|
|
namespace mozilla
|
|
|
|
{
|
|
|
|
|
|
|
|
class MockMediaResource : public MediaResource
|
|
|
|
{
|
|
|
|
public:
|
2014-10-11 01:28:35 +04:00
|
|
|
explicit MockMediaResource(const char* aFileName);
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsIURI* URI() const override { return nullptr; }
|
|
|
|
virtual nsresult Close() override { return NS_OK; }
|
|
|
|
virtual void Suspend(bool aCloseImmediately) override {}
|
|
|
|
virtual void Resume() override {}
|
|
|
|
virtual already_AddRefed<nsIPrincipal> GetCurrentPrincipal() override
|
2014-06-02 19:38:04 +04:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool CanClone() override { return false; }
|
2015-10-27 05:28:26 +03:00
|
|
|
virtual already_AddRefed<MediaResource> CloneData(MediaResourceCallback*)
|
2015-03-21 19:28:04 +03:00
|
|
|
override
|
2014-06-02 19:38:04 +04:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SetReadMode(MediaCacheStream::ReadMode aMode) override {}
|
|
|
|
virtual void SetPlaybackRate(uint32_t aBytesPerSecond) override {}
|
2014-06-02 19:38:04 +04:00
|
|
|
virtual nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint32_t* aBytes) override;
|
|
|
|
virtual int64_t Tell() override { return 0; }
|
|
|
|
virtual void Pin() override {}
|
|
|
|
virtual void Unpin() override {}
|
|
|
|
virtual double GetDownloadRate(bool* aIsReliable) override { return 0; }
|
|
|
|
virtual int64_t GetLength() override;
|
|
|
|
virtual int64_t GetNextCachedData(int64_t aOffset) override;
|
|
|
|
virtual int64_t GetCachedDataEnd(int64_t aOffset) override;
|
|
|
|
virtual bool IsDataCachedToEndOfResource(int64_t aOffset) override
|
2014-06-02 19:38:04 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsSuspendedByCache() override { return false; }
|
|
|
|
virtual bool IsSuspended() override { return false; }
|
2014-06-02 19:38:04 +04:00
|
|
|
virtual nsresult ReadFromCache(char* aBuffer, int64_t aOffset,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint32_t aCount) override
|
2014-06-02 19:38:04 +04:00
|
|
|
{
|
2015-01-10 13:05:28 +03:00
|
|
|
uint32_t bytesRead = 0;
|
|
|
|
nsresult rv = ReadAt(aOffset, aBuffer, aCount, &bytesRead);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return bytesRead == aCount ? NS_OK : NS_ERROR_FAILURE;
|
2014-06-02 19:38:04 +04:00
|
|
|
}
|
2015-01-10 13:05:28 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsTransportSeekable() override { return true; }
|
|
|
|
virtual nsresult Open(nsIStreamListener** aStreamListener) override;
|
2015-11-24 12:16:52 +03:00
|
|
|
virtual nsresult GetCachedRanges(MediaByteRangeSet& aRanges)
|
2015-03-21 19:28:04 +03:00
|
|
|
override;
|
|
|
|
virtual const nsCString& GetContentType() const override
|
2014-06-02 19:38:04 +04:00
|
|
|
{
|
|
|
|
return mContentType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MockClearBufferedRanges();
|
|
|
|
void MockAddBufferedRange(int64_t aStart, int64_t aEnd);
|
|
|
|
|
2015-07-09 23:42:23 +03:00
|
|
|
protected:
|
2014-06-02 19:38:04 +04:00
|
|
|
virtual ~MockMediaResource();
|
2015-07-09 23:42:23 +03:00
|
|
|
|
|
|
|
private:
|
2014-06-02 19:38:04 +04:00
|
|
|
FILE* mFileHandle;
|
|
|
|
const char* mFileName;
|
2015-11-24 12:16:52 +03:00
|
|
|
MediaByteRangeSet mRanges;
|
2014-06-02 19:38:04 +04:00
|
|
|
Atomic<int> mEntry;
|
|
|
|
nsCString mContentType;
|
|
|
|
};
|
2015-07-13 18:25:42 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|
2014-06-02 19:38:04 +04:00
|
|
|
|
|
|
|
#endif
|