OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/strings/stringize_macros.h" |
| 7 #include "base/sys_info.h" |
| 8 #include "remoting/client/chromoting_stats.h" |
| 9 #include "remoting/client/server_log_entry_client.h" |
| 10 #include "remoting/protocol/server_log_entry.h" |
| 11 #include "remoting/protocol/server_log_entry_unittest.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 14 |
| 15 using base::SysInfo; |
| 16 using buzz::XmlAttr; |
| 17 using buzz::XmlElement; |
| 18 using remoting::protocol::ConnectionToHost; |
| 19 using remoting::protocol::ServerLogEntry; |
| 20 using remoting::protocol::VerifyStanza; |
| 21 |
| 22 namespace remoting { |
| 23 |
| 24 TEST(ServerLogEntryClientTest, SessionStateChange) { |
| 25 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange( |
| 26 ConnectionToHost::CONNECTED, remoting::protocol::OK)); |
| 27 scoped_ptr<XmlElement> stanza = entry->ToStanza(); |
| 28 std::string error; |
| 29 std::map<std::string, std::string> key_value_pairs; |
| 30 key_value_pairs["role"] = "client"; |
| 31 key_value_pairs["event-name"] = "session-state"; |
| 32 key_value_pairs["session-state"] = "connected"; |
| 33 std::set<std::string> keys; |
| 34 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) |
| 35 << error; |
| 36 } |
| 37 |
| 38 TEST(ServerLogEntryClientTest, SessionStateChangeWithError) { |
| 39 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange( |
| 40 ConnectionToHost::FAILED, remoting::protocol::PEER_IS_OFFLINE)); |
| 41 scoped_ptr<XmlElement> stanza = entry->ToStanza(); |
| 42 std::string error; |
| 43 std::map<std::string, std::string> key_value_pairs; |
| 44 key_value_pairs["role"] = "client"; |
| 45 key_value_pairs["event-name"] = "session-state"; |
| 46 key_value_pairs["session-state"] = "connection-failed"; |
| 47 key_value_pairs["connection-error"] = "host-is-offline"; |
| 48 std::set<std::string> keys; |
| 49 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) |
| 50 << error; |
| 51 } |
| 52 |
| 53 TEST(ServerLogEntryClientTest, Statistics) { |
| 54 ChromotingStats statistics; |
| 55 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForStatistics(&statistics)); |
| 56 scoped_ptr<XmlElement> stanza = entry->ToStanza(); |
| 57 std::string error; |
| 58 std::map<std::string, std::string> key_value_pairs; |
| 59 key_value_pairs["role"] = "client"; |
| 60 key_value_pairs["event-name"] = "connection-statistics"; |
| 61 std::set<std::string> keys; |
| 62 keys.insert("video-bandwidth"); |
| 63 keys.insert("capture-latency"); |
| 64 keys.insert("encode-latency"); |
| 65 keys.insert("decode-latency"); |
| 66 keys.insert("render-latency"); |
| 67 keys.insert("roundtrip-latency"); |
| 68 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) |
| 69 << error; |
| 70 } |
| 71 |
| 72 TEST(ServerLogEntryClientTest, SessionIdChanged) { |
| 73 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionIdOld("abc")); |
| 74 scoped_ptr<XmlElement> stanza = entry->ToStanza(); |
| 75 std::string error; |
| 76 std::map<std::string, std::string> key_value_pairs; |
| 77 key_value_pairs["role"] = "client"; |
| 78 key_value_pairs["event-name"] = "session-id-old"; |
| 79 key_value_pairs["session-id"] = "abc"; |
| 80 std::set<std::string> keys; |
| 81 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) |
| 82 << error; |
| 83 |
| 84 entry = MakeLogEntryForSessionIdNew("def"); |
| 85 stanza = entry->ToStanza(); |
| 86 key_value_pairs["event-name"] = "session-id-new"; |
| 87 key_value_pairs["session-id"] = "def"; |
| 88 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) |
| 89 << error; |
| 90 } |
| 91 |
| 92 TEST(ServerLogEntryClientTest, AddClientFields) { |
| 93 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange( |
| 94 ConnectionToHost::CONNECTED, remoting::protocol::OK)); |
| 95 AddClientFieldsToLogEntry(entry.get()); |
| 96 scoped_ptr<XmlElement> stanza = entry->ToStanza(); |
| 97 std::string error; |
| 98 std::map<std::string, std::string> key_value_pairs; |
| 99 key_value_pairs["role"] = "client"; |
| 100 key_value_pairs["event-name"] = "session-state"; |
| 101 key_value_pairs["session-state"] = "connected"; |
| 102 key_value_pairs["os-name"] = SysInfo::OperatingSystemName(); |
| 103 key_value_pairs["os-version"] = SysInfo::OperatingSystemVersion(); |
| 104 key_value_pairs["app-version"] = STRINGIZE(VERSION); |
| 105 key_value_pairs["cpu"] = SysInfo::OperatingSystemArchitecture(); |
| 106 std::set<std::string> keys; |
| 107 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) << |
| 108 error; |
| 109 } |
| 110 |
| 111 TEST(ServerLogEntryClientTest, AddSessionDuration) { |
| 112 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange( |
| 113 ConnectionToHost::CONNECTED, remoting::protocol::OK)); |
| 114 AddSessionDurationToLogEntry(entry.get(), base::TimeDelta::FromSeconds(123)); |
| 115 scoped_ptr<XmlElement> stanza = entry->ToStanza(); |
| 116 std::string error; |
| 117 std::map<std::string, std::string> key_value_pairs; |
| 118 key_value_pairs["role"] = "client"; |
| 119 key_value_pairs["event-name"] = "session-state"; |
| 120 key_value_pairs["session-state"] = "connected"; |
| 121 key_value_pairs["session-duration"] = "123"; |
| 122 std::set<std::string> keys; |
| 123 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) |
| 124 << error; |
| 125 } |
| 126 |
| 127 } // namespace remoting |
OLD | NEW |