2013-07-10 00:45:36 +00:00
|
|
|
/*
|
|
|
|
|
* libjingle
|
|
|
|
|
* Copyright 2012, Google Inc.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
|
|
|
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// This file contains mock implementations of observers used in PeerConnection.
|
|
|
|
|
|
|
|
|
|
#ifndef TALK_APP_WEBRTC_TEST_MOCKPEERCONNECTIONOBSERVERS_H_
|
|
|
|
|
#define TALK_APP_WEBRTC_TEST_MOCKPEERCONNECTIONOBSERVERS_H_
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "talk/app/webrtc/datachannelinterface.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
class MockCreateSessionDescriptionObserver
|
|
|
|
|
: public webrtc::CreateSessionDescriptionObserver {
|
|
|
|
|
public:
|
|
|
|
|
MockCreateSessionDescriptionObserver()
|
|
|
|
|
: called_(false),
|
|
|
|
|
result_(false) {}
|
|
|
|
|
virtual ~MockCreateSessionDescriptionObserver() {}
|
|
|
|
|
virtual void OnSuccess(SessionDescriptionInterface* desc) {
|
|
|
|
|
called_ = true;
|
|
|
|
|
result_ = true;
|
|
|
|
|
desc_.reset(desc);
|
|
|
|
|
}
|
|
|
|
|
virtual void OnFailure(const std::string& error) {
|
|
|
|
|
called_ = true;
|
|
|
|
|
result_ = false;
|
|
|
|
|
}
|
|
|
|
|
bool called() const { return called_; }
|
|
|
|
|
bool result() const { return result_; }
|
|
|
|
|
SessionDescriptionInterface* release_desc() {
|
|
|
|
|
return desc_.release();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool called_;
|
|
|
|
|
bool result_;
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_ptr<SessionDescriptionInterface> desc_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MockSetSessionDescriptionObserver
|
|
|
|
|
: public webrtc::SetSessionDescriptionObserver {
|
|
|
|
|
public:
|
|
|
|
|
MockSetSessionDescriptionObserver()
|
|
|
|
|
: called_(false),
|
|
|
|
|
result_(false) {}
|
|
|
|
|
virtual ~MockSetSessionDescriptionObserver() {}
|
|
|
|
|
virtual void OnSuccess() {
|
|
|
|
|
called_ = true;
|
|
|
|
|
result_ = true;
|
|
|
|
|
}
|
|
|
|
|
virtual void OnFailure(const std::string& error) {
|
|
|
|
|
called_ = true;
|
|
|
|
|
result_ = false;
|
|
|
|
|
}
|
|
|
|
|
bool called() const { return called_; }
|
|
|
|
|
bool result() const { return result_; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool called_;
|
|
|
|
|
bool result_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MockDataChannelObserver : public webrtc::DataChannelObserver {
|
|
|
|
|
public:
|
|
|
|
|
explicit MockDataChannelObserver(webrtc::DataChannelInterface* channel)
|
2014-06-12 21:59:29 +00:00
|
|
|
: channel_(channel), received_message_count_(0) {
|
2013-07-10 00:45:36 +00:00
|
|
|
channel_->RegisterObserver(this);
|
|
|
|
|
state_ = channel_->state();
|
|
|
|
|
}
|
|
|
|
|
virtual ~MockDataChannelObserver() {
|
|
|
|
|
channel_->UnregisterObserver();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void OnStateChange() { state_ = channel_->state(); }
|
|
|
|
|
virtual void OnMessage(const DataBuffer& buffer) {
|
|
|
|
|
last_message_.assign(buffer.data.data(), buffer.data.length());
|
2014-06-12 21:59:29 +00:00
|
|
|
++received_message_count_;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IsOpen() const { return state_ == DataChannelInterface::kOpen; }
|
|
|
|
|
const std::string& last_message() const { return last_message_; }
|
2014-06-12 21:59:29 +00:00
|
|
|
size_t received_message_count() const { return received_message_count_; }
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
private:
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<webrtc::DataChannelInterface> channel_;
|
2013-07-10 00:45:36 +00:00
|
|
|
DataChannelInterface::DataState state_;
|
|
|
|
|
std::string last_message_;
|
2014-06-12 21:59:29 +00:00
|
|
|
size_t received_message_count_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MockStatsObserver : public webrtc::StatsObserver {
|
|
|
|
|
public:
|
2014-12-17 14:09:05 +00:00
|
|
|
MockStatsObserver() : called_(false), stats_() {}
|
2013-07-10 00:45:36 +00:00
|
|
|
virtual ~MockStatsObserver() {}
|
2014-12-17 14:09:05 +00:00
|
|
|
|
2014-08-15 08:38:30 +00:00
|
|
|
virtual void OnComplete(const StatsReports& reports) {
|
2014-12-17 14:09:05 +00:00
|
|
|
ASSERT(!called_);
|
2013-07-10 00:45:36 +00:00
|
|
|
called_ = true;
|
2014-12-17 14:09:05 +00:00
|
|
|
memset(&stats_, sizeof(stats_), 0);
|
|
|
|
|
stats_.number_of_reports = reports.size();
|
|
|
|
|
for (const auto* r : reports) {
|
|
|
|
|
if (r->type == StatsReport::kStatsReportTypeSsrc) {
|
|
|
|
|
GetIntValue(r, StatsReport::kStatsValueNameAudioOutputLevel,
|
|
|
|
|
&stats_.audio_output_level);
|
|
|
|
|
GetIntValue(r, StatsReport::kStatsValueNameAudioInputLevel,
|
|
|
|
|
&stats_.audio_input_level);
|
|
|
|
|
GetIntValue(r, StatsReport::kStatsValueNameBytesReceived,
|
|
|
|
|
&stats_.bytes_received);
|
|
|
|
|
GetIntValue(r, StatsReport::kStatsValueNameBytesSent,
|
|
|
|
|
&stats_.bytes_sent);
|
|
|
|
|
} else if (r->type == StatsReport::kStatsReportTypeBwe) {
|
|
|
|
|
GetIntValue(r, StatsReport::kStatsValueNameAvailableReceiveBandwidth,
|
|
|
|
|
&stats_.available_receive_bandwidth);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool called() const { return called_; }
|
2014-12-17 14:09:05 +00:00
|
|
|
size_t number_of_reports() const { return stats_.number_of_reports; }
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
int AudioOutputLevel() const {
|
|
|
|
|
ASSERT(called_);
|
|
|
|
|
return stats_.audio_output_level;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
int AudioInputLevel() const {
|
|
|
|
|
ASSERT(called_);
|
|
|
|
|
return stats_.audio_input_level;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
int BytesReceived() const {
|
|
|
|
|
ASSERT(called_);
|
|
|
|
|
return stats_.bytes_received;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
int BytesSent() const {
|
|
|
|
|
ASSERT(called_);
|
|
|
|
|
return stats_.bytes_sent;
|
2014-08-25 12:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
int AvailableReceiveBandwidth() const {
|
|
|
|
|
ASSERT(called_);
|
|
|
|
|
return stats_.available_receive_bandwidth;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2014-12-17 14:09:05 +00:00
|
|
|
bool GetIntValue(const StatsReport* report,
|
|
|
|
|
StatsReport::StatsValueName name,
|
|
|
|
|
int* value) {
|
2015-01-19 20:41:26 +00:00
|
|
|
for (const auto& v : report->values()) {
|
|
|
|
|
if (v->name == name) {
|
|
|
|
|
*value = rtc::FromString<int>(v->value);
|
2014-12-17 14:09:05 +00:00
|
|
|
return true;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-12-17 14:09:05 +00:00
|
|
|
return false;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool called_;
|
2014-12-17 14:09:05 +00:00
|
|
|
struct {
|
|
|
|
|
size_t number_of_reports;
|
|
|
|
|
int audio_output_level;
|
|
|
|
|
int audio_input_level;
|
|
|
|
|
int bytes_received;
|
|
|
|
|
int bytes_sent;
|
|
|
|
|
int available_receive_bandwidth;
|
|
|
|
|
} stats_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // TALK_APP_WEBRTC_TEST_MOCKPEERCONNECTIONOBSERVERS_H_
|