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) { |
| 407 const char* kTestSessionInfoMessage = |
| 408 "<cli:iq from='remoting@talk.google.com' " |
| 409 "from-channel='lcs' " |
| 410 "from-endpoint-id='user@gmail.com/xBrnereror=' " |
| 411 "to='user@gmail.com/chromiumsy5C6A652D' type='set' " |
| 412 "xmlns:cli='jabber:client'><jingle action='session-info' " |
| 413 "sid='2227053353' xmlns='urn:xmpp:jingle:1'><test-info>TestMessage" |
| 414 "</test-info></jingle></cli:iq>"; |
| 415 |
| 416 JingleMessage message; |
| 417 ParseFormatAndCompare(kTestSessionInfoMessage, &message); |
| 418 EXPECT_EQ(message.from.jid, "remoting@talk.google.com"); |
| 419 EXPECT_EQ(message.from.channel, SignalingAddress::Channel::LCS); |
| 420 EXPECT_EQ(message.from.endpoint_id, "user@gmail.com/xBrnereror="); |
| 421 EXPECT_EQ(message.from.id(), "user@gmail.com/xBrnereror="); |
| 422 |
| 423 EXPECT_EQ(message.to.jid, "user@gmail.com/chromiumsy5C6A652D"); |
| 424 EXPECT_EQ(message.to.channel, SignalingAddress::Channel::XMPP); |
| 425 EXPECT_EQ(message.to.endpoint_id, ""); |
| 426 EXPECT_EQ(message.to.id(), "user@gmail.com/chromiumsy5C6A652D"); |
| 427 |
| 428 EXPECT_EQ(message.action, JingleMessage::SESSION_INFO); |
| 429 } |
| 430 |
406 TEST(JingleMessageReplyTest, ToXml) { | 431 TEST(JingleMessageReplyTest, ToXml) { |
407 const char* kTestIncomingMessage = | 432 const char* kTestIncomingMessage1 = |
408 "<cli:iq from='user@gmail.com/chromoting016DBB07' id='4' " | 433 "<cli:iq from='user@gmail.com/chromoting016DBB07' id='4' " |
409 "to='user@gmail.com/chromiumsy5C6A652D' type='set' " | 434 "to='user@gmail.com/chromiumsy5C6A652D' type='set' " |
410 "xmlns:cli='jabber:client'><jingle action='session-terminate' " | 435 "xmlns:cli='jabber:client'><jingle action='session-terminate' " |
411 "sid='2227053353' xmlns='urn:xmpp:jingle:1'><reason><success/>" | 436 "sid='2227053353' xmlns='urn:xmpp:jingle:1'><reason><success/>" |
412 "</reason></jingle></cli:iq>"; | 437 "</reason></jingle></cli:iq>"; |
413 std::unique_ptr<XmlElement> incoming_message( | 438 const char* kTestIncomingMessage2 = |
414 XmlElement::ForStr(kTestIncomingMessage)); | 439 "<cli:iq from='remoting@talk.google.com' id='4' " |
415 ASSERT_TRUE(incoming_message.get()); | 440 "from-channel='lcs' from-endpoint-id='from@gmail.com/AbCdEf1234=' " |
| 441 "to='user@gmail.com/chromiumsy5C6A652D' type='set' " |
| 442 "xmlns:cli='jabber:client'><jingle action='session-terminate' " |
| 443 "sid='2227053353' xmlns='urn:xmpp:jingle:1'><reason><success/>" |
| 444 "</reason></jingle></cli:iq>"; |
416 | 445 |
417 struct TestCase { | 446 struct TestCase { |
418 const JingleMessageReply::ErrorType error; | 447 const JingleMessageReply::ErrorType error; |
419 std::string error_text; | 448 std::string error_text; |
420 std::string expected_text; | 449 std::string expected_text; |
| 450 std::string incoming_message; |
421 } tests[] = { | 451 } tests[] = { |
422 { JingleMessageReply::BAD_REQUEST, "", "<iq xmlns='jabber:client' " | 452 {JingleMessageReply::BAD_REQUEST, "", |
423 "to='user@gmail.com/chromoting016DBB07' id='4' type='error'><jingle " | 453 "<iq xmlns='jabber:client' " |
424 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" | 454 "to='user@gmail.com/chromoting016DBB07' id='4' type='error'><jingle " |
425 "<reason><success/></reason></jingle><error type='modify'><bad-request/>" | 455 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" |
426 "</error></iq>" }, | 456 "<reason><success/></reason></jingle><error type='modify'><bad-request/>" |
427 { JingleMessageReply::BAD_REQUEST, "ErrorText", "<iq xmlns='jabber:client' " | 457 "</error></iq>", |
428 "to='user@gmail.com/chromoting016DBB07' id='4' type='error'><jingle " | 458 kTestIncomingMessage1}, |
429 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" | 459 {JingleMessageReply::BAD_REQUEST, "ErrorText", |
430 "<reason><success/></reason></jingle><error type='modify'><bad-request/>" | 460 "<iq xmlns='jabber:client' " |
431 "<text xml:lang='en'>ErrorText</text></error></iq>" }, | 461 "to='user@gmail.com/chromoting016DBB07' id='4' type='error'><jingle " |
432 { JingleMessageReply::NOT_IMPLEMENTED, "", "<iq xmlns='jabber:client' " | 462 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" |
433 "to='user@gmail.com/chromoting016DBB07' id='4' type='error'><jingle " | 463 "<reason><success/></reason></jingle><error type='modify'><bad-request/>" |
434 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" | 464 "<text xml:lang='en'>ErrorText</text></error></iq>", |
435 "<reason><success/></reason></jingle><error type='cancel'>" | 465 kTestIncomingMessage1}, |
436 "<feature-bad-request/></error></iq>" }, | 466 {JingleMessageReply::NOT_IMPLEMENTED, "", |
437 { JingleMessageReply::INVALID_SID, "", "<iq xmlns='jabber:client' " | 467 "<iq xmlns='jabber:client' " |
438 "to='user@gmail.com/chromoting016DBB07' id='4' type='error'><jingle " | 468 "to='user@gmail.com/chromoting016DBB07' id='4' type='error'><jingle " |
439 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" | 469 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" |
440 "<reason><success/></reason></jingle><error type='modify'>" | 470 "<reason><success/></reason></jingle><error type='cancel'>" |
441 "<item-not-found/><text xml:lang='en'>Invalid SID</text></error></iq>" }, | 471 "<feature-bad-request/></error></iq>", |
442 { JingleMessageReply::INVALID_SID, "ErrorText", "<iq xmlns='jabber:client' " | 472 kTestIncomingMessage1}, |
443 "to='user@gmail.com/chromoting016DBB07' id='4' type='error'><jingle " | 473 {JingleMessageReply::INVALID_SID, "", |
444 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" | 474 "<iq xmlns='jabber:client' " |
445 "<reason><success/></reason></jingle><error type='modify'>" | 475 "to='user@gmail.com/chromoting016DBB07' id='4' type='error'><jingle " |
446 "<item-not-found/><text xml:lang='en'>ErrorText</text></error></iq>" }, | 476 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" |
447 { JingleMessageReply::UNEXPECTED_REQUEST, "", "<iq xmlns='jabber:client' " | 477 "<reason><success/></reason></jingle><error type='modify'>" |
448 "to='user@gmail.com/chromoting016DBB07' id='4' type='error'><jingle " | 478 "<item-not-found/><text xml:lang='en'>Invalid SID</text></error></iq>", |
449 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" | 479 kTestIncomingMessage1}, |
450 "<reason><success/></reason></jingle><error type='modify'>" | 480 {JingleMessageReply::INVALID_SID, "ErrorText", |
451 "<unexpected-request/></error></iq>" }, | 481 "<iq xmlns='jabber:client' " |
| 482 "to='user@gmail.com/chromoting016DBB07' id='4' type='error'><jingle " |
| 483 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" |
| 484 "<reason><success/></reason></jingle><error type='modify'>" |
| 485 "<item-not-found/><text xml:lang='en'>ErrorText</text></error></iq>", |
| 486 kTestIncomingMessage1}, |
| 487 {JingleMessageReply::UNEXPECTED_REQUEST, "", |
| 488 "<iq xmlns='jabber:client' " |
| 489 "to='user@gmail.com/chromoting016DBB07' id='4' type='error'><jingle " |
| 490 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" |
| 491 "<reason><success/></reason></jingle><error type='modify'>" |
| 492 "<unexpected-request/></error></iq>", |
| 493 kTestIncomingMessage1}, |
| 494 {JingleMessageReply::INVALID_SID, "ErrorText", |
| 495 "<iq xmlns='jabber:client' " |
| 496 "to='remoting@talk.google.com' to-channel='lcs' " |
| 497 "to-endpoint-id='from@gmail.com/AbCdEf1234=' id='4' " |
| 498 "type='error'><jingle " |
| 499 "action='session-terminate' sid='2227053353' xmlns='urn:xmpp:jingle:1'>" |
| 500 "<reason><success/></reason></jingle><error type='modify'>" |
| 501 "<item-not-found/><text xml:lang='en'>ErrorText</text></error></iq>", |
| 502 kTestIncomingMessage2}, |
| 503 {JingleMessageReply::NONE, "", |
| 504 "<iq xmlns='jabber:client' " |
| 505 "to='remoting@talk.google.com' to-channel='lcs' " |
| 506 "to-endpoint-id='from@gmail.com/AbCdEf1234=' id='4' type='result'></iq>", |
| 507 kTestIncomingMessage2}, |
452 }; | 508 }; |
453 | 509 |
454 for (size_t i = 0; i < arraysize(tests); ++i) { | 510 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 511 std::unique_ptr<XmlElement> incoming_message( |
| 512 XmlElement::ForStr(tests[i].incoming_message)); |
| 513 ASSERT_TRUE(incoming_message.get()); |
| 514 |
455 JingleMessageReply reply_msg; | 515 JingleMessageReply reply_msg; |
456 if (tests[i].error_text.empty()) { | 516 if (tests[i].error_text.empty()) { |
457 reply_msg = JingleMessageReply(tests[i].error); | 517 reply_msg = JingleMessageReply(tests[i].error); |
458 } else { | 518 } else { |
459 reply_msg = JingleMessageReply(tests[i].error, tests[i].error_text); | 519 reply_msg = JingleMessageReply(tests[i].error, tests[i].error_text); |
460 } | 520 } |
461 std::unique_ptr<XmlElement> reply(reply_msg.ToXml(incoming_message.get())); | 521 std::unique_ptr<XmlElement> reply(reply_msg.ToXml(incoming_message.get())); |
462 | 522 |
463 std::unique_ptr<XmlElement> expected( | 523 std::unique_ptr<XmlElement> expected( |
464 XmlElement::ForStr(tests[i].expected_text)); | 524 XmlElement::ForStr(tests[i].expected_text)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 EXPECT_FALSE(JingleMessage::IsJingleMessage(source_message.get())); | 561 EXPECT_FALSE(JingleMessage::IsJingleMessage(source_message.get())); |
502 | 562 |
503 JingleMessage message; | 563 JingleMessage message; |
504 std::string error; | 564 std::string error; |
505 EXPECT_FALSE(message.ParseXml(source_message.get(), &error)); | 565 EXPECT_FALSE(message.ParseXml(source_message.get(), &error)); |
506 EXPECT_FALSE(error.empty()); | 566 EXPECT_FALSE(error.empty()); |
507 } | 567 } |
508 | 568 |
509 } // namespace protocol | 569 } // namespace protocol |
510 } // namespace remoting | 570 } // namespace remoting |
OLD | NEW |