TestMostNested.cpp (1998B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 2 * vim: sw=2 ts=4 et : 3 */ 4 /* This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 7 8 /* 9 * Test nested sync message priorities. 10 */ 11 12 #include "gtest/gtest.h" 13 14 #include "mozilla/_ipdltest/IPDLUnitTest.h" 15 #include "mozilla/_ipdltest/PTestMostNestedChild.h" 16 #include "mozilla/_ipdltest/PTestMostNestedParent.h" 17 18 #if defined(XP_UNIX) 19 # include <unistd.h> 20 #else 21 # include <windows.h> 22 #endif 23 24 using namespace mozilla::ipc; 25 26 namespace mozilla::_ipdltest { 27 28 class TestMostNestedChild : public PTestMostNestedChild { 29 NS_INLINE_DECL_REFCOUNTING(TestMostNestedChild, override) 30 private: 31 IPCResult RecvStart() final override { 32 EXPECT_TRUE(SendMsg1()); 33 EXPECT_TRUE(SendMsg2()); 34 35 Close(); 36 return IPC_OK(); 37 } 38 39 IPCResult RecvStartInner() final override { 40 EXPECT_TRUE(SendMsg3()); 41 EXPECT_TRUE(SendMsg4()); 42 43 return IPC_OK(); 44 } 45 46 ~TestMostNestedChild() = default; 47 }; 48 49 class TestMostNestedParent : public PTestMostNestedParent { 50 NS_INLINE_DECL_REFCOUNTING(TestMostNestedParent, override) 51 private: 52 IPCResult RecvMsg1() final override { 53 EXPECT_EQ(msg_num, 0); 54 msg_num = 1; 55 return IPC_OK(); 56 } 57 58 IPCResult RecvMsg2() final override { 59 EXPECT_EQ(msg_num, 1); 60 msg_num = 2; 61 62 EXPECT_TRUE(SendStartInner()); 63 64 return IPC_OK(); 65 } 66 67 IPCResult RecvMsg3() final override { 68 EXPECT_EQ(msg_num, 2); 69 msg_num = 3; 70 return IPC_OK(); 71 } 72 73 IPCResult RecvMsg4() final override { 74 EXPECT_EQ(msg_num, 3); 75 msg_num = 4; 76 return IPC_OK(); 77 } 78 79 ~TestMostNestedParent() = default; 80 81 int msg_num = 0; 82 }; 83 84 // Can only run cross-process because nested sync messages have to come from the 85 // main thread. 86 IPDL_TEST_ON(CROSSPROCESS, TestMostNested) { EXPECT_TRUE(mActor->SendStart()); } 87 88 } // namespace mozilla::_ipdltest