Files
palemoon27/ipc/ipdl/test/cxx/TestBridgeMain.cpp
T
roytam1 1beb91ad2b import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1262671 - IPC sentinel checking (r=froydnj) (2bd39988fe)
- Bug 1262671 - IPC ReadData/ReadBytes elimination (r=froydnj) (85b47baffd)
- Bug 1272415: Don't include task.h everywhere. r=froydnj (6198aedfed)
- Bug 1273312 - Add task.h to ipdl unit tests (r=khuey) (42b8d3bb90)
- Bug 1268616 - Part 1: Check max message size before resizing. r=billm (6889a43e16)
- Bug 1268616 - Part 2: Stop sending messages that are too large. r=billm (a68e6624be)
- Bug 1268616 - Part 3: Reduce the maxmimum IPC message size. r=billm (581076632e)
- Bug 1262671 - Use BufferList for Pickle (r=froydnj) (f61d8b233d)
- Bug 1262671 - Introduce MFBT BufferList class (r=froydnj) (cb1aca1708)
- mfbt: BufferList: VC2013 fix (93da0d98f7)
2024-10-08 22:16:10 +08:00

230 lines
5.5 KiB
C++

#include "TestBridgeMain.h"
#include "base/task.h"
#include "IPDLUnitTests.h" // fail etc.
#include "IPDLUnitTestSubprocess.h"
using namespace std;
namespace mozilla {
namespace _ipdltest {
//-----------------------------------------------------------------------------
// main process
void
TestBridgeMainParent::Main()
{
if (!SendStart())
fail("sending Start");
}
PTestBridgeMainSubParent*
TestBridgeMainParent::AllocPTestBridgeMainSubParent(Transport* transport,
ProcessId otherPid)
{
nsAutoPtr<TestBridgeMainSubParent> a(new TestBridgeMainSubParent(transport));
if (!a->Open(transport, otherPid, XRE_GetIOMessageLoop(), ipc::ParentSide)) {
return nullptr;
}
return a.forget();
}
void
TestBridgeMainParent::ActorDestroy(ActorDestroyReason why)
{
if (NormalShutdown != why)
fail("unexpected destruction!");
passed("ok");
QuitParent();
}
bool
TestBridgeMainSubParent::RecvHello()
{
return SendHi();
}
bool
TestBridgeMainSubParent::RecvHelloSync()
{
return true;
}
bool
TestBridgeMainSubParent::AnswerHelloRpc()
{
return CallHiRpc();
}
void
TestBridgeMainSubParent::ActorDestroy(ActorDestroyReason why)
{
if (NormalShutdown != why)
fail("unexpected destruction!");
// ActorDestroy() is just a callback from IPDL-generated code,
// which needs the top-level actor (this) to stay alive a little
// longer so other things can be cleaned up.
MessageLoop::current()->PostTask(
do_AddRef(new DeleteTask<TestBridgeMainSubParent>(this)));
XRE_GetIOMessageLoop()->PostTask(
do_AddRef(new DeleteTask<Transport>(mTransport)));
}
//-----------------------------------------------------------------------------
// sub process --- child of main
TestBridgeMainChild* gBridgeMainChild;
TestBridgeMainChild::TestBridgeMainChild()
: mSubprocess(nullptr)
{
gBridgeMainChild = this;
}
bool
TestBridgeMainChild::RecvStart()
{
vector<string> subsubArgs;
subsubArgs.push_back("TestBridgeSub");
mSubprocess = new IPDLUnitTestSubprocess();
if (!mSubprocess->SyncLaunch(subsubArgs))
fail("problem launching subprocess");
IPC::Channel* transport = mSubprocess->GetChannel();
if (!transport)
fail("no transport");
TestBridgeSubParent* bsp = new TestBridgeSubParent();
bsp->Open(transport, base::GetProcId(mSubprocess->GetChildProcessHandle()));
bsp->Main();
return true;
}
void
TestBridgeMainChild::ActorDestroy(ActorDestroyReason why)
{
if (NormalShutdown != why)
fail("unexpected destruction!");
// NB: this is kosher because QuitChild() joins with the IO thread
XRE_GetIOMessageLoop()->PostTask(
do_AddRef(new DeleteTask<IPDLUnitTestSubprocess>(mSubprocess)));
QuitChild();
}
void
TestBridgeSubParent::Main()
{
if (!SendPing())
fail("sending Ping");
}
bool
TestBridgeSubParent::RecvBridgeEm()
{
if (NS_FAILED(PTestBridgeMainSub::Bridge(gBridgeMainChild, this)))
fail("bridging Main and Sub");
return true;
}
void
TestBridgeSubParent::ActorDestroy(ActorDestroyReason why)
{
if (NormalShutdown != why)
fail("unexpected destruction!");
gBridgeMainChild->Close();
// ActorDestroy() is just a callback from IPDL-generated code,
// which needs the top-level actor (this) to stay alive a little
// longer so other things can be cleaned up.
MessageLoop::current()->PostTask(
do_AddRef(new DeleteTask<TestBridgeSubParent>(this)));
}
//-----------------------------------------------------------------------------
// subsub process --- child of sub
static TestBridgeSubChild* gBridgeSubChild;
TestBridgeSubChild::TestBridgeSubChild()
{
gBridgeSubChild = this;
}
bool
TestBridgeSubChild::RecvPing()
{
if (!SendBridgeEm())
fail("sending BridgeEm");
return true;
}
PTestBridgeMainSubChild*
TestBridgeSubChild::AllocPTestBridgeMainSubChild(Transport* transport,
ProcessId otherPid)
{
nsAutoPtr<TestBridgeMainSubChild> a(new TestBridgeMainSubChild(transport));
if (!a->Open(transport, otherPid, XRE_GetIOMessageLoop(), ipc::ChildSide)) {
return nullptr;
}
if (!a->SendHello())
fail("sending Hello");
return a.forget();
}
void
TestBridgeSubChild::ActorDestroy(ActorDestroyReason why)
{
if (NormalShutdown != why)
fail("unexpected destruction!");
QuitChild();
}
bool
TestBridgeMainSubChild::RecvHi()
{
if (!SendHelloSync())
fail("sending HelloSync");
if (!CallHelloRpc())
fail("calling HelloRpc");
if (!mGotHi)
fail("didn't answer HiRpc");
// Need to close the channel without message-processing frames on
// the C++ stack
MessageLoop::current()->PostTask(
NewNonOwningRunnableMethod(this, &TestBridgeMainSubChild::Close));
return true;
}
bool
TestBridgeMainSubChild::AnswerHiRpc()
{
mGotHi = true; // d00d
return true;
}
void
TestBridgeMainSubChild::ActorDestroy(ActorDestroyReason why)
{
if (NormalShutdown != why)
fail("unexpected destruction!");
gBridgeSubChild->Close();
// ActorDestroy() is just a callback from IPDL-generated code,
// which needs the top-level actor (this) to stay alive a little
// longer so other things can be cleaned up.
MessageLoop::current()->PostTask(
do_AddRef(new DeleteTask<TestBridgeMainSubChild>(this)));
XRE_GetIOMessageLoop()->PostTask(
do_AddRef(new DeleteTask<Transport>(mTransport)));
}
} // namespace mozilla
} // namespace _ipdltest