2014-10-14 02:04:59 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
2014-10-21 10:16:19 +04:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "mozilla/Services.h"
|
2014-10-14 02:04:59 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2015-04-17 07:09:46 +03:00
|
|
|
#include "GMPTestMonitor.h"
|
2014-10-14 02:04:59 +04:00
|
|
|
#include "GMPVideoDecoderProxy.h"
|
|
|
|
#include "GMPVideoEncoderProxy.h"
|
2014-10-21 10:16:19 +04:00
|
|
|
#include "GMPDecryptorProxy.h"
|
2015-02-09 23:54:12 +03:00
|
|
|
#include "GMPServiceParent.h"
|
2014-10-14 02:04:59 +04:00
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsIFile.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
2014-10-21 10:16:19 +04:00
|
|
|
#include "mozilla/Atomics.h"
|
|
|
|
#include "nsNSSComponent.h"
|
2015-02-09 23:54:12 +03:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2014-10-21 10:16:19 +04:00
|
|
|
|
2014-11-03 13:02:30 +03:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
#include "mozilla/WindowsVersion.h"
|
|
|
|
#endif
|
|
|
|
|
2014-10-21 10:16:19 +04:00
|
|
|
using namespace std;
|
2014-10-14 02:04:59 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gmp;
|
|
|
|
|
|
|
|
struct GMPTestRunner
|
|
|
|
{
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPTestRunner)
|
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
void DoTest(void (GMPTestRunner::*aTestMethod)(GMPTestMonitor&));
|
|
|
|
void RunTestGMPTestCodec1(GMPTestMonitor& aMonitor);
|
|
|
|
void RunTestGMPTestCodec2(GMPTestMonitor& aMonitor);
|
|
|
|
void RunTestGMPTestCodec3(GMPTestMonitor& aMonitor);
|
|
|
|
void RunTestGMPCrossOrigin1(GMPTestMonitor& aMonitor);
|
|
|
|
void RunTestGMPCrossOrigin2(GMPTestMonitor& aMonitor);
|
|
|
|
void RunTestGMPCrossOrigin3(GMPTestMonitor& aMonitor);
|
|
|
|
void RunTestGMPCrossOrigin4(GMPTestMonitor& aMonitor);
|
2014-10-14 02:04:59 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
~GMPTestRunner() { }
|
|
|
|
};
|
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
template<class T, class Base,
|
|
|
|
nsresult (NS_STDCALL GeckoMediaPluginService::*Getter)(nsTArray<nsCString>*,
|
|
|
|
const nsACString&,
|
|
|
|
UniquePtr<Base>&&)>
|
|
|
|
class RunTestGMPVideoCodec : public Base
|
2014-10-14 02:04:59 +04:00
|
|
|
{
|
2015-02-10 13:48:29 +03:00
|
|
|
public:
|
2016-01-18 06:50:29 +03:00
|
|
|
void Done(T* aGMP, GMPVideoHost* aHost) override
|
2015-02-10 13:48:29 +03:00
|
|
|
{
|
|
|
|
EXPECT_TRUE(aGMP);
|
|
|
|
EXPECT_TRUE(aHost);
|
|
|
|
if (aGMP) {
|
|
|
|
aGMP->Close();
|
|
|
|
}
|
|
|
|
mMonitor.SetFinished();
|
|
|
|
}
|
2014-10-14 02:04:59 +04:00
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
static void Run(GMPTestMonitor& aMonitor, const nsCString& aOrigin)
|
|
|
|
{
|
|
|
|
UniquePtr<GMPCallbackType> callback(new RunTestGMPVideoCodec(aMonitor));
|
|
|
|
Get(aOrigin, Move(callback));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
typedef T GMPCodecType;
|
|
|
|
typedef Base GMPCallbackType;
|
|
|
|
|
|
|
|
explicit RunTestGMPVideoCodec(GMPTestMonitor& aMonitor)
|
|
|
|
: mMonitor(aMonitor)
|
|
|
|
{
|
|
|
|
}
|
2014-10-14 02:04:59 +04:00
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
static nsresult Get(const nsACString& aNodeId, UniquePtr<Base>&& aCallback)
|
|
|
|
{
|
|
|
|
nsTArray<nsCString> tags;
|
|
|
|
tags.AppendElement(NS_LITERAL_CSTRING("h264"));
|
2015-06-05 12:55:52 +03:00
|
|
|
tags.AppendElement(NS_LITERAL_CSTRING("fake"));
|
2014-10-14 02:04:59 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GeckoMediaPluginService> service =
|
2015-02-10 13:48:29 +03:00
|
|
|
GeckoMediaPluginService::GetGeckoMediaPluginService();
|
|
|
|
return ((*service).*Getter)(&tags, aNodeId, Move(aCallback));
|
|
|
|
}
|
2014-10-14 02:04:59 +04:00
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
protected:
|
|
|
|
GMPTestMonitor& mMonitor;
|
|
|
|
};
|
2014-10-14 02:04:59 +04:00
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
typedef RunTestGMPVideoCodec<GMPVideoDecoderProxy,
|
|
|
|
GetGMPVideoDecoderCallback,
|
|
|
|
&GeckoMediaPluginService::GetGMPVideoDecoder>
|
|
|
|
RunTestGMPVideoDecoder;
|
|
|
|
typedef RunTestGMPVideoCodec<GMPVideoEncoderProxy,
|
|
|
|
GetGMPVideoEncoderCallback,
|
|
|
|
&GeckoMediaPluginService::GetGMPVideoEncoder>
|
|
|
|
RunTestGMPVideoEncoder;
|
2014-10-14 02:04:59 +04:00
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
void
|
|
|
|
GMPTestRunner::RunTestGMPTestCodec1(GMPTestMonitor& aMonitor)
|
|
|
|
{
|
|
|
|
RunTestGMPVideoDecoder::Run(aMonitor, NS_LITERAL_CSTRING("o"));
|
2014-10-14 02:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-10 13:48:29 +03:00
|
|
|
GMPTestRunner::RunTestGMPTestCodec2(GMPTestMonitor& aMonitor)
|
2014-10-14 02:04:59 +04:00
|
|
|
{
|
2015-02-10 13:48:29 +03:00
|
|
|
RunTestGMPVideoDecoder::Run(aMonitor, NS_LITERAL_CSTRING(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPTestRunner::RunTestGMPTestCodec3(GMPTestMonitor& aMonitor)
|
|
|
|
{
|
|
|
|
RunTestGMPVideoEncoder::Run(aMonitor, NS_LITERAL_CSTRING(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class Base>
|
|
|
|
class RunTestGMPCrossOrigin : public Base
|
|
|
|
{
|
|
|
|
public:
|
2016-01-18 06:50:29 +03:00
|
|
|
void Done(typename Base::GMPCodecType* aGMP, GMPVideoHost* aHost) override
|
2015-02-10 13:48:29 +03:00
|
|
|
{
|
|
|
|
EXPECT_TRUE(aGMP);
|
|
|
|
|
|
|
|
UniquePtr<typename Base::GMPCallbackType> callback(
|
|
|
|
new Step2(Base::mMonitor, aGMP, mShouldBeEqual));
|
|
|
|
nsresult rv = Base::Get(mOrigin2, Move(callback));
|
|
|
|
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
Base::mMonitor.SetFinished();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Run(GMPTestMonitor& aMonitor, const nsCString& aOrigin1,
|
|
|
|
const nsCString& aOrigin2)
|
|
|
|
{
|
|
|
|
UniquePtr<typename Base::GMPCallbackType> callback(
|
|
|
|
new RunTestGMPCrossOrigin<Base>(aMonitor, aOrigin1, aOrigin2));
|
|
|
|
nsresult rv = Base::Get(aOrigin1, Move(callback));
|
|
|
|
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aMonitor.SetFinished();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RunTestGMPCrossOrigin(GMPTestMonitor& aMonitor, const nsCString& aOrigin1,
|
|
|
|
const nsCString& aOrigin2)
|
|
|
|
: Base(aMonitor),
|
|
|
|
mGMP(nullptr),
|
|
|
|
mOrigin2(aOrigin2),
|
|
|
|
mShouldBeEqual(aOrigin1.Equals(aOrigin2))
|
|
|
|
{
|
|
|
|
}
|
2014-10-14 02:04:59 +04:00
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
class Step2 : public Base
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Step2(GMPTestMonitor& aMonitor,
|
|
|
|
typename Base::GMPCodecType* aGMP,
|
|
|
|
bool aShouldBeEqual)
|
|
|
|
: Base(aMonitor),
|
|
|
|
mGMP(aGMP),
|
|
|
|
mShouldBeEqual(aShouldBeEqual)
|
|
|
|
{
|
|
|
|
}
|
2016-01-18 06:50:29 +03:00
|
|
|
void Done(typename Base::GMPCodecType* aGMP, GMPVideoHost* aHost) override
|
2015-02-10 13:48:29 +03:00
|
|
|
{
|
|
|
|
EXPECT_TRUE(aGMP);
|
|
|
|
if (aGMP) {
|
|
|
|
EXPECT_TRUE(mGMP &&
|
2015-06-05 12:55:51 +03:00
|
|
|
(mGMP->GetPluginId() == aGMP->GetPluginId()) == mShouldBeEqual);
|
2015-02-10 13:48:29 +03:00
|
|
|
}
|
|
|
|
if (mGMP) {
|
|
|
|
mGMP->Close();
|
|
|
|
}
|
|
|
|
Base::Done(aGMP, aHost);
|
|
|
|
}
|
2014-10-14 02:04:59 +04:00
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
private:
|
|
|
|
typename Base::GMPCodecType* mGMP;
|
|
|
|
bool mShouldBeEqual;
|
|
|
|
};
|
2014-10-14 02:04:59 +04:00
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
typename Base::GMPCodecType* mGMP;
|
|
|
|
nsCString mOrigin2;
|
|
|
|
bool mShouldBeEqual;
|
|
|
|
};
|
2014-10-14 02:04:59 +04:00
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
typedef RunTestGMPCrossOrigin<RunTestGMPVideoDecoder>
|
|
|
|
RunTestGMPVideoDecoderCrossOrigin;
|
|
|
|
typedef RunTestGMPCrossOrigin<RunTestGMPVideoEncoder>
|
|
|
|
RunTestGMPVideoEncoderCrossOrigin;
|
2014-10-14 02:04:59 +04:00
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
void
|
|
|
|
GMPTestRunner::RunTestGMPCrossOrigin1(GMPTestMonitor& aMonitor)
|
|
|
|
{
|
|
|
|
RunTestGMPVideoDecoderCrossOrigin::Run(
|
|
|
|
aMonitor, NS_LITERAL_CSTRING("origin1"), NS_LITERAL_CSTRING("origin2"));
|
|
|
|
}
|
2014-10-14 02:04:59 +04:00
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
void
|
|
|
|
GMPTestRunner::RunTestGMPCrossOrigin2(GMPTestMonitor& aMonitor)
|
|
|
|
{
|
|
|
|
RunTestGMPVideoEncoderCrossOrigin::Run(
|
|
|
|
aMonitor, NS_LITERAL_CSTRING("origin1"), NS_LITERAL_CSTRING("origin2"));
|
|
|
|
}
|
2014-10-14 02:04:59 +04:00
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
void
|
|
|
|
GMPTestRunner::RunTestGMPCrossOrigin3(GMPTestMonitor& aMonitor)
|
|
|
|
{
|
|
|
|
RunTestGMPVideoDecoderCrossOrigin::Run(
|
|
|
|
aMonitor, NS_LITERAL_CSTRING("origin1"), NS_LITERAL_CSTRING("origin1"));
|
|
|
|
}
|
2014-10-14 02:04:59 +04:00
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
void
|
|
|
|
GMPTestRunner::RunTestGMPCrossOrigin4(GMPTestMonitor& aMonitor)
|
|
|
|
{
|
|
|
|
RunTestGMPVideoEncoderCrossOrigin::Run(
|
|
|
|
aMonitor, NS_LITERAL_CSTRING("origin1"), NS_LITERAL_CSTRING("origin1"));
|
2014-10-14 02:04:59 +04:00
|
|
|
}
|
|
|
|
|
2014-10-23 11:37:55 +04:00
|
|
|
static already_AddRefed<nsIThread>
|
|
|
|
GetGMPThread()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GeckoMediaPluginService> service =
|
2014-10-23 11:37:55 +04:00
|
|
|
GeckoMediaPluginService::GetGeckoMediaPluginService();
|
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
EXPECT_TRUE(NS_SUCCEEDED(service->GetThread(getter_AddRefs(thread))));
|
|
|
|
return thread.forget();
|
|
|
|
}
|
|
|
|
|
2015-01-13 02:32:00 +03:00
|
|
|
/**
|
|
|
|
* Enumerate files under |aPath| (non-recursive).
|
|
|
|
*/
|
2015-01-06 20:51:00 +03:00
|
|
|
template<typename T>
|
|
|
|
static nsresult
|
2015-01-13 02:32:00 +03:00
|
|
|
EnumerateDir(nsIFile* aPath, T&& aDirIter)
|
2015-01-06 20:51:00 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> iter;
|
2015-01-13 02:32:00 +03:00
|
|
|
nsresult rv = aPath->GetDirectoryEntries(getter_AddRefs(iter));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2015-01-06 20:51:00 +03:00
|
|
|
|
|
|
|
bool hasMore = false;
|
|
|
|
while (NS_SUCCEEDED(iter->HasMoreElements(&hasMore)) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
rv = iter->GetNext(getter_AddRefs(supports));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-01-13 02:32:00 +03:00
|
|
|
|
2015-01-06 20:51:00 +03:00
|
|
|
nsCOMPtr<nsIFile> entry(do_QueryInterface(supports, &rv));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-01-13 02:32:00 +03:00
|
|
|
|
2015-01-06 20:51:00 +03:00
|
|
|
aDirIter(entry);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-13 02:32:00 +03:00
|
|
|
/**
|
2015-11-27 00:53:32 +03:00
|
|
|
* Enumerate files under $profileDir/gmp/$platform/gmp-fake/$aDir/ (non-recursive).
|
2015-01-13 02:32:00 +03:00
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
static nsresult
|
|
|
|
EnumerateGMPStorageDir(const nsACString& aDir, T&& aDirIter)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GeckoMediaPluginServiceParent> service =
|
2015-02-09 23:54:12 +03:00
|
|
|
GeckoMediaPluginServiceParent::GetSingleton();
|
2015-01-13 02:32:00 +03:00
|
|
|
MOZ_ASSERT(service);
|
|
|
|
|
2015-11-27 00:53:32 +03:00
|
|
|
// $profileDir/gmp/$platform/
|
2015-01-13 02:32:00 +03:00
|
|
|
nsCOMPtr<nsIFile> path;
|
|
|
|
nsresult rv = service->GetStorageDir(getter_AddRefs(path));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-11-27 00:53:32 +03:00
|
|
|
|
|
|
|
// $profileDir/gmp/$platform/gmp-fake/
|
|
|
|
rv = path->Append(NS_LITERAL_STRING("gmp-fake"));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// $profileDir/gmp/$platform/gmp-fake/$aDir/
|
2015-01-13 02:32:00 +03:00
|
|
|
rv = path->AppendNative(aDir);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EnumerateDir(path, aDirIter);
|
|
|
|
}
|
|
|
|
|
2014-10-23 11:37:55 +04:00
|
|
|
class GMPShutdownObserver : public nsIRunnable
|
|
|
|
, public nsIObserver {
|
|
|
|
public:
|
|
|
|
GMPShutdownObserver(nsIRunnable* aShutdownTask,
|
|
|
|
nsIRunnable* Continuation,
|
|
|
|
const nsACString& aNodeId)
|
|
|
|
: mShutdownTask(aShutdownTask)
|
|
|
|
, mContinuation(Continuation)
|
|
|
|
, mNodeId(NS_ConvertUTF8toUTF16(aNodeId))
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2014-10-23 11:37:55 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
EXPECT_TRUE(observerService);
|
|
|
|
observerService->AddObserver(this, "gmp-shutdown", false);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIThread> thread(GetGMPThread());
|
|
|
|
thread->Dispatch(mShutdownTask, NS_DISPATCH_NORMAL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
2015-03-21 19:28:04 +03:00
|
|
|
const char16_t* aSomeData) override
|
2014-10-23 11:37:55 +04:00
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, "gmp-shutdown") &&
|
|
|
|
mNodeId.Equals(nsDependentString(aSomeData))) {
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
EXPECT_TRUE(observerService);
|
|
|
|
observerService->RemoveObserver(this, "gmp-shutdown");
|
|
|
|
nsCOMPtr<nsIThread> thread(GetGMPThread());
|
|
|
|
thread->Dispatch(mContinuation, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~GMPShutdownObserver() {}
|
2015-03-17 19:29:17 +03:00
|
|
|
nsCOMPtr<nsIRunnable> mShutdownTask;
|
|
|
|
nsCOMPtr<nsIRunnable> mContinuation;
|
2014-10-23 11:37:55 +04:00
|
|
|
const nsString mNodeId;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(GMPShutdownObserver, nsIRunnable, nsIObserver)
|
|
|
|
|
2014-10-21 10:16:19 +04:00
|
|
|
class NotifyObserversTask : public nsRunnable {
|
|
|
|
public:
|
2014-10-11 01:28:35 +04:00
|
|
|
explicit NotifyObserversTask(const char* aTopic)
|
2014-10-21 10:16:19 +04:00
|
|
|
: mTopic(aTopic)
|
|
|
|
{}
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
|
|
|
observerService->NotifyObservers(nullptr, mTopic, nullptr);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
const char* mTopic;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ClearGMPStorageTask : public nsIRunnable
|
|
|
|
, public nsIObserver {
|
|
|
|
public:
|
|
|
|
ClearGMPStorageTask(nsIRunnable* Continuation,
|
2015-01-13 02:32:00 +03:00
|
|
|
nsIThread* aTarget, PRTime aSince)
|
2014-10-21 10:16:19 +04:00
|
|
|
: mContinuation(Continuation)
|
|
|
|
, mTarget(aTarget)
|
2015-01-13 02:32:00 +03:00
|
|
|
, mSince(aSince)
|
2014-10-21 10:16:19 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2014-10-21 10:16:19 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
EXPECT_TRUE(observerService);
|
|
|
|
observerService->AddObserver(this, "gmp-clear-storage-complete", false);
|
|
|
|
if (observerService) {
|
2015-01-13 02:32:00 +03:00
|
|
|
nsAutoString str;
|
|
|
|
if (mSince >= 0) {
|
|
|
|
str.AppendInt(static_cast<int64_t>(mSince));
|
|
|
|
}
|
|
|
|
observerService->NotifyObservers(
|
|
|
|
nullptr, "browser:purge-session-history", str.Data());
|
2014-10-21 10:16:19 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
2015-03-21 19:28:04 +03:00
|
|
|
const char16_t* aSomeData) override
|
2014-10-21 10:16:19 +04:00
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, "gmp-clear-storage-complete")) {
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
EXPECT_TRUE(observerService);
|
|
|
|
observerService->RemoveObserver(this, "gmp-clear-storage-complete");
|
|
|
|
mTarget->Dispatch(mContinuation, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~ClearGMPStorageTask() {}
|
2015-03-17 19:29:17 +03:00
|
|
|
nsCOMPtr<nsIRunnable> mContinuation;
|
2014-10-21 10:16:19 +04:00
|
|
|
nsCOMPtr<nsIThread> mTarget;
|
2015-01-13 02:32:00 +03:00
|
|
|
const PRTime mSince;
|
2014-10-21 10:16:19 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(ClearGMPStorageTask, nsIRunnable, nsIObserver)
|
|
|
|
|
|
|
|
static void
|
|
|
|
ClearGMPStorage(nsIRunnable* aContinuation,
|
2015-01-13 02:32:00 +03:00
|
|
|
nsIThread* aTarget, PRTime aSince = -1)
|
2014-10-21 10:16:19 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ClearGMPStorageTask> task(
|
2015-01-13 02:32:00 +03:00
|
|
|
new ClearGMPStorageTask(aContinuation, aTarget, aSince));
|
2014-10-21 10:16:19 +04:00
|
|
|
NS_DispatchToMainThread(task, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SimulatePBModeExit()
|
|
|
|
{
|
|
|
|
NS_DispatchToMainThread(new NotifyObserversTask("last-pb-context-exited"), NS_DISPATCH_SYNC);
|
|
|
|
}
|
|
|
|
|
2015-02-10 13:48:52 +03:00
|
|
|
class TestGetNodeIdCallback : public GetNodeIdCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TestGetNodeIdCallback(nsCString& aNodeId, nsresult& aResult)
|
|
|
|
: mNodeId(aNodeId),
|
|
|
|
mResult(aResult)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Done(nsresult aResult, const nsACString& aNodeId)
|
|
|
|
{
|
|
|
|
mResult = aResult;
|
|
|
|
mNodeId = aNodeId;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCString& mNodeId;
|
|
|
|
nsresult& mResult;
|
|
|
|
};
|
|
|
|
|
2014-10-21 10:16:19 +04:00
|
|
|
static nsCString
|
|
|
|
GetNodeId(const nsAString& aOrigin,
|
|
|
|
const nsAString& aTopLevelOrigin,
|
|
|
|
bool aInPBMode)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GeckoMediaPluginServiceParent> service =
|
2015-02-09 23:54:12 +03:00
|
|
|
GeckoMediaPluginServiceParent::GetSingleton();
|
2014-10-21 10:16:19 +04:00
|
|
|
EXPECT_TRUE(service);
|
|
|
|
nsCString nodeId;
|
2015-02-10 13:48:52 +03:00
|
|
|
nsresult result;
|
|
|
|
UniquePtr<GetNodeIdCallback> callback(new TestGetNodeIdCallback(nodeId,
|
|
|
|
result));
|
|
|
|
// We rely on the fact that the GetNodeId implementation for
|
|
|
|
// GeckoMediaPluginServiceParent is synchronous.
|
2014-10-21 10:16:19 +04:00
|
|
|
nsresult rv = service->GetNodeId(aOrigin,
|
|
|
|
aTopLevelOrigin,
|
2015-11-27 00:53:31 +03:00
|
|
|
NS_LITERAL_STRING("gmp-fake"),
|
2014-10-21 10:16:19 +04:00
|
|
|
aInPBMode,
|
2015-02-10 13:48:52 +03:00
|
|
|
Move(callback));
|
|
|
|
EXPECT_TRUE(NS_SUCCEEDED(rv) && NS_SUCCEEDED(result));
|
2014-10-21 10:16:19 +04:00
|
|
|
return nodeId;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsGMPStorageIsEmpty()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GeckoMediaPluginServiceParent> service =
|
2015-02-09 23:54:12 +03:00
|
|
|
GeckoMediaPluginServiceParent::GetSingleton();
|
2014-10-21 10:16:19 +04:00
|
|
|
MOZ_ASSERT(service);
|
|
|
|
nsCOMPtr<nsIFile> storage;
|
|
|
|
nsresult rv = service->GetStorageDir(getter_AddRefs(storage));
|
|
|
|
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
bool exists = false;
|
|
|
|
if (storage) {
|
|
|
|
storage->Exists(&exists);
|
|
|
|
}
|
|
|
|
return !exists;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AssertIsOnGMPThread()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GeckoMediaPluginService> service =
|
2014-10-21 10:16:19 +04:00
|
|
|
GeckoMediaPluginService::GetGeckoMediaPluginService();
|
|
|
|
MOZ_ASSERT(service);
|
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
service->GetThread(getter_AddRefs(thread));
|
|
|
|
MOZ_ASSERT(thread);
|
|
|
|
nsCOMPtr<nsIThread> currentThread;
|
|
|
|
DebugOnly<nsresult> rv = NS_GetCurrentThread(getter_AddRefs(currentThread));
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
MOZ_ASSERT(currentThread == thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
class GMPStorageTest : public GMPDecryptorProxyCallback
|
|
|
|
{
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPStorageTest)
|
|
|
|
|
|
|
|
void DoTest(void (GMPStorageTest::*aTestMethod)()) {
|
|
|
|
EnsureNSSInitializedChromeOrContent();
|
|
|
|
nsCOMPtr<nsIThread> thread(GetGMPThread());
|
|
|
|
ClearGMPStorage(NS_NewRunnableMethod(this, aTestMethod), thread);
|
|
|
|
AwaitFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
GMPStorageTest()
|
|
|
|
: mDecryptor(nullptr)
|
|
|
|
, mMonitor("GMPStorageTest")
|
|
|
|
, mFinished(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Update(const nsCString& aMessage)
|
|
|
|
{
|
|
|
|
nsTArray<uint8_t> msg;
|
|
|
|
msg.AppendElements(aMessage.get(), aMessage.Length());
|
|
|
|
mDecryptor->UpdateSession(1, NS_LITERAL_CSTRING("fake-session-id"), msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGetNodeId()
|
|
|
|
{
|
|
|
|
AssertIsOnGMPThread();
|
|
|
|
|
|
|
|
EXPECT_TRUE(IsGMPStorageIsEmpty());
|
|
|
|
|
2015-04-07 08:32:00 +03:00
|
|
|
const nsString origin1 = NS_LITERAL_STRING("http://example1.com");
|
|
|
|
const nsString origin2 = NS_LITERAL_STRING("http://example2.org");
|
2014-10-21 10:16:19 +04:00
|
|
|
|
|
|
|
nsCString PBnodeId1 = GetNodeId(origin1, origin2, true);
|
|
|
|
nsCString PBnodeId2 = GetNodeId(origin1, origin2, true);
|
|
|
|
|
|
|
|
// Node ids for the same origins should be the same in PB mode.
|
|
|
|
EXPECT_TRUE(PBnodeId1.Equals(PBnodeId2));
|
|
|
|
|
|
|
|
nsCString PBnodeId3 = GetNodeId(origin2, origin1, true);
|
|
|
|
|
|
|
|
// Node ids with origin and top level origin swapped should be different.
|
|
|
|
EXPECT_TRUE(!PBnodeId3.Equals(PBnodeId1));
|
|
|
|
|
|
|
|
// Getting node ids in PB mode should not result in the node id being stored.
|
|
|
|
EXPECT_TRUE(IsGMPStorageIsEmpty());
|
|
|
|
|
|
|
|
nsCString nodeId1 = GetNodeId(origin1, origin2, false);
|
|
|
|
nsCString nodeId2 = GetNodeId(origin1, origin2, false);
|
|
|
|
|
|
|
|
// NodeIds for the same origin pair in non-pb mode should be the same.
|
|
|
|
EXPECT_TRUE(nodeId1.Equals(nodeId2));
|
|
|
|
|
|
|
|
// Node ids for a given origin pair should be different for the PB origins should be the same in PB mode.
|
|
|
|
EXPECT_TRUE(!PBnodeId1.Equals(nodeId1));
|
|
|
|
EXPECT_TRUE(!PBnodeId2.Equals(nodeId2));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIThread> thread(GetGMPThread());
|
|
|
|
ClearGMPStorage(NS_NewRunnableMethodWithArg<nsCString>(
|
|
|
|
this, &GMPStorageTest::TestGetNodeId_Continuation, nodeId1), thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGetNodeId_Continuation(nsCString aNodeId1) {
|
|
|
|
EXPECT_TRUE(IsGMPStorageIsEmpty());
|
|
|
|
|
|
|
|
// Once we clear storage, the node ids generated for the same origin-pair
|
|
|
|
// should be different.
|
2015-04-07 08:32:00 +03:00
|
|
|
const nsString origin1 = NS_LITERAL_STRING("http://example1.com");
|
|
|
|
const nsString origin2 = NS_LITERAL_STRING("http://example2.org");
|
2014-10-21 10:16:19 +04:00
|
|
|
nsCString nodeId3 = GetNodeId(origin1, origin2, false);
|
|
|
|
EXPECT_TRUE(!aNodeId1.Equals(nodeId3));
|
|
|
|
|
|
|
|
SetFinished();
|
|
|
|
}
|
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
class CreateDecryptorDone : public GetGMPDecryptorCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CreateDecryptorDone(GMPStorageTest* aRunner, nsIRunnable* aContinuation)
|
|
|
|
: mRunner(aRunner),
|
|
|
|
mContinuation(aContinuation)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
void Done(GMPDecryptorProxy* aDecryptor) override
|
2015-02-10 13:48:29 +03:00
|
|
|
{
|
|
|
|
mRunner->mDecryptor = aDecryptor;
|
|
|
|
EXPECT_TRUE(!!mRunner->mDecryptor);
|
|
|
|
|
|
|
|
if (mRunner->mDecryptor) {
|
|
|
|
mRunner->mDecryptor->Init(mRunner);
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIThread> thread(GetGMPThread());
|
|
|
|
thread->Dispatch(mContinuation, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> mRunner;
|
2015-02-10 13:48:29 +03:00
|
|
|
nsCOMPtr<nsIRunnable> mContinuation;
|
|
|
|
};
|
|
|
|
|
|
|
|
void CreateDecryptor(const nsAString& aOrigin,
|
|
|
|
const nsAString& aTopLevelOrigin,
|
|
|
|
bool aInPBMode,
|
|
|
|
const nsCString& aUpdate)
|
|
|
|
{
|
|
|
|
nsTArray<nsCString> updates;
|
|
|
|
updates.AppendElement(aUpdate);
|
|
|
|
CreateDecryptor(aOrigin, aTopLevelOrigin, aInPBMode, Move(updates));
|
|
|
|
}
|
|
|
|
class Updates : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Updates(GMPStorageTest* aRunner, nsTArray<nsCString>&& aUpdates)
|
|
|
|
: mRunner(aRunner),
|
|
|
|
mUpdates(aUpdates)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
for (auto& update : mUpdates) {
|
|
|
|
mRunner->Update(update);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> mRunner;
|
2015-02-10 13:48:29 +03:00
|
|
|
nsTArray<nsCString> mUpdates;
|
|
|
|
};
|
|
|
|
void CreateDecryptor(const nsAString& aOrigin,
|
|
|
|
const nsAString& aTopLevelOrigin,
|
|
|
|
bool aInPBMode,
|
|
|
|
nsTArray<nsCString>&& aUpdates) {
|
|
|
|
nsCOMPtr<nsIRunnable> updates(new Updates(this, Move(aUpdates)));
|
|
|
|
CreateDecryptor(aOrigin, aTopLevelOrigin, aInPBMode, updates);
|
|
|
|
}
|
2014-10-21 10:16:19 +04:00
|
|
|
void CreateDecryptor(const nsAString& aOrigin,
|
|
|
|
const nsAString& aTopLevelOrigin,
|
2015-02-10 13:48:29 +03:00
|
|
|
bool aInPBMode,
|
|
|
|
nsIRunnable* aContinuation) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GeckoMediaPluginService> service =
|
2014-10-21 10:16:19 +04:00
|
|
|
GeckoMediaPluginService::GetGeckoMediaPluginService();
|
|
|
|
EXPECT_TRUE(service);
|
|
|
|
|
2014-10-23 11:37:55 +04:00
|
|
|
mNodeId = GetNodeId(aOrigin, aTopLevelOrigin, aInPBMode);
|
|
|
|
EXPECT_TRUE(!mNodeId.IsEmpty());
|
2014-10-21 10:16:19 +04:00
|
|
|
|
|
|
|
nsTArray<nsCString> tags;
|
|
|
|
tags.AppendElement(NS_LITERAL_CSTRING("fake"));
|
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
UniquePtr<GetGMPDecryptorCallback> callback(
|
|
|
|
new CreateDecryptorDone(this, aContinuation));
|
|
|
|
nsresult rv =
|
|
|
|
service->GetGMPDecryptor(&tags, mNodeId, Move(callback));
|
2014-10-21 10:16:19 +04:00
|
|
|
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestBasicStorage() {
|
|
|
|
AssertIsOnGMPThread();
|
|
|
|
EXPECT_TRUE(IsGMPStorageIsEmpty());
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GeckoMediaPluginService> service =
|
2014-10-21 10:16:19 +04:00
|
|
|
GeckoMediaPluginService::GetGeckoMediaPluginService();
|
|
|
|
|
|
|
|
// Send a message to the fake GMP for it to run its own tests internally.
|
|
|
|
// It sends us a "test-storage complete" message when its passed, or
|
|
|
|
// some other message if its tests fail.
|
|
|
|
Expect(NS_LITERAL_CSTRING("test-storage complete"),
|
|
|
|
NS_NewRunnableMethod(this, &GMPStorageTest::SetFinished));
|
2015-02-10 13:48:29 +03:00
|
|
|
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://example1.com"),
|
|
|
|
NS_LITERAL_STRING("http://example2.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
false,
|
|
|
|
NS_LITERAL_CSTRING("test-storage"));
|
2014-10-21 10:16:19 +04:00
|
|
|
}
|
|
|
|
|
2015-01-06 20:51:00 +03:00
|
|
|
/**
|
|
|
|
* 1. Generate storage data for some sites.
|
|
|
|
* 2. Forget about one of the sites.
|
|
|
|
* 3. Check if the storage data for the forgotten site are erased correctly.
|
|
|
|
* 4. Check if the storage data for other sites remain unchanged.
|
|
|
|
*/
|
|
|
|
void TestForgetThisSite() {
|
|
|
|
AssertIsOnGMPThread();
|
|
|
|
EXPECT_TRUE(IsGMPStorageIsEmpty());
|
|
|
|
|
|
|
|
// Generate storage data for some site.
|
|
|
|
nsCOMPtr<nsIRunnable> r = NS_NewRunnableMethod(
|
|
|
|
this, &GMPStorageTest::TestForgetThisSite_AnotherSite);
|
|
|
|
Expect(NS_LITERAL_CSTRING("test-storage complete"), r);
|
2015-02-10 13:48:29 +03:00
|
|
|
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://example1.com"),
|
|
|
|
NS_LITERAL_STRING("http://example2.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
false,
|
|
|
|
NS_LITERAL_CSTRING("test-storage"));
|
2015-01-06 20:51:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestForgetThisSite_AnotherSite() {
|
|
|
|
Shutdown();
|
|
|
|
|
|
|
|
// Generate storage data for another site.
|
|
|
|
nsCOMPtr<nsIRunnable> r = NS_NewRunnableMethod(
|
|
|
|
this, &GMPStorageTest::TestForgetThisSite_CollectSiteInfo);
|
|
|
|
Expect(NS_LITERAL_CSTRING("test-storage complete"), r);
|
2015-02-10 13:48:29 +03:00
|
|
|
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://example3.com"),
|
|
|
|
NS_LITERAL_STRING("http://example4.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
false,
|
|
|
|
NS_LITERAL_CSTRING("test-storage"));
|
2015-01-06 20:51:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
struct NodeInfo {
|
|
|
|
explicit NodeInfo(const nsACString& aSite) : siteToForget(aSite) {}
|
|
|
|
nsCString siteToForget;
|
|
|
|
nsTArray<nsCString> expectedRemainingNodeIds;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeIdCollector {
|
|
|
|
public:
|
|
|
|
explicit NodeIdCollector(NodeInfo* aInfo) : mNodeInfo(aInfo) {}
|
|
|
|
void operator()(nsIFile* aFile) {
|
|
|
|
nsCString salt;
|
|
|
|
nsresult rv = ReadSalt(aFile, salt);
|
|
|
|
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
if (!MatchOrigin(aFile, mNodeInfo->siteToForget)) {
|
|
|
|
mNodeInfo->expectedRemainingNodeIds.AppendElement(salt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
NodeInfo* mNodeInfo;
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestForgetThisSite_CollectSiteInfo() {
|
|
|
|
nsAutoPtr<NodeInfo> siteInfo(
|
2015-04-07 08:32:00 +03:00
|
|
|
new NodeInfo(NS_LITERAL_CSTRING("http://example1.com")));
|
2015-01-06 20:51:00 +03:00
|
|
|
// Collect nodeIds that are expected to remain for later comparison.
|
2015-01-13 02:32:00 +03:00
|
|
|
EnumerateGMPStorageDir(NS_LITERAL_CSTRING("id"), NodeIdCollector(siteInfo));
|
2015-01-06 20:51:00 +03:00
|
|
|
// Invoke "Forget this site" on the main thread.
|
|
|
|
NS_DispatchToMainThread(NS_NewRunnableMethodWithArg<nsAutoPtr<NodeInfo>>(
|
|
|
|
this, &GMPStorageTest::TestForgetThisSite_Forget, siteInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestForgetThisSite_Forget(nsAutoPtr<NodeInfo> aSiteInfo) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GeckoMediaPluginServiceParent> service =
|
2015-02-09 23:54:12 +03:00
|
|
|
GeckoMediaPluginServiceParent::GetSingleton();
|
2015-01-06 20:51:00 +03:00
|
|
|
service->ForgetThisSite(NS_ConvertUTF8toUTF16(aSiteInfo->siteToForget));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
service->GetThread(getter_AddRefs(thread));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> r = NS_NewRunnableMethodWithArg<nsAutoPtr<NodeInfo>>(
|
|
|
|
this, &GMPStorageTest::TestForgetThisSite_Verify, aSiteInfo);
|
|
|
|
thread->Dispatch(r, NS_DISPATCH_NORMAL);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> f = NS_NewRunnableMethod(
|
|
|
|
this, &GMPStorageTest::SetFinished);
|
|
|
|
thread->Dispatch(f, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
class NodeIdVerifier {
|
|
|
|
public:
|
|
|
|
explicit NodeIdVerifier(const NodeInfo* aInfo)
|
|
|
|
: mNodeInfo(aInfo)
|
|
|
|
, mExpectedRemainingNodeIds(aInfo->expectedRemainingNodeIds) {}
|
|
|
|
void operator()(nsIFile* aFile) {
|
|
|
|
nsCString salt;
|
|
|
|
nsresult rv = ReadSalt(aFile, salt);
|
|
|
|
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
// Shouldn't match the origin if we clear correctly.
|
|
|
|
EXPECT_FALSE(MatchOrigin(aFile, mNodeInfo->siteToForget));
|
|
|
|
// Check if remaining nodeIDs are as expected.
|
|
|
|
EXPECT_TRUE(mExpectedRemainingNodeIds.RemoveElement(salt));
|
|
|
|
}
|
|
|
|
~NodeIdVerifier() {
|
|
|
|
EXPECT_TRUE(mExpectedRemainingNodeIds.IsEmpty());
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
const NodeInfo* mNodeInfo;
|
|
|
|
nsTArray<nsCString> mExpectedRemainingNodeIds;
|
|
|
|
};
|
|
|
|
|
|
|
|
class StorageVerifier {
|
|
|
|
public:
|
|
|
|
explicit StorageVerifier(const NodeInfo* aInfo)
|
|
|
|
: mExpectedRemainingNodeIds(aInfo->expectedRemainingNodeIds) {}
|
|
|
|
void operator()(nsIFile* aFile) {
|
|
|
|
nsCString salt;
|
|
|
|
nsresult rv = aFile->GetNativeLeafName(salt);
|
|
|
|
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
EXPECT_TRUE(mExpectedRemainingNodeIds.RemoveElement(salt));
|
|
|
|
}
|
|
|
|
~StorageVerifier() {
|
|
|
|
EXPECT_TRUE(mExpectedRemainingNodeIds.IsEmpty());
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsTArray<nsCString> mExpectedRemainingNodeIds;
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestForgetThisSite_Verify(nsAutoPtr<NodeInfo> aSiteInfo) {
|
2015-01-13 02:32:00 +03:00
|
|
|
nsresult rv = EnumerateGMPStorageDir(
|
2015-01-06 20:51:00 +03:00
|
|
|
NS_LITERAL_CSTRING("id"), NodeIdVerifier(aSiteInfo));
|
|
|
|
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
|
2015-01-13 02:32:00 +03:00
|
|
|
rv = EnumerateGMPStorageDir(
|
2015-01-06 20:51:00 +03:00
|
|
|
NS_LITERAL_CSTRING("storage"), StorageVerifier(aSiteInfo));
|
|
|
|
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
}
|
|
|
|
|
2015-01-13 02:32:00 +03:00
|
|
|
/**
|
|
|
|
* 1. Generate some storage data.
|
2015-11-27 00:53:32 +03:00
|
|
|
* 2. Find the max mtime |t| in $profileDir/gmp/$platform/gmp-fake/id/.
|
2015-01-13 02:32:00 +03:00
|
|
|
* 3. Pass |t| to clear recent history.
|
2015-11-27 00:53:32 +03:00
|
|
|
* 4. Check if all directories in $profileDir/gmp/$platform/gmp-fake/id/ and
|
|
|
|
* $profileDir/gmp/$platform/gmp-fake/storage are removed.
|
2015-01-13 02:32:00 +03:00
|
|
|
*/
|
|
|
|
void TestClearRecentHistory1() {
|
|
|
|
AssertIsOnGMPThread();
|
|
|
|
EXPECT_TRUE(IsGMPStorageIsEmpty());
|
|
|
|
|
|
|
|
// Generate storage data for some site.
|
|
|
|
nsCOMPtr<nsIRunnable> r = NS_NewRunnableMethod(
|
|
|
|
this, &GMPStorageTest::TestClearRecentHistory1_Clear);
|
|
|
|
Expect(NS_LITERAL_CSTRING("test-storage complete"), r);
|
|
|
|
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://example1.com"),
|
|
|
|
NS_LITERAL_STRING("http://example2.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
false,
|
|
|
|
NS_LITERAL_CSTRING("test-storage"));
|
|
|
|
}
|
2015-01-13 02:32:00 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 1. Generate some storage data.
|
2015-11-27 00:53:32 +03:00
|
|
|
* 2. Find the max mtime |t| in $profileDir/gmp/$platform/gmp-fake/storage/.
|
2015-01-13 02:32:00 +03:00
|
|
|
* 3. Pass |t| to clear recent history.
|
2015-11-27 00:53:32 +03:00
|
|
|
* 4. Check if all directories in $profileDir/gmp/$platform/gmp-fake/id/ and
|
|
|
|
* $profileDir/gmp/$platform/gmp-fake/storage are removed.
|
2015-01-13 02:32:00 +03:00
|
|
|
*/
|
|
|
|
void TestClearRecentHistory2() {
|
|
|
|
AssertIsOnGMPThread();
|
|
|
|
EXPECT_TRUE(IsGMPStorageIsEmpty());
|
|
|
|
|
|
|
|
// Generate storage data for some site.
|
|
|
|
nsCOMPtr<nsIRunnable> r = NS_NewRunnableMethod(
|
|
|
|
this, &GMPStorageTest::TestClearRecentHistory2_Clear);
|
|
|
|
Expect(NS_LITERAL_CSTRING("test-storage complete"), r);
|
|
|
|
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://example1.com"),
|
|
|
|
NS_LITERAL_STRING("http://example2.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
false,
|
|
|
|
NS_LITERAL_CSTRING("test-storage"));
|
2015-01-13 02:32:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 1. Generate some storage data.
|
2015-11-27 00:53:32 +03:00
|
|
|
* 2. Find the max mtime |t| in $profileDir/gmp/$platform/gmp-fake/storage/.
|
2015-01-13 02:32:00 +03:00
|
|
|
* 3. Pass |t+1| to clear recent history.
|
2015-11-27 00:53:32 +03:00
|
|
|
* 4. Check if all directories in $profileDir/gmp/$platform/gmp-fake/id/ and
|
|
|
|
* $profileDir/gmp/$platform/gmp-fake/storage remain unchanged.
|
2015-01-13 02:32:00 +03:00
|
|
|
*/
|
|
|
|
void TestClearRecentHistory3() {
|
|
|
|
AssertIsOnGMPThread();
|
|
|
|
EXPECT_TRUE(IsGMPStorageIsEmpty());
|
|
|
|
|
|
|
|
// Generate storage data for some site.
|
|
|
|
nsCOMPtr<nsIRunnable> r = NS_NewRunnableMethod(
|
|
|
|
this, &GMPStorageTest::TestClearRecentHistory3_Clear);
|
|
|
|
Expect(NS_LITERAL_CSTRING("test-storage complete"), r);
|
|
|
|
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://example1.com"),
|
|
|
|
NS_LITERAL_STRING("http://example2.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
false,
|
|
|
|
NS_LITERAL_CSTRING("test-storage"));
|
2015-01-13 02:32:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class MaxMTimeFinder {
|
|
|
|
public:
|
|
|
|
MaxMTimeFinder() : mMaxTime(0) {}
|
|
|
|
void operator()(nsIFile* aFile) {
|
|
|
|
PRTime lastModified;
|
|
|
|
nsresult rv = aFile->GetLastModifiedTime(&lastModified);
|
|
|
|
if (NS_SUCCEEDED(rv) && lastModified > mMaxTime) {
|
|
|
|
mMaxTime = lastModified;
|
|
|
|
}
|
|
|
|
EnumerateDir(aFile, *this);
|
|
|
|
}
|
|
|
|
PRTime GetResult() const { return mMaxTime; }
|
|
|
|
private:
|
|
|
|
PRTime mMaxTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestClearRecentHistory1_Clear() {
|
|
|
|
MaxMTimeFinder f;
|
|
|
|
nsresult rv = EnumerateGMPStorageDir(NS_LITERAL_CSTRING("id"), f);
|
|
|
|
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> r = NS_NewRunnableMethod(
|
|
|
|
this, &GMPStorageTest::TestClearRecentHistory_CheckEmpty);
|
|
|
|
nsCOMPtr<nsIThread> t(GetGMPThread());
|
|
|
|
ClearGMPStorage(r, t, f.GetResult());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestClearRecentHistory2_Clear() {
|
|
|
|
MaxMTimeFinder f;
|
|
|
|
nsresult rv = EnumerateGMPStorageDir(NS_LITERAL_CSTRING("storage"), f);
|
|
|
|
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> r = NS_NewRunnableMethod(
|
|
|
|
this, &GMPStorageTest::TestClearRecentHistory_CheckEmpty);
|
|
|
|
nsCOMPtr<nsIThread> t(GetGMPThread());
|
|
|
|
ClearGMPStorage(r, t, f.GetResult());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestClearRecentHistory3_Clear() {
|
|
|
|
MaxMTimeFinder f;
|
|
|
|
nsresult rv = EnumerateGMPStorageDir(NS_LITERAL_CSTRING("storage"), f);
|
|
|
|
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> r = NS_NewRunnableMethod(
|
|
|
|
this, &GMPStorageTest::TestClearRecentHistory_CheckNonEmpty);
|
|
|
|
nsCOMPtr<nsIThread> t(GetGMPThread());
|
|
|
|
ClearGMPStorage(r, t, f.GetResult() + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
class FileCounter {
|
|
|
|
public:
|
|
|
|
FileCounter() : mCount(0) {}
|
|
|
|
void operator()(nsIFile* aFile) {
|
|
|
|
++mCount;
|
|
|
|
}
|
|
|
|
int GetCount() const { return mCount; }
|
|
|
|
private:
|
|
|
|
int mCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestClearRecentHistory_CheckEmpty() {
|
|
|
|
FileCounter c1;
|
|
|
|
nsresult rv = EnumerateGMPStorageDir(NS_LITERAL_CSTRING("id"), c1);
|
|
|
|
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
2015-11-27 00:53:32 +03:00
|
|
|
// There should be no files under $profileDir/gmp/$platform/gmp-fake/id/
|
2015-01-13 02:32:00 +03:00
|
|
|
EXPECT_EQ(c1.GetCount(), 0);
|
|
|
|
|
|
|
|
FileCounter c2;
|
|
|
|
rv = EnumerateGMPStorageDir(NS_LITERAL_CSTRING("storage"), c2);
|
|
|
|
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
2015-11-27 00:53:32 +03:00
|
|
|
// There should be no files under $profileDir/gmp/$platform/gmp-fake/storage/
|
2015-01-13 02:32:00 +03:00
|
|
|
EXPECT_EQ(c2.GetCount(), 0);
|
|
|
|
|
|
|
|
SetFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestClearRecentHistory_CheckNonEmpty() {
|
|
|
|
FileCounter c1;
|
|
|
|
nsresult rv = EnumerateGMPStorageDir(NS_LITERAL_CSTRING("id"), c1);
|
|
|
|
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
2015-11-27 00:53:32 +03:00
|
|
|
// There should be one directory under $profileDir/gmp/$platform/gmp-fake/id/
|
2015-01-13 02:32:00 +03:00
|
|
|
EXPECT_EQ(c1.GetCount(), 1);
|
|
|
|
|
|
|
|
FileCounter c2;
|
|
|
|
rv = EnumerateGMPStorageDir(NS_LITERAL_CSTRING("storage"), c2);
|
|
|
|
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
2015-11-27 00:53:32 +03:00
|
|
|
// There should be one directory under $profileDir/gmp/$platform/gmp-fake/storage/
|
2015-01-13 02:32:00 +03:00
|
|
|
EXPECT_EQ(c2.GetCount(), 1);
|
|
|
|
|
|
|
|
SetFinished();
|
|
|
|
}
|
|
|
|
|
2014-10-21 10:16:19 +04:00
|
|
|
void TestCrossOriginStorage() {
|
|
|
|
EXPECT_TRUE(!mDecryptor);
|
|
|
|
|
|
|
|
// Send the decryptor the message "store recordid $time"
|
|
|
|
// Wait for the decrytor to send us "stored recordid $time"
|
|
|
|
auto t = time(0);
|
|
|
|
nsCString response("stored crossOriginTestRecordId ");
|
|
|
|
response.AppendInt((int64_t)t);
|
|
|
|
Expect(response, NS_NewRunnableMethod(this,
|
|
|
|
&GMPStorageTest::TestCrossOriginStorage_RecordStoredContinuation));
|
|
|
|
|
|
|
|
nsCString update("store crossOriginTestRecordId ");
|
|
|
|
update.AppendInt((int64_t)t);
|
2015-02-10 13:48:29 +03:00
|
|
|
|
|
|
|
// Open decryptor on one, origin, write a record, and test that that
|
|
|
|
// record can't be read on another origin.
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://example3.com"),
|
|
|
|
NS_LITERAL_STRING("http://example4.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
false,
|
|
|
|
update);
|
2014-10-21 10:16:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestCrossOriginStorage_RecordStoredContinuation() {
|
|
|
|
// Close the old decryptor, and create a new one on a different origin,
|
|
|
|
// and try to read the record.
|
|
|
|
Shutdown();
|
|
|
|
|
|
|
|
Expect(NS_LITERAL_CSTRING("retrieve crossOriginTestRecordId succeeded (length 0 bytes)"),
|
|
|
|
NS_NewRunnableMethod(this, &GMPStorageTest::SetFinished));
|
2015-02-10 13:48:29 +03:00
|
|
|
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://example5.com"),
|
|
|
|
NS_LITERAL_STRING("http://example6.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
false,
|
|
|
|
NS_LITERAL_CSTRING("retrieve crossOriginTestRecordId"));
|
2014-10-21 10:16:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestPBStorage() {
|
|
|
|
// Send the decryptor the message "store recordid $time"
|
|
|
|
// Wait for the decrytor to send us "stored recordid $time"
|
|
|
|
nsCString response("stored pbdata test-pb-data");
|
|
|
|
Expect(response, NS_NewRunnableMethod(this,
|
|
|
|
&GMPStorageTest::TestPBStorage_RecordStoredContinuation));
|
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
// Open decryptor on one, origin, write a record, close decryptor,
|
|
|
|
// open another, and test that record can be read, close decryptor,
|
|
|
|
// then send pb-last-context-closed notification, then open decryptor
|
|
|
|
// and check that it can't read that data; it should have been purged.
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://pb1.com"),
|
|
|
|
NS_LITERAL_STRING("http://pb2.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
true,
|
|
|
|
NS_LITERAL_CSTRING("store pbdata test-pb-data"));
|
2014-10-21 10:16:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestPBStorage_RecordStoredContinuation() {
|
|
|
|
Shutdown();
|
|
|
|
|
|
|
|
Expect(NS_LITERAL_CSTRING("retrieve pbdata succeeded (length 12 bytes)"),
|
|
|
|
NS_NewRunnableMethod(this,
|
|
|
|
&GMPStorageTest::TestPBStorage_RecordRetrievedContinuation));
|
2015-02-10 13:48:29 +03:00
|
|
|
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://pb1.com"),
|
|
|
|
NS_LITERAL_STRING("http://pb2.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
true,
|
|
|
|
NS_LITERAL_CSTRING("retrieve pbdata"));
|
2014-10-21 10:16:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestPBStorage_RecordRetrievedContinuation() {
|
|
|
|
Shutdown();
|
|
|
|
SimulatePBModeExit();
|
|
|
|
|
|
|
|
Expect(NS_LITERAL_CSTRING("retrieve pbdata succeeded (length 0 bytes)"),
|
|
|
|
NS_NewRunnableMethod(this,
|
|
|
|
&GMPStorageTest::SetFinished));
|
2015-02-10 13:48:29 +03:00
|
|
|
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://pb1.com"),
|
|
|
|
NS_LITERAL_STRING("http://pb2.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
true,
|
|
|
|
NS_LITERAL_CSTRING("retrieve pbdata"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void NextAsyncShutdownTimeoutTest(nsIRunnable* aContinuation)
|
|
|
|
{
|
|
|
|
if (mDecryptor) {
|
|
|
|
Update(NS_LITERAL_CSTRING("shutdown-mode timeout"));
|
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIThread> thread(GetGMPThread());
|
|
|
|
thread->Dispatch(aContinuation, NS_DISPATCH_NORMAL);
|
2014-10-23 11:37:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void CreateAsyncShutdownTimeoutGMP(const nsAString& aOrigin1,
|
2015-02-10 13:48:29 +03:00
|
|
|
const nsAString& aOrigin2,
|
|
|
|
void (GMPStorageTest::*aCallback)()) {
|
|
|
|
nsCOMPtr<nsIRunnable> continuation(
|
|
|
|
NS_NewRunnableMethodWithArg<nsCOMPtr<nsIRunnable>>(
|
|
|
|
this,
|
|
|
|
&GMPStorageTest::NextAsyncShutdownTimeoutTest,
|
|
|
|
NS_NewRunnableMethod(this, aCallback)));
|
|
|
|
|
|
|
|
CreateDecryptor(aOrigin1, aOrigin2, false, continuation);
|
2014-10-23 11:37:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestAsyncShutdownTimeout() {
|
|
|
|
// Create decryptors that timeout in their async shutdown.
|
|
|
|
// If the gtest hangs on shutdown, test fails!
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateAsyncShutdownTimeoutGMP(NS_LITERAL_STRING("http://example7.com"),
|
|
|
|
NS_LITERAL_STRING("http://example8.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
&GMPStorageTest::TestAsyncShutdownTimeout2);
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestAsyncShutdownTimeout2() {
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateAsyncShutdownTimeoutGMP(NS_LITERAL_STRING("http://example9.com"),
|
|
|
|
NS_LITERAL_STRING("http://example10.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
&GMPStorageTest::TestAsyncShutdownTimeout3);
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestAsyncShutdownTimeout3() {
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateAsyncShutdownTimeoutGMP(NS_LITERAL_STRING("http://example11.com"),
|
|
|
|
NS_LITERAL_STRING("http://example12.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
&GMPStorageTest::SetFinished);
|
2014-10-23 11:37:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void TestAsyncShutdownStorage() {
|
|
|
|
// Instruct the GMP to write a token (the current timestamp, so it's
|
|
|
|
// unique) during async shutdown, then shutdown the plugin, re-create
|
|
|
|
// it, and check that the token was successfully stored.
|
|
|
|
auto t = time(0);
|
|
|
|
nsCString update("shutdown-mode token ");
|
|
|
|
nsCString token;
|
|
|
|
token.AppendInt((int64_t)t);
|
|
|
|
update.Append(token);
|
|
|
|
|
|
|
|
// Wait for a response from the GMP, so we know it's had time to receive
|
|
|
|
// the token.
|
|
|
|
nsCString response("shutdown-token received ");
|
|
|
|
response.Append(token);
|
|
|
|
Expect(response, NS_NewRunnableMethodWithArg<nsCString>(this,
|
|
|
|
&GMPStorageTest::TestAsyncShutdownStorage_ReceivedShutdownToken, token));
|
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
// Test that a GMP can write to storage during shutdown, and retrieve
|
|
|
|
// that written data in a subsequent session.
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://example13.com"),
|
|
|
|
NS_LITERAL_STRING("http://example14.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
false,
|
|
|
|
update);
|
2014-10-23 11:37:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestAsyncShutdownStorage_ReceivedShutdownToken(const nsCString& aToken) {
|
|
|
|
ShutdownThen(NS_NewRunnableMethodWithArg<nsCString>(this,
|
|
|
|
&GMPStorageTest::TestAsyncShutdownStorage_AsyncShutdownComplete, aToken));
|
|
|
|
}
|
2014-10-21 10:16:19 +04:00
|
|
|
|
2014-10-23 11:37:55 +04:00
|
|
|
void TestAsyncShutdownStorage_AsyncShutdownComplete(const nsCString& aToken) {
|
|
|
|
// Create a new instance of the plugin, retrieve the token written
|
|
|
|
// during shutdown and verify it is correct.
|
|
|
|
nsCString response("retrieved shutdown-token ");
|
|
|
|
response.Append(aToken);
|
|
|
|
Expect(response,
|
|
|
|
NS_NewRunnableMethod(this, &GMPStorageTest::SetFinished));
|
2015-02-10 13:48:29 +03:00
|
|
|
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://example13.com"),
|
|
|
|
NS_LITERAL_STRING("http://example14.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
false,
|
|
|
|
NS_LITERAL_CSTRING("retrieve-shutdown-token"));
|
2014-10-21 10:16:19 +04:00
|
|
|
}
|
|
|
|
|
2014-11-03 13:02:30 +03:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
void TestOutputProtection() {
|
|
|
|
Shutdown();
|
|
|
|
|
|
|
|
Expect(NS_LITERAL_CSTRING("OP tests completed"),
|
|
|
|
NS_NewRunnableMethod(this, &GMPStorageTest::SetFinished));
|
2015-02-10 13:48:29 +03:00
|
|
|
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://example15.com"),
|
|
|
|
NS_LITERAL_STRING("http://example16.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
false,
|
|
|
|
NS_LITERAL_CSTRING("test-op-apis"));
|
2014-11-03 13:02:30 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-11-14 11:39:39 +03:00
|
|
|
void TestPluginVoucher() {
|
|
|
|
Expect(NS_LITERAL_CSTRING("retrieved plugin-voucher: gmp-fake placeholder voucher"),
|
|
|
|
NS_NewRunnableMethod(this, &GMPStorageTest::SetFinished));
|
2015-02-10 13:48:29 +03:00
|
|
|
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://example17.com"),
|
|
|
|
NS_LITERAL_STRING("http://example18.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
false,
|
|
|
|
NS_LITERAL_CSTRING("retrieve-plugin-voucher"));
|
2014-11-14 11:39:39 +03:00
|
|
|
}
|
|
|
|
|
2014-11-21 02:25:12 +03:00
|
|
|
void TestGetRecordNamesInMemoryStorage() {
|
|
|
|
TestGetRecordNames(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString mRecordNames;
|
|
|
|
|
|
|
|
void AppendIntPadded(nsACString& aString, uint32_t aInt) {
|
|
|
|
if (aInt > 0 && aInt < 10) {
|
|
|
|
aString.AppendLiteral("0");
|
|
|
|
}
|
|
|
|
aString.AppendInt(aInt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGetRecordNames(bool aPrivateBrowsing) {
|
|
|
|
// Create a number of records of different names.
|
|
|
|
const uint32_t num = 100;
|
2015-02-10 13:48:29 +03:00
|
|
|
nsTArray<nsCString> updates(num);
|
2014-11-21 02:25:12 +03:00
|
|
|
for (uint32_t i = 0; i < num; i++) {
|
|
|
|
nsAutoCString response;
|
|
|
|
response.AppendLiteral("stored data");
|
|
|
|
AppendIntPadded(response, i);
|
|
|
|
response.AppendLiteral(" test-data");
|
|
|
|
AppendIntPadded(response, i);
|
|
|
|
|
|
|
|
if (i != 0) {
|
|
|
|
mRecordNames.AppendLiteral(",");
|
|
|
|
}
|
|
|
|
mRecordNames.AppendLiteral("data");
|
|
|
|
AppendIntPadded(mRecordNames, i);
|
|
|
|
|
2015-02-10 13:48:29 +03:00
|
|
|
nsCString& update = *updates.AppendElement();
|
2014-11-21 02:25:12 +03:00
|
|
|
update.AppendLiteral("store data");
|
|
|
|
AppendIntPadded(update, i);
|
|
|
|
update.AppendLiteral(" test-data");
|
|
|
|
AppendIntPadded(update, i);
|
|
|
|
|
|
|
|
nsIRunnable* continuation = nullptr;
|
|
|
|
if (i + 1 == num) {
|
|
|
|
continuation =
|
|
|
|
NS_NewRunnableMethod(this, &GMPStorageTest::TestGetRecordNames_QueryNames);
|
|
|
|
}
|
|
|
|
Expect(response, continuation);
|
|
|
|
}
|
2015-02-10 13:48:29 +03:00
|
|
|
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://foo.com"),
|
|
|
|
NS_LITERAL_STRING("http://bar.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
aPrivateBrowsing,
|
|
|
|
Move(updates));
|
2014-11-21 02:25:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGetRecordNames_QueryNames() {
|
|
|
|
nsCString response("record-names ");
|
|
|
|
response.Append(mRecordNames);
|
|
|
|
Expect(response,
|
|
|
|
NS_NewRunnableMethod(this, &GMPStorageTest::SetFinished));
|
|
|
|
Update(NS_LITERAL_CSTRING("retrieve-record-names"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetRecordNamesPersistentStorage() {
|
|
|
|
TestGetRecordNames(false);
|
|
|
|
}
|
|
|
|
|
2014-12-03 15:36:00 +03:00
|
|
|
void TestLongRecordNames() {
|
|
|
|
NS_NAMED_LITERAL_CSTRING(longRecordName,
|
|
|
|
"A_"
|
|
|
|
"very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
|
|
|
|
"very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
|
|
|
|
"very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
|
|
|
|
"very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
|
|
|
|
"very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
|
|
|
|
"very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
|
|
|
|
"very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
|
|
|
|
"very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
|
|
|
|
"very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
|
|
|
|
"very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
|
|
|
|
"very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
|
|
|
|
"very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
|
|
|
|
"very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
|
|
|
|
"very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
|
|
|
|
"very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
|
|
|
|
"long_record_name");
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(data, "Just_some_arbitrary_data.");
|
|
|
|
|
|
|
|
MOZ_ASSERT(longRecordName.Length() < GMP_MAX_RECORD_NAME_SIZE);
|
|
|
|
MOZ_ASSERT(longRecordName.Length() > 260); // Windows MAX_PATH
|
|
|
|
|
|
|
|
nsCString response("stored ");
|
|
|
|
response.Append(longRecordName);
|
|
|
|
response.AppendLiteral(" ");
|
|
|
|
response.Append(data);
|
|
|
|
Expect(response, NS_NewRunnableMethod(this, &GMPStorageTest::SetFinished));
|
|
|
|
|
|
|
|
nsCString update("store ");
|
|
|
|
update.Append(longRecordName);
|
|
|
|
update.AppendLiteral(" ");
|
|
|
|
update.Append(data);
|
2015-04-07 08:32:00 +03:00
|
|
|
CreateDecryptor(NS_LITERAL_STRING("http://fuz.com"),
|
|
|
|
NS_LITERAL_STRING("http://baz.com"),
|
2015-02-10 13:48:29 +03:00
|
|
|
false,
|
|
|
|
update);
|
2014-12-03 15:36:00 +03:00
|
|
|
}
|
|
|
|
|
2014-10-21 10:16:19 +04:00
|
|
|
void Expect(const nsCString& aMessage, nsIRunnable* aContinuation) {
|
|
|
|
mExpected.AppendElement(ExpectedMessage(aMessage, aContinuation));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AwaitFinished() {
|
|
|
|
while (!mFinished) {
|
|
|
|
NS_ProcessNextEvent(nullptr, true);
|
|
|
|
}
|
|
|
|
mFinished = false;
|
|
|
|
}
|
|
|
|
|
2014-10-23 11:37:55 +04:00
|
|
|
void ShutdownThen(nsIRunnable* aContinuation) {
|
|
|
|
EXPECT_TRUE(!!mDecryptor);
|
|
|
|
if (!mDecryptor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EXPECT_FALSE(mNodeId.IsEmpty());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPShutdownObserver> task(
|
2014-10-23 11:37:55 +04:00
|
|
|
new GMPShutdownObserver(NS_NewRunnableMethod(this, &GMPStorageTest::Shutdown),
|
|
|
|
aContinuation, mNodeId));
|
|
|
|
NS_DispatchToMainThread(task, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
2014-10-21 10:16:19 +04:00
|
|
|
void Shutdown() {
|
|
|
|
if (mDecryptor) {
|
|
|
|
mDecryptor->Close();
|
|
|
|
mDecryptor = nullptr;
|
2014-10-23 11:37:55 +04:00
|
|
|
mNodeId = EmptyCString();
|
2014-10-21 10:16:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dummy() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetFinished() {
|
|
|
|
mFinished = true;
|
|
|
|
Shutdown();
|
|
|
|
NS_DispatchToMainThread(NS_NewRunnableMethod(this, &GMPStorageTest::Dummy));
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
void SessionMessage(const nsCString& aSessionId,
|
|
|
|
GMPSessionMessageType aMessageType,
|
|
|
|
const nsTArray<uint8_t>& aMessage) override
|
2014-10-21 10:16:19 +04:00
|
|
|
{
|
|
|
|
MonitorAutoLock mon(mMonitor);
|
|
|
|
|
|
|
|
nsCString msg((const char*)aMessage.Elements(), aMessage.Length());
|
|
|
|
EXPECT_TRUE(mExpected.Length() > 0);
|
|
|
|
bool matches = mExpected[0].mMessage.Equals(msg);
|
2014-11-03 13:02:30 +03:00
|
|
|
EXPECT_STREQ(mExpected[0].mMessage.get(), msg.get());
|
2014-10-21 10:16:19 +04:00
|
|
|
if (mExpected.Length() > 0 && matches) {
|
2015-03-17 19:29:17 +03:00
|
|
|
nsCOMPtr<nsIRunnable> continuation = mExpected[0].mContinuation;
|
2014-10-21 10:16:19 +04:00
|
|
|
mExpected.RemoveElementAt(0);
|
|
|
|
if (continuation) {
|
|
|
|
NS_DispatchToCurrentThread(continuation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
void SetSessionId(uint32_t aCreateSessionToken,
|
|
|
|
const nsCString& aSessionId) override { }
|
|
|
|
void ResolveLoadSessionPromise(uint32_t aPromiseId,
|
|
|
|
bool aSuccess) override {}
|
|
|
|
void ResolvePromise(uint32_t aPromiseId) override {}
|
|
|
|
void RejectPromise(uint32_t aPromiseId,
|
|
|
|
nsresult aException,
|
|
|
|
const nsCString& aSessionId) override { }
|
|
|
|
void ExpirationChange(const nsCString& aSessionId,
|
|
|
|
GMPTimestamp aExpiryTime) override {}
|
|
|
|
void SessionClosed(const nsCString& aSessionId) override {}
|
|
|
|
void SessionError(const nsCString& aSessionId,
|
|
|
|
nsresult aException,
|
|
|
|
uint32_t aSystemCode,
|
|
|
|
const nsCString& aMessage) override {}
|
|
|
|
void KeyStatusChanged(const nsCString& aSessionId,
|
|
|
|
const nsTArray<uint8_t>& aKeyId,
|
|
|
|
GMPMediaKeyStatus aStatus) override { }
|
|
|
|
void SetCaps(uint64_t aCaps) override {}
|
|
|
|
void Decrypted(uint32_t aId,
|
|
|
|
GMPErr aResult,
|
|
|
|
const nsTArray<uint8_t>& aDecryptedData) override { }
|
|
|
|
void Terminated() override {
|
2015-06-05 12:55:52 +03:00
|
|
|
if (mDecryptor) {
|
|
|
|
mDecryptor->Close();
|
|
|
|
mDecryptor = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2014-10-21 10:16:19 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
~GMPStorageTest() { }
|
|
|
|
|
|
|
|
struct ExpectedMessage {
|
|
|
|
ExpectedMessage(const nsCString& aMessage, nsIRunnable* aContinuation)
|
|
|
|
: mMessage(aMessage)
|
|
|
|
, mContinuation(aContinuation)
|
|
|
|
{}
|
|
|
|
nsCString mMessage;
|
2015-03-17 19:29:17 +03:00
|
|
|
nsCOMPtr<nsIRunnable> mContinuation;
|
2014-10-21 10:16:19 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
nsTArray<ExpectedMessage> mExpected;
|
|
|
|
|
|
|
|
GMPDecryptorProxy* mDecryptor;
|
|
|
|
Monitor mMonitor;
|
|
|
|
Atomic<bool> mFinished;
|
2014-10-23 11:37:55 +04:00
|
|
|
nsCString mNodeId;
|
2014-10-21 10:16:19 +04:00
|
|
|
};
|
|
|
|
|
2014-10-14 02:04:59 +04:00
|
|
|
void
|
2015-02-10 13:48:29 +03:00
|
|
|
GMPTestRunner::DoTest(void (GMPTestRunner::*aTestMethod)(GMPTestMonitor&))
|
2014-10-14 02:04:59 +04:00
|
|
|
{
|
2015-02-10 13:48:29 +03:00
|
|
|
nsCOMPtr<nsIThread> thread(GetGMPThread());
|
|
|
|
|
|
|
|
GMPTestMonitor monitor;
|
|
|
|
thread->Dispatch(NS_NewRunnableMethodWithArg<GMPTestMonitor&>(this,
|
|
|
|
aTestMethod,
|
|
|
|
monitor),
|
|
|
|
NS_DISPATCH_NORMAL);
|
|
|
|
monitor.AwaitFinished();
|
2014-10-14 02:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GeckoMediaPlugins, GMPTestCodec) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPTestRunner> runner = new GMPTestRunner();
|
2015-02-10 13:48:29 +03:00
|
|
|
runner->DoTest(&GMPTestRunner::RunTestGMPTestCodec1);
|
|
|
|
runner->DoTest(&GMPTestRunner::RunTestGMPTestCodec2);
|
|
|
|
runner->DoTest(&GMPTestRunner::RunTestGMPTestCodec3);
|
2014-10-14 02:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GeckoMediaPlugins, GMPCrossOrigin) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPTestRunner> runner = new GMPTestRunner();
|
2015-02-10 13:48:29 +03:00
|
|
|
runner->DoTest(&GMPTestRunner::RunTestGMPCrossOrigin1);
|
|
|
|
runner->DoTest(&GMPTestRunner::RunTestGMPCrossOrigin2);
|
|
|
|
runner->DoTest(&GMPTestRunner::RunTestGMPCrossOrigin3);
|
|
|
|
runner->DoTest(&GMPTestRunner::RunTestGMPCrossOrigin4);
|
2014-10-14 02:04:59 +04:00
|
|
|
}
|
2014-10-21 10:16:19 +04:00
|
|
|
|
|
|
|
TEST(GeckoMediaPlugins, GMPStorageGetNodeId) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> runner = new GMPStorageTest();
|
2014-10-21 10:16:19 +04:00
|
|
|
runner->DoTest(&GMPStorageTest::TestGetNodeId);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GeckoMediaPlugins, GMPStorageBasic) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> runner = new GMPStorageTest();
|
2014-10-21 10:16:19 +04:00
|
|
|
runner->DoTest(&GMPStorageTest::TestBasicStorage);
|
|
|
|
}
|
|
|
|
|
2015-01-06 20:51:00 +03:00
|
|
|
TEST(GeckoMediaPlugins, GMPStorageForgetThisSite) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> runner = new GMPStorageTest();
|
2015-01-06 20:51:00 +03:00
|
|
|
runner->DoTest(&GMPStorageTest::TestForgetThisSite);
|
|
|
|
}
|
|
|
|
|
2015-01-13 02:32:00 +03:00
|
|
|
TEST(GeckoMediaPlugins, GMPStorageClearRecentHistory1) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> runner = new GMPStorageTest();
|
2015-01-13 02:32:00 +03:00
|
|
|
runner->DoTest(&GMPStorageTest::TestClearRecentHistory1);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GeckoMediaPlugins, GMPStorageClearRecentHistory2) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> runner = new GMPStorageTest();
|
2015-01-13 02:32:00 +03:00
|
|
|
runner->DoTest(&GMPStorageTest::TestClearRecentHistory2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GeckoMediaPlugins, GMPStorageClearRecentHistory3) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> runner = new GMPStorageTest();
|
2015-01-13 02:32:00 +03:00
|
|
|
runner->DoTest(&GMPStorageTest::TestClearRecentHistory3);
|
|
|
|
}
|
|
|
|
|
2014-10-21 10:16:19 +04:00
|
|
|
TEST(GeckoMediaPlugins, GMPStorageCrossOrigin) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> runner = new GMPStorageTest();
|
2014-10-21 10:16:19 +04:00
|
|
|
runner->DoTest(&GMPStorageTest::TestCrossOriginStorage);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GeckoMediaPlugins, GMPStoragePrivateBrowsing) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> runner = new GMPStorageTest();
|
2014-10-21 10:16:19 +04:00
|
|
|
runner->DoTest(&GMPStorageTest::TestPBStorage);
|
|
|
|
}
|
2014-10-23 11:37:55 +04:00
|
|
|
|
|
|
|
TEST(GeckoMediaPlugins, GMPStorageAsyncShutdownTimeout) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> runner = new GMPStorageTest();
|
2014-10-23 11:37:55 +04:00
|
|
|
runner->DoTest(&GMPStorageTest::TestAsyncShutdownTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GeckoMediaPlugins, GMPStorageAsyncShutdownStorage) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> runner = new GMPStorageTest();
|
2014-10-23 11:37:55 +04:00
|
|
|
runner->DoTest(&GMPStorageTest::TestAsyncShutdownStorage);
|
|
|
|
}
|
2014-11-03 13:02:30 +03:00
|
|
|
|
2014-11-14 11:39:39 +03:00
|
|
|
TEST(GeckoMediaPlugins, GMPPluginVoucher) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> runner = new GMPStorageTest();
|
2014-11-14 11:39:39 +03:00
|
|
|
runner->DoTest(&GMPStorageTest::TestPluginVoucher);
|
|
|
|
}
|
|
|
|
|
2014-11-03 13:02:30 +03:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
TEST(GeckoMediaPlugins, GMPOutputProtection) {
|
|
|
|
// Output Protection is not available pre-Vista.
|
|
|
|
if (!IsVistaOrLater()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> runner = new GMPStorageTest();
|
2014-11-03 13:02:30 +03:00
|
|
|
runner->DoTest(&GMPStorageTest::TestOutputProtection);
|
|
|
|
}
|
|
|
|
#endif
|
2014-11-21 02:25:12 +03:00
|
|
|
|
|
|
|
TEST(GeckoMediaPlugins, GMPStorageGetRecordNamesInMemoryStorage) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> runner = new GMPStorageTest();
|
2014-11-21 02:25:12 +03:00
|
|
|
runner->DoTest(&GMPStorageTest::TestGetRecordNamesInMemoryStorage);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GeckoMediaPlugins, GMPStorageGetRecordNamesPersistentStorage) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> runner = new GMPStorageTest();
|
2014-11-21 02:25:12 +03:00
|
|
|
runner->DoTest(&GMPStorageTest::GetRecordNamesPersistentStorage);
|
|
|
|
}
|
2014-12-03 15:36:00 +03:00
|
|
|
|
|
|
|
TEST(GeckoMediaPlugins, GMPStorageLongRecordNames) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPStorageTest> runner = new GMPStorageTest();
|
2014-12-03 15:36:00 +03:00
|
|
|
runner->DoTest(&GMPStorageTest::TestLongRecordNames);
|
|
|
|
}
|