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:
|
2016-03-09 13:21:57 +03:00
|
|
|
explicit MockMediaResource(const char* aFileName, const nsACString& aMimeType = NS_LITERAL_CSTRING("video/mp4"));
|
2016-01-18 06:50:29 +03:00
|
|
|
nsIURI* URI() const override { return nullptr; }
|
|
|
|
nsresult Close() override { return NS_OK; }
|
|
|
|
void Suspend(bool aCloseImmediately) override {}
|
|
|
|
void Resume() override {}
|
|
|
|
already_AddRefed<nsIPrincipal> GetCurrentPrincipal() override
|
2014-06-02 19:38:04 +04:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-01-18 06:50:29 +03:00
|
|
|
bool CanClone() override { return false; }
|
|
|
|
already_AddRefed<MediaResource> CloneData(MediaResourceCallback*)
|
2015-03-21 19:28:04 +03:00
|
|
|
override
|
2014-06-02 19:38:04 +04:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-01-18 06:50:29 +03:00
|
|
|
void SetReadMode(MediaCacheStream::ReadMode aMode) override {}
|
|
|
|
void SetPlaybackRate(uint32_t aBytesPerSecond) override {}
|
|
|
|
nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount,
|
|
|
|
uint32_t* aBytes) override;
|
|
|
|
int64_t Tell() override { return 0; }
|
|
|
|
void Pin() override {}
|
|
|
|
void Unpin() override {}
|
|
|
|
double GetDownloadRate(bool* aIsReliable) override { return 0; }
|
|
|
|
int64_t GetLength() override;
|
|
|
|
int64_t GetNextCachedData(int64_t aOffset) override;
|
|
|
|
int64_t GetCachedDataEnd(int64_t aOffset) override;
|
|
|
|
bool IsDataCachedToEndOfResource(int64_t aOffset) override
|
2014-06-02 19:38:04 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-18 06:50:29 +03:00
|
|
|
bool IsSuspendedByCache() override { return false; }
|
|
|
|
bool IsSuspended() override { return false; }
|
|
|
|
nsresult ReadFromCache(char* aBuffer, int64_t aOffset,
|
|
|
|
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
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
bool IsTransportSeekable() override { return true; }
|
|
|
|
nsresult Open(nsIStreamListener** aStreamListener) override;
|
|
|
|
nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override;
|
|
|
|
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;
|
2016-03-09 13:21:57 +03:00
|
|
|
const nsCString mContentType;
|
2014-06-02 19:38:04 +04:00
|
|
|
};
|
2015-07-13 18:25:42 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|
2014-06-02 19:38:04 +04:00
|
|
|
|
|
|
|
#endif
|