| 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 <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 9 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 14 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
| 13 | 15 |
| 14 namespace remoting { | 16 namespace remoting { |
| 15 | 17 |
| 16 class XmppStreamParserTest : public testing::Test { | 18 class XmppStreamParserTest : public testing::Test { |
| 17 public: | 19 public: |
| 18 XmppStreamParserTest() : error_(false) {} | 20 XmppStreamParserTest() : error_(false) {} |
| 19 | 21 |
| 20 void SetUp() override { | 22 void SetUp() override { |
| 21 parser_.reset(new remoting::XmppStreamParser()); | 23 parser_.reset(new remoting::XmppStreamParser()); |
| 22 parser_->SetCallbacks( | 24 parser_->SetCallbacks( |
| 23 base::Bind(&XmppStreamParserTest::OnStanza, base::Unretained(this)), | 25 base::Bind(&XmppStreamParserTest::OnStanza, base::Unretained(this)), |
| 24 base::Bind(&XmppStreamParserTest::OnError, base::Unretained(this))); | 26 base::Bind(&XmppStreamParserTest::OnError, base::Unretained(this))); |
| 25 } | 27 } |
| 26 | 28 |
| 27 void TearDown() override { | 29 void TearDown() override { |
| 28 parser_.reset(); | 30 parser_.reset(); |
| 29 base::RunLoop().RunUntilIdle(); | 31 base::RunLoop().RunUntilIdle(); |
| 30 } | 32 } |
| 31 | 33 |
| 32 void OnStanza(scoped_ptr<buzz::XmlElement> stanza) { | 34 void OnStanza(scoped_ptr<buzz::XmlElement> stanza) { |
| 33 received_stanzas_.push_back(stanza.Pass()); | 35 received_stanzas_.push_back(std::move(stanza)); |
| 34 } | 36 } |
| 35 | 37 |
| 36 void OnError() { | 38 void OnError() { |
| 37 error_ = true; | 39 error_ = true; |
| 38 } | 40 } |
| 39 | 41 |
| 40 protected: | 42 protected: |
| 41 base::MessageLoop message_loop_; | 43 base::MessageLoop message_loop_; |
| 42 | 44 |
| 43 scoped_ptr<XmppStreamParser> parser_; | 45 scoped_ptr<XmppStreamParser> parser_; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 parser_->AppendData("<stream p!='a'>"); | 87 parser_->AppendData("<stream p!='a'>"); |
| 86 EXPECT_TRUE(error_); | 88 EXPECT_TRUE(error_); |
| 87 }; | 89 }; |
| 88 | 90 |
| 89 TEST_F(XmppStreamParserTest, FailOnLooseText) { | 91 TEST_F(XmppStreamParserTest, FailOnLooseText) { |
| 90 parser_->AppendData("stream<"); | 92 parser_->AppendData("stream<"); |
| 91 EXPECT_TRUE(error_); | 93 EXPECT_TRUE(error_); |
| 92 }; | 94 }; |
| 93 | 95 |
| 94 } // namespace remoting | 96 } // namespace remoting |
| OLD | NEW |