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