summaryrefslogtreecommitdiffstats
path: root/ipc/ipdl/test/gtest
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:42 +0000
commitda4c7e7ed675c3bf405668739c3012d140856109 (patch)
treecdd868dba063fecba609a1d819de271f0d51b23e /ipc/ipdl/test/gtest
parentAdding upstream version 125.0.3. (diff)
downloadfirefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz
firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ipc/ipdl/test/gtest')
-rw-r--r--ipc/ipdl/test/gtest/PTestUniquePtrIPC.ipdl16
-rw-r--r--ipc/ipdl/test/gtest/TestHangs.cpp14
-rw-r--r--ipc/ipdl/test/gtest/TestUniquePtrIPC.cpp27
3 files changed, 39 insertions, 18 deletions
diff --git a/ipc/ipdl/test/gtest/PTestUniquePtrIPC.ipdl b/ipc/ipdl/test/gtest/PTestUniquePtrIPC.ipdl
index b55d8f19d1..2ef3d9cb59 100644
--- a/ipc/ipdl/test/gtest/PTestUniquePtrIPC.ipdl
+++ b/ipc/ipdl/test/gtest/PTestUniquePtrIPC.ipdl
@@ -1,15 +1,25 @@
+using std::string from "string";
+
+// std::string is an arbitrary simple type declared inside a namespace,
+// to test that that will work when used in a UniquePtr inside a union.
+
namespace mozilla {
namespace _ipdltest {
struct DummyStruct {
- int x;
+ string x;
+};
+
+union DummyUnion {
+ UniquePtr<string>;
+ int;
};
[ChildProc=any, ChildImpl=virtual, ParentImpl=virtual]
protocol PTestUniquePtrIPC {
child:
- async TestMessage(UniquePtr<int> a1, UniquePtr<DummyStruct> a2,
- DummyStruct a3, UniquePtr<int> a4);
+ async TestMessage(UniquePtr<string> a1, UniquePtr<DummyStruct> a2,
+ DummyStruct a3, UniquePtr<string> a4, DummyUnion a5);
async TestSendReference(UniquePtr<DummyStruct> a);
};
diff --git a/ipc/ipdl/test/gtest/TestHangs.cpp b/ipc/ipdl/test/gtest/TestHangs.cpp
index ddc4a0c7d0..56f28c8afa 100644
--- a/ipc/ipdl/test/gtest/TestHangs.cpp
+++ b/ipc/ipdl/test/gtest/TestHangs.cpp
@@ -25,8 +25,7 @@ enum class HangMode : uint32_t {
/// The synchronous call should time out.
Hang,
/// The synchronous call should time out but the response should still be
- /// received
- /// (racing with the reply timeout logic).
+ /// received (racing with the reply timeout logic).
HangButReceive,
/// The synchronous call should time out but the response should still be
/// received because the child indicates that processing should continue after
@@ -50,8 +49,10 @@ class TestHangsChild : public PTestHangsChild {
this->hangMode = (HangMode)hangMode;
auto result = SendHang(hangMode, timeout->CloneHandle());
+ // Only the `Hang` mode should actually fail.
if (this->hangMode == HangMode::Hang) {
- // Only the `Hang` mode should actually fail.
+ // See description in parent.
+ timeout->Signal();
EXPECT_FALSE(result);
} else {
EXPECT_TRUE(result);
@@ -102,6 +103,13 @@ class TestHangsParent : public PTestHangsParent {
// Wait to ensure the child process has called
// ShouldContinueFromReplyTimeout().
timeout->Wait();
+
+ if (hangMode == (uint32_t)HangMode::Hang) {
+ // Wait to ensure the child process has returned from `SendHang()`,
+ // otherwise the reply message can race with the processing after
+ // ShouldContinueFromReplyTimeout().
+ timeout->Wait();
+ }
}
return IPC_OK();
}
diff --git a/ipc/ipdl/test/gtest/TestUniquePtrIPC.cpp b/ipc/ipdl/test/gtest/TestUniquePtrIPC.cpp
index 52ca322f8e..b3c68b99b4 100644
--- a/ipc/ipdl/test/gtest/TestUniquePtrIPC.cpp
+++ b/ipc/ipdl/test/gtest/TestUniquePtrIPC.cpp
@@ -26,18 +26,20 @@ class TestUniquePtrIPCParent : public PTestUniquePtrIPCParent {
class TestUniquePtrIPCChild : public PTestUniquePtrIPCChild {
NS_INLINE_DECL_REFCOUNTING(TestUniquePtrIPCChild, override)
private:
- IPCResult RecvTestMessage(const UniquePtr<int>& aA1,
+ IPCResult RecvTestMessage(const UniquePtr<std::string>& aA1,
const UniquePtr<DummyStruct>& aA2,
const DummyStruct& aA3,
- const UniquePtr<int>& aA4) final override {
+ const UniquePtr<std::string>& aA4,
+ const DummyUnion& aA5) final override {
EXPECT_TRUE(aA1) << "TestMessage received NULL aA1";
EXPECT_TRUE(aA2) << "TestMessage received NULL aA2";
EXPECT_FALSE(aA4)
<< "TestMessage received non-NULL when expecting NULL aA4";
- EXPECT_EQ(*aA1, 1);
- EXPECT_EQ(aA2->x(), 2);
- EXPECT_EQ(aA3.x(), 3);
+ EXPECT_EQ(*aA1, std::string("unique"));
+ EXPECT_EQ(aA2->x(), std::string("uniqueStruct"));
+ EXPECT_EQ(aA3.x(), std::string("struct"));
+ EXPECT_EQ(*aA5.get_string(), std::string("union"));
return IPC_OK();
}
@@ -45,7 +47,7 @@ class TestUniquePtrIPCChild : public PTestUniquePtrIPCChild {
IPCResult RecvTestSendReference(
const UniquePtr<DummyStruct>& aA) final override {
EXPECT_TRUE(aA) << "TestSendReference received NULL item in child";
- EXPECT_EQ(aA->x(), 1);
+ EXPECT_EQ(aA->x(), std::string("reference"));
Close();
return IPC_OK();
@@ -55,12 +57,13 @@ class TestUniquePtrIPCChild : public PTestUniquePtrIPCChild {
};
IPDL_TEST(TestUniquePtrIPC) {
- UniquePtr<int> a1 = MakeUnique<int>(1);
- UniquePtr<DummyStruct> a2 = MakeUnique<DummyStruct>(2);
- DummyStruct a3(3);
- UniquePtr<int> a4;
+ UniquePtr<std::string> a1 = MakeUnique<std::string>("unique");
+ UniquePtr<DummyStruct> a2 = MakeUnique<DummyStruct>("uniqueStruct");
+ DummyStruct a3("struct");
+ UniquePtr<std::string> a4;
+ DummyUnion a5(MakeUnique<std::string>("union"));
- EXPECT_TRUE(mActor->SendTestMessage(a1, a2, a3, a4));
+ EXPECT_TRUE(mActor->SendTestMessage(a1, a2, a3, a4, a5));
EXPECT_TRUE(a1)
<< "IPC arguments are passed by const reference and shouldn't be moved";
@@ -70,7 +73,7 @@ IPDL_TEST(TestUniquePtrIPC) {
EXPECT_FALSE(a4) << "somehow turned null ptr into non-null by sending it";
// Pass UniquePtr by reference
- UniquePtr<DummyStruct> b = MakeUnique<DummyStruct>(1);
+ UniquePtr<DummyStruct> b = MakeUnique<DummyStruct>("reference");
EXPECT_TRUE(mActor->SendTestSendReference(b));
EXPECT_TRUE(b)