summaryrefslogtreecommitdiffstats
path: root/webkit/glue/devtools/devtools_rpc_unittest.cc
blob: d900fb8bce4a34c0c44cd897fd7c8b009cd9b244 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "PlatformString.h"
#undef LOG

#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/glue/devtools/devtools_mock_rpc.h"
#include "webkit/glue/devtools/devtools_rpc.h"

namespace {

#define TEST_RPC_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3, METHOD4) \
  METHOD0(Method0) \
  METHOD1(Method1, int) \
  METHOD2(Method2, int, String) \
  METHOD3(Method3, int, String, Value)
DEFINE_RPC_CLASS(TestRpcClass, TEST_RPC_STRUCT)

#define ANOTHER_TEST_RPC_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3, METHOD4) \
  METHOD0(Method0)
DEFINE_RPC_CLASS(AnotherTestRpcClass, ANOTHER_TEST_RPC_STRUCT)

class MockTestRpcClass : public TestRpcClassStub,
                         public DevToolsMockRpc {
 public:
  MockTestRpcClass() : TestRpcClassStub(NULL) {
    set_delegate(this);
  }
  ~MockTestRpcClass() {}
};

class MockAnotherTestRpcClass : public AnotherTestRpcClassStub,
                                public DevToolsMockRpc {
 public:
  MockAnotherTestRpcClass() : AnotherTestRpcClassStub(NULL) {
    set_delegate(this);
  }
  ~MockAnotherTestRpcClass() {}
};

class DevToolsRpcTests : public testing::Test {
 public:
  DevToolsRpcTests() {}

 protected:
  virtual void SetUp() {}
  virtual void TearDown() {}
};

// Tests method call serialization.
TEST_F(DevToolsRpcTests, TestSerialize) {
  MockTestRpcClass mock;
  mock.Method0();
  EXPECT_EQ("[\"TestRpcClass\",\"Method0\"]", mock.get_log());
  mock.Reset();

  mock.Method1(10);
  EXPECT_EQ("[\"TestRpcClass\",\"Method1\",10]", mock.get_log());
  mock.Reset();

  mock.Method2(20, "foo");
  EXPECT_EQ("[\"TestRpcClass\",\"Method2\",20,\"foo\"]", mock.get_log());
  mock.Reset();

  StringValue value("bar");
  mock.Method3(30, "foo", value);
  EXPECT_EQ("[\"TestRpcClass\",\"Method3\",30,\"foo\",\"bar\"]",
      mock.get_log());
  mock.Reset();
}

// Tests method call dispatch.
TEST_F(DevToolsRpcTests, TestDispatch) {
  MockTestRpcClass local;
  MockTestRpcClass remote;

  // Call 1.
  local.Reset();
  local.Method0();
  remote.Reset();
  remote.Method0();
  remote.Replay();

  TestRpcClassDispatch::Dispatch(&remote, local.get_log());
  remote.Verify();

  // Call 2.
  local.Reset();
  local.Method1(10);
  remote.Reset();
  remote.Method1(10);
  remote.Replay();
  TestRpcClassDispatch::Dispatch(&remote, local.get_log());
  remote.Verify();

  // Call 3.
  local.Reset();
  remote.Reset();
  local.Method2(20, "foo");
  remote.Method2(20, "foo");

  remote.Replay();
  TestRpcClassDispatch::Dispatch(&remote, local.get_log());
  remote.Verify();

  // Call 4.
  local.Reset();
  remote.Reset();
  StringValue value("bar");
  local.Method3(30, "foo", value);
  remote.Method3(30, "foo", value);

  remote.Replay();
  TestRpcClassDispatch::Dispatch(&remote, local.get_log());
  remote.Verify();
}

}  // namespace