Add ICU message format support
[chromium-blink-merge.git] / extensions / browser / api / cast_channel / cast_test_util.h
blob423f4c328bf3c5d8cb6da36735c3bb4e09f066e3
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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_TEST_UTIL_H_
6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_TEST_UTIL_H_
8 #include <string>
10 #include "extensions/browser/api/cast_channel/cast_socket.h"
11 #include "extensions/browser/api/cast_channel/cast_transport.h"
12 #include "extensions/common/api/cast_channel/cast_channel.pb.h"
13 #include "net/base/ip_endpoint.h"
14 #include "testing/gmock/include/gmock/gmock.h"
16 namespace extensions {
17 namespace api {
18 namespace cast_channel {
20 extern const char kTestExtensionId[];
22 class MockCastTransport : public extensions::api::cast_channel::CastTransport {
23 public:
24 MockCastTransport();
25 ~MockCastTransport() override;
27 void SetReadDelegate(scoped_ptr<CastTransport::Delegate> delegate) override;
29 MOCK_METHOD2(SendMessage,
30 void(const extensions::api::cast_channel::CastMessage& message,
31 const net::CompletionCallback& callback));
33 MOCK_METHOD0(Start, void(void));
35 // Gets the read delegate that is currently active for this transport.
36 CastTransport::Delegate* current_delegate() const;
38 private:
39 scoped_ptr<CastTransport::Delegate> delegate_;
41 DISALLOW_COPY_AND_ASSIGN(MockCastTransport);
44 class MockCastTransportDelegate : public CastTransport::Delegate {
45 public:
46 MockCastTransportDelegate();
47 ~MockCastTransportDelegate() override;
49 MOCK_METHOD1(OnError, void(ChannelError error));
50 MOCK_METHOD1(OnMessage, void(const CastMessage& message));
51 MOCK_METHOD0(Start, void(void));
53 private:
54 DISALLOW_COPY_AND_ASSIGN(MockCastTransportDelegate);
57 class MockCastSocket : public CastSocket {
58 public:
59 MockCastSocket();
60 ~MockCastSocket() override;
62 // Mockable version of Connect. Accepts a bare pointer to a mock object.
63 // (GMock won't compile with scoped_ptr method parameters.)
64 MOCK_METHOD2(ConnectRawPtr,
65 void(CastTransport::Delegate* delegate,
66 base::Callback<void(ChannelError)> callback));
68 // Proxy for ConnectRawPtr. Unpacks scoped_ptr into a GMock-friendly bare
69 // ptr.
70 void Connect(scoped_ptr<CastTransport::Delegate> delegate,
71 base::Callback<void(ChannelError)> callback) override {
72 delegate_ = delegate.Pass();
73 ConnectRawPtr(delegate_.get(), callback);
76 MOCK_METHOD1(Close, void(const net::CompletionCallback& callback));
77 MOCK_CONST_METHOD0(ip_endpoint, const net::IPEndPoint&());
78 MOCK_CONST_METHOD0(id, int());
79 MOCK_METHOD1(set_id, void(int id));
80 MOCK_CONST_METHOD0(channel_auth, ChannelAuthType());
81 MOCK_CONST_METHOD0(ready_state, ReadyState());
82 MOCK_CONST_METHOD0(error_state, ChannelError());
83 MOCK_CONST_METHOD0(keep_alive, bool(void));
84 MOCK_METHOD1(SetErrorState, void(ChannelError error_state));
86 CastTransport* transport() const override { return mock_transport_.get(); }
88 MockCastTransport* mock_transport() const { return mock_transport_.get(); }
90 private:
91 scoped_ptr<MockCastTransport> mock_transport_;
92 scoped_ptr<CastTransport::Delegate> delegate_;
94 DISALLOW_COPY_AND_ASSIGN(MockCastSocket);
97 // Creates the IPEndpoint 192.168.1.1.
98 net::IPEndPoint CreateIPEndPointForTest();
100 // Checks if two proto messages are the same.
101 // From
102 // third_party/cacheinvalidation/overrides/google/cacheinvalidation/deps/gmock.h
103 // TODO(kmarshall): promote to a shared testing library.
104 MATCHER_P(EqualsProto, message, "") {
105 std::string expected_serialized, actual_serialized;
106 message.SerializeToString(&expected_serialized);
107 arg.SerializeToString(&actual_serialized);
108 return expected_serialized == actual_serialized;
111 ACTION_TEMPLATE(RunCompletionCallback,
112 HAS_1_TEMPLATE_PARAMS(int, cb_idx),
113 AND_1_VALUE_PARAMS(rv)) {
114 testing::get<cb_idx>(args).Run(rv);
117 } // namespace cast_channel
118 } // namespace api
119 } // namespace extensions
121 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_TEST_UTIL_H_