Bug 1072024 - GTest for cross-origin separation of Gecko Media Plugins r=cpearce

This commit is contained in:
Edwin Flores 2014-10-14 11:04:59 +13:00
parent e9665e894b
commit 070aa9c478
3 changed files with 126 additions and 0 deletions

View File

@ -0,0 +1,123 @@
/* -*- 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);
}

View File

@ -6,6 +6,7 @@
UNIFIED_SOURCES += [
'TestAudioCompactor.cpp',
'TestGMPCrossOrigin.cpp',
'TestTrackEncoder.cpp',
'TestVideoSegment.cpp',
'TestWebMBuffered.cpp'
@ -25,6 +26,7 @@ include('/ipc/chromium/chromium-config.mozbuild')
LOCAL_INCLUDES += [
'/content/media/encoder',
'/content/media/gmp',
]
FINAL_LIBRARY = 'xul-gtest'

View File

@ -67,6 +67,7 @@ class GTests(object):
"""
env["MOZILLA_FIVE_HOME"] = self.xre_path
env["MOZ_XRE_DIR"] = self.xre_path
env["MOZ_GMP_PATH"] = os.path.join(self.xre_path, "gmp-fake", "1.0")
env["XPCOM_DEBUG_BREAK"] = "stack-and-abort"
env["MOZ_CRASHREPORTER_NO_REPORT"] = "1"
env["MOZ_CRASHREPORTER"] = "1"