Backed out 8 changesets (bug 1251482, bug 1251494, bug 1251473, bug 1239870) for gtest failures

Backed out changeset f064a5efbb8c (bug 1251494)
Backed out changeset 9e33adec1aa6 (bug 1251482)
Backed out changeset ab0347657e25 (bug 1251473)
Backed out changeset 1d385d4f195d (bug 1239870)
Backed out changeset ceb3e1ee7dda (bug 1239870)
Backed out changeset 8574075bf42f (bug 1239870)
Backed out changeset ba077a3afbc7 (bug 1239870)
Backed out changeset eb99ab06414d (bug 1239870)

MozReview-Commit-ID: 7r9SEk4VGNU
This commit is contained in:
Wes Kocher 2016-02-26 17:14:57 -08:00
Родитель d2d269f00a
Коммит 72d9604d91
53 изменённых файлов: 1456 добавлений и 634 удалений

Просмотреть файл

@ -199,12 +199,14 @@ AudioSegment::WriteTo(uint64_t aID, AudioMixer& aMixer, uint32_t aOutputChannels
offset += c.mDuration * aOutputChannels;
#if !defined(MOZILLA_XPCOMRT_API)
if (!c.mTimeStamp.IsNull()) {
TimeStamp now = TimeStamp::Now();
// would be more efficient to c.mTimeStamp to ms on create time then pass here
LogTime(AsyncLatencyLogger::AudioMediaStreamTrack, aID,
(now - c.mTimeStamp).ToMilliseconds(), c.mTimeStamp);
}
#endif // !defined(MOZILLA_XPCOMRT_API)
}
if (offset) {

Просмотреть файл

@ -267,7 +267,10 @@ public:
MOZ_ASSERT(channels == segmentChannelCount);
output.SetLength(channels);
bufferPtrs.SetLength(channels);
#if !defined(MOZILLA_XPCOMRT_API)
// FIXME Bug 1126414 - XPCOMRT does not support dom::WebAudioUtils::SpeexResamplerProcess
uint32_t inFrames = c.mDuration;
#endif // !defined(MOZILLA_XPCOMRT_API)
// Round up to allocate; the last frame may not be used.
NS_ASSERTION((UINT32_MAX - aInRate + 1) / c.mDuration >= aOutRate,
"Dropping samples");
@ -276,11 +279,14 @@ public:
T* out = output[i].AppendElements(outSize);
uint32_t outFrames = outSize;
#if !defined(MOZILLA_XPCOMRT_API)
// FIXME Bug 1126414 - XPCOMRT does not support dom::WebAudioUtils::SpeexResamplerProcess
const T* in = static_cast<const T*>(c.mChannelData[i]);
dom::WebAudioUtils::SpeexResamplerProcess(aResampler, i,
in, &inFrames,
out, &outFrames);
MOZ_ASSERT(inFrames == c.mDuration);
#endif // !defined(MOZILLA_XPCOMRT_API)
bufferPtrs[i] = out;
output[i].SetLength(outFrames);

Просмотреть файл

@ -39,6 +39,7 @@ VideoFrame::TakeFrom(VideoFrame* aFrame)
mForceBlack = aFrame->GetForceBlack();
}
#if !defined(MOZILLA_XPCOMRT_API)
/* static */ already_AddRefed<Image>
VideoFrame::CreateBlackImage(const gfx::IntSize& aSize)
{
@ -83,6 +84,7 @@ VideoFrame::CreateBlackImage(const gfx::IntSize& aSize)
return image.forget();
}
#endif // !defined(MOZILLA_XPCOMRT_API)
VideoChunk::VideoChunk()
{}

Просмотреть файл

@ -10,7 +10,11 @@
#include "nsCOMPtr.h"
#include "gfxPoint.h"
#include "nsAutoPtr.h"
#if defined(MOZILLA_XPCOMRT_API)
#include "SimpleImageBuffer.h"
#else
#include "ImageContainer.h"
#endif
namespace mozilla {
@ -20,7 +24,11 @@ class Image;
class VideoFrame {
public:
#if defined(MOZILLA_XPCOMRT_API)
typedef mozilla::SimpleImageBuffer Image;
#else
typedef mozilla::layers::Image Image;
#endif
VideoFrame(already_AddRefed<Image>& aImage, const gfx::IntSize& aIntrinsicSize);
VideoFrame();
@ -44,8 +52,10 @@ public:
void SetNull();
void TakeFrom(VideoFrame* aFrame);
#if !defined(MOZILLA_XPCOMRT_API)
// Create a planar YCbCr black image.
static already_AddRefed<Image> CreateBlackImage(const gfx::IntSize& aSize);
#endif // !defined(MOZILLA_XPCOMRT_API)
protected:
// mImage can be null to indicate "no video" (aka "empty frame"). It can
@ -93,7 +103,11 @@ struct VideoChunk {
class VideoSegment : public MediaSegmentBase<VideoSegment, VideoChunk> {
public:
#if defined(MOZILLA_XPCOMRT_API)
typedef mozilla::SimpleImageBuffer Image;
#else
typedef mozilla::layers::Image Image;
#endif
typedef mozilla::gfx::IntSize IntSize;
VideoSegment();

Просмотреть файл

@ -33,6 +33,7 @@ if CONFIG['MOZ_WEBRTC']:
]
DEFINES['MOZILLA_INTERNAL_API'] = True
DEFINES['MOZILLA_XPCOMRT_API'] = True
DEFINES['MOZILLA_EXTERNAL_LINKAGE'] = True
include('/ipc/chromium/chromium-config.mozbuild')

Просмотреть файл

@ -396,10 +396,15 @@ void NrIceCtx::trickle_cb(void *arg, nr_ice_ctx *ice_ctx,
s->SignalCandidate(s, candidate_str);
}
void NrIceCtx::Init(bool allow_loopback,
bool tcp_enabled,
bool allow_link_local)
{
RefPtr<NrIceCtx> NrIceCtx::Create(const std::string& name,
bool offerer,
bool allow_loopback,
bool tcp_enabled,
bool allow_link_local,
bool hide_non_default,
Policy policy) {
RefPtr<NrIceCtx> ctx = new NrIceCtx(name, offerer, policy);
// Initialize the crypto callbacks and logging stuff
if (!initialized) {
NR_reg_init(NR_REG_MODE_LOCAL);
@ -472,19 +477,6 @@ void NrIceCtx::Init(bool allow_loopback,
NR_reg_set_string((char *)NR_ICE_REG_PREF_FORCE_INTERFACE_NAME, const_cast<char*>(flat.get()));
}
}
}
RefPtr<NrIceCtx> NrIceCtx::Create(const std::string& name,
bool offerer,
bool allow_loopback,
bool tcp_enabled,
bool allow_link_local,
bool hide_non_default,
Policy policy) {
RefPtr<NrIceCtx> ctx = new NrIceCtx(name, offerer, policy);
// Initialize the crypto callbacks and logging stuff
Init(allow_loopback, tcp_enabled, allow_link_local);
// Create the ICE context
int r;

Просмотреть файл

@ -215,10 +215,6 @@ class NrIceCtx {
ICE_POLICY_ALL
};
static void Init(bool allow_loopback = false,
bool tcp_enabled = true,
bool allow_link_local = false);
// TODO(ekr@rtfm.com): Too many bools here. Bug 1193437.
static RefPtr<NrIceCtx> Create(const std::string& name,
bool offerer,

Просмотреть файл

@ -59,3 +59,19 @@ TEST_F(TestSyncRunnable, TestDispatchStatic)
SyncRunnable::DispatchToThread(gThread, r);
ASSERT_TRUE(r->ran());
}
#include "mtransport_test_utils.h"
MtransportTestUtils *test_utils;
int main(int argc, char **argv)
{
test_utils = new MtransportTestUtils();
// Start the tests
::testing::InitGoogleTest(&argc, argv);
int rv = RUN_ALL_TESTS();
delete test_utils;
return rv;
}

Просмотреть файл

@ -23,6 +23,7 @@ extern "C" {
}
#include "databuffer.h"
#include "mtransport_test_utils.h"
#include "dummysocket.h"
#include "nr_socket_prsock.h"
@ -32,6 +33,7 @@ extern "C" {
#include "gtest_utils.h"
using namespace mozilla;
MtransportTestUtils *test_utils;
static uint8_t kStunMessage[] = {
0x00, 0x01, 0x00, 0x08, 0x21, 0x12, 0xa4, 0x42,
@ -41,20 +43,17 @@ static uint8_t kStunMessage[] = {
};
static size_t kStunMessageLen = sizeof(kStunMessage);
class BufferedStunSocketTest : public MtransportTest {
class BufferedStunSocketTest : public ::testing::Test {
public:
BufferedStunSocketTest()
: MtransportTest(),
dummy_(nullptr),
test_socket_(nullptr) { }
: dummy_(nullptr),
test_socket_(nullptr) {}
~BufferedStunSocketTest() {
nr_socket_destroy(&test_socket_);
}
void SetUp() {
MtransportTest::SetUp();
RefPtr<DummySocket> dummy(new DummySocket());
int r = nr_socket_buffered_stun_create(
@ -296,3 +295,20 @@ TEST_F(BufferedStunSocketTest, TestReceiveRecvFromReallyLong) {
&addr);
ASSERT_EQ(R_BAD_DATA, r);
}
int main(int argc, char **argv)
{
test_utils = new MtransportTestUtils();
NSS_NoDB_Init(nullptr);
NSS_SetDomesticPolicy();
// Start the tests
::testing::InitGoogleTest(&argc, argv);
int rv = RUN_ALL_TESTS();
delete test_utils;
return rv;
}

Просмотреть файл

@ -13,8 +13,8 @@
#define GTEST_HAS_RTTI 0
#include "gtest/gtest.h"
#include "gtest_utils.h"
#include "mtransport_test_utils.h"
#include "runnable_utils.h"
#include "rlogringbuffer.h"

Просмотреть файл

@ -36,8 +36,8 @@
*/
// Original author: ekr@rtfm.com
#ifndef gtest_utils__h__
#define gtest_utils__h__
#ifndef gtest_utils_h__
#define gtest_utils_h__
#include <iostream>
@ -48,16 +48,6 @@
#define GTEST_HAS_RTTI 0
#include "gtest/gtest.h"
#include "gtest_ringbuffer_dumper.h"
#include "mtransport_test_utils.h"
#include "nss.h"
#include "ssl.h"
extern "C" {
#include "registry.h"
#include "transport_addr.h"
}
// Wait up to timeout seconds for expression to be true
#define WAIT(expression, timeout) \
do { \
@ -98,106 +88,4 @@ extern "C" {
ASSERT_EQ(expected, actual); \
} while(0)
using test::RingbufferDumper;
class MtransportTest : public ::testing::Test {
public:
MtransportTest()
: test_utils_(nullptr)
, dumper_(nullptr)
{
}
void SetUp() override {
test_utils_ = new MtransportTestUtils();
NSS_NoDB_Init(nullptr);
NSS_SetDomesticPolicy();
NR_reg_init(NR_REG_MODE_LOCAL);
// Attempt to load env vars used by tests.
GetEnvironment("TURN_SERVER_ADDRESS", turn_server_);
GetEnvironment("TURN_SERVER_USER", turn_user_);
GetEnvironment("TURN_SERVER_PASSWORD", turn_password_);
GetEnvironment("STUN_SERVER_ADDRESS", stun_server_address_);
GetEnvironment("STUN_SERVER_HOSTNAME", stun_server_hostname_);
std::string disable_non_local;
GetEnvironment("MOZ_DISABLE_NONLOCAL_CONNECTIONS", disable_non_local);
std::string upload_dir;
GetEnvironment("MOZ_UPLOAD_DIR", upload_dir);
if ((!disable_non_local.empty() && disable_non_local != "0") ||
!upload_dir.empty()) {
// We're assuming that MOZ_UPLOAD_DIR is only set on tbpl;
// MOZ_DISABLE_NONLOCAL_CONNECTIONS probably should be set when running the
// cpp unit-tests, but is not presently.
stun_server_address_ = "";
stun_server_hostname_ = "";
turn_server_ = "";
}
// Some tests are flaky and need to check if they're supposed to run.
webrtc_enabled_ = CheckEnvironmentFlag("MOZ_WEBRTC_TESTS");
::testing::TestEventListeners& listeners =
::testing::UnitTest::GetInstance()->listeners();
dumper_ = new RingbufferDumper(test_utils_);
listeners.Append(dumper_);
}
void TearDown() override {
::testing::UnitTest::GetInstance()->listeners().Release(dumper_);
delete dumper_;
delete test_utils_;
}
void GetEnvironment(const char* aVar, std::string& out) {
char* value = getenv(aVar);
if (value) {
out = value;
}
}
bool CheckEnvironmentFlag(const char* aVar) {
std::string value;
GetEnvironment(aVar, value);
return value == "1";
}
bool WarnIfTurnNotConfigured() const {
bool configured =
!turn_server_.empty() &&
!turn_user_.empty() &&
!turn_password_.empty();
if (configured) {
nr_transport_addr addr;
if (nr_str_port_to_transport_addr(turn_server_.c_str(), 3478,
IPPROTO_UDP, &addr)) {
printf("Invalid TURN_SERVER_ADDRESS \"%s\". Only IP numbers supported.\n",
turn_server_.c_str());
configured = false;
}
} else {
printf(
"Set TURN_SERVER_ADDRESS, TURN_SERVER_USER, and TURN_SERVER_PASSWORD\n"
"environment variables to run this test\n");
}
return !configured;
}
MtransportTestUtils* test_utils_;
RingbufferDumper* dumper_;
std::string turn_server_;
std::string turn_user_;
std::string turn_password_;
std::string stun_server_address_;
std::string stun_server_hostname_;
bool webrtc_enabled_;
};
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -5,30 +5,28 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
if CONFIG['OS_TARGET'] != 'WINNT' and CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
SOURCES += [
'buffered_stun_socket_unittest.cpp',
'ice_unittest.cpp',
'multi_tcp_socket_unittest.cpp',
'nrappkit_unittest.cpp',
'proxy_tunnel_socket_unittest.cpp',
'rlogringbuffer_unittest.cpp',
'runnable_utils_unittest.cpp',
'simpletokenbucket_unittest.cpp',
'sockettransportservice_unittest.cpp',
'stunserver.cpp',
'test_nr_socket_unittest.cpp',
'TestSyncRunnable.cpp',
'transport_unittests.cpp',
'turn_unittest.cpp',
]
CppUnitTests([
'buffered_stun_socket_unittest',
'ice_unittest',
'multi_tcp_socket_unittest',
'nrappkit_unittest',
'proxy_tunnel_socket_unittest',
'rlogringbuffer_unittest',
'runnable_utils_unittest',
'simpletokenbucket_unittest',
'sockettransportservice_unittest',
'test_nr_socket_unittest',
'TestSyncRunnable',
'transport_unittests',
'turn_unittest',
])
if CONFIG['MOZ_SCTP']:
SOURCES += [
'sctp_unittest.cpp',
]
CppUnitTests([
'sctp_unittest',
])
for var in ('HAVE_STRDUP', 'NR_SOCKET_IS_VOID_PTR', 'SCTP_DEBUG', 'INET'):
for var in ('MOZILLA_INTERNAL_API', 'MOZILLA_XPCOMRT_API', 'MOZILLA_EXTERNAL_LINKAGE', 'HAVE_STRDUP', 'NR_SOCKET_IS_VOID_PTR', 'SCTP_DEBUG', 'INET'):
DEFINES[var] = True
if CONFIG['OS_TARGET'] == 'Android':
@ -45,6 +43,12 @@ if CONFIG['OS_TARGET'] == 'Linux':
LOCAL_INCLUDES += [
'/media/mtransport/third_party/nrappkit/src/port/linux/include',
]
USE_LIBS += [
'nspr',
]
OS_LIBS += [
'-lrt',
]
if CONFIG['OS_TARGET'] == 'Darwin':
LOCAL_INCLUDES += [
@ -90,8 +94,35 @@ LOCAL_INCLUDES += [
'/media/mtransport/third_party/nrappkit/src/stats',
'/media/mtransport/third_party/nrappkit/src/util/',
'/media/mtransport/third_party/nrappkit/src/util/libekr',
'/media/webrtc/trunk/testing/gtest/include/',
'/netwerk/sctp/src/',
'/xpcom/tests/'
'/xpcom/libxpcomrt',
]
FINAL_LIBRARY = 'xul-gtest'
USE_LIBS += [
'/media/webrtc/trunk/testing/gtest_gtest/gtest',
'fallible',
'mfbt',
'mozglue',
'mtransport_standalone',
'necko_standalone',
'nicer',
'nrappkit',
'nspr',
'nss',
'unicharutil_standalone',
'xpcomrt',
]
if not CONFIG['MOZ_NATIVE_NSS'] and not CONFIG['MOZ_FOLD_LIBS']:
USE_LIBS += [
# Statically linking NSS libssl ensures that we can debug NSS too
'static:/security/nss/lib/ssl/ssl',
]
if CONFIG['MOZ_SCTP']:
USE_LIBS += [
'nksctp_s',
]
USE_LIBS += ['mozglue']

Просмотреть файл

@ -9,20 +9,54 @@
#ifndef mtransport_test_utils_h__
#define mtransport_test_utils_h__
#include <iostream>
#include "nspr.h"
#include "nsCOMPtr.h"
#include "nsNetCID.h"
#include "nsXPCOMGlue.h"
#include "nsXPCOM.h"
#include "nsIComponentManager.h"
#include "nsIComponentRegistrar.h"
#include "nsIEventTarget.h"
#include "nsIIOService.h"
#include "nsIServiceManager.h"
#include "nsISocketTransportService.h"
#include "nsDirectoryServiceUtils.h"
#include "nsDirectoryServiceDefs.h"
#ifdef MOZ_CRASHREPORTER
#include "nsICrashReporter.h"
#endif
#include "nsPISocketTransportService.h"
#include "nsServiceManagerUtils.h"
#if !defined(MOZILLA_XPCOMRT_API)
#include "TestHarness.h"
#else
#include "XPCOMRTInit.h"
class ScopedXPCOM {
public:
explicit ScopedXPCOM(const char*)
{
NS_InitXPCOMRT();
}
~ScopedXPCOM()
{
NS_ShutdownXPCOMRT();
}
};
#endif
class MtransportTestUtils {
public:
MtransportTestUtils() {
MtransportTestUtils() : xpcom_("") {
if (!sts_) {
InitServices();
}
}
~MtransportTestUtils() {
sts_->Shutdown();
}
void InitServices() {
@ -31,16 +65,47 @@ class MtransportTestUtils {
MOZ_ASSERT(NS_SUCCEEDED(rv));
sts_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
MOZ_ASSERT(NS_SUCCEEDED(rv));
#ifdef MOZ_CRASHREPORTER
char *crashreporter = PR_GetEnv("MOZ_CRASHREPORTER");
if (crashreporter && !strcmp(crashreporter, "1")) {
//TODO: move this to an even-more-common location to use in all
// C++ unittests
crashreporter_ = do_GetService("@mozilla.org/toolkit/crash-reporter;1");
if (crashreporter_) {
std::cerr << "Setting up crash reporting" << std::endl;
nsCOMPtr<nsIProperties> dirsvc =
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID);
nsCOMPtr<nsIFile> cwd;
rv = dirsvc->Get(NS_OS_CURRENT_WORKING_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(cwd));
MOZ_ASSERT(NS_SUCCEEDED(rv));
crashreporter_->SetEnabled(true);
crashreporter_->SetMinidumpPath(cwd);
}
}
#endif
}
nsCOMPtr<nsIEventTarget> sts_target() { return sts_target_; }
private:
ScopedXPCOM xpcom_;
nsCOMPtr<nsIEventTarget> sts_target_;
nsCOMPtr<nsPISocketTransportService> sts_;
#ifdef MOZ_CRASHREPORTER
nsCOMPtr<nsICrashReporter> crashreporter_;
#endif
};
MtransportTestUtils *mtransport_test_utils;
#define SETUP_MTRANSPORT_TEST_UTILS() \
MtransportTestUtils utils_; mtransport_test_utils = &utils_
#define CHECK_ENVIRONMENT_FLAG(envname) \
char *test_flag = getenv(envname); \
if (!test_flag || strcmp(test_flag, "1")) { \
@ -50,3 +115,4 @@ class MtransportTestUtils {
#endif

Просмотреть файл

@ -21,9 +21,15 @@ extern "C" {
#include "nr_socket_multi_tcp.h"
}
#include "mtransport_test_utils.h"
#include "gtest_ringbuffer_dumper.h"
#include "nr_socket_prsock.h"
#include "stunserver.h"
// TODO(bcampen@mozilla.com): Big fat hack since the build system doesn't give
// us a clean way to add object files to a single executable.
#include "stunserver.cpp"
#include "nricectx.h"
#include "nricemediastream.h"
@ -33,39 +39,23 @@ extern "C" {
#include "gtest_utils.h"
using namespace mozilla;
MtransportTestUtils *test_utils;
namespace {
class MultiTcpSocketTest : public MtransportTest {
class MultiTcpSocketTest : public ::testing::Test {
public:
MultiTcpSocketTest()
:MtransportTest(),
socks(3,nullptr),
:socks(3,nullptr),
readable(false),
ice_ctx_()
ice_ctx_(NrIceCtx::Create("stun", true))
{}
void SetUp() {
MtransportTest::SetUp();
ice_ctx_ = NrIceCtx::Create("stun", true);
test_utils_->sts_target()->Dispatch(
WrapRunnableNM(&TestStunTcpServer::GetInstance, AF_INET),
NS_DISPATCH_SYNC);
test_utils_->sts_target()->Dispatch(
WrapRunnableNM(&TestStunTcpServer::GetInstance, AF_INET6),
NS_DISPATCH_SYNC);
}
void TearDown() {
test_utils_->sts_target()->Dispatch(
~MultiTcpSocketTest() {
test_utils->sts_target()->Dispatch(
WrapRunnable(
this, &MultiTcpSocketTest::Shutdown_s),
NS_DISPATCH_SYNC);
MtransportTest::TearDown();
}
DISALLOW_COPY_ASSIGN(MultiTcpSocketTest);
@ -134,7 +124,7 @@ class MultiTcpSocketTest : public MtransportTest {
std::string stun_server_addr = "",
uint16_t stun_server_port = 0) {
nr_socket *sock=nullptr;
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnable(
this, &MultiTcpSocketTest::Create_s, tcp_type,
stun_server_addr, stun_server_port, &sock),
@ -152,7 +142,7 @@ class MultiTcpSocketTest : public MtransportTest {
}
void Listen(nr_socket *sock) {
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnable(
this, &MultiTcpSocketTest::Listen_s, sock),
NS_DISPATCH_SYNC);
@ -164,7 +154,7 @@ class MultiTcpSocketTest : public MtransportTest {
}
void Destroy(nr_socket *sock) {
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnable(
this, &MultiTcpSocketTest::Destroy_s, sock),
NS_DISPATCH_SYNC);
@ -183,7 +173,7 @@ class MultiTcpSocketTest : public MtransportTest {
}
void Connect(nr_socket *from, nr_socket *to) {
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnable(
this, &MultiTcpSocketTest::Connect_s, from, to),
NS_DISPATCH_SYNC);
@ -204,7 +194,7 @@ class MultiTcpSocketTest : public MtransportTest {
}
void ConnectSo(nr_socket *from, nr_socket *to) {
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnable(
this, &MultiTcpSocketTest::ConnectSo_s, from, to),
NS_DISPATCH_SYNC);
@ -223,7 +213,7 @@ class MultiTcpSocketTest : public MtransportTest {
}
void SendData(nr_socket *from, nr_transport_addr *to, const char *data, size_t len) {
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnable(
this, &MultiTcpSocketTest::SendDataToAddress_s, from, to, data,
len),
@ -240,7 +230,7 @@ class MultiTcpSocketTest : public MtransportTest {
}
void SendData(nr_socket *from, nr_socket *to, const char *data, size_t len) {
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnable(
this, &MultiTcpSocketTest::SendDataToSocket_s, from, to, data,
len),
@ -281,7 +271,7 @@ class MultiTcpSocketTest : public MtransportTest {
void RecvData(nr_transport_addr *expected_from, nr_socket *sent_to,
const char *expected_data = nullptr, size_t expected_len = 0) {
ASSERT_TRUE_WAIT(IsReadable(), 1000);
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnable(
this, &MultiTcpSocketTest::RecvDataFromAddress_s,
expected_from, sent_to, expected_data,
@ -302,7 +292,7 @@ class MultiTcpSocketTest : public MtransportTest {
void RecvData(nr_socket *expected_from, nr_socket *sent_to,
const char *expected_data, size_t expected_len) {
ASSERT_TRUE_WAIT(IsReadable(), 1000);
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnable(
this, &MultiTcpSocketTest::RecvDataFromSocket_s,
expected_from, sent_to, expected_data, expected_len),
@ -327,7 +317,7 @@ class MultiTcpSocketTest : public MtransportTest {
void RecvDataFailed(nr_socket *sent_to, size_t expected_len,
int expected_err) {
ASSERT_TRUE_WAIT(IsReadable(), 1000);
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnable(
this, &MultiTcpSocketTest::RecvDataFailed_s, sent_to, expected_len,
expected_err),
@ -539,3 +529,33 @@ TEST_F(MultiTcpSocketTest, TestBigData) {
RecvData(socks[1], socks[0], buf2, sizeof(buf2));
RecvData(socks[1], socks[0], buf1, sizeof(buf1));
}
int main(int argc, char **argv)
{
test_utils = new MtransportTestUtils();
NSS_NoDB_Init(nullptr); // For random number generation
::testing::TestEventListeners& listeners =
::testing::UnitTest::GetInstance()->listeners();
// Adds a listener to the end. Google Test takes the ownership.
listeners.Append(new test::RingbufferDumper(test_utils));
test_utils->sts_target()->Dispatch(
WrapRunnableNM(&TestStunTcpServer::GetInstance, AF_INET),
NS_DISPATCH_SYNC);
test_utils->sts_target()->Dispatch(
WrapRunnableNM(&TestStunTcpServer::GetInstance, AF_INET6),
NS_DISPATCH_SYNC);
// Start the tests
::testing::InitGoogleTest(&argc, argv);
int rv = RUN_ALL_TESTS();
test_utils->sts_target()->Dispatch(
WrapRunnableNM(&TestStunTcpServer::ShutdownInstance), NS_DISPATCH_SYNC);
delete test_utils;
return rv;
}

Просмотреть файл

@ -17,6 +17,7 @@ extern "C" {
#include "async_timer.h"
}
#include "mtransport_test_utils.h"
#include "runnable_utils.h"
#define GTEST_HAS_RTTI 0
@ -25,17 +26,18 @@ extern "C" {
using namespace mozilla;
MtransportTestUtils *test_utils;
namespace {
class TimerTest : public MtransportTest {
class TimerTest : public ::testing::Test {
public:
TimerTest() : MtransportTest(), handle_(nullptr), fired_(false) {}
virtual ~TimerTest() {}
TimerTest() : handle_(nullptr), fired_(false) {}
int ArmTimer(int timeout) {
int ret;
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnableRet(&ret, this, &TimerTest::ArmTimer_w, timeout),
NS_DISPATCH_SYNC);
@ -45,7 +47,7 @@ class TimerTest : public MtransportTest {
int ArmCancelTimer(int timeout) {
int ret;
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnableRet(&ret, this, &TimerTest::ArmCancelTimer_w, timeout),
NS_DISPATCH_SYNC);
@ -68,7 +70,7 @@ class TimerTest : public MtransportTest {
int CancelTimer() {
int ret;
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnableRet(&ret, this, &TimerTest::CancelTimer_w),
NS_DISPATCH_SYNC);
@ -82,7 +84,7 @@ class TimerTest : public MtransportTest {
int Schedule() {
int ret;
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnableRet(&ret, this, &TimerTest::Schedule_w),
NS_DISPATCH_SYNC);
@ -132,3 +134,14 @@ TEST_F(TimerTest, ScheduleTest) {
Schedule();
ASSERT_TRUE_WAIT(fired_, 1000);
}
int main(int argc, char **argv) {
test_utils = new MtransportTestUtils();
// Start the tests
::testing::InitGoogleTest(&argc, argv);
int rv = RUN_ALL_TESTS();
delete test_utils;
return rv;
}

Просмотреть файл

@ -23,6 +23,7 @@ extern "C" {
}
#include "databuffer.h"
#include "mtransport_test_utils.h"
#include "dummysocket.h"
#include "nr_socket_prsock.h"
@ -33,6 +34,7 @@ extern "C" {
#include "gtest_utils.h"
using namespace mozilla;
MtransportTestUtils *test_utils;
const std::string kRemoteAddr = "192.0.2.133";
const uint16_t kRemotePort = 3333;
@ -106,7 +108,7 @@ class DummyResolver {
nr_resolver *resolver_;
};
class ProxyTunnelSocketTest : public MtransportTest {
class ProxyTunnelSocketTest : public ::testing::Test {
public:
ProxyTunnelSocketTest()
: socket_impl_(nullptr),
@ -117,9 +119,7 @@ class ProxyTunnelSocketTest : public MtransportTest {
nr_proxy_tunnel_config_destroy(&config_);
}
void SetUp() override {
MtransportTest::SetUp();
void SetUp() {
nr_resolver_ = resolver_impl_.get_nr_resolver();
int r = nr_str_port_to_transport_addr(
@ -188,16 +188,14 @@ TEST_F(ProxyTunnelSocketTest, TestConnectProxyAddress) {
NR_TRANSPORT_ADDR_CMP_MODE_ALL));
}
// TODO: Reenable once bug 1251212 is fixed
TEST_F(ProxyTunnelSocketTest, DISABLED_TestConnectProxyRequest) {
TEST_F(ProxyTunnelSocketTest, TestConnectProxyRequest) {
Connect();
std::string msg = connect_message(kRemoteAddr, kRemotePort, "", kHelloMessage);
socket_impl_->CheckWriteBuffer(reinterpret_cast<const uint8_t *>(msg.c_str()), msg.size());
}
// TODO: Reenable once bug 1251212 is fixed
TEST_F(ProxyTunnelSocketTest, DISABLED_TestAlpnConnect) {
TEST_F(ProxyTunnelSocketTest, TestAlpnConnect) {
const std::string alpn = "this,is,alpn";
int r = nr_proxy_tunnel_config_set_alpn(config_, alpn.c_str());
EXPECT_EQ(0, r);
@ -209,8 +207,7 @@ TEST_F(ProxyTunnelSocketTest, DISABLED_TestAlpnConnect) {
socket_impl_->CheckWriteBuffer(reinterpret_cast<const uint8_t *>(msg.c_str()), msg.size());
}
// TODO: Reenable once bug 1251212 is fixed
TEST_F(ProxyTunnelSocketTest, DISABLED_TestNullAlpnConnect) {
TEST_F(ProxyTunnelSocketTest, TestNullAlpnConnect) {
int r = nr_proxy_tunnel_config_set_alpn(config_, nullptr);
EXPECT_EQ(0, r);
@ -221,8 +218,7 @@ TEST_F(ProxyTunnelSocketTest, DISABLED_TestNullAlpnConnect) {
socket_impl_->CheckWriteBuffer(reinterpret_cast<const uint8_t *>(msg.c_str()), msg.size());
}
// TODO: Reenable once bug 1251212 is fixed
TEST_F(ProxyTunnelSocketTest, DISABLED_TestConnectProxyHostRequest) {
TEST_F(ProxyTunnelSocketTest, TestConnectProxyHostRequest) {
nr_proxy_tunnel_config_set_proxy(config_, kProxyHost.c_str(), kProxyPort);
Configure();
// Because kProxyHost is a domain name and not an IP address,
@ -245,8 +241,7 @@ TEST_F(ProxyTunnelSocketTest, DISABLED_TestConnectProxyHostRequest) {
socket_impl_->CheckWriteBuffer(reinterpret_cast<const uint8_t *>(msg.c_str()), msg.size());
}
// TODO: Reenable once bug 1251212 is fixed
TEST_F(ProxyTunnelSocketTest, DISABLED_TestConnectProxyWrite) {
TEST_F(ProxyTunnelSocketTest, TestConnectProxyWrite) {
Connect();
socket_impl_->ClearWriteBuffer();
@ -344,3 +339,18 @@ TEST_F(ProxyTunnelSocketTest, TestConnectProxyGarbageResponse) {
r = nr_socket_read(nr_socket_, buf, sizeof(buf), &read, 0);
ASSERT_EQ(0ul, read);
}
int main(int argc, char **argv)
{
test_utils = new MtransportTestUtils();
NSS_NoDB_Init(nullptr);
NSS_SetDomesticPolicy();
// Start the tests
::testing::InitGoogleTest(&argc, argv);
int rv = RUN_ALL_TESTS();
delete test_utils;
return rv;
}

Просмотреть файл

@ -35,14 +35,6 @@ class RLogRingBufferTest : public ::testing::Test {
Free();
}
static void SetUpTestCase() {
NR_reg_init(NR_REG_MODE_LOCAL);
r_log_init();
/* Would be nice to be able to unregister in the fixture */
const char* facility = "rlogringbuffer_test";
r_log_register(const_cast<char*>(facility), &NR_LOG_TEST);
}
void Init() {
RLogRingBuffer::CreateInstance();
}
@ -262,3 +254,16 @@ TEST_F(RLogRingBufferTest, TestReInit) {
RLogRingBuffer::GetInstance()->GetAny(0, &logs);
ASSERT_EQ(0U, logs.size());
}
int main(int argc, char** argv) {
NR_reg_init(NR_REG_MODE_LOCAL);
r_log_init();
/* Would be nice to be able to register/unregister in the fixture */
const char* facility = "rlogringbuffer_test";
r_log_register(const_cast<char*>(facility), &NR_LOG_TEST);
::testing::InitGoogleTest(&argc, argv);
int rv = RUN_ALL_TESTS();
return rv;
}

Просмотреть файл

@ -26,12 +26,14 @@
#include "nsThreadUtils.h"
#include "runnable_utils.h"
#include "mtransport_test_utils.h"
#define GTEST_HAS_RTTI 0
#include "gtest/gtest.h"
#include "gtest_utils.h"
using namespace mozilla;
MtransportTestUtils *test_utils;
namespace {
@ -82,9 +84,9 @@ class TargetClass {
};
class RunnableArgsTest : public MtransportTest {
class RunnableArgsTest : public ::testing::Test {
public:
RunnableArgsTest() : MtransportTest(), ran_(0), cl_(&ran_){}
RunnableArgsTest() : ran_(0), cl_(&ran_){}
void Test1Arg() {
nsRunnable * r = WrapRunnable(&cl_, &TargetClass::m1, 1);
@ -103,13 +105,11 @@ class RunnableArgsTest : public MtransportTest {
TargetClass cl_;
};
class DispatchTest : public MtransportTest {
class DispatchTest : public ::testing::Test {
public:
DispatchTest() : MtransportTest(), ran_(0), cl_(&ran_) {}
DispatchTest() : ran_(0), cl_(&ran_) {}
void SetUp() {
MtransportTest::SetUp();
nsresult rv;
target_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
ASSERT_TRUE(NS_SUCCEEDED(rv));
@ -185,7 +185,7 @@ int SetNonMethodRet(TargetClass *cl, int x) {
}
TEST_F(DispatchTest, TestNonMethod) {
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnableNM(SetNonMethod, &cl_, 10), NS_DISPATCH_SYNC);
ASSERT_EQ(1, ran_);
@ -194,7 +194,7 @@ TEST_F(DispatchTest, TestNonMethod) {
TEST_F(DispatchTest, TestNonMethodRet) {
int z;
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnableNMRet(&z, SetNonMethodRet, &cl_, 10), NS_DISPATCH_SYNC);
ASSERT_EQ(1, ran_);
@ -225,3 +225,16 @@ TEST_F(DispatchTest, TestDestructorRef) {
} // end of namespace
int main(int argc, char **argv) {
test_utils = new MtransportTestUtils();
// Start the tests
::testing::InitGoogleTest(&argc, argv);
int rv = RUN_ALL_TESTS();
delete test_utils;
return rv;
}

Просмотреть файл

@ -23,6 +23,7 @@
#include "transportlayer.h"
#include "transportlayerloopback.h"
#include "mtransport_test_utils.h"
#include "runnable_utils.h"
#include "usrsctp.h"
@ -33,6 +34,7 @@
using namespace mozilla;
MtransportTestUtils *test_utils;
static bool sctp_logging = false;
static int port_number = 5000;
@ -61,16 +63,14 @@ NS_IMPL_ISUPPORTS(SendPeriodic, nsITimerCallback)
class TransportTestPeer : public sigslot::has_slots<> {
public:
TransportTestPeer(std::string name, int local_port, int remote_port,
MtransportTestUtils* utils)
TransportTestPeer(std::string name, int local_port, int remote_port)
: name_(name), connected_(false),
sent_(0), received_(0),
flow_(new TransportFlow()),
loopback_(new TransportLayerLoopback()),
sctp_(usrsctp_socket(AF_CONN, SOCK_STREAM, IPPROTO_SCTP, receive_cb, nullptr, 0, nullptr)),
timer_(do_CreateInstance(NS_TIMER_CONTRACTID)),
periodic_(nullptr),
test_utils_(utils) {
periodic_(nullptr) {
std::cerr << "Creating TransportTestPeer; flow=" <<
static_cast<void *>(flow_.get()) <<
" local=" << local_port <<
@ -124,7 +124,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
usrsctp_close(sctp_);
usrsctp_deregister_address(static_cast<void *>(this));
test_utils_->sts_target()->Dispatch(WrapRunnable(this,
test_utils->sts_target()->Dispatch(WrapRunnable(this,
&TransportTestPeer::Disconnect_s),
NS_DISPATCH_SYNC);
@ -132,7 +132,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
}
void ConnectSocket(TransportTestPeer *peer) {
test_utils_->sts_target()->Dispatch(WrapRunnable(
test_utils->sts_target()->Dispatch(WrapRunnable(
this, &TransportTestPeer::ConnectSocket_s, peer),
NS_DISPATCH_SYNC);
}
@ -170,7 +170,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
void StartTransfer(size_t to_send) {
periodic_ = new SendPeriodic(this, to_send);
timer_->SetTarget(test_utils_->sts_target());
timer_->SetTarget(test_utils->sts_target());
timer_->InitWithCallback(periodic_, 10, nsITimer::TYPE_REPEATING_SLACK);
}
@ -215,7 +215,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
// normal for most transfers outside of connect() and close(). Passes
// a refptr to flow_ to avoid any async deletion issues (since we can't
// make 'this' into a refptr as it isn't refcounted)
RUN_ON_THREAD(test_utils_->sts_target(), WrapRunnableNM(
RUN_ON_THREAD(test_utils->sts_target(), WrapRunnableNM(
&TransportTestPeer::SendPacket_s, buffer, len, flow_),
NS_DISPATCH_NORMAL);
@ -296,7 +296,6 @@ class TransportTestPeer : public sigslot::has_slots<> {
struct socket *sctp_;
nsCOMPtr<nsITimer> timer_;
RefPtr<SendPeriodic> periodic_;
MtransportTestUtils* test_utils_;
};
@ -310,12 +309,18 @@ NS_IMETHODIMP SendPeriodic::Notify(nsITimer *timer) {
return NS_OK;
}
class SctpTransportTest : public MtransportTest {
class TransportTest : public ::testing::Test {
public:
SctpTransportTest() {
TransportTest() {
}
~SctpTransportTest() {
~TransportTest() {
if (p1_)
p1_->Disconnect();
if (p2_)
p2_->Disconnect();
delete p1_;
delete p2_;
}
static void debug_printf(const char *format, ...) {
@ -336,26 +341,17 @@ class SctpTransportTest : public MtransportTest {
}
}
void TearDown() override {
if (p1_)
p1_->Disconnect();
if (p2_)
p2_->Disconnect();
delete p1_;
delete p2_;
MtransportTest::TearDown();
void SetUp() {
}
void ConnectSocket(int p1port = 0, int p2port = 0) {
if (!p1port)
p1port = port_number++;
if (!p2port)
p2port = port_number++;
p1_ = new TransportTestPeer("P1", p1port, p2port, test_utils_);
p2_ = new TransportTestPeer("P2", p2port, p1port, test_utils_);
p1_ = new TransportTestPeer("P1", p1port, p2port);
p2_ = new TransportTestPeer("P2", p2port, p1port);
p1_->ConnectSocket(p2_);
p2_->ConnectSocket(p1_);
@ -376,18 +372,35 @@ class SctpTransportTest : public MtransportTest {
TransportTestPeer *p2_;
};
TEST_F(SctpTransportTest, TestConnect) {
TEST_F(TransportTest, TestConnect) {
ConnectSocket();
}
TEST_F(SctpTransportTest, TestConnectSymmetricalPorts) {
TEST_F(TransportTest, TestConnectSymmetricalPorts) {
ConnectSocket(5002,5002);
}
TEST_F(SctpTransportTest, TestTransfer) {
TEST_F(TransportTest, TestTransfer) {
ConnectSocket();
TestTransfer(50);
}
} // end namespace
int main(int argc, char **argv)
{
test_utils = new MtransportTestUtils();
// Start the tests
::testing::InitGoogleTest(&argc, argv);
for(int i=0; i<argc; i++) {
if (!strcmp(argv[i],"-v")) {
sctp_logging = true;
}
}
int rv = RUN_ALL_TESTS();
delete test_utils;
return rv;
}

Просмотреть файл

@ -105,3 +105,11 @@ TEST(SimpleTokenBucketTest, TestNoOverflow) {
b.fastForward(50000);
ASSERT_EQ(10U, b.getTokens(11));
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
int rv = RUN_ALL_TESTS();
return rv;
}

Просмотреть файл

@ -24,16 +24,18 @@
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
#include "mtransport_test_utils.h"
#define GTEST_HAS_RTTI 0
#include "gtest/gtest.h"
#include "gtest_utils.h"
MtransportTestUtils *test_utils;
namespace {
class SocketTransportServiceTest : public MtransportTest {
class SocketTransportServiceTest : public ::testing::Test {
public:
SocketTransportServiceTest() : MtransportTest(),
received_(0),
SocketTransportServiceTest() : received_(0),
readpipe_(nullptr),
writepipe_(nullptr),
registered_(false) {
@ -141,8 +143,6 @@ class SocketHandler : public nsASocketHandler {
NS_IMPL_ISUPPORTS0(SocketHandler)
void SocketTransportServiceTest::SetUp() {
MtransportTest::SetUp();
// Get the transport service as a dispatch target
nsresult rv;
target_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
@ -204,3 +204,15 @@ TEST_F(SocketTransportServiceTest, SendPacket) {
} // end namespace
int main(int argc, char **argv) {
test_utils = new MtransportTestUtils();
// Start the tests
::testing::InitGoogleTest(&argc, argv);
int rv = RUN_ALL_TESTS();
delete test_utils;
return rv;
}

Просмотреть файл

@ -25,6 +25,7 @@ extern "C" {
#include "nsServiceManagerUtils.h"
#include "nsAutoPtr.h"
#include "runnable_utils.h"
#include "mtransport_test_utils.h"
#include <vector>
@ -36,31 +37,23 @@ extern "C" {
namespace mozilla {
class TestNrSocketTest : public MtransportTest {
class TestNrSocketTest : public ::testing::Test {
public:
TestNrSocketTest() :
MtransportTest(),
wait_done_for_main_(false),
sts_(),
public_addrs_(),
private_addrs_(),
nats_() {
}
void SetUp() override {
MtransportTest::SetUp();
// Get the transport service as a dispatch target
nsresult rv;
sts_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
EXPECT_TRUE(NS_SUCCEEDED(rv)) << "Failed to get STS: " << (int)rv;
}
void TearDown() override {
~TestNrSocketTest() {
sts_->Dispatch(WrapRunnable(this, &TestNrSocketTest::TearDown_s),
NS_DISPATCH_SYNC);
MtransportTest::TearDown();
}
void TearDown_s() {
@ -861,3 +854,18 @@ TEST_F(TestNrSocketTest, NoConnectivityPublicToPrivateTcp)
ASSERT_FALSE(CheckTcpConnectivity(public_addrs_[0], private_addrs_[0]));
}
int main(int argc, char **argv)
{
// Inits STS and some other stuff.
MtransportTestUtils test_utils;
NR_reg_init(NR_REG_MODE_LOCAL);
// Start the tests
::testing::InitGoogleTest(&argc, argv);
int rv = RUN_ALL_TESTS();
return rv;
}

Просмотреть файл

@ -35,6 +35,7 @@
#include "transportlayerlog.h"
#include "transportlayerloopback.h"
#include "mtransport_test_utils.h"
#include "runnable_utils.h"
#define GTEST_HAS_RTTI 0
@ -44,6 +45,8 @@
using namespace mozilla;
MOZ_MTLOG_MODULE("mtransport")
MtransportTestUtils *test_utils;
const uint8_t kTlsChangeCipherSpecType = 0x14;
const uint8_t kTlsHandshakeType = 0x16;
@ -433,7 +436,7 @@ class TlsServerKeyExchangeECDHE {
namespace {
class TransportTestPeer : public sigslot::has_slots<> {
public:
TransportTestPeer(nsCOMPtr<nsIEventTarget> target, std::string name, MtransportTestUtils* utils)
TransportTestPeer(nsCOMPtr<nsIEventTarget> target, std::string name)
: name_(name), target_(target),
received_packets_(0),received_bytes_(0),flow_(new TransportFlow(name)),
loopback_(new TransportLayerLoopback()),
@ -450,8 +453,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
gathering_complete_(false),
enabled_cipersuites_(),
disabled_cipersuites_(),
reuse_dhe_key_(false),
test_utils_(utils) {
reuse_dhe_key_(false) {
std::vector<NrIceStunServer> stun_servers;
UniquePtr<NrIceStunServer> server(NrIceStunServer::Create(
std::string((char *)"stun.services.mozilla.com"), 3478));
@ -472,7 +474,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
}
~TransportTestPeer() {
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnable(this, &TransportTestPeer::DestroyFlow),
NS_DISPATCH_SYNC);
}
@ -589,7 +591,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
}
void ConnectSocket(TransportTestPeer *peer) {
RUN_ON_THREAD(test_utils_->sts_target(),
RUN_ON_THREAD(test_utils->sts_target(),
WrapRunnable(this, & TransportTestPeer::ConnectSocket_s,
peer),
NS_DISPATCH_SYNC);
@ -628,7 +630,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
layers->push(ice_);
layers->push(dtls_);
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnableRet(&res, flow_, &TransportFlow::PushLayers, layers),
NS_DISPATCH_SYNC);
@ -639,7 +641,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
flow_->SignalStateChange.connect(this, &TransportTestPeer::StateChanged);
// Start gathering
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnableRet(&res, ice_ctx_, &NrIceCtx::StartGathering),
NS_DISPATCH_SYNC);
ASSERT_TRUE(NS_SUCCEEDED(res));
@ -679,7 +681,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
}
// First send attributes
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnableRet(&res, peer_->ice_ctx_,
&NrIceCtx::ParseGlobalAttributes,
ice_ctx_->GetGlobalAttributes()),
@ -687,7 +689,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
ASSERT_TRUE(NS_SUCCEEDED(res));
for (size_t i=0; i<streams_.size(); ++i) {
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnableRet(&res, peer_->streams_[i], &NrIceMediaStream::ParseAttributes,
candidates_[streams_[i]->name()]), NS_DISPATCH_SYNC);
@ -695,7 +697,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
}
// Start checks on the other peer.
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnableRet(&res, peer_->ice_ctx_, &NrIceCtx::StartChecks),
NS_DISPATCH_SYNC);
ASSERT_TRUE(NS_SUCCEEDED(res));
@ -703,7 +705,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
TransportResult SendPacket(const unsigned char* data, size_t len) {
TransportResult ret;
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnableRet(&ret, flow_, &TransportFlow::SendPacket, data, len),
NS_DISPATCH_SYNC);
@ -755,7 +757,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
TransportLayer::State state() {
TransportLayer::State tstate;
RUN_ON_THREAD(test_utils_->sts_target(),
RUN_ON_THREAD(test_utils->sts_target(),
WrapRunnableRet(&tstate, flow_, &TransportFlow::state));
return tstate;
@ -776,7 +778,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
uint16_t cipherSuite() const {
nsresult rv;
uint16_t cipher;
RUN_ON_THREAD(test_utils_->sts_target(),
RUN_ON_THREAD(test_utils->sts_target(),
WrapRunnableRet(&rv, dtls_, &TransportLayerDtls::GetCipherSuite,
&cipher));
@ -789,7 +791,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
uint16_t srtpCipher() const {
nsresult rv;
uint16_t cipher;
RUN_ON_THREAD(test_utils_->sts_target(),
RUN_ON_THREAD(test_utils->sts_target(),
WrapRunnableRet(&rv, dtls_, &TransportLayerDtls::GetSrtpCipher,
&cipher));
if (NS_FAILED(rv)) {
@ -820,25 +822,23 @@ class TransportTestPeer : public sigslot::has_slots<> {
std::vector<uint16_t> enabled_cipersuites_;
std::vector<uint16_t> disabled_cipersuites_;
bool reuse_dhe_key_;
MtransportTestUtils* test_utils_;
};
class TransportTest : public MtransportTest {
class TransportTest : public ::testing::Test {
public:
TransportTest() {
fds_[0] = nullptr;
fds_[1] = nullptr;
}
void TearDown() override {
~TransportTest() {
delete p1_;
delete p2_;
// Can't detach these
// PR_Close(fds_[0]);
// PR_Close(fds_[1]);
MtransportTest::TearDown();
}
void DestroyPeerFlows() {
@ -846,9 +846,7 @@ class TransportTest : public MtransportTest {
p2_->DisconnectDestroyFlow();
}
void SetUp() override {
MtransportTest::SetUp();
void SetUp() {
nsresult rv;
target_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
ASSERT_TRUE(NS_SUCCEEDED(rv));
@ -857,8 +855,8 @@ class TransportTest : public MtransportTest {
}
void Reset() {
p1_ = new TransportTestPeer(target_, "P1", test_utils_);
p2_ = new TransportTestPeer(target_, "P2", test_utils_);
p1_ = new TransportTestPeer(target_, "P1");
p2_ = new TransportTestPeer(target_, "P2");
}
void SetupSrtp() {
@ -943,10 +941,10 @@ class TransportTest : public MtransportTest {
protected:
void ConnectSocketInternal() {
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnable(p1_, &TransportTestPeer::ConnectSocket, p2_),
NS_DISPATCH_SYNC);
test_utils_->sts_target()->Dispatch(
test_utils->sts_target()->Dispatch(
WrapRunnable(p2_, &TransportTestPeer::ConnectSocket, p1_),
NS_DISPATCH_SYNC);
}
@ -1326,3 +1324,17 @@ TEST(PushTests, LayersFail) {
}
} // end namespace
int main(int argc, char **argv)
{
test_utils = new MtransportTestUtils();
NSS_NoDB_Init(nullptr);
NSS_SetDomesticPolicy();
// Start the tests
::testing::InitGoogleTest(&argc, argv);
int rv = RUN_ALL_TESTS();
delete test_utils;
return rv;
}

Просмотреть файл

@ -53,6 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "nsThreadUtils.h"
#include "nsXPCOM.h"
#include "mtransport_test_utils.h"
#include "runnable_utils.h"
#define GTEST_HAS_RTTI 0
@ -81,14 +82,20 @@ extern "C" {
#include "nricectx.h"
MtransportTestUtils *test_utils;
using namespace mozilla;
static std::string kDummyTurnServer("192.0.2.1"); // From RFC 5737
std::string g_turn_server;
std::string g_turn_user;
std::string g_turn_password;
class TurnClient : public MtransportTest {
std::string kDummyTurnServer("192.0.2.1"); // From RFC 5737
class TurnClient : public ::testing::Test {
public:
TurnClient()
: MtransportTest(),
: turn_server_(g_turn_server),
real_socket_(nullptr),
net_socket_(nullptr),
buffered_socket_(nullptr),
@ -102,10 +109,6 @@ class TurnClient : public MtransportTest {
~TurnClient() {
}
static void SetUpTestCase() {
NrIceCtx::Init(false, false, false);
}
void SetTcp() {
protocol_ = IPPROTO_TCP;
}
@ -134,11 +137,11 @@ class TurnClient : public MtransportTest {
ASSERT_EQ(0, r);
std::vector<unsigned char> password_vec(
turn_password_.begin(), turn_password_.end());
g_turn_password.begin(), g_turn_password.end());
Data password;
INIT_DATA(password, &password_vec[0], password_vec.size());
r = nr_turn_client_ctx_create("test", net_socket_,
turn_user_.c_str(),
g_turn_user.c_str(),
&password,
&addr, &turn_ctx_);
ASSERT_EQ(0, r);
@ -160,7 +163,7 @@ class TurnClient : public MtransportTest {
}
void TearDown() {
RUN_ON_THREAD(test_utils_->sts_target(),
RUN_ON_THREAD(test_utils->sts_target(),
WrapRunnable(this, &TurnClient::TearDown_s),
NS_DISPATCH_SYNC);
}
@ -176,7 +179,7 @@ class TurnClient : public MtransportTest {
}
void Allocate(bool expect_success=true) {
RUN_ON_THREAD(test_utils_->sts_target(),
RUN_ON_THREAD(test_utils->sts_target(),
WrapRunnable(this, &TurnClient::Allocate_s),
NS_DISPATCH_SYNC);
@ -216,7 +219,7 @@ class TurnClient : public MtransportTest {
}
void Deallocate() {
RUN_ON_THREAD(test_utils_->sts_target(),
RUN_ON_THREAD(test_utils->sts_target(),
WrapRunnable(this, &TurnClient::Deallocate_s),
NS_DISPATCH_SYNC);
}
@ -245,7 +248,7 @@ class TurnClient : public MtransportTest {
}
void RequestPermission(const std::string& target) {
RUN_ON_THREAD(test_utils_->sts_target(),
RUN_ON_THREAD(test_utils->sts_target(),
WrapRunnable(this, &TurnClient::RequestPermission_s, target),
NS_DISPATCH_SYNC);
@ -343,7 +346,7 @@ class TurnClient : public MtransportTest {
}
void SendTo(const std::string& target, int expect_return=0) {
RUN_ON_THREAD(test_utils_->sts_target(),
RUN_ON_THREAD(test_utils->sts_target(),
WrapRunnable(this, &TurnClient::SendTo_s, target,
expect_return),
NS_DISPATCH_SYNC);
@ -373,33 +376,21 @@ class TurnClient : public MtransportTest {
};
TEST_F(TurnClient, Allocate) {
if (WarnIfTurnNotConfigured())
return;
Allocate();
}
TEST_F(TurnClient, AllocateTcp) {
if (WarnIfTurnNotConfigured())
return;
SetTcp();
Allocate();
}
TEST_F(TurnClient, AllocateAndHold) {
if (WarnIfTurnNotConfigured())
return;
Allocate();
PR_Sleep(20000);
ASSERT_TRUE(turn_ctx_->state == NR_TURN_CLIENT_STATE_ALLOCATED);
}
TEST_F(TurnClient, SendToSelf) {
if (WarnIfTurnNotConfigured())
return;
Allocate();
SendTo(relay_addr_);
ASSERT_TRUE_WAIT(received() == 100, 5000);
@ -409,9 +400,6 @@ TEST_F(TurnClient, SendToSelf) {
TEST_F(TurnClient, SendToSelfTcp) {
if (WarnIfTurnNotConfigured())
return;
SetTcp();
Allocate();
SendTo(relay_addr_);
@ -421,9 +409,6 @@ TEST_F(TurnClient, SendToSelfTcp) {
}
TEST_F(TurnClient, PermissionDenied) {
if (WarnIfTurnNotConfigured())
return;
Allocate();
RequestPermission(relay_addr_);
PR_Sleep(1000);
@ -447,9 +432,6 @@ TEST_F(TurnClient, PermissionDenied) {
}
TEST_F(TurnClient, DeallocateReceiveFailure) {
if (WarnIfTurnNotConfigured())
return;
Allocate();
SendTo(relay_addr_);
ASSERT_TRUE_WAIT(received() == 100, 5000);
@ -461,9 +443,6 @@ TEST_F(TurnClient, DeallocateReceiveFailure) {
}
TEST_F(TurnClient, DeallocateReceiveFailureTcp) {
if (WarnIfTurnNotConfigured())
return;
SetTcp();
Allocate();
SendTo(relay_addr_);
@ -480,9 +459,59 @@ TEST_F(TurnClient, DeallocateReceiveFailureTcp) {
}
TEST_F(TurnClient, AllocateDummyServer) {
if (WarnIfTurnNotConfigured())
return;
turn_server_ = kDummyTurnServer;
Allocate(false);
}
static std::string get_environment(const char *name) {
char *value = getenv(name);
if (!value)
return "";
return value;
}
int main(int argc, char **argv)
{
g_turn_server = get_environment("TURN_SERVER_ADDRESS");
g_turn_user = get_environment("TURN_SERVER_USER");
g_turn_password = get_environment("TURN_SERVER_PASSWORD");
if (g_turn_server.empty() ||
g_turn_user.empty(),
g_turn_password.empty()) {
printf(
"Set TURN_SERVER_ADDRESS, TURN_SERVER_USER, and TURN_SERVER_PASSWORD\n"
"environment variables to run this test\n");
return 0;
}
{
nr_transport_addr addr;
if (nr_str_port_to_transport_addr(g_turn_server.c_str(), 3478,
IPPROTO_UDP, &addr)) {
printf("Invalid TURN_SERVER_ADDRESS \"%s\". Only IP numbers supported.\n",
g_turn_server.c_str());
return 0;
}
}
test_utils = new MtransportTestUtils();
NSS_NoDB_Init(nullptr);
NSS_SetDomesticPolicy();
// Set up the ICE registry, etc.
// TODO(ekr@rtfm.com): Clean up
std::string dummy("dummy");
RUN_ON_THREAD(test_utils->sts_target(),
WrapRunnableNM(&NrIceCtx::Create,
dummy, false, false, false, false, false,
NrIceCtx::ICE_POLICY_ALL),
NS_DISPATCH_SYNC);
// Start the tests
::testing::InitGoogleTest(&argc, argv);
int rv = RUN_ALL_TESTS();
delete test_utils;
return rv;
}

Просмотреть файл

@ -35,8 +35,6 @@
#include "FakeIPC.h"
#include "FakeIPC.cpp"
#include "TestHarness.h"
namespace mozilla {
static std::string kAEqualsCandidate("a=candidate:");
const static size_t kNumCandidatesPerComponent = 3;

Просмотреть файл

@ -22,8 +22,6 @@
#include "FakeIPC.h"
#include "FakeIPC.cpp"
#include "TestHarness.h"
namespace mozilla {
class JsepTrackTest : public ::testing::Test

Просмотреть файл

@ -43,8 +43,6 @@
#include "gtest/gtest.h"
#include "gtest_utils.h"
#include "TestHarness.h"
using namespace mozilla;
MOZ_MTLOG_MODULE("mediapipeline")
@ -701,7 +699,6 @@ TEST_F(MediaPipelineTest, TestAudioSendEmptyBundleFilter) {
int main(int argc, char **argv) {
ScopedXPCOM xpcom("mediapipeline_unittest");
test_utils = new MtransportTestUtils();
// Start the tests
NSS_NoDB_Init(nullptr);

Просмотреть файл

@ -47,8 +47,6 @@ extern "C" {
#include "FakeIPC.h"
#include "FakeIPC.cpp"
#include "TestHarness.h"
using namespace mozilla;
namespace test {
@ -4238,8 +4236,6 @@ TEST(NewSdpTestNoFixture, CheckRidSerialize)
} // End namespace test.
int main(int argc, char **argv) {
ScopedXPCOM xpcom("sdp_unittests");
test_utils = new MtransportTestUtils();
NSS_NoDB_Init(nullptr);
NSS_SetDomesticPolicy();

Просмотреть файл

@ -65,7 +65,12 @@ public:
* @param aName The name of the module.
* @return A log module for the given name. This may be shared.
*/
#if !defined(MOZILLA_XPCOMRT_API)
static LogModule* Get(const char* aName);
#else
// For simplicity, libxpcomrt doesn't supoort logging.
static LogModule* Get(const char* aName) { return nullptr; }
#endif
static void Init();
@ -171,9 +176,13 @@ inline bool log_test(const LogModule* module, LogLevel level) {
return module && module->ShouldLog(level);
}
#if !defined(MOZILLA_XPCOMRT_API)
void log_print(const LogModule* aModule,
LogLevel aLevel,
const char* aFmt, ...);
#else
inline void log_print(const LogModule* aModule, LogLevel aLevel, const char* aFmt, ...) {}
#endif
} // namespace detail
} // namespace mozilla

Просмотреть файл

@ -333,8 +333,9 @@ NS_DebugBreak(uint32_t aSeverity, const char* aStr, const char* aExpr,
if (sMultiprocessDescription) {
PrintToBuffer("%s ", sMultiprocessDescription);
}
#if !defined(MOZILLA_XPCOMRT_API)
PrintToBuffer("%d] ", base::GetCurrentProcId());
#endif // !defined(MOZILLA_XPCOMRT_API)
PrintToBuffer("%s: ", sevString);
@ -380,7 +381,7 @@ NS_DebugBreak(uint32_t aSeverity, const char* aStr, const char* aExpr,
return;
case NS_DEBUG_ABORT: {
#if defined(MOZ_CRASHREPORTER)
#if defined(MOZ_CRASHREPORTER) && !defined(MOZILLA_XPCOMRT_API)
// Updating crash annotations in the child causes us to do IPC. This can
// really cause trouble if we're asserting from within IPC code. So we
// have to do without the annotations in that case.
@ -397,7 +398,7 @@ NS_DebugBreak(uint32_t aSeverity, const char* aStr, const char* aExpr,
#if defined(DEBUG) && defined(_WIN32)
RealBreak();
#endif
#if defined(DEBUG)
#if defined(DEBUG) && !defined(MOZILLA_XPCOMRT_API)
nsTraceRefcnt::WalkTheStack(stderr);
#endif
Abort(buf.buffer);
@ -422,11 +423,15 @@ NS_DebugBreak(uint32_t aSeverity, const char* aStr, const char* aExpr,
return;
case NS_ASSERT_STACK:
#if !defined(MOZILLA_XPCOMRT_API)
nsTraceRefcnt::WalkTheStack(stderr);
#endif // !defined(MOZILLA_XPCOMRT_API)
return;
case NS_ASSERT_STACK_AND_ABORT:
#if !defined(MOZILLA_XPCOMRT_API)
nsTraceRefcnt::WalkTheStack(stderr);
#endif // !defined(MOZILLA_XPCOMRT_API)
// Fall through to abort
MOZ_FALLTHROUGH;
@ -598,7 +603,7 @@ NS_ErrorAccordingToNSPR()
void
NS_ABORT_OOM(size_t aSize)
{
#if defined(MOZ_CRASHREPORTER)
#if defined(MOZ_CRASHREPORTER) && !defined(MOZILLA_XPCOMRT_API)
CrashReporter::AnnotateOOMAllocationSize(aSize);
#endif
MOZ_CRASH();

Просмотреть файл

@ -515,7 +515,7 @@ nsresult RegisterNonJSSizeOfTab(NonJSSizeOfTabFn aSizeOfTabFn);
}
#if defined(MOZ_DMD)
#if defined(MOZ_DMD) && !defined(MOZILLA_XPCOMRT_API)
#if !defined(MOZ_MEMORY)
#error "MOZ_DMD requires MOZ_MEMORY"
#endif

Просмотреть файл

@ -5,8 +5,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "FileLocation.h"
#if !defined(MOZILLA_XPCOMRT_API)
#include "nsZipArchive.h"
#include "nsURLHelper.h"
#endif // !defined(MOZILLA_XPCOMRT_API)
namespace mozilla {
@ -34,9 +36,11 @@ FileLocation::FileLocation(const FileLocation& aFile, const char* aPath)
if (aFile.mBaseFile) {
Init(aFile.mBaseFile, aFile.mPath.get());
}
#if !defined(MOZILLA_XPCOMRT_API)
else {
Init(aFile.mBaseZip, aFile.mPath.get());
}
#endif
if (aPath) {
int32_t i = mPath.RFindChar('/');
if (kNotFound == i) {
@ -74,7 +78,9 @@ FileLocation::FileLocation(const FileLocation& aFile, const char* aPath)
void
FileLocation::Init(nsIFile* aFile)
{
#if !defined(MOZILLA_XPCOMRT_API)
mBaseZip = nullptr;
#endif //!defined(MOZILLA_XPCOMRT_API)
mBaseFile = aFile;
mPath.Truncate();
}
@ -82,7 +88,9 @@ FileLocation::Init(nsIFile* aFile)
void
FileLocation::Init(nsIFile* aFile, const char* aPath)
{
#if !defined(MOZILLA_XPCOMRT_API)
mBaseZip = nullptr;
#endif // !defined(MOZILLA_XPCOMRT_API)
mBaseFile = aFile;
mPath = aPath;
}
@ -90,7 +98,9 @@ FileLocation::Init(nsIFile* aFile, const char* aPath)
void
FileLocation::Init(nsZipArchive* aZip, const char* aPath)
{
#if !defined(MOZILLA_XPCOMRT_API)
mBaseZip = aZip;
#endif // !defined(MOZILLA_XPCOMRT_API)
mBaseFile = nullptr;
mPath = aPath;
}
@ -98,6 +108,7 @@ FileLocation::Init(nsZipArchive* aZip, const char* aPath)
void
FileLocation::GetURIString(nsACString& aResult) const
{
#if !defined(MOZILLA_XPCOMRT_API)
if (mBaseFile) {
net_GetURLSpecFromActualFile(mBaseFile, aResult);
} else if (mBaseZip) {
@ -109,11 +120,13 @@ FileLocation::GetURIString(nsACString& aResult) const
aResult += "!/";
aResult += mPath;
}
#endif // !defined(MOZILLA_XPCOMRT_API)
}
already_AddRefed<nsIFile>
FileLocation::GetBaseFile()
{
#if !defined(MOZILLA_XPCOMRT_API)
if (IsZip() && mBaseZip) {
RefPtr<nsZipHandle> handler = mBaseZip->GetFD();
if (handler) {
@ -121,6 +134,7 @@ FileLocation::GetBaseFile()
}
return nullptr;
}
#endif // !defined(MOZILLA_XPCOMRT_API)
nsCOMPtr<nsIFile> file = mBaseFile;
return file.forget();
@ -140,6 +154,7 @@ FileLocation::Equals(const FileLocation& aFile) const
const FileLocation* a = this;
const FileLocation* b = &aFile;
#if !defined(MOZILLA_XPCOMRT_API)
if (a->mBaseZip) {
RefPtr<nsZipHandle> handler = a->mBaseZip->GetFD();
a = &handler->mFile;
@ -148,6 +163,7 @@ FileLocation::Equals(const FileLocation& aFile) const
RefPtr<nsZipHandle> handler = b->mBaseZip->GetFD();
b = &handler->mFile;
}
#endif // !defined(MOZILLA_XPCOMRT_API)
return a->Equals(*b);
}
@ -155,6 +171,7 @@ FileLocation::Equals(const FileLocation& aFile) const
nsresult
FileLocation::GetData(Data& aData)
{
#if !defined(MOZILLA_XPCOMRT_API)
if (!IsZip()) {
return mBaseFile->OpenNSPRFileDesc(PR_RDONLY, 0444, &aData.mFd.rwget());
}
@ -167,6 +184,7 @@ FileLocation::GetData(Data& aData)
if (aData.mItem) {
return NS_OK;
}
#endif // !defined(MOZILLA_XPCOMRT_API)
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
}
@ -186,10 +204,12 @@ FileLocation::Data::GetSize(uint32_t* aResult)
*aResult = fileInfo.size;
return NS_OK;
}
#if !defined(MOZILLA_XPCOMRT_API)
else if (mItem) {
*aResult = mItem->RealSize();
return NS_OK;
}
#endif // !defined(MOZILLA_XPCOMRT_API)
return NS_ERROR_NOT_INITIALIZED;
}
@ -207,6 +227,7 @@ FileLocation::Data::Copy(char* aBuf, uint32_t aLen)
}
return NS_OK;
}
#if !defined(MOZILLA_XPCOMRT_API)
else if (mItem) {
nsZipCursor cursor(mItem, mZip, reinterpret_cast<uint8_t*>(aBuf),
aLen, true);
@ -218,6 +239,7 @@ FileLocation::Data::Copy(char* aBuf, uint32_t aLen)
}
return NS_OK;
}
#endif // !defined(MOZILLA_XPCOMRT_API)
return NS_ERROR_NOT_INITIALIZED;
}

Просмотреть файл

@ -89,7 +89,11 @@ public:
* Boolean value corresponding to whether the file location is initialized
* or not.
*/
#if defined(MOZILLA_XPCOMRT_API)
explicit operator bool() const { return mBaseFile; }
#else
explicit operator bool() const { return mBaseFile || mBaseZip; }
#endif // defined(MOZILLA_XPCOMRT_API)
/**
* Returns whether another FileLocation points to the same resource
@ -113,7 +117,9 @@ public:
nsresult Copy(char* aBuf, uint32_t aLen);
protected:
friend class FileLocation;
#if !defined(MOZILLA_XPCOMRT_API)
nsZipItem* mItem;
#endif // !defined(MOZILLA_XPCOMRT_API)
RefPtr<nsZipArchive> mZip;
mozilla::AutoFDClose mFd;
};
@ -125,7 +131,9 @@ public:
nsresult GetData(Data& aData);
private:
nsCOMPtr<nsIFile> mBaseFile;
#if !defined(MOZILLA_XPCOMRT_API)
RefPtr<nsZipArchive> mBaseZip;
#endif // !defined(MOZILLA_XPCOMRT_API)
nsCString mPath;
}; /* class FileLocation */

Просмотреть файл

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// IWYU pragma: private, include "mozilla/Services.h"
#if !defined(MOZILLA_XPCOMRT_API)
#ifdef ACCESSIBILITY
MOZ_SERVICE(AccessibilityService, nsIAccessibilityService,
"@mozilla.org/accessibilityService;1")
@ -19,8 +20,10 @@ MOZ_SERVICE(XULOverlayProviderService, nsIXULOverlayProvider,
"@mozilla.org/chrome/chrome-registry;1")
MOZ_SERVICE(IOService, nsIIOService,
"@mozilla.org/network/io-service;1")
#endif // !defined(MOZILLA_XPCOMRT_API)
MOZ_SERVICE(ObserverService, nsIObserverService,
"@mozilla.org/observer-service;1")
#if !defined(MOZILLA_XPCOMRT_API)
MOZ_SERVICE(StringBundleService, nsIStringBundleService,
"@mozilla.org/intl/stringbundle;1")
MOZ_SERVICE(XPConnect, nsIXPConnect,
@ -48,3 +51,4 @@ MOZ_SERVICE(HistoryService, IHistory,
#ifdef MOZ_USE_NAMESPACE
} // namespace mozilla
#endif
#endif // !defined(MOZILLA_XPCOMRT_API)

Просмотреть файл

@ -11,6 +11,7 @@
#include "nsNetCID.h"
#include "nsObserverService.h"
#include "nsXPCOMPrivate.h"
#if !defined(MOZILLA_XPCOMRT_API)
#include "nsIIOService.h"
#include "nsIDirectoryService.h"
#ifdef ACCESSIBILITY
@ -28,6 +29,7 @@
#include "nsIAsyncShutdown.h"
#include "nsIUUIDGenerator.h"
#include "nsIGfxInfo.h"
#endif // !defined(MOZILLA_XPCOMRT_API)
using namespace mozilla;
using namespace mozilla::services;

Просмотреть файл

@ -8,7 +8,9 @@
#define ManifestParser_h
#include "nsComponentManager.h"
#if !defined(MOZILLA_XPCOMRT_API)
#include "nsChromeRegistry.h"
#endif // !defined(MOZILLA_XPCOMRT_API)
#include "mozilla/FileLocation.h"
void ParseManifest(NSLocationType aType, mozilla::FileLocation& aFile,

Просмотреть файл

@ -418,7 +418,9 @@ nsCategoryManager::nsCategoryManager()
void
nsCategoryManager::InitMemoryReporter()
{
#if !defined(MOZILLA_XPCOMRT_API)
RegisterStrongMemoryReporter(this);
#endif // !defined(MOZILLA_XPCOMRT_API)
}
nsCategoryManager::~nsCategoryManager()
@ -803,8 +805,10 @@ NS_CreateServicesFromCategory(const char* aCategory,
nsCOMPtr<nsISupports> instance = do_GetService(contractID);
if (!instance) {
#if !defined(MOZILLA_XPCOMRT_API)
LogMessage("While creating services from category '%s', could not create service for entry '%s', contract ID '%s'",
aCategory, entryString.get(), contractID.get());
#endif // !defined(MOZILLA_XPCOMRT_API)
continue;
}
@ -814,8 +818,10 @@ NS_CreateServicesFromCategory(const char* aCategory,
if (observer) {
observer->Observe(aOrigin, aObserverTopic, EmptyString().get());
} else {
#if !defined(MOZILLA_XPCOMRT_API)
LogMessage("While creating services from category '%s', service for entry '%s', contract ID '%s' does not implement nsIObserver.",
aCategory, entryString.get(), contractID.get());
#endif // !defined(MOZILLA_XPCOMRT_API)
}
}
}

Просмотреть файл

@ -58,8 +58,10 @@
#include "private/pprthred.h"
#include "nsTArray.h"
#include "prio.h"
#if !defined(MOZILLA_XPCOMRT_API)
#include "ManifestParser.h"
#include "nsNetUtil.h"
#endif // !defined(MOZILLA_XPCOMRT_API)
#include "mozilla/Services.h"
#include "mozilla/GenericFactory.h"
@ -252,6 +254,7 @@ private:
} // namespace
#if !defined(MOZILLA_XPCOMRT_API)
// this is safe to call during InitXPCOM
static already_AddRefed<nsIFile>
GetLocationFromDirectoryService(const char* aProp)
@ -288,6 +291,7 @@ CloneAndAppend(nsIFile* aBase, const nsACString& aAppend)
f->AppendNative(aAppend);
return f.forget();
}
#endif // !defined(MOZILLA_XPCOMRT_API)
////////////////////////////////////////////////////////////////////////////////
// nsComponentManagerImpl
@ -320,8 +324,10 @@ nsComponentManagerImpl::nsComponentManagerImpl()
nsTArray<const mozilla::Module*>* nsComponentManagerImpl::sStaticModules;
#if !defined(MOZILLA_XPCOMRT_API)
NSMODULE_DEFN(start_kPStaticModules);
NSMODULE_DEFN(end_kPStaticModules);
#endif // !defined(MOZILLA_XPCOMRT_API)
/* The content between start_kPStaticModules and end_kPStaticModules is gathered
* by the linker from various objects containing symbols in a specific section.
@ -337,12 +343,14 @@ nsComponentManagerImpl::InitializeStaticModules()
}
sStaticModules = new nsTArray<const mozilla::Module*>;
#if !defined(MOZILLA_XPCOMRT_API)
for (const mozilla::Module * const* staticModules =
&NSMODULE_NAME(start_kPStaticModules) + 1;
staticModules < &NSMODULE_NAME(end_kPStaticModules); ++staticModules)
if (*staticModules) { // ASAN adds padding
sStaticModules->AppendElement(*staticModules);
}
#endif // !defined(MOZILLA_XPCOMRT_API)
}
nsTArray<nsComponentManagerImpl::ComponentLocation>*
@ -366,26 +374,37 @@ nsComponentManagerImpl::Init()
// Initialize our arena
PL_INIT_ARENA_POOL(&mArena, "ComponentManagerArena", NS_CM_BLOCK_SIZE);
#if !defined(MOZILLA_XPCOMRT_API)
nsCOMPtr<nsIFile> greDir =
GetLocationFromDirectoryService(NS_GRE_DIR);
nsCOMPtr<nsIFile> appDir =
GetLocationFromDirectoryService(NS_XPCOM_CURRENT_PROCESS_DIR);
#endif
InitializeStaticModules();
#if !defined(MOZILLA_XPCOMRT_API)
nsresult rv = mNativeModuleLoader.Init();
if (NS_FAILED(rv)) {
return rv;
}
nsCategoryManager::GetSingleton()->SuppressNotifications(true);
#endif
#if defined(MOZILLA_XPCOMRT_API)
RegisterModule(&kXPCOMRTModule, nullptr);
RegisterModule(&kNeckoStandaloneModule, nullptr);
RegisterModule(&kStunUDPSocketFilterHandlerModule, nullptr);
#else
RegisterModule(&kXPCOMModule, nullptr);
#endif // defined(MOZILLA_XPCOMRT_API)
for (uint32_t i = 0; i < sStaticModules->Length(); ++i) {
RegisterModule((*sStaticModules)[i], nullptr);
}
#if !defined(MOZILLA_XPCOMRT_API)
// The overall order in which chrome.manifests are expected to be treated
// is the following:
// - greDir
@ -444,6 +463,7 @@ nsComponentManagerImpl::Init()
// component manager initialization we know it is setup and we can register
// for notifications.
LogModulePrefWatcher::RegisterPrefWatcher();
#endif
// Unfortunately, we can't register the nsCategoryManager memory reporter
// in its constructor (which is triggered by the GetSingleton() call
@ -552,10 +572,12 @@ nsComponentManagerImpl::RegisterCIDEntryLocked(
existing = "<unknown module>";
}
SafeMutexAutoUnlock unlock(mLock);
#if !defined(MOZILLA_XPCOMRT_API)
LogMessage("While registering XPCOM module %s, trying to re-register CID '%s' already registered by %s.",
aModule->Description().get(),
idstr,
existing.get());
#endif // !defined(MOZILLA_XPCOMRT_API)
return;
}
@ -581,9 +603,11 @@ nsComponentManagerImpl::RegisterContractIDLocked(
aEntry->cid->ToProvidedString(idstr);
SafeMutexAutoUnlock unlock(mLock);
#if !defined(MOZILLA_XPCOMRT_API)
LogMessage("Could not map contract ID '%s' to CID %s because no implementation of the CID is registered.",
aEntry->contractid,
idstr);
#endif // !defined(MOZILLA_XPCOMRT_API)
return;
}
@ -591,6 +615,7 @@ nsComponentManagerImpl::RegisterContractIDLocked(
mContractIDs.Put(nsDependentCString(aEntry->contractid), f);
}
#if !defined(MOZILLA_XPCOMRT_API)
static void
CutExtension(nsCString& aPath)
{
@ -833,10 +858,12 @@ nsComponentManagerImpl::RereadChromeManifests(bool aChromeOnly)
RegisterManifest(l.type, l.location, aChromeOnly);
}
}
#endif // !defined(MOZILLA_XPCOMRT_API)
bool
nsComponentManagerImpl::KnownModule::EnsureLoader()
{
#if !defined(MOZILLA_XPCOMRT_API)
if (!mLoader) {
nsCString extension;
mFile.GetURIString(extension);
@ -844,6 +871,7 @@ nsComponentManagerImpl::KnownModule::EnsureLoader()
mLoader =
nsComponentManagerImpl::gComponentManager->LoaderForExtension(extension);
}
#endif // !defined(MOZILLA_XPCOMRT_API)
return !!mLoader;
}
@ -900,7 +928,9 @@ nsresult nsComponentManagerImpl::Shutdown(void)
MOZ_LOG(nsComponentManagerLog, LogLevel::Debug,
("nsComponentManager: Beginning Shutdown."));
#if !defined(MOZILLA_XPCOMRT_API)
UnregisterWeakMemoryReporter(this);
#endif
// Release all cached factories
mContractIDs.Clear();
@ -916,8 +946,10 @@ nsresult nsComponentManagerImpl::Shutdown(void)
sXPTIInfosBook = nullptr;
#endif
#if !defined(MOZILLA_XPCOMRT_API)
// Unload libraries
mNativeModuleLoader.UnloadLibraries();
#endif // !defined(MOZILLA_XPCOMRT_API)
// delete arena for strings and small objects
PL_FinishArenaPool(&mArena);
@ -1588,6 +1620,7 @@ nsComponentManagerImpl::GetServiceByContractID(const char* aContractID,
return NS_OK;
}
#if !defined(MOZILLA_XPCOMRT_API)
already_AddRefed<mozilla::ModuleLoader>
nsComponentManagerImpl::LoaderForExtension(const nsACString& aExt)
{
@ -1604,6 +1637,7 @@ nsComponentManagerImpl::LoaderForExtension(const nsACString& aExt)
return loader.forget();
}
#endif
NS_IMETHODIMP
nsComponentManagerImpl::RegisterFactory(const nsCID& aClass,
@ -1676,8 +1710,12 @@ nsComponentManagerImpl::UnregisterFactory(const nsCID& aClass,
NS_IMETHODIMP
nsComponentManagerImpl::AutoRegister(nsIFile* aLocation)
{
#if !defined(MOZILLA_XPCOMRT_API)
XRE_AddManifestLocation(NS_EXTENSION_LOCATION, aLocation);
return NS_OK;
#else
return NS_ERROR_NOT_IMPLEMENTED;
#endif // !defined(MOZILLA_XPCOMRT_API)
}
NS_IMETHODIMP
@ -1995,6 +2033,7 @@ XRE_AddStaticComponent(const mozilla::Module* aComponent)
NS_IMETHODIMP
nsComponentManagerImpl::AddBootstrappedManifestLocation(nsIFile* aLocation)
{
#if !defined(MOZILLA_XPCOMRT_API)
nsString path;
nsresult rv = aLocation->GetPath(path);
if (NS_FAILED(rv)) {
@ -2008,11 +2047,15 @@ nsComponentManagerImpl::AddBootstrappedManifestLocation(nsIFile* aLocation)
nsCOMPtr<nsIFile> manifest =
CloneAndAppend(aLocation, NS_LITERAL_CSTRING("chrome.manifest"));
return XRE_AddManifestLocation(NS_BOOTSTRAPPED_LOCATION, manifest);
#else
return NS_ERROR_NOT_IMPLEMENTED;
#endif // !defined(MOZILLA_XPCOMRT_API)
}
NS_IMETHODIMP
nsComponentManagerImpl::RemoveBootstrappedManifestLocation(nsIFile* aLocation)
{
#if !defined(MOZILLA_XPCOMRT_API)
nsCOMPtr<nsIChromeRegistry> cr = mozilla::services::GetChromeRegistryService();
if (!cr) {
return NS_ERROR_FAILURE;
@ -2042,11 +2085,15 @@ nsComponentManagerImpl::RemoveBootstrappedManifestLocation(nsIFile* aLocation)
rv = cr->CheckForNewChrome();
return rv;
#else
return NS_ERROR_NOT_IMPLEMENTED;
#endif // !defined(MOZILLA_XPCOMRT_API)
}
NS_IMETHODIMP
nsComponentManagerImpl::GetManifestLocations(nsIArray** aLocations)
{
#if !defined(MOZILLA_XPCOMRT_API)
NS_ENSURE_ARG_POINTER(aLocations);
*aLocations = nullptr;
@ -2070,6 +2117,9 @@ nsComponentManagerImpl::GetManifestLocations(nsIArray** aLocations)
locations.forget(aLocations);
return NS_OK;
#else
return NS_ERROR_NOT_IMPLEMENTED;
#endif // !defined(MOZILLA_XPCOMRT_API)
}
#ifdef MOZ_B2G_LOADER
@ -2118,6 +2168,7 @@ PreloadXPT(nsIFile* aOmnijarFile)
#endif /* MOZ_B2G_LOADER */
#if !defined(MOZILLA_XPCOMRT_API)
EXPORT_XPCOM_API(nsresult)
XRE_AddManifestLocation(NSLocationType aType, nsIFile* aLocation)
{
@ -2158,4 +2209,5 @@ XRE_AddJarManifestLocation(NSLocationType aType, nsIFile* aLocation)
return NS_OK;
}
#endif // !defined(MOZILLA_XPCOMRT_API)

Просмотреть файл

@ -69,7 +69,13 @@ extern const char staticComponentType[];
#endif
////////////////////////////////////////////////////////////////////////////////
#if defined(MOZILLA_XPCOMRT_API)
extern const mozilla::Module kXPCOMRTModule;
extern const mozilla::Module kNeckoStandaloneModule;
extern const mozilla::Module kStunUDPSocketFilterHandlerModule;
#else
extern const mozilla::Module kXPCOMModule;
#endif
/**
* This is a wrapper around mozilla::Mutex which provides runtime

Просмотреть файл

@ -172,13 +172,17 @@ nsObserverService::~nsObserverService(void)
void
nsObserverService::RegisterReporter()
{
#if !defined(MOZILLA_XPCOMRT_API)
RegisterWeakMemoryReporter(this);
#endif // !defined(MOZILLA_XPCOMRT_API)
}
void
nsObserverService::Shutdown()
{
#if !defined(MOZILLA_XPCOMRT_API)
UnregisterWeakMemoryReporter(this);
#endif // !defined(MOZILLA_XPCOMRT_API)
mShuttingDown = true;
@ -318,6 +322,7 @@ nsObserverService::UnmarkGrayStrongObservers()
{
NS_ENSURE_VALIDCALL
#if !defined(MOZILLA_XPCOMRT_API)
nsCOMArray<nsIObserver> strongObservers;
for (auto iter = mObserverTopicTable.Iter(); !iter.Done(); iter.Next()) {
nsObserverList* aObserverList = iter.Get();
@ -329,6 +334,7 @@ nsObserverService::UnmarkGrayStrongObservers()
for (uint32_t i = 0; i < strongObservers.Length(); ++i) {
xpc_TryUnmarkWrappedGrayObject(strongObservers[i]);
}
#endif // !defined(MOZILLA_XPCOMRT_API)
return NS_OK;
}

Просмотреть файл

@ -23,7 +23,7 @@
#include "mozilla/ReentrantMonitor.h"
#include "mozilla/Mutex.h"
#if defined(MOZILLA_INTERNAL_API)
#if defined(MOZILLA_INTERNAL_API) && !defined(MOZILLA_XPCOMRT_API)
#include "GeckoProfiler.h"
#endif //MOZILLA_INTERNAL_API
@ -461,7 +461,7 @@ ReentrantMonitor::Wait(PRIntervalTime aInterval)
mChainPrev = 0;
nsresult rv;
#if defined(MOZILLA_INTERNAL_API)
#if defined(MOZILLA_INTERNAL_API) && !defined(MOZILLA_XPCOMRT_API)
{
GeckoProfilerSleepRAII profiler_sleep;
#endif //MOZILLA_INTERNAL_API
@ -470,7 +470,7 @@ ReentrantMonitor::Wait(PRIntervalTime aInterval)
rv = PR_Wait(mReentrantMonitor, aInterval) == PR_SUCCESS ? NS_OK :
NS_ERROR_FAILURE;
#if defined(MOZILLA_INTERNAL_API)
#if defined(MOZILLA_INTERNAL_API) && !defined(MOZILLA_XPCOMRT_API)
}
#endif //MOZILLA_INTERNAL_API

Просмотреть файл

@ -128,7 +128,7 @@ private:
// Macros for reference-count and constructor logging
#if defined(NS_BUILD_REFCNT_LOGGING)
#if defined(NS_BUILD_REFCNT_LOGGING) && !defined(MOZILLA_XPCOMRT_API)
#define NS_LOG_ADDREF(_p, _rc, _type, _size) \
NS_LogAddRef((_p), (_rc), (_type), (uint32_t) (_size))

Просмотреть файл

@ -0,0 +1,199 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:set ts=4 sw=4 sts=4 ci et: */
/* 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 "mozilla/Module.h"
#include "mozilla/ModuleUtils.h"
#include "mozilla/NullPtr.h"
#include "mozilla/TimeStamp.h"
#include "nsCategoryManager.h"
#include "nsComponentManager.h"
#include "nsDebugImpl.h"
#include "nsIErrorService.h"
#include "nsMemoryImpl.h"
#include "nsNetCID.h"
#include "nsNetModuleStandalone.h"
#include "nsObserverService.h"
#include "nsThreadManager.h"
#include "nsThreadPool.h"
#include "nsUUIDGenerator.h"
#include "nsXPCOMCIDInternal.h"
#include "nsXPCOMPrivate.h"
#include "TimerThread.h"
#include "XPCOMRTInit.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsUUIDGenerator, Init)
static nsresult
nsThreadManagerGetSingleton(nsISupports* aOuter,
const nsIID& aIID,
void** aInstancePtr)
{
NS_ASSERTION(aInstancePtr, "null outptr");
if (NS_WARN_IF(aOuter)) {
return NS_ERROR_NO_AGGREGATION;
}
return nsThreadManager::get()->QueryInterface(aIID, aInstancePtr);
}
NS_GENERIC_FACTORY_CONSTRUCTOR(nsThreadPool)
nsComponentManagerImpl* nsComponentManagerImpl::gComponentManager = nullptr;
bool gXPCOMShuttingDown = false;
bool gXPCOMThreadsShutDown = false;
#define COMPONENT(NAME, Ctor) static NS_DEFINE_CID(kNS_##NAME##_CID, NS_##NAME##_CID);
#include "XPCOMRTModule.inc"
#undef COMPONENT
#define COMPONENT(NAME, Ctor) { &kNS_##NAME##_CID, false, nullptr, Ctor },
const mozilla::Module::CIDEntry kXPCOMCIDEntries[] = {
{ &kComponentManagerCID, true, nullptr, nsComponentManagerImpl::Create },
#include "XPCOMRTModule.inc"
{ nullptr }
};
#undef COMPONENT
#define COMPONENT(NAME, Ctor) { NS_##NAME##_CONTRACTID, &kNS_##NAME##_CID },
const mozilla::Module::ContractIDEntry kXPCOMContracts[] = {
#include "XPCOMRTModule.inc"
{ nullptr }
};
#undef COMPONENT
const mozilla::Module kXPCOMRTModule = {
mozilla::Module::kVersion, kXPCOMCIDEntries, kXPCOMContracts
};
nsresult
NS_InitXPCOMRT()
{
nsresult rv = NS_OK;
NS_SetMainThread();
mozilla::TimeStamp::Startup();
rv = nsThreadManager::get()->Init();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// Set up the timer globals/timer thread
rv = nsTimerImpl::Startup();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsComponentManagerImpl::gComponentManager = new nsComponentManagerImpl();
NS_ADDREF(nsComponentManagerImpl::gComponentManager);
rv = nsComponentManagerImpl::gComponentManager->Init();
if (NS_FAILED(rv)) {
NS_RELEASE(nsComponentManagerImpl::gComponentManager);
return rv;
}
mozilla::InitNetModuleStandalone();
return NS_OK;
}
nsresult
NS_ShutdownXPCOMRT()
{
nsresult rv = NS_OK;
// Notify observers of xpcom shutting down
{
// Block it so that the COMPtr will get deleted before we hit
// servicemanager shutdown
nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
if (NS_WARN_IF(!thread)) {
return NS_ERROR_UNEXPECTED;
}
RefPtr<nsObserverService> observerService;
CallGetService("@mozilla.org/observer-service;1",
(nsObserverService**)getter_AddRefs(observerService));
if (observerService) {
observerService->NotifyObservers(nullptr,
NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID,
nullptr);
nsCOMPtr<nsIServiceManager> mgr;
rv = NS_GetServiceManager(getter_AddRefs(mgr));
if (NS_SUCCEEDED(rv)) {
observerService->NotifyObservers(mgr, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
nullptr);
}
}
// This must happen after the shutdown of media and widgets, which
// are triggered by the NS_XPCOM_SHUTDOWN_OBSERVER_ID notification.
NS_ProcessPendingEvents(thread);
if (observerService)
observerService->NotifyObservers(nullptr,
NS_XPCOM_SHUTDOWN_THREADS_OBSERVER_ID,
nullptr);
gXPCOMThreadsShutDown = true;
NS_ProcessPendingEvents(thread);
// Shutdown the timer thread and all timers that might still be alive before
// shutting down the component manager
nsTimerImpl::Shutdown();
NS_ProcessPendingEvents(thread);
// Net module needs to be shutdown before the thread manager or else
// the thread manager will hang waiting for the socket transport
// service to shutdown.
mozilla::ShutdownNetModuleStandalone();
// Shutdown all remaining threads. This method does not return until
// all threads created using the thread manager (with the exception of
// the main thread) have exited.
nsThreadManager::get()->Shutdown();
NS_ProcessPendingEvents(thread);
}
mozilla::services::Shutdown();
// Shutdown global servicemanager
if (nsComponentManagerImpl::gComponentManager) {
nsComponentManagerImpl::gComponentManager->FreeServices();
}
// Shutdown xpcom. This will release all loaders and cause others holding
// a refcount to the component manager to release it.
if (nsComponentManagerImpl::gComponentManager) {
rv = (nsComponentManagerImpl::gComponentManager)->Shutdown();
NS_ASSERTION(NS_SUCCEEDED(rv), "Component Manager shutdown failed.");
} else {
NS_WARNING("Component Manager was never created ...");
}
// Finally, release the component manager last because it unloads the
// libraries:
if (nsComponentManagerImpl::gComponentManager) {
nsrefcnt cnt;
NS_RELEASE2(nsComponentManagerImpl::gComponentManager, cnt);
NS_ASSERTION(cnt == 0, "Component Manager being held past XPCOM shutdown.");
}
nsComponentManagerImpl::gComponentManager = nullptr;
nsCategoryManager::Destroy();
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,15 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:set ts=4 sw=4 sts=4 ci et: */
/* 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 XPCOMRT_INIT_H__
#define XPCOMRT_INIT_H__
#include "nsError.h"
nsresult NS_InitXPCOMRT();
nsresult NS_ShutdownXPCOMRT();
#endif // define XPCOMRT_INIT_H__

Просмотреть файл

@ -0,0 +1,8 @@
COMPONENT(MEMORY, nsMemoryImpl::Create)
COMPONENT(DEBUG, nsDebugImpl::Create)
COMPONENT(CATEGORYMANAGER, nsCategoryManager::Create)
COMPONENT(OBSERVERSERVICE, nsObserverService::Create)
COMPONENT(TIMER, nsTimerImplConstructor)
COMPONENT(THREADMANAGER, nsThreadManagerGetSingleton)
COMPONENT(THREADPOOL, nsThreadPoolConstructor)
COMPONENT(UUID_GENERATOR, nsUUIDGeneratorConstructor)

Просмотреть файл

@ -0,0 +1,65 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:set ts=4 sw=4 sts=4 ci et: */
/* 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 "nsXULAppAPI.h"
#include "mozilla/TimeStamp.h"
GeckoProcessType
XRE_GetProcessType()
{
return GeckoProcessType_Default;
}
bool
XRE_IsParentProcess()
{
return XRE_GetProcessType() == GeckoProcessType_Default;
}
bool
XRE_IsContentProcess()
{
return XRE_GetProcessType() == GeckoProcessType_Content;
}
#define PRINT_CALLED fprintf(stderr, "!!! ERROR: function %s defined in file %s should not be called, needs to be correctly implemented.\n", __FUNCTION__, __FILE__)
class nsAString;
class nsCString;
namespace base {
class Histogram;
} // namespace base
namespace mozilla {
namespace Telemetry {
#include "mozilla/TelemetryHistogramEnums.h"
void Accumulate(ID id, uint32_t sample) {}
void Accumulate(ID id, const nsCString& key, uint32_t sample) {}
void Accumulate(const char* name, uint32_t sample) {}
void AccumulateTimeDelta(ID id, TimeStamp start, TimeStamp end) {}
base::Histogram* GetHistogramById(ID id)
{
return nullptr;
}
base::Histogram* GetKeyedHistogramById(ID id, const nsAString&)
{
return nullptr;
}
} // namespace Telemetry
namespace detail {
void log_print(const PRLogModuleInfo* aModule, LogLevel aLevel, const char* aFmt, ...) {}
} // namespace detail
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,40 @@
==========================
XPCOM Standalone Library
==========================
What it is for
--------------
The XPCOM standalone library, libxpcomrt, was created to support building the WebRTC
standalone library. The libxpcomrt library contains only the parts of XPCOM that are required
to run WebRTC; parts such as the cycle collector and the startup cache required only by Gecko
are not included. A library containing a small subset of Necko was also
created to support the WebRTC standalone library.
The libxcomrt library was created specifically to support the WebRTC standalone library.
It is not intended to be used as a general purpose library to add XPCOM functionality to
an application. It is likely that some of the code contained in the libxpcomrt library
has unresolved symbols that may be exposed if used for purposes other than being linked
into the WebRTC standalone library.
How to use it
-------------
When compiling code utilizing libxpcomrt, both ``MOZILLA_INTERNAL_API`` and ``MOZILLA_XPCOMRT_API``
must be defined in addition to whatever standard flags are used to compile Gecko.
The library is initialized with ``NS_InitXPCOMRT()`` and shutdown with ``NS_ShutdownXPCOMRT()``.
Both functions are declared in xpcom/libxpcomrt/XPCOMRTInit.h.
Only a small number of services which are required for the WebRTC
standalone library to function are included with libxpcomrt. The dynamic loading of services is not
supported. Including a service through ``NSMODULE_DEFN`` and static linking is also not supported.
The only way to add a service to libxpcomrt is to explicitly start the service during
``nsComponentManagerImpl::Init`` in xpcom/components/nsComponentManager.cpp.
The best method to determine what parts of XPCOM are included in libxpcomrt is to examine the
xpcom/libxpcomrt/moz.build file. It contains all of the XPCOM source files used to build libxpcomrt.
A few of the services that are included are:
* UUID Generator
* DNS Service
* Socket Transport Service
* IDN Service
All dependencies on ipc/chromium have been removed.
IO and preference services are not included making this library of limited utility.

142
xpcom/libxpcomrt/moz.build Normal file
Просмотреть файл

@ -0,0 +1,142 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
if CONFIG['OS_TARGET'] != 'WINNT' and CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
Library('xpcomrt')
src_list = [
'XPCOMRTInit.cpp',
'XPCOMRTStubs.cpp',
]
xpcom_base_src = [
'nsDebugImpl.cpp',
'nsMemoryImpl.cpp',
'nsUUIDGenerator.cpp',
]
src_list += [
'/xpcom/base/%s' % s for s in xpcom_base_src
]
xpcom_build_src = [
'FileLocation.cpp',
'Services.cpp',
]
src_list += [
'/xpcom/build/%s' % s for s in xpcom_build_src
]
xpcom_components_src = [
'nsCategoryManager.cpp',
'nsComponentManager.cpp',
]
src_list += [
'/xpcom/components/%s' % s for s in xpcom_components_src
]
xpcom_ds_src = [
'nsObserverList.cpp',
'nsObserverService.cpp',
'nsStringEnumerator.cpp',
'nsSupportsPrimitives.cpp',
]
src_list += [
'/xpcom/ds/%s' % s for s in xpcom_ds_src
]
xpcom_glue_src = [
'BlockingResourceBase.cpp',
'nsArrayEnumerator.cpp',
'nsClassInfoImpl.cpp',
'nsCOMArray.cpp',
'nsCOMPtr.cpp',
'nsCRTGlue.cpp',
'nsComponentManagerUtils.cpp',
'nsEnumeratorUtils.cpp',
'GenericFactory.cpp',
'nsID.cpp',
'nsISupportsImpl.cpp',
'nsMemory.cpp',
'nsQuickSort.cpp',
'nsTArray.cpp',
'nsTObserverArray.cpp',
'nsThreadUtils.cpp',
'nsWeakReference.cpp',
'PLDHashTable.cpp',
]
src_list += [
'/xpcom/glue/%s' % s for s in xpcom_glue_src
]
xpcom_io_src = [
'nsNativeCharsetUtils.cpp',
]
src_list += [
'/xpcom/io/%s' % s for s in xpcom_io_src
]
xpcom_string_src = [
'nsDependentSubstring.cpp',
'nsPromiseFlatString.cpp',
'nsReadableUtils.cpp',
'nsString.cpp',
'nsStringComparator.cpp',
'nsStringObsolete.cpp',
'nsSubstring.cpp',
'nsSubstringTuple.cpp',
]
if CONFIG['INTEL_ARCHITECTURE']:
xpcom_string_src += ['nsUTF8UtilsSSE2.cpp']
src_list += [
'/xpcom/string/%s' % s for s in xpcom_string_src
]
xpcom_threads_src = [
'LazyIdleThread.cpp',
'nsEnvironment.cpp',
'nsEventQueue.cpp',
'nsMemoryPressure.cpp',
'nsProcessCommon.cpp',
'nsThread.cpp',
'nsThreadManager.cpp',
'nsThreadPool.cpp',
'nsTimerImpl.cpp',
'TimerThread.cpp',
]
src_list += [
'/xpcom/threads/%s' % s for s in xpcom_threads_src
]
SOURCES += sorted(src_list)
if CONFIG['INTEL_ARCHITECTURE']:
sse_string_path = '/xpcom/string/nsUTF8UtilsSSE2.cpp'
SOURCES[sse_string_path].flags += CONFIG['SSE2_FLAGS']
LOCAL_INCLUDES = [
'!..',
'../base',
'../build',
'../components',
'../ds',
'../glue',
'../threads',
'/netwerk/standalone/',
'/xpcom/reflect/xptinfo/',
]
DEFINES['MOZILLA_INTERNAL_API'] = True
DEFINES['MOZILLA_XPCOMRT_API'] = True
DEFINES['MOZILLA_EXTERNAL_LINKAGE'] = True
include('/ipc/chromium/chromium-config.mozbuild')
SPHINX_TREES['libxpcomrt'] = 'docs'
if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wshadow']

Просмотреть файл

@ -24,6 +24,7 @@ DIRS += [
'system',
'../chrome',
'build',
'libxpcomrt',
]
if CONFIG['OS_ARCH'] == 'WINNT' and CONFIG['MOZ_DEBUG']:

Просмотреть файл

@ -179,8 +179,10 @@ LazyIdleThread::EnsureThread()
void
LazyIdleThread::InitThread()
{
#if !defined(MOZILLA_XPCOMRT_API)
char aLocal;
profiler_register_thread(mName.get(), &aLocal);
#endif // !defined(MOZILLA_XPCOMRT_API)
PR_SetCurrentThreadName(mName.get());
@ -211,7 +213,9 @@ LazyIdleThread::CleanupThread()
mThreadIsShuttingDown = true;
}
#if !defined(MOZILLA_XPCOMRT_API)
profiler_unregister_thread();
#endif // !defined(MOZILLA_XPCOMRT_API)
}
void

Просмотреть файл

@ -6,7 +6,9 @@
#include "nsThread.h"
#if !defined(MOZILLA_XPCOMRT_API)
#include "base/message_loop.h"
#endif // !defined(MOZILLA_XPCOMRT_API)
// Chromium's logging can sometimes leak through...
#ifdef LOG
@ -24,10 +26,12 @@
#include "mozilla/CycleCollectedJSRuntime.h"
#include "mozilla/Logging.h"
#include "nsIObserverService.h"
#if !defined(MOZILLA_XPCOMRT_API)
#include "mozilla/HangMonitor.h"
#include "mozilla/IOInterposer.h"
#include "mozilla/ipc/MessageChannel.h"
#include "mozilla/ipc/BackgroundChild.h"
#endif // defined(MOZILLA_XPCOMRT_API)
#include "mozilla/Services.h"
#include "nsXPCOMPrivate.h"
#include "mozilla/ChaosMode.h"
@ -293,7 +297,9 @@ public:
NS_IMETHOD Run()
{
mThread->mShutdownContext = mShutdownContext;
#if !defined(MOZILLA_XPCOMRT_API)
MessageLoop::current()->Quit();
#endif // !defined(MOZILLA_XPCOMRT_API)
return NS_OK;
}
private:
@ -364,7 +370,9 @@ SetupCurrentThreadForChaosMode()
/*static*/ void
nsThread::ThreadFunc(void* aArg)
{
#if !defined(MOZILLA_XPCOMRT_API)
using mozilla::ipc::BackgroundChild;
#endif // !defined(MOZILLA_XPCOMRT_API)
nsThread* self = static_cast<nsThread*>(aArg); // strong reference
self->mThread = PR_GetCurrentThread();
@ -373,7 +381,9 @@ nsThread::ThreadFunc(void* aArg)
// Inform the ThreadManager
nsThreadManager::get()->RegisterCurrentThread(self);
#if !defined(MOZILLA_XPCOMRT_API)
mozilla::IOInterposer::RegisterCurrentThread();
#endif // !defined(MOZILLA_XPCOMRT_API)
// Wait for and process startup event
nsCOMPtr<nsIRunnable> event;
@ -388,6 +398,11 @@ nsThread::ThreadFunc(void* aArg)
event = nullptr;
{
#if defined(MOZILLA_XPCOMRT_API)
while(!self->mShutdownContext) {
NS_ProcessNextEvent();
}
#else
// Scope for MessageLoop.
nsAutoPtr<MessageLoop> loop(
new MessageLoop(MessageLoop::TYPE_MOZILLA_NONMAINTHREAD));
@ -396,6 +411,7 @@ nsThread::ThreadFunc(void* aArg)
loop->Run();
BackgroundChild::CloseForCurrentThread();
#endif // defined(MOZILLA_XPCOMRT_API)
// NB: The main thread does not shut down here! It shuts down via
// nsThreadManager::Shutdown.
@ -425,7 +441,9 @@ nsThread::ThreadFunc(void* aArg)
}
}
#if !defined(MOZILLA_XPCOMRT_API)
mozilla::IOInterposer::UnregisterCurrentThread();
#endif // !defined(MOZILLA_XPCOMRT_API)
// Inform the threadmanager that this thread is going away
nsThreadManager::get()->UnregisterCurrentThread(self);
@ -887,10 +905,12 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult)
LOG(("THRD(%p) ProcessNextEvent [%u %u]\n", this, aMayWait,
mNestedEventLoopDepth));
#if !defined(MOZILLA_XPCOMRT_API)
// If we're on the main thread, we shouldn't be dispatching CPOWs.
if (mIsMainThread == MAIN_THREAD) {
ipc::CancelCPOWs();
}
#endif // !defined(MOZILLA_XPCOMRT_API)
if (NS_WARN_IF(PR_GetCurrentThread() != mThread)) {
return NS_ERROR_NOT_SAME_THREAD;
@ -906,9 +926,11 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult)
// and repeat the nested event loop since its state change hasn't happened yet.
bool reallyWait = aMayWait && (mNestedEventLoopDepth > 0 || !ShuttingDown());
#if !defined(MOZILLA_XPCOMRT_API)
if (MAIN_THREAD == mIsMainThread && reallyWait) {
HangMonitor::Suspend();
}
#endif // !defined(MOZILLA_XPCOMRT_API)
// Fire a memory pressure notification, if we're the main thread and one is
// pending.
@ -988,9 +1010,11 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult)
if (event) {
LOG(("THRD(%p) running [%p]\n", this, event.get()));
#if !defined(MOZILLA_XPCOMRT_API)
if (MAIN_THREAD == mIsMainThread) {
HangMonitor::NotifyActivity();
}
#endif // !defined(MOZILLA_XPCOMRT_API)
event->Run();
} else if (aMayWait) {
MOZ_ASSERT(ShuttingDown(),

Просмотреть файл

@ -464,8 +464,10 @@ nsTimerImpl::Fire()
return;
}
#if !defined(MOZILLA_XPCOMRT_API)
PROFILER_LABEL("Timer", "Fire",
js::ProfileEntry::Category::OTHER);
#endif
TimeStamp now = TimeStamp::Now();
if (MOZ_LOG_TEST(GetTimerLog(), LogLevel::Debug)) {