From 1a619cdb5d742c8a0b535c74115411ea4c34e645 Mon Sep 17 00:00:00 2001 From: zhihuang Date: Thu, 5 Jan 2017 12:21:52 -0800 Subject: [PATCH] Create the MockIceTransport The src/remoting/protocol/channel_socket_adapter_unittest.cc will use this class instead of creating its own MockTransportChannel which subclasses the TransportChannel. This will make it easier to switch the base class of P2PTransportChannel from TransportChannel to IceTransportInternal. BUG=webrtc:6951 Review-Url: https://codereview.webrtc.org/2610663003 Cr-Commit-Position: refs/heads/master@{#15922} --- webrtc/p2p/BUILD.gn | 1 + webrtc/p2p/base/mockicetransport.h | 70 ++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 webrtc/p2p/base/mockicetransport.h diff --git a/webrtc/p2p/BUILD.gn b/webrtc/p2p/BUILD.gn index 120a800dc6..649e9cfd21 100644 --- a/webrtc/p2p/BUILD.gn +++ b/webrtc/p2p/BUILD.gn @@ -150,6 +150,7 @@ if (rtc_include_tests) { "base/fakeportallocator.h", "base/faketransportcontroller.h", "base/jseptransport_unittest.cc", + "base/mockicetransport.h", "base/p2ptransportchannel_unittest.cc", "base/port_unittest.cc", "base/portallocator_unittest.cc", diff --git a/webrtc/p2p/base/mockicetransport.h b/webrtc/p2p/base/mockicetransport.h new file mode 100644 index 0000000000..6b8b237529 --- /dev/null +++ b/webrtc/p2p/base/mockicetransport.h @@ -0,0 +1,70 @@ +/* + * Copyright 2016 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_P2P_BASE_MOCKICETRANSPORT_H_ +#define WEBRTC_P2P_BASE_MOCKICETRANSPORT_H_ + +#include +#include +#include + +#include "webrtc/base/gunit.h" +#include "webrtc/p2p/base/icetransportinternal.h" +#include "webrtc/test/gmock.h" + +using testing::_; +using testing::Return; + +namespace cricket { + +// Used in Chromium/remoting/protocol/channel_socket_adapter_unittest.cc +class MockIceTransport : public cricket::TransportChannel { + public: + MockIceTransport() : cricket::TransportChannel(std::string(), 0) { + set_writable(true); + } + + MOCK_METHOD4(SendPacket, + int(const char* data, + size_t len, + const rtc::PacketOptions& options, + int flags)); + MOCK_METHOD2(SetOption, int(rtc::Socket::Option opt, int value)); + MOCK_METHOD0(GetError, int()); + MOCK_CONST_METHOD0(GetIceRole, cricket::IceRole()); + MOCK_METHOD1(GetStats, bool(cricket::ConnectionInfos* infos)); + MOCK_CONST_METHOD0(IsDtlsActive, bool()); + MOCK_CONST_METHOD1(GetSslRole, bool(rtc::SSLRole* role)); + MOCK_METHOD1(SetSrtpCiphers, bool(const std::vector& ciphers)); + MOCK_METHOD1(GetSrtpCipher, bool(std::string* cipher)); + MOCK_METHOD1(GetSslCipher, bool(std::string* cipher)); + MOCK_CONST_METHOD0(GetLocalCertificate, + rtc::scoped_refptr()); + + // This can't be a real mock method because gmock doesn't support move-only + // return values. + std::unique_ptr GetRemoteSSLCertificate() + const override { + EXPECT_TRUE(false); // Never called. + return nullptr; + } + + MOCK_METHOD6(ExportKeyingMaterial, + bool(const std::string& label, + const uint8_t* context, + size_t context_len, + bool use_context, + uint8_t* result, + size_t result_len)); +}; + +} // namespace cricket + +#endif // WEBRTC_P2P_BASE_MOCKICETRANSPORT_H_