gecko/content/media/gtest/TestGMPCrossOrigin.cpp

124 lines
3.8 KiB
C++
Raw Normal View History

/* -*- 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"
#include "mozilla/StaticPtr.h"
#include "GMPVideoDecoderProxy.h"
#include "GMPVideoEncoderProxy.h"
#include "GMPService.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIFile.h"
#include "nsISimpleEnumerator.h"
using namespace mozilla;
using namespace mozilla::gmp;
struct GMPTestRunner
{
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPTestRunner)
void DoTest(void (GMPTestRunner::*aTestMethod)());
void RunTestGMPTestCodec();
void RunTestGMPCrossOrigin();
private:
~GMPTestRunner() { }
};
void
GMPTestRunner::RunTestGMPTestCodec()
{
nsRefPtr<GeckoMediaPluginService> service =
GeckoMediaPluginService::GetGeckoMediaPluginService();
GMPVideoHost* host = nullptr;
GMPVideoDecoderProxy* decoder = nullptr;
GMPVideoDecoderProxy* decoder2 = nullptr;
GMPVideoEncoderProxy* encoder = nullptr;
nsTArray<nsCString> tags;
tags.AppendElement(NS_LITERAL_CSTRING("h264"));
service->GetGMPVideoDecoder(&tags, NS_LITERAL_STRING("o"), &host, &decoder2);
service->GetGMPVideoDecoder(&tags, NS_LITERAL_STRING(""), &host, &decoder);
service->GetGMPVideoEncoder(&tags, NS_LITERAL_STRING(""), &host, &encoder);
EXPECT_TRUE(host);
EXPECT_TRUE(decoder);
EXPECT_TRUE(decoder2);
EXPECT_TRUE(encoder);
if (decoder) decoder->Close();
if (decoder2) decoder2->Close();
if (encoder) encoder->Close();
}
void
GMPTestRunner::RunTestGMPCrossOrigin()
{
nsRefPtr<GeckoMediaPluginService> service =
GeckoMediaPluginService::GetGeckoMediaPluginService();
GMPVideoHost* host = nullptr;
nsTArray<nsCString> tags;
tags.AppendElement(NS_LITERAL_CSTRING("h264"));
GMPVideoDecoderProxy* decoder1 = nullptr;
GMPVideoDecoderProxy* decoder2 = nullptr;
GMPVideoEncoderProxy* encoder1 = nullptr;
GMPVideoEncoderProxy* encoder2 = nullptr;
service->GetGMPVideoDecoder(&tags, NS_LITERAL_STRING("origin1"), &host, &decoder1);
service->GetGMPVideoDecoder(&tags, NS_LITERAL_STRING("origin2"), &host, &decoder2);
EXPECT_TRUE(!!decoder1 && !!decoder2 &&
decoder1->ParentID() != decoder2->ParentID());
service->GetGMPVideoEncoder(&tags, NS_LITERAL_STRING("origin1"), &host, &encoder1);
service->GetGMPVideoEncoder(&tags, NS_LITERAL_STRING("origin2"), &host, &encoder2);
EXPECT_TRUE(!!encoder1 && !!encoder2 &&
encoder1->ParentID() != encoder2->ParentID());
if (decoder2) decoder2->Close();
if (encoder2) encoder2->Close();
service->GetGMPVideoDecoder(&tags, NS_LITERAL_STRING("origin1"), &host, &decoder2);
EXPECT_TRUE(!!decoder1 && !!decoder2 &&
decoder1->ParentID() == decoder2->ParentID());
service->GetGMPVideoEncoder(&tags, NS_LITERAL_STRING("origin1"), &host, &encoder2);
EXPECT_TRUE(!!encoder1 && !!encoder2 &&
encoder1->ParentID() == encoder2->ParentID());
if (decoder1) decoder1->Close();
if (decoder2) decoder2->Close();
if (encoder1) encoder1->Close();
if (encoder2) encoder2->Close();
}
void
GMPTestRunner::DoTest(void (GMPTestRunner::*aTestMethod)())
{
nsRefPtr<GeckoMediaPluginService> service =
GeckoMediaPluginService::GetGeckoMediaPluginService();
nsCOMPtr<nsIThread> thread;
service->GetThread(getter_AddRefs(thread));
thread->Dispatch(NS_NewRunnableMethod(this, aTestMethod), NS_DISPATCH_SYNC);
}
TEST(GeckoMediaPlugins, GMPTestCodec) {
nsRefPtr<GMPTestRunner> runner = new GMPTestRunner();
runner->DoTest(&GMPTestRunner::RunTestGMPTestCodec);
}
TEST(GeckoMediaPlugins, GMPCrossOrigin) {
nsRefPtr<GMPTestRunner> runner = new GMPTestRunner();
runner->DoTest(&GMPTestRunner::RunTestGMPCrossOrigin);
}