Chromium Code Reviews| 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" |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 | 396 |
| 397 JingleMessage message; | 397 JingleMessage message; |
| 398 ParseFormatAndCompare(kTestSessionInfoMessage, &message); | 398 ParseFormatAndCompare(kTestSessionInfoMessage, &message); |
| 399 | 399 |
| 400 EXPECT_EQ(message.action, JingleMessage::SESSION_INFO); | 400 EXPECT_EQ(message.action, JingleMessage::SESSION_INFO); |
| 401 ASSERT_TRUE(message.info.get() != nullptr); | 401 ASSERT_TRUE(message.info.get() != nullptr); |
| 402 EXPECT_TRUE(message.info->Name() == | 402 EXPECT_TRUE(message.info->Name() == |
| 403 buzz::QName("urn:xmpp:jingle:1", "test-info")); | 403 buzz::QName("urn:xmpp:jingle:1", "test-info")); |
| 404 } | 404 } |
| 405 | 405 |
| 406 TEST(JingleMessageTest, Address) { | 406 TEST(JingleMessageTest, ParseAddress) { |
| 407 const char* kTestSessionInfoMessage = | 407 const char* kTestSessionInfoMessage = |
| 408 "<cli:iq from='remoting@talk.google.com' " | 408 "<cli:iq from='remoting@talk.google.com' " |
| 409 "from-channel='lcs' " | 409 "to='user@gmail.com/chromiumsy5C6A652D' type='set' " |
| 410 "from-endpoint-id='user@gmail.com/xBrnereror=' " | 410 "xmlns:cli='jabber:client'>" |
| 411 "to='user@gmail.com/chromiumsy5C6A652D' type='set' " | 411 "<jingle action='session-info' " |
| 412 "xmlns:cli='jabber:client'><jingle action='session-info' " | 412 "sid='2227053353' xmlns='urn:xmpp:jingle:1' " |
| 413 "sid='2227053353' xmlns='urn:xmpp:jingle:1'><test-info>TestMessage" | 413 "from-channel='lcs' " |
| 414 "</test-info></jingle></cli:iq>"; | 414 "from-endpoint-id='user@gmail.com/xBrnereror='>" |
| 415 "<test-info>TestMessage</test-info>" | |
| 416 "</jingle>" | |
| 417 "</cli:iq>"; | |
| 415 | 418 |
| 416 JingleMessage message; | 419 JingleMessage message; |
| 417 ParseFormatAndCompare(kTestSessionInfoMessage, &message); | 420 ParseFormatAndCompare(kTestSessionInfoMessage, &message); |
| 418 EXPECT_EQ(message.from.jid, "remoting@talk.google.com"); | 421 EXPECT_EQ(message.from.jid, "remoting@talk.google.com"); |
| 419 EXPECT_EQ(message.from.channel, SignalingAddress::Channel::LCS); | 422 EXPECT_EQ(message.from.channel, SignalingAddress::Channel::LCS); |
| 420 EXPECT_EQ(message.from.endpoint_id, "user@gmail.com/xBrnereror="); | 423 EXPECT_EQ(message.from.endpoint_id, "user@gmail.com/xBrnereror="); |
| 421 EXPECT_EQ(message.from.id(), "user@gmail.com/xBrnereror="); | 424 EXPECT_EQ(message.from.id(), "user@gmail.com/xBrnereror="); |
| 422 | 425 |
| 423 EXPECT_EQ(message.to.jid, "user@gmail.com/chromiumsy5C6A652D"); | 426 EXPECT_EQ(message.to.jid, "user@gmail.com/chromiumsy5C6A652D"); |
| 424 EXPECT_EQ(message.to.channel, SignalingAddress::Channel::XMPP); | 427 EXPECT_EQ(message.to.channel, SignalingAddress::Channel::XMPP); |
| 425 EXPECT_EQ(message.to.endpoint_id, ""); | 428 EXPECT_EQ(message.to.endpoint_id, ""); |
| 426 EXPECT_EQ(message.to.id(), "user@gmail.com/chromiumsy5C6A652D"); | 429 EXPECT_EQ(message.to.id(), "user@gmail.com/chromiumsy5C6A652D"); |
| 427 | 430 |
| 428 EXPECT_EQ(message.action, JingleMessage::SESSION_INFO); | 431 EXPECT_EQ(message.action, JingleMessage::SESSION_INFO); |
| 429 } | 432 } |
| 430 | 433 |
| 431 TEST(JingleMessageReplyTest, ToXml) { | 434 TEST(JingleMessageReplyTest, ToXml) { |
| 432 const char* kTestIncomingMessage1 = | 435 const char* kTestIncomingMessage1 = |
| 433 "<cli:iq from='user@gmail.com/chromoting016DBB07' id='4' " | 436 "<cli:iq from='user@gmail.com/chromoting016DBB07' id='4' " |
| 434 "to='user@gmail.com/chromiumsy5C6A652D' type='set' " | 437 "to='user@gmail.com/chromiumsy5C6A652D' type='set' " |
| 435 "xmlns:cli='jabber:client'><jingle action='session-terminate' " | 438 "xmlns:cli='jabber:client'><jingle action='session-terminate' " |
| 436 "sid='2227053353' xmlns='urn:xmpp:jingle:1'><reason><success/>" | 439 "sid='2227053353' xmlns='urn:xmpp:jingle:1'><reason><success/>" |
| 437 "</reason></jingle></cli:iq>"; | 440 "</reason></jingle></cli:iq>"; |
| 438 const char* kTestIncomingMessage2 = | 441 const char* kTestIncomingMessage2 = |
| 439 "<cli:iq from='remoting@talk.google.com' id='4' " | 442 "<cli:iq from='remoting@talk.google.com' id='4' " |
| 440 "from-channel='lcs' from-endpoint-id='from@gmail.com/AbCdEf1234=' " | |
| 441 "to='user@gmail.com/chromiumsy5C6A652D' type='set' " | 443 "to='user@gmail.com/chromiumsy5C6A652D' type='set' " |
| 442 "xmlns:cli='jabber:client'><jingle action='session-terminate' " | 444 "xmlns:cli='jabber:client'><jingle action='session-terminate' " |
| 445 "from-channel='lcs' from-endpoint-id='from@gmail.com/AbCdEf1234=' " | |
| 443 "sid='2227053353' xmlns='urn:xmpp:jingle:1'><reason><success/>" | 446 "sid='2227053353' xmlns='urn:xmpp:jingle:1'><reason><success/>" |
| 444 "</reason></jingle></cli:iq>"; | 447 "</reason></jingle></cli:iq>"; |
| 445 | 448 |
| 446 struct TestCase { | 449 struct TestCase { |
| 447 const JingleMessageReply::ErrorType error; | 450 const JingleMessageReply::ErrorType error; |
| 448 std::string error_text; | 451 std::string error_text; |
| 449 std::string expected_text; | 452 std::string expected_text; |
| 450 std::string incoming_message; | 453 std::string incoming_message; |
| 451 } tests[] = { | 454 } tests[] = { |
| 452 {JingleMessageReply::BAD_REQUEST, "", | 455 {JingleMessageReply::BAD_REQUEST, "", |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 kTestIncomingMessage1}, | 489 kTestIncomingMessage1}, |
| 487 {JingleMessageReply::UNEXPECTED_REQUEST, "", | 490 {JingleMessageReply::UNEXPECTED_REQUEST, "", |
| 488 "<iq xmlns='jabber:client' " | 491 "<iq xmlns='jabber:client' " |
| 489 "to='user@gmail.com/chromoting016DBB07' id='4' type='error'><jingle " | 492 "to='user@gmail.com/chromoting016DBB07' id='4' type='error'><jingle " |
| 490 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" | 493 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" |
| 491 "<reason><success/></reason></jingle><error type='modify'>" | 494 "<reason><success/></reason></jingle><error type='modify'>" |
| 492 "<unexpected-request/></error></iq>", | 495 "<unexpected-request/></error></iq>", |
| 493 kTestIncomingMessage1}, | 496 kTestIncomingMessage1}, |
| 494 {JingleMessageReply::INVALID_SID, "ErrorText", | 497 {JingleMessageReply::INVALID_SID, "ErrorText", |
| 495 "<iq xmlns='jabber:client' " | 498 "<iq xmlns='jabber:client' " |
| 496 "to='remoting@talk.google.com' to-channel='lcs' " | 499 "to='remoting@talk.google.com' id='4' " |
| 497 "to-endpoint-id='from@gmail.com/AbCdEf1234=' id='4' " | |
| 498 "type='error'><jingle " | 500 "type='error'><jingle " |
| 499 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" | 501 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1' " |
| 502 "from-channel='lcs' from-endpoint-id='from@gmail.com/AbCdEf1234='>" | |
| 500 "<reason><success/></reason></jingle><error type='modify'>" | 503 "<reason><success/></reason></jingle><error type='modify'>" |
| 501 "<item-not-found/><text xml:lang='en'>ErrorText</text></error></iq>", | 504 "<item-not-found/><text xml:lang='en'>ErrorText</text></error></iq>", |
| 502 kTestIncomingMessage2}, | 505 kTestIncomingMessage2}, |
| 503 {JingleMessageReply::NONE, "", | 506 {JingleMessageReply::NONE, "", |
| 504 "<iq xmlns='jabber:client' " | 507 "<iq xmlns='jabber:client' to='remoting@talk.google.com' id='4' " |
| 505 "to='remoting@talk.google.com' to-channel='lcs' " | 508 "type='result'><jingle xmlns='urn:xmpp:jingle:1' to-channel='lcs' " |
| 506 "to-endpoint-id='from@gmail.com/AbCdEf1234=' id='4' type='result'></iq>", | 509 "to-endpoint-id='from@gmail.com/AbCdEf1234='></jingle></iq>", |
|
Sergey Ulanov
2016/06/04 17:10:31
Nit: replace "></jingle>" with "/>"
kelvinp
2016/06/06 20:43:41
Done.
| |
| 507 kTestIncomingMessage2}, | 510 kTestIncomingMessage2}, |
| 508 }; | 511 }; |
| 509 | 512 |
| 510 for (size_t i = 0; i < arraysize(tests); ++i) { | 513 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 511 std::unique_ptr<XmlElement> incoming_message( | 514 std::unique_ptr<XmlElement> incoming_message( |
| 512 XmlElement::ForStr(tests[i].incoming_message)); | 515 XmlElement::ForStr(tests[i].incoming_message)); |
| 513 ASSERT_TRUE(incoming_message.get()); | 516 ASSERT_TRUE(incoming_message.get()); |
| 514 | 517 |
| 518 LOG(INFO) << "Running test case: " << i; | |
|
Sergey Ulanov
2016/06/04 17:10:31
To avoid spamming the console, replace this with S
kelvinp
2016/06/06 20:43:41
Done.
| |
| 515 JingleMessageReply reply_msg; | 519 JingleMessageReply reply_msg; |
| 516 if (tests[i].error_text.empty()) { | 520 if (tests[i].error_text.empty()) { |
| 517 reply_msg = JingleMessageReply(tests[i].error); | 521 reply_msg = JingleMessageReply(tests[i].error); |
| 518 } else { | 522 } else { |
| 519 reply_msg = JingleMessageReply(tests[i].error, tests[i].error_text); | 523 reply_msg = JingleMessageReply(tests[i].error, tests[i].error_text); |
| 520 } | 524 } |
| 521 std::unique_ptr<XmlElement> reply(reply_msg.ToXml(incoming_message.get())); | 525 std::unique_ptr<XmlElement> reply(reply_msg.ToXml(incoming_message.get())); |
| 522 | 526 |
| 523 std::unique_ptr<XmlElement> expected( | 527 std::unique_ptr<XmlElement> expected( |
| 524 XmlElement::ForStr(tests[i].expected_text)); | 528 XmlElement::ForStr(tests[i].expected_text)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 EXPECT_FALSE(JingleMessage::IsJingleMessage(source_message.get())); | 565 EXPECT_FALSE(JingleMessage::IsJingleMessage(source_message.get())); |
| 562 | 566 |
| 563 JingleMessage message; | 567 JingleMessage message; |
| 564 std::string error; | 568 std::string error; |
| 565 EXPECT_FALSE(message.ParseXml(source_message.get(), &error)); | 569 EXPECT_FALSE(message.ParseXml(source_message.get(), &error)); |
| 566 EXPECT_FALSE(error.empty()); | 570 EXPECT_FALSE(error.empty()); |
| 567 } | 571 } |
| 568 | 572 |
| 569 } // namespace protocol | 573 } // namespace protocol |
| 570 } // namespace remoting | 574 } // namespace remoting |
| OLD | NEW |