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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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.
4
5 #include "remoting/signaling/xmpp_stream_parser.h"
6
7 #include "base/bind.h"
8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop/message_loop.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
12
13 namespace remoting {
14
15 class XmppStreamParserTest : public testing::Test {
16 public:
17 XmppStreamParserTest() : error_(false) {}
18
19 void SetUp() override {
20 parser_.reset(new remoting::XmppStreamParser());
21 parser_->SetCallbacks(
22 base::Bind(&XmppStreamParserTest::OnStanza, base::Unretained(this)),
23 base::Bind(&XmppStreamParserTest::OnError, base::Unretained(this)));
24 }
25
26 void OnStanza(scoped_ptr<buzz::XmlElement> stanza) {
27 received_stanzas_.push_back(stanza.Pass());
28 }
29
30 void OnError() {
31 error_ = true;
32 }
33
34 protected:
35 base::MessageLoop message_loop_;
36
37 scoped_ptr<XmppStreamParser> parser_;
38 ScopedVector<buzz::XmlElement> received_stanzas_;
39 bool error_;
40 };
41
42 TEST_F(XmppStreamParserTest, ParseXmppStream) {
43 parser_->AppendData("<stream><iq>text</iq>");
44 EXPECT_EQ(received_stanzas_[0]->Str(), "<iq>text</iq>");
45 };
46
47 TEST_F(XmppStreamParserTest, HandleMultipleIncomingStanzas) {
48 parser_->AppendData("<stream><iq>text</iq><iq>more text</iq>");
49 EXPECT_EQ(received_stanzas_[0]->Str(), "<iq>text</iq>");
50 EXPECT_EQ(received_stanzas_[1]->Str(), "<iq>more text</iq>");
51 };
52
53 TEST_F(XmppStreamParserTest, IgnoreWhitespaceBetweenStanzas) {
54 parser_->AppendData("<stream> <iq>text</iq>");
55 EXPECT_EQ(received_stanzas_[0]->Str(), "<iq>text</iq>");
56 };
57
58 TEST_F(XmppStreamParserTest, AssembleMessagesFromChunks) {
59 parser_->AppendData("<stream><i");
60 parser_->AppendData("q>");
61
62 // Split one UTF-8 sequence into two chunks
63 std::string data = "😃";
64 parser_->AppendData(data.substr(0, 2));
65 parser_->AppendData(data.substr(2));
66
67 parser_->AppendData("</iq>");
68
69 EXPECT_EQ(received_stanzas_[0]->Str(), "<iq>😃</iq>");
70 };
71
72 TEST_F(XmppStreamParserTest, StopParsingOnErrors) {
73 parser_->AppendData("<stream><invalidtag p!='a'></invalidtag><iq>text</iq>");
74 EXPECT_TRUE(error_);
75 EXPECT_TRUE(received_stanzas_.empty());
76 };
77
78 TEST_F(XmppStreamParserTest, FailOnInvalidStreamHeader) {
79 parser_->AppendData("<stream p!='a'>");
80 EXPECT_TRUE(error_);
81 };
82
83 TEST_F(XmppStreamParserTest, FailOnLooseText) {
84 parser_->AppendData("stream<");
85 EXPECT_TRUE(error_);
86 };
87
88 } // namespace remoting
OLDNEW
« remoting/signaling/xmpp_signal_strategy.cc ('K') | « remoting/signaling/xmpp_stream_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698