summaryrefslogtreecommitdiffstats
path: root/ipc/ipdl/test/gtest/TestMostNested.cpp
blob: d3fb3582c65957760e59ee4489a6e701deb12eaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * vim: sw=2 ts=4 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/. */

/*
 * Test nested sync message priorities.
 */

#include "gtest/gtest.h"

#include "mozilla/_ipdltest/IPDLUnitTest.h"
#include "mozilla/_ipdltest/PTestMostNestedChild.h"
#include "mozilla/_ipdltest/PTestMostNestedParent.h"

#if defined(XP_UNIX)
#  include <unistd.h>
#else
#  include <windows.h>
#endif

using namespace mozilla::ipc;

namespace mozilla::_ipdltest {

class TestMostNestedChild : public PTestMostNestedChild {
  NS_INLINE_DECL_REFCOUNTING(TestMostNestedChild, override)
 private:
  IPCResult RecvStart() final override {
    EXPECT_TRUE(SendMsg1());
    EXPECT_TRUE(SendMsg2());

    Close();
    return IPC_OK();
  }

  IPCResult RecvStartInner() final override {
    EXPECT_TRUE(SendMsg3());
    EXPECT_TRUE(SendMsg4());

    return IPC_OK();
  }

  ~TestMostNestedChild() = default;
};

class TestMostNestedParent : public PTestMostNestedParent {
  NS_INLINE_DECL_REFCOUNTING(TestMostNestedParent, override)
 private:
  IPCResult RecvMsg1() final override {
    EXPECT_EQ(msg_num, 0);
    msg_num = 1;
    return IPC_OK();
  }

  IPCResult RecvMsg2() final override {
    EXPECT_EQ(msg_num, 1);
    msg_num = 2;

    EXPECT_TRUE(SendStartInner());

    return IPC_OK();
  }

  IPCResult RecvMsg3() final override {
    EXPECT_EQ(msg_num, 2);
    msg_num = 3;
    return IPC_OK();
  }

  IPCResult RecvMsg4() final override {
    EXPECT_EQ(msg_num, 3);
    msg_num = 4;
    return IPC_OK();
  }

  ~TestMostNestedParent() = default;

  int msg_num = 0;
};

// Can only run cross-process because nested sync messages have to come from the
// main thread.
IPDL_TEST_ON(CROSSPROCESS, TestMostNested) { EXPECT_TRUE(mActor->SendStart()); }

}  // namespace mozilla::_ipdltest