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

Unified Diff: remoting/protocol/jingle_session_unittest.cc

Issue 2586403003: [Chromoting] Add SessionPlugin in JingleSession (Closed)
Patch Set: Resolve review comments Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: remoting/protocol/jingle_session_unittest.cc
diff --git a/remoting/protocol/jingle_session_unittest.cc b/remoting/protocol/jingle_session_unittest.cc
index 64808e3ab88bda396505469bc05e8c5d281c74d2..b33a8f3856c2ccb6f4a13ab43f6b38136e9afda2 100644
--- a/remoting/protocol/jingle_session_unittest.cc
+++ b/remoting/protocol/jingle_session_unittest.cc
@@ -11,6 +11,7 @@
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/test/test_timeouts.h"
#include "base/time/time.h"
@@ -25,6 +26,7 @@
#include "remoting/protocol/fake_authenticator.h"
#include "remoting/protocol/jingle_session_manager.h"
#include "remoting/protocol/network_settings.h"
+#include "remoting/protocol/session_plugin.h"
#include "remoting/protocol/transport.h"
#include "remoting/protocol/transport_context.h"
#include "remoting/signaling/fake_signal_strategy.h"
@@ -101,6 +103,44 @@ class FakeTransport : public Transport {
base::Closure on_message_callback_;
};
+class FakePlugin : public SessionPlugin {
+ public:
+ std::unique_ptr<buzz::XmlElement> OnOutgoing(
+ Session::State state,
+ JingleMessage::ActionType action) override {
+ std::string tag_name = "test-tag-";
+ tag_name += base::IntToString(outgoing_messages_.size());
+ std::unique_ptr<buzz::XmlElement> new_message(new buzz::XmlElement(
+ buzz::QName("test-namespace", tag_name)));
+ outgoing_messages_.push_back(*new_message);
+ return new_message;
+ }
+
+ void OnIncoming(Session::State state,
+ JingleMessage::ActionType action,
+ const buzz::XmlElement* attachments) override {
+ if (attachments) {
+ for (const buzz::XmlElement* it = attachments->FirstElement();
+ it != nullptr;
+ it = it->NextElement()) {
+ incoming_messages_.push_back(*it);
+ }
+ }
+ }
+
+ const std::vector<buzz::XmlElement>& outgoing_messages() const {
+ return outgoing_messages_;
+ }
+
+ const std::vector<buzz::XmlElement>& incoming_messages() const {
+ return incoming_messages_;
+ }
+
+ private:
+ std::vector<buzz::XmlElement> outgoing_messages_;
+ std::vector<buzz::XmlElement> incoming_messages_;
+};
+
std::unique_ptr<buzz::XmlElement> CreateTransportInfo(const std::string& id) {
std::unique_ptr<buzz::XmlElement> result(
buzz::XmlElement::ForStr("<transport xmlns='google:remoting:ice'/>"));
@@ -124,6 +164,9 @@ class JingleSessionTest : public testing::Test {
host_session_.reset(session);
host_session_->SetEventHandler(&host_session_event_handler_);
host_session_->SetTransport(&host_transport_);
+ std::unique_ptr<FakePlugin> plugin(new FakePlugin());
+ host_plugin_ = plugin.get();
+ host_session_->AddPlugin(std::move(plugin));
}
void DeleteHostSession() { host_session_.reset(); }
@@ -237,6 +280,9 @@ class JingleSessionTest : public testing::Test {
client_server_->Connect(host_jid_, std::move(authenticator));
client_session_->SetEventHandler(&client_session_event_handler_);
client_session_->SetTransport(&client_transport_);
+ std::unique_ptr<FakePlugin> plugin(new FakePlugin());
+ client_plugin_ = plugin.get();
+ client_session_->AddPlugin(std::move(plugin));
base::RunLoop().RunUntilIdle();
}
@@ -277,6 +323,9 @@ class JingleSessionTest : public testing::Test {
std::unique_ptr<Session> client_session_;
MockSessionEventHandler client_session_event_handler_;
FakeTransport client_transport_;
+
+ FakePlugin* host_plugin_;
+ FakePlugin* client_plugin_;
};
@@ -555,5 +604,24 @@ TEST_F(JingleSessionTest, TransportInfoDuringAuthentication) {
EXPECT_EQ("1", client_transport_.received_messages()[0]->Attr(buzz::QN_ID));
}
+TEST_F(JingleSessionTest, TestSessionPlugin) {
+ CreateSessionManagers(3, FakeAuthenticator::ACCEPT);
+ ASSERT_NO_FATAL_FAILURE(
+ InitiateConnection(3, FakeAuthenticator::ACCEPT, false));
+ ASSERT_EQ(client_plugin_->outgoing_messages().size(),
+ host_plugin_->incoming_messages().size());
+ for (size_t i = 0; i < client_plugin_->outgoing_messages().size(); i++) {
+ ASSERT_EQ(client_plugin_->outgoing_messages()[i].Str(),
+ host_plugin_->incoming_messages()[i].Str());
+ }
+
+ ASSERT_EQ(client_plugin_->incoming_messages().size(),
+ host_plugin_->outgoing_messages().size());
+ for (size_t i = 0; i < client_plugin_->incoming_messages().size(); i++) {
+ ASSERT_EQ(client_plugin_->incoming_messages()[i].Str(),
+ host_plugin_->outgoing_messages()[i].Str());
+ }
+}
+
} // namespace protocol
} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698