Index: sync/engine/traffic_recorder_unittest.cc |
diff --git a/sync/engine/traffic_recorder_unittest.cc b/sync/engine/traffic_recorder_unittest.cc |
index cf821f5e408402e86662115a16099f596ce6e15a..c918840df2a0df16884b5a6e6ab4fd720d08444a 100644 |
--- a/sync/engine/traffic_recorder_unittest.cc |
+++ b/sync/engine/traffic_recorder_unittest.cc |
@@ -2,9 +2,13 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "base/values.h" |
+ |
#include "sync/engine/traffic_recorder.h" |
#include "sync/protocol/sync.pb.h" |
+#include "sync/test/engine/fake_traffic_recorder.h" |
+#include "sync/util/time.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace syncer { |
@@ -39,4 +43,55 @@ TEST(TrafficRecorderTest, MaxMessageSizeTest) { |
EXPECT_TRUE(record.message.empty()); |
} |
+// Ensure that timestamp is recorded correctly in traffic record |
rlarocque
2013/01/31 19:13:10
nit: Please put periods after comments throughout
|
+TEST(TrafficRecorderTest, TimestampTest) { |
+ sync_pb::ClientToServerResponse response; |
+ |
+ FakeTrafficRecorder recorder(kMaxMessages, kMaxMessageSize); |
+ recorder.SetTime(3); |
+ recorder.RecordClientToServerResponse(response); |
+ |
+ base::Time expect_time = ProtoTimeToTime(3); |
+ TrafficRecorder::TrafficRecord record = recorder.records().front(); |
+ EXPECT_EQ(expect_time, record.timestamp); |
+} |
+ |
+// Ensure that timestamps are recorded correctly in traffic records |
+TEST(TrafficRecorderTest, MultipleTimestampTest) { |
+ sync_pb::ClientToServerResponse response; |
+ base::Time sample_time_1 = ProtoTimeToTime(1359484676659324); |
+ base::Time sample_time_2 = ProtoTimeToTime(1359484676659324 * 2); |
+ |
+ FakeTrafficRecorder recorder(kMaxMessages, kMaxMessageSize); |
+ recorder.SetTime(sample_time_1); |
+ recorder.RecordClientToServerResponse(response); |
+ recorder.SetTime(sample_time_2); |
+ recorder.RecordClientToServerResponse(response); |
+ |
+ TrafficRecorder::TrafficRecord record_1 = recorder.records().front(); |
+ TrafficRecorder::TrafficRecord record_2 = recorder.records().back(); |
+ EXPECT_EQ(sample_time_1, record_1.timestamp); |
+ EXPECT_EQ(sample_time_2, record_2.timestamp); |
+} |
+ |
+// Ensure that timestamp is added to ListValue of DictionaryValues in ToValue() |
+TEST(TrafficRecorderTest, ToValueTimestampTest) { |
+ sync_pb::ClientToServerResponse response; |
+ base::Time sample_time = ProtoTimeToTime(1359484676659324); |
+ std::string expect_time_str = GetTimeDebugString(sample_time); |
+ |
+ FakeTrafficRecorder recorder(kMaxMessages, kMaxMessageSize); |
+ recorder.SetTime(sample_time); |
+ recorder.RecordClientToServerResponse(response); |
+ |
+ ListValue* value = recorder.ToValue(); |
+ DictionaryValue* record_value; |
+ std::string time_str; |
+ |
+ EXPECT_TRUE(value->GetDictionary(0, &record_value)); |
rlarocque
2013/01/31 19:13:10
Make this ASSERT_TRUE? ASSERTs will abort the tes
|
+ EXPECT_TRUE(record_value->GetString("timestamp", &time_str)); |
+ EXPECT_EQ(expect_time_str, time_str); |
+} |
+ |
rlarocque
2013/01/31 19:13:10
nit: Please remove extra whitespace.
|
+ |
} // namespace syncer |