Re-land: C++ readability review
[chromium-blink-merge.git] / remoting / client / server_log_entry_client_unittest.cc
blob1a39a2e2bb2f195b9a496fad3cf0d24ec2ecb7bc
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.
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/signaling/server_log_entry.h"
11 #include "remoting/signaling/server_log_entry_unittest.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
15 using base::SysInfo;
16 using buzz::XmlAttr;
17 using buzz::XmlElement;
18 using remoting::protocol::ConnectionToHost;
20 namespace remoting {
22 TEST(ServerLogEntryClientTest, SessionStateChange) {
23 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange(
24 ConnectionToHost::CONNECTED, remoting::protocol::OK));
25 scoped_ptr<XmlElement> stanza = entry->ToStanza();
26 std::string error;
27 std::map<std::string, std::string> key_value_pairs;
28 key_value_pairs["role"] = "client";
29 key_value_pairs["event-name"] = "session-state";
30 key_value_pairs["session-state"] = "connected";
31 std::set<std::string> keys;
32 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error))
33 << error;
36 TEST(ServerLogEntryClientTest, SessionStateChangeWithError) {
37 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange(
38 ConnectionToHost::FAILED, remoting::protocol::PEER_IS_OFFLINE));
39 scoped_ptr<XmlElement> stanza = entry->ToStanza();
40 std::string error;
41 std::map<std::string, std::string> key_value_pairs;
42 key_value_pairs["role"] = "client";
43 key_value_pairs["event-name"] = "session-state";
44 key_value_pairs["session-state"] = "connection-failed";
45 key_value_pairs["connection-error"] = "host-is-offline";
46 std::set<std::string> keys;
47 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error))
48 << error;
51 TEST(ServerLogEntryClientTest, Statistics) {
52 ChromotingStats statistics;
53 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForStatistics(&statistics));
54 scoped_ptr<XmlElement> stanza = entry->ToStanza();
55 std::string error;
56 std::map<std::string, std::string> key_value_pairs;
57 key_value_pairs["role"] = "client";
58 key_value_pairs["event-name"] = "connection-statistics";
59 std::set<std::string> keys;
60 keys.insert("video-bandwidth");
61 keys.insert("capture-latency");
62 keys.insert("encode-latency");
63 keys.insert("decode-latency");
64 keys.insert("render-latency");
65 keys.insert("roundtrip-latency");
66 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error))
67 << error;
70 TEST(ServerLogEntryClientTest, SessionIdChanged) {
71 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionIdOld("abc"));
72 scoped_ptr<XmlElement> stanza = entry->ToStanza();
73 std::string error;
74 std::map<std::string, std::string> key_value_pairs;
75 key_value_pairs["role"] = "client";
76 key_value_pairs["event-name"] = "session-id-old";
77 key_value_pairs["session-id"] = "abc";
78 std::set<std::string> keys;
79 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error))
80 << error;
82 entry = MakeLogEntryForSessionIdNew("def");
83 stanza = entry->ToStanza();
84 key_value_pairs["event-name"] = "session-id-new";
85 key_value_pairs["session-id"] = "def";
86 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error))
87 << error;
90 TEST(ServerLogEntryClientTest, AddClientFields) {
91 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange(
92 ConnectionToHost::CONNECTED, remoting::protocol::OK));
93 AddClientFieldsToLogEntry(entry.get());
94 scoped_ptr<XmlElement> stanza = entry->ToStanza();
95 std::string error;
96 std::map<std::string, std::string> key_value_pairs;
97 key_value_pairs["role"] = "client";
98 key_value_pairs["event-name"] = "session-state";
99 key_value_pairs["session-state"] = "connected";
100 key_value_pairs["os-name"] = SysInfo::OperatingSystemName();
101 key_value_pairs["os-version"] = SysInfo::OperatingSystemVersion();
102 key_value_pairs["app-version"] = STRINGIZE(VERSION);
103 key_value_pairs["cpu"] = SysInfo::OperatingSystemArchitecture();
104 std::set<std::string> keys;
105 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) <<
106 error;
109 TEST(ServerLogEntryClientTest, AddSessionDuration) {
110 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange(
111 ConnectionToHost::CONNECTED, remoting::protocol::OK));
112 AddSessionDurationToLogEntry(entry.get(), base::TimeDelta::FromSeconds(123));
113 scoped_ptr<XmlElement> stanza = entry->ToStanza();
114 std::string error;
115 std::map<std::string, std::string> key_value_pairs;
116 key_value_pairs["role"] = "client";
117 key_value_pairs["event-name"] = "session-state";
118 key_value_pairs["session-state"] = "connected";
119 key_value_pairs["session-duration"] = "123";
120 std::set<std::string> keys;
121 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error))
122 << error;
125 } // namespace remoting