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

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