| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/protocol/content_description.h" | 5 #include "remoting/protocol/content_description.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "remoting/protocol/authenticator.h" | 11 #include "remoting/protocol/authenticator.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 14 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
| 15 | 15 |
| 16 namespace remoting { | 16 namespace remoting { |
| 17 namespace protocol { | 17 namespace protocol { |
| 18 | 18 |
| 19 TEST(ContentDescriptionTest, FormatAndParse) { | 19 TEST(ContentDescriptionTest, FormatAndParse) { |
| 20 scoped_ptr<CandidateSessionConfig> config = | 20 std::unique_ptr<CandidateSessionConfig> config = |
| 21 CandidateSessionConfig::CreateDefault(); | 21 CandidateSessionConfig::CreateDefault(); |
| 22 ContentDescription description( | 22 ContentDescription description( |
| 23 std::move(config), Authenticator::CreateEmptyAuthenticatorMessage()); | 23 std::move(config), Authenticator::CreateEmptyAuthenticatorMessage()); |
| 24 scoped_ptr<buzz::XmlElement> xml(description.ToXml()); | 24 std::unique_ptr<buzz::XmlElement> xml(description.ToXml()); |
| 25 LOG(ERROR) << xml->Str(); | 25 LOG(ERROR) << xml->Str(); |
| 26 scoped_ptr<ContentDescription> parsed( | 26 std::unique_ptr<ContentDescription> parsed( |
| 27 ContentDescription::ParseXml(xml.get(), false)); | 27 ContentDescription::ParseXml(xml.get(), false)); |
| 28 ASSERT_TRUE(parsed.get()); | 28 ASSERT_TRUE(parsed.get()); |
| 29 EXPECT_TRUE(description.config()->control_configs() == | 29 EXPECT_TRUE(description.config()->control_configs() == |
| 30 parsed->config()->control_configs()); | 30 parsed->config()->control_configs()); |
| 31 EXPECT_TRUE(description.config()->video_configs() == | 31 EXPECT_TRUE(description.config()->video_configs() == |
| 32 parsed->config()->video_configs()); | 32 parsed->config()->video_configs()); |
| 33 EXPECT_TRUE(description.config()->event_configs() == | 33 EXPECT_TRUE(description.config()->event_configs() == |
| 34 parsed->config()->event_configs()); | 34 parsed->config()->event_configs()); |
| 35 EXPECT_TRUE(description.config()->audio_configs() == | 35 EXPECT_TRUE(description.config()->audio_configs() == |
| 36 parsed->config()->audio_configs()); | 36 parsed->config()->audio_configs()); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // Verify that we can still parse configs with transports that we don't | 39 // Verify that we can still parse configs with transports that we don't |
| 40 // recognize. | 40 // recognize. |
| 41 TEST(ContentDescriptionTest, ParseUnknown) { | 41 TEST(ContentDescriptionTest, ParseUnknown) { |
| 42 std::string kTestDescription = | 42 std::string kTestDescription = |
| 43 "<description xmlns=\"google:remoting\">" | 43 "<description xmlns=\"google:remoting\">" |
| 44 " <standard-ice/>" | 44 " <standard-ice/>" |
| 45 " <control transport=\"stream\" version=\"2\"/>" | 45 " <control transport=\"stream\" version=\"2\"/>" |
| 46 " <event transport=\"stream\" version=\"2\"/>" | 46 " <event transport=\"stream\" version=\"2\"/>" |
| 47 " <event transport=\"new_awesome_transport\" version=\"3\"/>" | 47 " <event transport=\"new_awesome_transport\" version=\"3\"/>" |
| 48 " <video transport=\"stream\" version=\"2\" codec=\"vp8\"/>" | 48 " <video transport=\"stream\" version=\"2\" codec=\"vp8\"/>" |
| 49 " <authentication/>" | 49 " <authentication/>" |
| 50 "</description>"; | 50 "</description>"; |
| 51 scoped_ptr<buzz::XmlElement> xml(buzz::XmlElement::ForStr(kTestDescription)); | 51 std::unique_ptr<buzz::XmlElement> xml( |
| 52 scoped_ptr<ContentDescription> parsed( | 52 buzz::XmlElement::ForStr(kTestDescription)); |
| 53 std::unique_ptr<ContentDescription> parsed( |
| 53 ContentDescription::ParseXml(xml.get(), false)); | 54 ContentDescription::ParseXml(xml.get(), false)); |
| 54 ASSERT_TRUE(parsed.get()); | 55 ASSERT_TRUE(parsed.get()); |
| 55 EXPECT_EQ(1U, parsed->config()->event_configs().size()); | 56 EXPECT_EQ(1U, parsed->config()->event_configs().size()); |
| 56 EXPECT_TRUE(parsed->config()->event_configs().front() == | 57 EXPECT_TRUE(parsed->config()->event_configs().front() == |
| 57 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, | 58 ChannelConfig(ChannelConfig::TRANSPORT_STREAM, |
| 58 kDefaultStreamVersion, | 59 kDefaultStreamVersion, |
| 59 ChannelConfig::CODEC_UNDEFINED)); | 60 ChannelConfig::CODEC_UNDEFINED)); |
| 60 } | 61 } |
| 61 | 62 |
| 62 // Verify that we can parse configs with none transport without version and | 63 // Verify that we can parse configs with none transport without version and |
| 63 // codec. | 64 // codec. |
| 64 TEST(ContentDescriptionTest, NoneTransport) { | 65 TEST(ContentDescriptionTest, NoneTransport) { |
| 65 std::string kTestDescription = | 66 std::string kTestDescription = |
| 66 "<description xmlns=\"google:remoting\">" | 67 "<description xmlns=\"google:remoting\">" |
| 67 " <standard-ice/>" | 68 " <standard-ice/>" |
| 68 " <control transport=\"stream\" version=\"2\"/>" | 69 " <control transport=\"stream\" version=\"2\"/>" |
| 69 " <event transport=\"stream\" version=\"2\"/>" | 70 " <event transport=\"stream\" version=\"2\"/>" |
| 70 " <event transport=\"stream\" version=\"2\"/>" | 71 " <event transport=\"stream\" version=\"2\"/>" |
| 71 " <video transport=\"stream\" version=\"2\" codec=\"vp8\"/>" | 72 " <video transport=\"stream\" version=\"2\" codec=\"vp8\"/>" |
| 72 " <audio transport=\"none\"/>" | 73 " <audio transport=\"none\"/>" |
| 73 " <authentication/>" | 74 " <authentication/>" |
| 74 "</description>"; | 75 "</description>"; |
| 75 scoped_ptr<buzz::XmlElement> xml(buzz::XmlElement::ForStr(kTestDescription)); | 76 std::unique_ptr<buzz::XmlElement> xml( |
| 76 scoped_ptr<ContentDescription> parsed( | 77 buzz::XmlElement::ForStr(kTestDescription)); |
| 78 std::unique_ptr<ContentDescription> parsed( |
| 77 ContentDescription::ParseXml(xml.get(), false)); | 79 ContentDescription::ParseXml(xml.get(), false)); |
| 78 ASSERT_TRUE(parsed.get()); | 80 ASSERT_TRUE(parsed.get()); |
| 79 EXPECT_EQ(1U, parsed->config()->audio_configs().size()); | 81 EXPECT_EQ(1U, parsed->config()->audio_configs().size()); |
| 80 EXPECT_TRUE(parsed->config()->audio_configs().front() == ChannelConfig()); | 82 EXPECT_TRUE(parsed->config()->audio_configs().front() == ChannelConfig()); |
| 81 } | 83 } |
| 82 | 84 |
| 83 // Verify that we can parse configs with none transport with version and | 85 // Verify that we can parse configs with none transport with version and |
| 84 // codec. | 86 // codec. |
| 85 TEST(ContentDescriptionTest, NoneTransportWithCodec) { | 87 TEST(ContentDescriptionTest, NoneTransportWithCodec) { |
| 86 std::string kTestDescription = | 88 std::string kTestDescription = |
| 87 "<description xmlns=\"google:remoting\">" | 89 "<description xmlns=\"google:remoting\">" |
| 88 " <standard-ice/>" | 90 " <standard-ice/>" |
| 89 " <control transport=\"stream\" version=\"2\"/>" | 91 " <control transport=\"stream\" version=\"2\"/>" |
| 90 " <event transport=\"stream\" version=\"2\"/>" | 92 " <event transport=\"stream\" version=\"2\"/>" |
| 91 " <event transport=\"stream\" version=\"2\"/>" | 93 " <event transport=\"stream\" version=\"2\"/>" |
| 92 " <video transport=\"stream\" version=\"2\" codec=\"vp8\"/>" | 94 " <video transport=\"stream\" version=\"2\" codec=\"vp8\"/>" |
| 93 " <audio transport=\"none\" version=\"2\" codec=\"verbatim\"/>" | 95 " <audio transport=\"none\" version=\"2\" codec=\"verbatim\"/>" |
| 94 " <authentication/>" | 96 " <authentication/>" |
| 95 "</description>"; | 97 "</description>"; |
| 96 scoped_ptr<buzz::XmlElement> xml(buzz::XmlElement::ForStr(kTestDescription)); | 98 std::unique_ptr<buzz::XmlElement> xml( |
| 97 scoped_ptr<ContentDescription> parsed( | 99 buzz::XmlElement::ForStr(kTestDescription)); |
| 100 std::unique_ptr<ContentDescription> parsed( |
| 98 ContentDescription::ParseXml(xml.get(), false)); | 101 ContentDescription::ParseXml(xml.get(), false)); |
| 99 ASSERT_TRUE(parsed.get()); | 102 ASSERT_TRUE(parsed.get()); |
| 100 EXPECT_EQ(1U, parsed->config()->audio_configs().size()); | 103 EXPECT_EQ(1U, parsed->config()->audio_configs().size()); |
| 101 EXPECT_TRUE(parsed->config()->audio_configs().front() == ChannelConfig()); | 104 EXPECT_TRUE(parsed->config()->audio_configs().front() == ChannelConfig()); |
| 102 } | 105 } |
| 103 | 106 |
| 104 } // namespace protocol | 107 } // namespace protocol |
| 105 } // namespace remoting | 108 } // namespace remoting |
| 106 | 109 |
| OLD | NEW |