| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/signaling/xmpp_stream_parser.h" | 5 #include "remoting/signaling/xmpp_stream_parser.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <utility> | 8 #include <utility> |
| 9 #include <vector> |
| 8 | 10 |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/memory/scoped_vector.h" | |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h" | 15 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h" |
| 15 | 16 |
| 16 namespace remoting { | 17 namespace remoting { |
| 17 | 18 |
| 18 class XmppStreamParserTest : public testing::Test { | 19 class XmppStreamParserTest : public testing::Test { |
| 19 public: | 20 public: |
| 20 XmppStreamParserTest() : error_(false) {} | 21 XmppStreamParserTest() : error_(false) {} |
| (...skipping 15 matching lines...) Expand all Loading... |
| 36 } | 37 } |
| 37 | 38 |
| 38 void OnError() { | 39 void OnError() { |
| 39 error_ = true; | 40 error_ = true; |
| 40 } | 41 } |
| 41 | 42 |
| 42 protected: | 43 protected: |
| 43 base::MessageLoop message_loop_; | 44 base::MessageLoop message_loop_; |
| 44 | 45 |
| 45 std::unique_ptr<XmppStreamParser> parser_; | 46 std::unique_ptr<XmppStreamParser> parser_; |
| 46 ScopedVector<buzz::XmlElement> received_stanzas_; | 47 std::vector<std::unique_ptr<buzz::XmlElement>> received_stanzas_; |
| 47 bool error_; | 48 bool error_; |
| 48 }; | 49 }; |
| 49 | 50 |
| 50 TEST_F(XmppStreamParserTest, ParseXmppStream) { | 51 TEST_F(XmppStreamParserTest, ParseXmppStream) { |
| 51 parser_->AppendData("<stream><iq>text</iq>"); | 52 parser_->AppendData("<stream><iq>text</iq>"); |
| 52 EXPECT_EQ(received_stanzas_[0]->Str(), "<iq>text</iq>"); | 53 EXPECT_EQ(received_stanzas_[0]->Str(), "<iq>text</iq>"); |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 TEST_F(XmppStreamParserTest, HandleMultipleIncomingStanzas) { | 56 TEST_F(XmppStreamParserTest, HandleMultipleIncomingStanzas) { |
| 56 parser_->AppendData("<stream><iq>text</iq><iq>more text</iq>"); | 57 parser_->AppendData("<stream><iq>text</iq><iq>more text</iq>"); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 87 parser_->AppendData("<stream p!='a'>"); | 88 parser_->AppendData("<stream p!='a'>"); |
| 88 EXPECT_TRUE(error_); | 89 EXPECT_TRUE(error_); |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 TEST_F(XmppStreamParserTest, FailOnLooseText) { | 92 TEST_F(XmppStreamParserTest, FailOnLooseText) { |
| 92 parser_->AppendData("stream<"); | 93 parser_->AppendData("stream<"); |
| 93 EXPECT_TRUE(error_); | 94 EXPECT_TRUE(error_); |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 } // namespace remoting | 97 } // namespace remoting |
| OLD | NEW |