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

Unified Diff: remoting/signaling/xmpp_stream_parser_unittest.cc

Issue 958703003: Remove dependency on XMPP implementation in WebRTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months 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
« no previous file with comments | « remoting/signaling/xmpp_stream_parser.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/signaling/xmpp_stream_parser_unittest.cc
diff --git a/remoting/signaling/xmpp_stream_parser_unittest.cc b/remoting/signaling/xmpp_stream_parser_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a76e02c013a91e02b73c0a539b2f4339b0aa8b49
--- /dev/null
+++ b/remoting/signaling/xmpp_stream_parser_unittest.cc
@@ -0,0 +1,94 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/signaling/xmpp_stream_parser.h"
+
+#include "base/bind.h"
+#include "base/memory/scoped_vector.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
+
+namespace remoting {
+
+class XmppStreamParserTest : public testing::Test {
+ public:
+ XmppStreamParserTest() : error_(false) {}
+
+ void SetUp() override {
+ parser_.reset(new remoting::XmppStreamParser());
+ parser_->SetCallbacks(
+ base::Bind(&XmppStreamParserTest::OnStanza, base::Unretained(this)),
+ base::Bind(&XmppStreamParserTest::OnError, base::Unretained(this)));
+ }
+
+ void TearDown() override {
+ parser_.reset();
+ base::RunLoop().RunUntilIdle();
+ }
+
+ void OnStanza(scoped_ptr<buzz::XmlElement> stanza) {
+ received_stanzas_.push_back(stanza.Pass());
+ }
+
+ void OnError() {
+ error_ = true;
+ }
+
+ protected:
+ base::MessageLoop message_loop_;
+
+ scoped_ptr<XmppStreamParser> parser_;
+ ScopedVector<buzz::XmlElement> received_stanzas_;
+ bool error_;
+};
+
+TEST_F(XmppStreamParserTest, ParseXmppStream) {
+ parser_->AppendData("<stream><iq>text</iq>");
+ EXPECT_EQ(received_stanzas_[0]->Str(), "<iq>text</iq>");
+};
+
+TEST_F(XmppStreamParserTest, HandleMultipleIncomingStanzas) {
+ parser_->AppendData("<stream><iq>text</iq><iq>more text</iq>");
+ EXPECT_EQ(received_stanzas_[0]->Str(), "<iq>text</iq>");
+ EXPECT_EQ(received_stanzas_[1]->Str(), "<iq>more text</iq>");
+};
+
+TEST_F(XmppStreamParserTest, IgnoreWhitespaceBetweenStanzas) {
+ parser_->AppendData("<stream> <iq>text</iq>");
+ EXPECT_EQ(received_stanzas_[0]->Str(), "<iq>text</iq>");
+};
+
+TEST_F(XmppStreamParserTest, AssembleMessagesFromChunks) {
+ parser_->AppendData("<stream><i");
+ parser_->AppendData("q>");
+
+ // Split one UTF-8 sequence into two chunks
+ std::string data = "😃";
+ parser_->AppendData(data.substr(0, 2));
+ parser_->AppendData(data.substr(2));
+
+ parser_->AppendData("</iq>");
+
+ EXPECT_EQ(received_stanzas_[0]->Str(), "<iq>😃</iq>");
+};
+
+TEST_F(XmppStreamParserTest, StopParsingOnErrors) {
+ parser_->AppendData("<stream><invalidtag p!='a'></invalidtag><iq>text</iq>");
+ EXPECT_TRUE(error_);
+ EXPECT_TRUE(received_stanzas_.empty());
+};
+
+TEST_F(XmppStreamParserTest, FailOnInvalidStreamHeader) {
+ parser_->AppendData("<stream p!='a'>");
+ EXPECT_TRUE(error_);
+};
+
+TEST_F(XmppStreamParserTest, FailOnLooseText) {
+ parser_->AppendData("stream<");
+ EXPECT_TRUE(error_);
+};
+
+} // namespace remoting
« no previous file with comments | « remoting/signaling/xmpp_stream_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698