Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: components/cast_channel/cast_test_util.h

Issue 2974523002: [cast_channel] Make CastSocketService a global leaky singleton (Closed)
Patch Set: merge with master Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_CAST_CHANNEL_CAST_TEST_UTIL_H_ 5 #ifndef COMPONENTS_CAST_CHANNEL_CAST_TEST_UTIL_H_
6 #define COMPONENTS_CAST_CHANNEL_CAST_TEST_UTIL_H_ 6 #define COMPONENTS_CAST_CHANNEL_CAST_TEST_UTIL_H_
7 7
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "components/cast_channel/cast_socket.h" 13 #include "components/cast_channel/cast_socket.h"
14 #include "components/cast_channel/cast_socket_service.h"
14 #include "components/cast_channel/cast_transport.h" 15 #include "components/cast_channel/cast_transport.h"
15 #include "components/cast_channel/proto/cast_channel.pb.h" 16 #include "components/cast_channel/proto/cast_channel.pb.h"
16 #include "net/base/ip_endpoint.h" 17 #include "net/base/ip_endpoint.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 19
19 namespace cast_channel { 20 namespace cast_channel {
20 21
21 class MockCastTransport : public CastTransport { 22 class MockCastTransport : public CastTransport {
22 public: 23 public:
23 MockCastTransport(); 24 MockCastTransport();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 class MockCastSocketObserver : public CastSocket::Observer { 58 class MockCastSocketObserver : public CastSocket::Observer {
58 public: 59 public:
59 MockCastSocketObserver(); 60 MockCastSocketObserver();
60 ~MockCastSocketObserver() override; 61 ~MockCastSocketObserver() override;
61 62
62 MOCK_METHOD2(OnError, void(const CastSocket& socket, ChannelError error)); 63 MOCK_METHOD2(OnError, void(const CastSocket& socket, ChannelError error));
63 MOCK_METHOD2(OnMessage, 64 MOCK_METHOD2(OnMessage,
64 void(const CastSocket& socket, const CastMessage& message)); 65 void(const CastSocket& socket, const CastMessage& message));
65 }; 66 };
66 67
68 class MockCastSocketService : public CastSocketService {
69 public:
70 MockCastSocketService();
71 ~MockCastSocketService() override;
72
73 MOCK_METHOD4(OpenSocket,
74 int(const net::IPEndPoint& ip_endpoint,
75 net::NetLog* net_log,
76 const CastSocket::OnOpenCallback& open_cb,
77 CastSocket::Observer* observer));
78 MOCK_CONST_METHOD1(GetSocket, CastSocket*(int channel_id));
79 };
80
67 class MockCastSocket : public CastSocket { 81 class MockCastSocket : public CastSocket {
68 public: 82 public:
69 MockCastSocket(); 83 MockCastSocket();
70 ~MockCastSocket() override; 84 ~MockCastSocket() override;
71 85
72 MOCK_METHOD1(Connect, void(const OnOpenCallback& callback)); 86 MOCK_METHOD1(Connect, void(const OnOpenCallback& callback));
73 MOCK_METHOD1(Close, void(const net::CompletionCallback& callback)); 87 MOCK_METHOD1(Close, void(const net::CompletionCallback& callback));
74 MOCK_CONST_METHOD0(ready_state, ReadyState()); 88 MOCK_CONST_METHOD0(ready_state, ReadyState());
75 MOCK_METHOD1(AddObserver, void(Observer* observer)); 89 MOCK_METHOD1(AddObserver, void(Observer* observer));
90 MOCK_METHOD1(RemoveObserver, void(Observer* observer));
76 91
77 const net::IPEndPoint& ip_endpoint() const override { return ip_endpoint_; } 92 const net::IPEndPoint& ip_endpoint() const override { return ip_endpoint_; }
78 void SetIPEndpoint(const net::IPEndPoint& ip_endpoint) { 93 void SetIPEndpoint(const net::IPEndPoint& ip_endpoint) {
79 ip_endpoint_ = ip_endpoint; 94 ip_endpoint_ = ip_endpoint;
80 } 95 }
81 96
82 int id() const override { return channel_id_; } 97 int id() const override { return channel_id_; }
83 void set_id(int id) override { channel_id_ = id; } 98 void set_id(int id) override { channel_id_ = id; }
84 99
85 ChannelError error_state() const override { return error_state_; } 100 ChannelError error_state() const override { return error_state_; }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 ACTION_TEMPLATE(PostCompletionCallbackTask, 141 ACTION_TEMPLATE(PostCompletionCallbackTask,
127 HAS_1_TEMPLATE_PARAMS(int, cb_idx), 142 HAS_1_TEMPLATE_PARAMS(int, cb_idx),
128 AND_1_VALUE_PARAMS(rv)) { 143 AND_1_VALUE_PARAMS(rv)) {
129 base::ThreadTaskRunnerHandle::Get()->PostTask( 144 base::ThreadTaskRunnerHandle::Get()->PostTask(
130 FROM_HERE, base::Bind(testing::get<cb_idx>(args), rv)); 145 FROM_HERE, base::Bind(testing::get<cb_idx>(args), rv));
131 } 146 }
132 147
133 } // namespace cast_channel 148 } // namespace cast_channel
134 149
135 #endif // COMPONENTS_CAST_CHANNEL_CAST_TEST_UTIL_H_ 150 #endif // COMPONENTS_CAST_CHANNEL_CAST_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « components/cast_channel/cast_socket_service_unittest.cc ('k') | components/cast_channel/cast_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698