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