Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / extensions / browser / api / cast_channel / cast_test_util.h
blob2323e340c1065d7c1fd279470134510efaf0ac44
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 core_api {
18 namespace cast_channel {
20 extern const char kTestExtensionId[];
22 class MockCastTransport
23 : public extensions::core_api::cast_channel::CastTransport {
24 public:
25 MockCastTransport();
26 ~MockCastTransport() override;
28 void SetReadDelegate(scoped_ptr<CastTransport::Delegate> delegate) override;
30 MOCK_METHOD2(
31 SendMessage,
32 void(const extensions::core_api::cast_channel::CastMessage& message,
33 const net::CompletionCallback& callback));
35 MOCK_METHOD0(Start, void(void));
37 // Gets the read delegate that is currently active for this transport.
38 CastTransport::Delegate* current_delegate() const;
40 private:
41 scoped_ptr<CastTransport::Delegate> delegate_;
43 DISALLOW_COPY_AND_ASSIGN(MockCastTransport);
46 class MockCastTransportDelegate : public CastTransport::Delegate {
47 public:
48 MockCastTransportDelegate();
49 ~MockCastTransportDelegate() override;
51 MOCK_METHOD1(OnError, void(ChannelError error));
52 MOCK_METHOD1(OnMessage, void(const CastMessage& message));
53 MOCK_METHOD0(Start, void(void));
55 private:
56 DISALLOW_COPY_AND_ASSIGN(MockCastTransportDelegate);
59 class MockCastSocket : public CastSocket {
60 public:
61 MockCastSocket();
62 ~MockCastSocket() override;
64 // Mockable version of Connect. Accepts a bare pointer to a mock object.
65 // (GMock won't compile with scoped_ptr method parameters.)
66 MOCK_METHOD2(ConnectRawPtr,
67 void(CastTransport::Delegate* delegate,
68 base::Callback<void(ChannelError)> callback));
70 // Proxy for ConnectRawPtr. Unpacks scoped_ptr into a GMock-friendly bare
71 // ptr.
72 void Connect(scoped_ptr<CastTransport::Delegate> delegate,
73 base::Callback<void(ChannelError)> callback) override {
74 delegate_ = delegate.Pass();
75 ConnectRawPtr(delegate_.get(), callback);
78 MOCK_METHOD1(Close, void(const net::CompletionCallback& callback));
79 MOCK_CONST_METHOD0(ip_endpoint, const net::IPEndPoint&());
80 MOCK_CONST_METHOD0(id, int());
81 MOCK_METHOD1(set_id, void(int id));
82 MOCK_CONST_METHOD0(channel_auth, ChannelAuthType());
83 MOCK_CONST_METHOD0(cast_url, std::string());
84 MOCK_CONST_METHOD0(ready_state, ReadyState());
85 MOCK_CONST_METHOD0(error_state, ChannelError());
86 MOCK_CONST_METHOD0(keep_alive, bool(void));
87 MOCK_METHOD1(SetErrorState, void(ChannelError error_state));
89 CastTransport* transport() const override { return mock_transport_.get(); }
91 MockCastTransport* mock_transport() const { return mock_transport_.get(); }
93 private:
94 scoped_ptr<MockCastTransport> mock_transport_;
95 scoped_ptr<CastTransport::Delegate> delegate_;
97 DISALLOW_COPY_AND_ASSIGN(MockCastSocket);
100 // Creates the IPEndpoint 192.168.1.1.
101 net::IPEndPoint CreateIPEndPointForTest();
103 // Checks if two proto messages are the same.
104 // From
105 // third_party/cacheinvalidation/overrides/google/cacheinvalidation/deps/gmock.h
106 // TODO(kmarshall): promote to a shared testing library.
107 MATCHER_P(EqualsProto, message, "") {
108 std::string expected_serialized, actual_serialized;
109 message.SerializeToString(&expected_serialized);
110 arg.SerializeToString(&actual_serialized);
111 return expected_serialized == actual_serialized;
114 ACTION_TEMPLATE(RunCompletionCallback,
115 HAS_1_TEMPLATE_PARAMS(int, cb_idx),
116 AND_1_VALUE_PARAMS(rv)) {
117 testing::get<cb_idx>(args).Run(rv);
120 } // namespace cast_channel
121 } // namespace core_api
122 } // namespace extensions
124 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_TEST_UTIL_H_