diff options
author | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-22 22:21:23 +0000 |
---|---|---|
committer | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-22 22:21:23 +0000 |
commit | b580f427af37403f68694cf2f5ea59b0eeb73539 (patch) | |
tree | a439e387c372b5cd3d7d92af6eb1d158b6ae110e /remoting/client | |
parent | 49701e0a8e8c72efc5088032e290613f641f9de5 (diff) | |
download | chromium_src-b580f427af37403f68694cf2f5ea59b0eeb73539.zip chromium_src-b580f427af37403f68694cf2f5ea59b0eeb73539.tar.gz chromium_src-b580f427af37403f68694cf2f5ea59b0eeb73539.tar.bz2 |
Pull out common code from client and host versions of ServerLogEntry.
This also adds unittests for ServerLogEntry client code, with common code
pulled out to a separate file.
This doesn't affect LogToServer classes - they will be refactored in a
separate CL. Also fix some IWYU issues uncovered by the refactor.
TEST=unittests
Review URL: https://codereview.chromium.org/282063005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272346 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/client')
-rw-r--r-- | remoting/client/jni/chromoting_jni_instance.cc | 4 | ||||
-rw-r--r-- | remoting/client/log_to_server.cc | 22 | ||||
-rw-r--r-- | remoting/client/log_to_server.h | 2 | ||||
-rw-r--r-- | remoting/client/server_log_entry.h | 93 | ||||
-rw-r--r-- | remoting/client/server_log_entry_client.cc (renamed from remoting/client/server_log_entry.cc) | 226 | ||||
-rw-r--r-- | remoting/client/server_log_entry_client.h | 41 | ||||
-rw-r--r-- | remoting/client/server_log_entry_client_unittest.cc | 125 |
7 files changed, 257 insertions, 256 deletions
diff --git a/remoting/client/jni/chromoting_jni_instance.cc b/remoting/client/jni/chromoting_jni_instance.cc index 3f9bd22..a2add66 100644 --- a/remoting/client/jni/chromoting_jni_instance.cc +++ b/remoting/client/jni/chromoting_jni_instance.cc @@ -13,11 +13,11 @@ #include "remoting/client/jni/android_keymap.h" #include "remoting/client/jni/chromoting_jni_runtime.h" #include "remoting/client/log_to_server.h" -#include "remoting/client/server_log_entry.h" #include "remoting/client/software_video_renderer.h" #include "remoting/jingle_glue/chromium_port_allocator.h" #include "remoting/jingle_glue/chromium_socket_factory.h" #include "remoting/jingle_glue/network_settings.h" +#include "remoting/jingle_glue/server_log_entry.h" #include "remoting/protocol/host_stub.h" #include "remoting/protocol/libjingle_transport_factory.h" @@ -336,7 +336,7 @@ void ChromotingJniInstance::ConnectToHostOnNetworkThread() { net::ClientSocketFactory::GetDefaultFactory(), jni_runtime_->url_requester(), xmpp_config_)); - log_to_server_.reset(new client::LogToServer(client::ServerLogEntry::ME2ME, + log_to_server_.reset(new client::LogToServer(ServerLogEntry::ME2ME, signaling_.get(), "remoting@bot.talk.google.com")); diff --git a/remoting/client/log_to_server.cc b/remoting/client/log_to_server.cc index c45ad38..e29de135 100644 --- a/remoting/client/log_to_server.cc +++ b/remoting/client/log_to_server.cc @@ -8,6 +8,7 @@ #include "base/rand_util.h" #include "remoting/base/constants.h" #include "remoting/client/chromoting_stats.h" +#include "remoting/client/server_log_entry_client.h" #include "remoting/jingle_glue/iq_sender.h" #include "remoting/jingle_glue/signal_strategy.h" #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" @@ -69,8 +70,8 @@ void LogToServer::LogSessionStateChange( DCHECK(CalledOnValidThread()); scoped_ptr<ServerLogEntry> entry( - ServerLogEntry::MakeForSessionStateChange(state, error)); - entry->AddClientFields(); + MakeLogEntryForSessionStateChange(state, error)); + AddClientFieldsToLogEntry(entry.get()); entry->AddModeField(mode_); MaybeExpireSessionId(); @@ -85,12 +86,13 @@ void LogToServer::LogSessionStateChange( } if (!session_id_.empty()) { - entry->AddSessionId(session_id_); + AddSessionIdToLogEntry(entry.get(), session_id_); } // Maybe clear the session start time and log the session duration. if (ShouldAddDuration(state) && !session_start_time_.is_null()) { - entry->AddSessionDuration(base::TimeTicks::Now() - session_start_time_); + AddSessionDurationToLogEntry(entry.get(), + base::TimeTicks::Now() - session_start_time_); } if (IsEndOfSession(state)) { @@ -106,11 +108,10 @@ void LogToServer::LogStatistics(ChromotingStats* statistics) { MaybeExpireSessionId(); - scoped_ptr<ServerLogEntry> entry( - ServerLogEntry::MakeForStatistics(statistics)); - entry->AddClientFields(); + scoped_ptr<ServerLogEntry> entry(MakeLogEntryForStatistics(statistics)); + AddClientFieldsToLogEntry(entry.get()); entry->AddModeField(mode_); - entry->AddSessionId(session_id_); + AddSessionIdToLogEntry(entry.get(), session_id_); Log(*entry.get()); } @@ -174,8 +175,7 @@ void LogToServer::MaybeExpireSessionId() { base::TimeDelta max_age = base::TimeDelta::FromDays(kMaxSessionIdAgeDays); if (base::TimeTicks::Now() - session_id_generation_time_ > max_age) { // Log the old session ID. - scoped_ptr<ServerLogEntry> entry( - ServerLogEntry::MakeForSessionIdOld(session_id_)); + scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionIdOld(session_id_)); entry->AddModeField(mode_); Log(*entry.get()); @@ -183,7 +183,7 @@ void LogToServer::MaybeExpireSessionId() { GenerateSessionId(); // Log the new session ID. - entry = ServerLogEntry::MakeForSessionIdNew(session_id_); + entry = MakeLogEntryForSessionIdNew(session_id_); entry->AddModeField(mode_); Log(*entry.get()); } diff --git a/remoting/client/log_to_server.h b/remoting/client/log_to_server.h index 35f3c96..cd70ff5 100644 --- a/remoting/client/log_to_server.h +++ b/remoting/client/log_to_server.h @@ -11,7 +11,7 @@ #include "base/threading/non_thread_safe.h" #include "base/time/time.h" -#include "remoting/client/server_log_entry.h" +#include "remoting/jingle_glue/server_log_entry.h" #include "remoting/jingle_glue/signal_strategy.h" #include "remoting/protocol/connection_to_host.h" #include "remoting/protocol/errors.h" diff --git a/remoting/client/server_log_entry.h b/remoting/client/server_log_entry.h deleted file mode 100644 index 9f861d2..0000000 --- a/remoting/client/server_log_entry.h +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef REMOTING_CLIENT_SERVER_LOG_ENTRY_H_ -#define REMOTING_CLIENT_SERVER_LOG_ENTRY_H_ - -#include <map> -#include <string> - -#include "base/memory/scoped_ptr.h" -#include "base/time/time.h" -#include "remoting/protocol/connection_to_host.h" -#include "remoting/protocol/errors.h" - -namespace buzz { -class XmlElement; -} // namespace buzz - -namespace remoting { - -class ChromotingStats; - -// Temporary namespace to prevent conflict with the same-named class in -// remoting/host when linking unittests. -// -// TODO(lambroslambrou): Remove this and factor out any shared code. -namespace client { - -class ServerLogEntry { - public: - // The mode of a connection. - enum Mode { - IT2ME, - ME2ME - }; - - // Constructs a log stanza. The caller should add one or more log entry - // stanzas as children of this stanza, before sending the log stanza to - // the remoting bot. - static scoped_ptr<buzz::XmlElement> MakeStanza(); - - // Constructs a log entry for a session state change. - static scoped_ptr<ServerLogEntry> MakeForSessionStateChange( - remoting::protocol::ConnectionToHost::State state, - remoting::protocol::ErrorCode error); - - // Constructs a log entry for reporting statistics. - static scoped_ptr<ServerLogEntry> MakeForStatistics( - remoting::ChromotingStats* statistics); - - // Constructs a log entry for reporting session ID is old. - static scoped_ptr<ServerLogEntry> MakeForSessionIdOld( - const std::string& session_id); - - // Constructs a log entry for reporting session ID is old. - static scoped_ptr<ServerLogEntry> MakeForSessionIdNew( - const std::string& session_id); - - ~ServerLogEntry(); - - // Adds fields describing the client to this log entry. - void AddClientFields(); - - // Adds a field describing the mode of a connection to this log entry. - void AddModeField(Mode mode); - - void AddEventName(const std::string& event_name); - void AddSessionId(const std::string& session_id); - void AddSessionDuration(base::TimeDelta duration); - - // Converts this object to an XML stanza. - scoped_ptr<buzz::XmlElement> ToStanza() const; - - private: - typedef std::map<std::string, std::string> ValuesMap; - - ServerLogEntry(); - void Set(const std::string& key, const std::string& value); - - static const char* GetValueSessionState( - remoting::protocol::ConnectionToHost::State state); - static const char* GetValueError(remoting::protocol::ErrorCode error); - static const char* GetValueMode(Mode mode); - - ValuesMap values_map_; -}; - -} // namespace client - -} // namespace remoting - -#endif // REMOTING_CLIENT_SERVER_LOG_ENTRY_H_ diff --git a/remoting/client/server_log_entry.cc b/remoting/client/server_log_entry_client.cc index cd580d8..f664f8f 100644 --- a/remoting/client/server_log_entry.cc +++ b/remoting/client/server_log_entry_client.cc @@ -2,50 +2,35 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "remoting/client/server_log_entry.h" +#include "remoting/client/server_log_entry_client.h" -#include "base/logging.h" -#include "base/macros.h" -#include "base/rand_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/stringize_macros.h" #include "base/strings/stringprintf.h" #include "base/sys_info.h" -#include "remoting/base/constants.h" #include "remoting/client/chromoting_stats.h" -#include "remoting/protocol/connection_to_host.h" -#include "remoting/protocol/errors.h" -#include "third_party/libjingle/source/talk/xmllite/xmlelement.h" +#include "remoting/jingle_glue/server_log_entry.h" using base::StringPrintf; using base::SysInfo; -using buzz::QName; -using buzz::XmlElement; using remoting::protocol::ConnectionToHost; +using remoting::protocol::ErrorCode; namespace remoting { -namespace client { - namespace { -const char kLogCommand[] = "log"; - -const char kLogEntry[] = "entry"; +const char kValueRoleClient[] = "client"; -const char kKeyEventName[] = "event-name"; const char kValueEventNameSessionState[] = "session-state"; const char kValueEventNameStatistics[] = "connection-statistics"; const char kValueEventNameSessionIdOld[] = "session-id-old"; const char kValueEventNameSessionIdNew[] = "session-id-new"; -const char kKeyRole[] = "role"; -const char kValueRoleClient[] = "client"; - -const char kKeyMode[] = "mode"; -const char kValueModeIt2Me[] = "it2me"; -const char kValueModeMe2Me[] = "me2me"; +const char kKeySessionId[] = "session-id"; +const char kKeySessionDuration[] = "session-duration"; const char kKeySessionState[] = "session-state"; +const char kKeyConnectionError[] = "connection-error"; const char kValueSessionStateConnected[] = "connected"; const char kValueSessionStateClosed[] = "closed"; @@ -53,126 +38,7 @@ const char kKeyOsName[] = "os-name"; const char kKeyOsVersion[] = "os-version"; const char kKeyAppVersion[] = "app-version"; -const char kKeyCpu[] = "cpu"; - -} // namespace - -ServerLogEntry::ServerLogEntry() { -} - -ServerLogEntry::~ServerLogEntry() { -} - -// static -scoped_ptr<buzz::XmlElement> ServerLogEntry::MakeStanza() { - return scoped_ptr<buzz::XmlElement>( - new XmlElement(QName(kChromotingXmlNamespace, kLogCommand))); -} - -// static -scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForSessionStateChange( - protocol::ConnectionToHost::State state, - protocol::ErrorCode error) { - scoped_ptr<ServerLogEntry> entry(new ServerLogEntry()); - entry->Set(kKeyRole, kValueRoleClient); - entry->Set(kKeyEventName, kValueEventNameSessionState); - - entry->Set(kKeySessionState, GetValueSessionState(state)); - if (error != protocol::OK) { - entry->Set("connection-error", GetValueError(error)); - } - - return entry.Pass(); -} - -// static -scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForStatistics( - ChromotingStats* statistics) { - scoped_ptr<ServerLogEntry> entry(new ServerLogEntry()); - entry->Set(kKeyRole, kValueRoleClient); - entry->Set(kKeyEventName, kValueEventNameStatistics); - - entry->Set("video-bandwidth", - StringPrintf("%.2f", statistics->video_bandwidth()->Rate())); - entry->Set("capture-latency", - StringPrintf("%.2f", statistics->video_capture_ms()->Average())); - entry->Set("encode-latency", - StringPrintf("%.2f", statistics->video_encode_ms()->Average())); - entry->Set("decode-latency", - StringPrintf("%.2f", statistics->video_decode_ms()->Average())); - entry->Set("render-latency", - StringPrintf("%.2f", statistics->video_frame_rate()->Rate())); - entry->Set("roundtrip-latency", - StringPrintf("%.2f", statistics->round_trip_ms()->Average())); - - return entry.Pass(); -} - -// static -scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForSessionIdOld( - const std::string& session_id) { - scoped_ptr<ServerLogEntry> entry(new ServerLogEntry()); - entry->Set(kKeyRole, kValueRoleClient); - entry->Set(kKeyEventName, kValueEventNameSessionIdOld); - entry->AddSessionId(session_id); - return entry.Pass(); -} - -// static -scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForSessionIdNew( - const std::string& session_id) { - scoped_ptr<ServerLogEntry> entry(new ServerLogEntry()); - entry->Set(kKeyRole, kValueRoleClient); - entry->Set(kKeyEventName, kValueEventNameSessionIdNew); - entry->AddSessionId(session_id); - return entry.Pass(); -} - -void ServerLogEntry::AddClientFields() { - Set(kKeyOsName, SysInfo::OperatingSystemName()); - Set(kKeyOsVersion, SysInfo::OperatingSystemVersion()); - Set(kKeyAppVersion, STRINGIZE(VERSION)); - Set(kKeyCpu, SysInfo::OperatingSystemArchitecture()); -}; - -void ServerLogEntry::AddModeField(ServerLogEntry::Mode mode) { - Set(kKeyMode, GetValueMode(mode)); -} - -void ServerLogEntry::AddSessionId(const std::string& session_id) { - Set("session-id", session_id); -} - -void ServerLogEntry::AddSessionDuration(base::TimeDelta duration) { - Set("session-duration", base::Int64ToString(duration.InSeconds())); -} - -// static -const char* ServerLogEntry::GetValueMode(ServerLogEntry::Mode mode) { - switch (mode) { - case IT2ME: - return kValueModeIt2Me; - case ME2ME: - return kValueModeMe2Me; - default: - NOTREACHED(); - return NULL; - } -} - -scoped_ptr<XmlElement> ServerLogEntry::ToStanza() const { - scoped_ptr<XmlElement> stanza(new XmlElement(QName( - kChromotingXmlNamespace, kLogEntry))); - ValuesMap::const_iterator iter; - for (iter = values_map_.begin(); iter != values_map_.end(); ++iter) { - stanza->AddAttr(QName(std::string(), iter->first), iter->second); - } - return stanza.Pass(); -} - -// static -const char* ServerLogEntry::GetValueSessionState( - ConnectionToHost::State state) { +const char* GetValueSessionState(ConnectionToHost::State state) { switch (state) { // Where possible, these are the same strings that the webapp sends for the // corresponding state - see remoting/webapp/server_log_entry.js. @@ -194,8 +60,7 @@ const char* ServerLogEntry::GetValueSessionState( } } -// static -const char* ServerLogEntry::GetValueError(protocol::ErrorCode error) { +const char* GetValueError(ErrorCode error) { switch (error) { // Where possible, these are the same strings that the webapp sends for the // corresponding error - see remoting/webapp/server_log_entry.js. @@ -225,14 +90,77 @@ const char* ServerLogEntry::GetValueError(protocol::ErrorCode error) { } } -void ServerLogEntry::AddEventName(const std::string& event_name) { - Set("event-name", event_name); +} // namespace + +scoped_ptr<ServerLogEntry> MakeLogEntryForSessionStateChange( + ConnectionToHost::State state, + ErrorCode error) { + scoped_ptr<ServerLogEntry> entry(new ServerLogEntry()); + entry->AddRoleField(kValueRoleClient); + entry->AddEventNameField(kValueEventNameSessionState); + + entry->Set(kKeySessionState, GetValueSessionState(state)); + if (error != protocol::OK) { + entry->Set(kKeyConnectionError, GetValueError(error)); + } + + return entry.Pass(); +} + +scoped_ptr<ServerLogEntry> MakeLogEntryForStatistics( + ChromotingStats* statistics) { + scoped_ptr<ServerLogEntry> entry(new ServerLogEntry()); + entry->AddRoleField(kValueRoleClient); + entry->AddEventNameField(kValueEventNameStatistics); + + entry->Set("video-bandwidth", + StringPrintf("%.2f", statistics->video_bandwidth()->Rate())); + entry->Set("capture-latency", + StringPrintf("%.2f", statistics->video_capture_ms()->Average())); + entry->Set("encode-latency", + StringPrintf("%.2f", statistics->video_encode_ms()->Average())); + entry->Set("decode-latency", + StringPrintf("%.2f", statistics->video_decode_ms()->Average())); + entry->Set("render-latency", + StringPrintf("%.2f", statistics->video_frame_rate()->Rate())); + entry->Set("roundtrip-latency", + StringPrintf("%.2f", statistics->round_trip_ms()->Average())); + + return entry.Pass(); +} + +scoped_ptr<ServerLogEntry> MakeLogEntryForSessionIdOld( + const std::string& session_id) { + scoped_ptr<ServerLogEntry> entry(new ServerLogEntry()); + entry->AddRoleField(kValueRoleClient); + entry->AddEventNameField(kValueEventNameSessionIdOld); + AddSessionIdToLogEntry(entry.get(), session_id); + return entry.Pass(); } -void ServerLogEntry::Set(const std::string& key, const std::string& value) { - values_map_[key] = value; +scoped_ptr<ServerLogEntry> MakeLogEntryForSessionIdNew( + const std::string& session_id) { + scoped_ptr<ServerLogEntry> entry(new ServerLogEntry()); + entry->AddRoleField(kValueRoleClient); + entry->AddEventNameField(kValueEventNameSessionIdNew); + AddSessionIdToLogEntry(entry.get(), session_id); + return entry.Pass(); +} + +void AddClientFieldsToLogEntry(ServerLogEntry* entry) { + entry->Set(kKeyOsName, SysInfo::OperatingSystemName()); + entry->Set(kKeyOsVersion, SysInfo::OperatingSystemVersion()); + entry->Set(kKeyAppVersion, STRINGIZE(VERSION)); + entry->AddCpuField(); } -} // namespace client +void AddSessionIdToLogEntry(ServerLogEntry* entry, const std::string& id) { + entry->Set(kKeySessionId, id); +} + +void AddSessionDurationToLogEntry(ServerLogEntry* entry, + base::TimeDelta duration) { + entry->Set(kKeySessionDuration, base::Int64ToString(duration.InSeconds())); +} } // namespace remoting diff --git a/remoting/client/server_log_entry_client.h b/remoting/client/server_log_entry_client.h new file mode 100644 index 0000000..b2ef262 --- /dev/null +++ b/remoting/client/server_log_entry_client.h @@ -0,0 +1,41 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef REMOTING_CLIENT_SERVER_LOG_ENTRY_CLIENT_H_ +#define REMOTING_CLIENT_SERVER_LOG_ENTRY_CLIENT_H_ + +#include "base/time/time.h" +#include "remoting/protocol/connection_to_host.h" +#include "remoting/protocol/errors.h" + +namespace remoting { + +class ChromotingStats; +class ServerLogEntry; + +// Constructs a log entry for a session state change. +scoped_ptr<ServerLogEntry> MakeLogEntryForSessionStateChange( + protocol::ConnectionToHost::State state, + protocol::ErrorCode error); + +// Constructs a log entry for reporting statistics. +scoped_ptr<ServerLogEntry> MakeLogEntryForStatistics( + ChromotingStats* statistics); + +// Constructs a log entry for reporting session ID is old. +scoped_ptr<ServerLogEntry> MakeLogEntryForSessionIdOld( + const std::string& session_id); + +// Constructs a log entry for reporting session ID is old. +scoped_ptr<ServerLogEntry> MakeLogEntryForSessionIdNew( + const std::string& session_id); + +void AddClientFieldsToLogEntry(ServerLogEntry* entry); +void AddSessionIdToLogEntry(ServerLogEntry* entry, const std::string& id); +void AddSessionDurationToLogEntry(ServerLogEntry* entry, + base::TimeDelta duration); + +} // namespace remoting + +#endif // REMOTING_CLIENT_SERVER_LOG_ENTRY_CLIENT_H_ diff --git a/remoting/client/server_log_entry_client_unittest.cc b/remoting/client/server_log_entry_client_unittest.cc new file mode 100644 index 0000000..9861b18 --- /dev/null +++ b/remoting/client/server_log_entry_client_unittest.cc @@ -0,0 +1,125 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/memory/scoped_ptr.h" +#include "base/strings/stringize_macros.h" +#include "base/sys_info.h" +#include "remoting/client/chromoting_stats.h" +#include "remoting/client/server_log_entry_client.h" +#include "remoting/jingle_glue/server_log_entry.h" +#include "remoting/jingle_glue/server_log_entry_unittest.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/libjingle/source/talk/xmllite/xmlelement.h" + +using base::SysInfo; +using buzz::XmlAttr; +using buzz::XmlElement; +using remoting::protocol::ConnectionToHost; + +namespace remoting { + +TEST(ServerLogEntryClientTest, SessionStateChange) { + scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange( + ConnectionToHost::CONNECTED, remoting::protocol::OK)); + scoped_ptr<XmlElement> stanza = entry->ToStanza(); + std::string error; + std::map<std::string, std::string> key_value_pairs; + key_value_pairs["role"] = "client"; + key_value_pairs["event-name"] = "session-state"; + key_value_pairs["session-state"] = "connected"; + std::set<std::string> keys; + ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) + << error; +} + +TEST(ServerLogEntryClientTest, SessionStateChangeWithError) { + scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange( + ConnectionToHost::FAILED, remoting::protocol::PEER_IS_OFFLINE)); + scoped_ptr<XmlElement> stanza = entry->ToStanza(); + std::string error; + std::map<std::string, std::string> key_value_pairs; + key_value_pairs["role"] = "client"; + key_value_pairs["event-name"] = "session-state"; + key_value_pairs["session-state"] = "connection-failed"; + key_value_pairs["connection-error"] = "host-is-offline"; + std::set<std::string> keys; + ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) + << error; +} + +TEST(ServerLogEntryClientTest, Statistics) { + ChromotingStats statistics; + scoped_ptr<ServerLogEntry> entry(MakeLogEntryForStatistics(&statistics)); + scoped_ptr<XmlElement> stanza = entry->ToStanza(); + std::string error; + std::map<std::string, std::string> key_value_pairs; + key_value_pairs["role"] = "client"; + key_value_pairs["event-name"] = "connection-statistics"; + std::set<std::string> keys; + keys.insert("video-bandwidth"); + keys.insert("capture-latency"); + keys.insert("encode-latency"); + keys.insert("decode-latency"); + keys.insert("render-latency"); + keys.insert("roundtrip-latency"); + ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) + << error; +} + +TEST(ServerLogEntryClientTest, SessionIdChanged) { + scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionIdOld("abc")); + scoped_ptr<XmlElement> stanza = entry->ToStanza(); + std::string error; + std::map<std::string, std::string> key_value_pairs; + key_value_pairs["role"] = "client"; + key_value_pairs["event-name"] = "session-id-old"; + key_value_pairs["session-id"] = "abc"; + std::set<std::string> keys; + ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) + << error; + + entry = MakeLogEntryForSessionIdNew("def"); + stanza = entry->ToStanza(); + key_value_pairs["event-name"] = "session-id-new"; + key_value_pairs["session-id"] = "def"; + ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) + << error; +} + +TEST(ServerLogEntryClientTest, AddClientFields) { + scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange( + ConnectionToHost::CONNECTED, remoting::protocol::OK)); + AddClientFieldsToLogEntry(entry.get()); + scoped_ptr<XmlElement> stanza = entry->ToStanza(); + std::string error; + std::map<std::string, std::string> key_value_pairs; + key_value_pairs["role"] = "client"; + key_value_pairs["event-name"] = "session-state"; + key_value_pairs["session-state"] = "connected"; + key_value_pairs["os-name"] = SysInfo::OperatingSystemName(); + key_value_pairs["os-version"] = SysInfo::OperatingSystemVersion(); + key_value_pairs["app-version"] = STRINGIZE(VERSION); + key_value_pairs["cpu"] = SysInfo::OperatingSystemArchitecture(); + std::set<std::string> keys; + ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) << + error; +} + +TEST(ServerLogEntryClientTest, AddSessionDuration) { + scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange( + ConnectionToHost::CONNECTED, remoting::protocol::OK)); + AddSessionDurationToLogEntry(entry.get(), base::TimeDelta::FromSeconds(123)); + scoped_ptr<XmlElement> stanza = entry->ToStanza(); + std::string error; + std::map<std::string, std::string> key_value_pairs; + key_value_pairs["role"] = "client"; + key_value_pairs["event-name"] = "session-state"; + key_value_pairs["session-state"] = "connected"; + key_value_pairs["session-duration"] = "123"; + std::set<std::string> keys; + ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) + << error; +} + +} // namespace remoting |