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/jingle_messages.h" | 5 #include "remoting/protocol/jingle_messages.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/string_util.h" |
11 #include "remoting/protocol/content_description.h" | 12 #include "remoting/protocol/content_description.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 15 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
15 #include "third_party/webrtc/libjingle/xmpp/constants.h" | 16 #include "third_party/webrtc/libjingle/xmpp/constants.h" |
16 | 17 |
17 using buzz::QName; | 18 using buzz::QName; |
18 using buzz::XmlAttr; | 19 using buzz::XmlAttr; |
19 using buzz::XmlElement; | 20 using buzz::XmlElement; |
20 | 21 |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 } else { | 594 } else { |
594 ParseFormatAndCompare(message_str.c_str(), &message); | 595 ParseFormatAndCompare(message_str.c_str(), &message); |
595 } | 596 } |
596 | 597 |
597 EXPECT_EQ(message.action, JingleMessage::SESSION_TERMINATE); | 598 EXPECT_EQ(message.action, JingleMessage::SESSION_TERMINATE); |
598 EXPECT_EQ(message.reason, JingleMessage::DECLINE); | 599 EXPECT_EQ(message.reason, JingleMessage::DECLINE); |
599 EXPECT_EQ(message.error_code, error); | 600 EXPECT_EQ(message.error_code, error); |
600 } | 601 } |
601 } | 602 } |
602 | 603 |
| 604 TEST(JingleMessageTest, AttachmentsMessage) { |
| 605 // Ordering of the "attachments" tag and other tags are irrelevent. But the |
| 606 // JingleMessage implementation always puts it before other tags, so we do the |
| 607 // same thing in test cases. |
| 608 const char* kMessageWithPluginTag = |
| 609 "<cli:iq from='user@gmail.com/chromoting016DBB07' " |
| 610 "to='user@gmail.com/chromiumsy5C6A652D' type='set' " |
| 611 "xmlns:cli='jabber:client'><jingle action='$1' " |
| 612 "sid='2227053353' xmlns='urn:xmpp:jingle:1'>" |
| 613 "<gr:attachments xmlns:gr='google:remoting'>" |
| 614 "<gr:sometag>some-message</gr:sometag>" |
| 615 "</gr:attachments>$2</jingle></cli:iq>"; |
| 616 for (int i = JingleMessage::SESSION_INITIATE; |
| 617 i <= JingleMessage::TRANSPORT_INFO; i++) { |
| 618 JingleMessage::ActionType action_type = |
| 619 static_cast<JingleMessage::ActionType>(i); |
| 620 std::vector<std::string> substitutes = { |
| 621 JingleMessage::GetActionName(action_type) |
| 622 }; |
| 623 if (action_type == JingleMessage::SESSION_INFO) { |
| 624 substitutes.push_back("<test-info>test-message</test-info>"); |
| 625 } else if (action_type == JingleMessage::SESSION_TERMINATE) { |
| 626 substitutes.emplace_back(); |
| 627 } else if (action_type == JingleMessage::TRANSPORT_INFO) { |
| 628 substitutes.push_back( |
| 629 "<content name='chromoting' creator='initiator'>" |
| 630 "<transport xmlns='google:remoting:webrtc'>" |
| 631 "<credentials channel='event' ufrag='tPUyEAmQrEw3y7hi' " |
| 632 "password='2iRdhLfawKZC5ydJ'/>" |
| 633 "<credentials channel='video' ufrag='EPK3CXo5sTLJSez0' " |
| 634 "password='eM0VUfUkZ+1Pyi0M'/>" |
| 635 "<candidate name='event' foundation='725747215' " |
| 636 "address='172.23.164.186' port='59089' type='local' " |
| 637 "protocol='udp' priority='2122194688' generation='0'/>" |
| 638 "<candidate name='video' foundation='3623806809' " |
| 639 "address='172.23.164.186' port='57040' type='local' " |
| 640 "protocol='udp' priority='2122194688' generation='0'/>" |
| 641 "</transport>" |
| 642 "</content>"); |
| 643 } else { |
| 644 substitutes.push_back("<content name='chromoting' creator='initiator'>" |
| 645 "<description xmlns='google:remoting'>" |
| 646 "<authentication><auth-token>" |
| 647 "j7whCMii0Z0AAPwj7whCM/j7whCMii0Z0AAPw=" |
| 648 "</auth-token></authentication>" |
| 649 "</description>" |
| 650 "<transport xmlns='google:remoting:webrtc' />" |
| 651 "</content>"); |
| 652 } |
| 653 std::string message_str = base::ReplaceStringPlaceholders( |
| 654 kMessageWithPluginTag, substitutes, nullptr); |
| 655 |
| 656 JingleMessage message; |
| 657 ParseFormatAndCompare(message_str.c_str(), &message); |
| 658 |
| 659 EXPECT_TRUE(message.attachments); |
| 660 XmlElement expected(QName("google:remoting", "attachments")); |
| 661 expected.AddElement(new XmlElement(QName("google:remoting", "sometag"))); |
| 662 expected.FirstElement()->SetBodyText("some-message"); |
| 663 std::string error; |
| 664 EXPECT_TRUE(VerifyXml(&expected, message.attachments.get(), &error)) |
| 665 << error; |
| 666 } |
| 667 } |
| 668 |
603 } // namespace protocol | 669 } // namespace protocol |
604 } // namespace remoting | 670 } // namespace remoting |
OLD | NEW |