diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /ipc/ipdl/test/cxx/TestBadActor.cpp | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ipc/ipdl/test/cxx/TestBadActor.cpp')
-rw-r--r-- | ipc/ipdl/test/cxx/TestBadActor.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/ipc/ipdl/test/cxx/TestBadActor.cpp b/ipc/ipdl/test/cxx/TestBadActor.cpp new file mode 100644 index 0000000000..6c6991dbb2 --- /dev/null +++ b/ipc/ipdl/test/cxx/TestBadActor.cpp @@ -0,0 +1,59 @@ +#include "TestBadActor.h" +#include "IPDLUnitTests.h" +#include "mozilla/Unused.h" + +namespace mozilla { +namespace _ipdltest { + +void TestBadActorParent::Main() { + // This test is designed to test a race condition where the child sends us + // a message on an actor that we've already destroyed. The child process + // should die, and the parent process should not abort. + + PTestBadActorSubParent* child = SendPTestBadActorSubConstructor(); + if (!child) fail("Sending constructor"); + + Unused << child->Call__delete__(child); +} + +// By default, fatal errors kill the parent process, but this makes it +// hard to test, so instead we use the previous behavior and kill the +// child process. +void TestBadActorParent::HandleFatalError(const char* aErrorMsg) { + if (!!strcmp(aErrorMsg, "incoming message racing with actor deletion")) { + fail("wrong fatal error"); + } + + ipc::ScopedProcessHandle otherProcessHandle; + if (!base::OpenProcessHandle(OtherPid(), &otherProcessHandle.rwget())) { + fail("couldn't open child process"); + } else { + if (!base::KillProcess(otherProcessHandle, 0, false)) { + fail("terminating child process"); + } + } +} + +PTestBadActorSubParent* TestBadActorParent::AllocPTestBadActorSubParent() { + return new TestBadActorSubParent(); +} + +mozilla::ipc::IPCResult TestBadActorSubParent::RecvPing() { + fail("Shouldn't have received ping."); + return IPC_FAIL_NO_REASON(this); +} + +PTestBadActorSubChild* TestBadActorChild::AllocPTestBadActorSubChild() { + return new TestBadActorSubChild(); +} + +mozilla::ipc::IPCResult TestBadActorChild::RecvPTestBadActorSubConstructor( + PTestBadActorSubChild* actor) { + if (!actor->SendPing()) { + fail("Couldn't send ping to an actor which supposedly isn't dead yet."); + } + return IPC_OK(); +} + +} // namespace _ipdltest +} // namespace mozilla |