Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: sync/engine/traffic_recorder_unittest.cc

Issue 12088080: [Sync] Add timestamp to TrafficRecorder records (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/values.h"
6
5 #include "sync/engine/traffic_recorder.h" 7 #include "sync/engine/traffic_recorder.h"
6 8
7 #include "sync/protocol/sync.pb.h" 9 #include "sync/protocol/sync.pb.h"
10 #include "sync/test/engine/fake_traffic_recorder.h"
11 #include "sync/util/time.h"
8 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
9 13
10 namespace syncer { 14 namespace syncer {
11 15
12 const unsigned int kMaxMessages = 10; 16 const unsigned int kMaxMessages = 10;
13 const unsigned int kMaxMessageSize = 5 * 1024; 17 const unsigned int kMaxMessageSize = 5 * 1024;
14 18
15 // Ensure the number of records don't exceed |kMaxMessages|. 19 // Ensure the number of records don't exceed |kMaxMessages|.
16 TEST(TrafficRecorderTest, MaxRecordsTest) { 20 TEST(TrafficRecorderTest, MaxRecordsTest) {
17 TrafficRecorder recorder(kMaxMessages, kMaxMessageSize); 21 TrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
(...skipping 14 matching lines...) Expand all
32 error->set_error_description(error_description); 36 error->set_error_description(error_description);
33 37
34 TrafficRecorder recorder(kMaxMessages, kMaxMessageSize); 38 TrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
35 recorder.RecordClientToServerResponse(response); 39 recorder.RecordClientToServerResponse(response);
36 40
37 TrafficRecorder::TrafficRecord record = recorder.records().front(); 41 TrafficRecorder::TrafficRecord record = recorder.records().front();
38 EXPECT_TRUE(record.truncated); 42 EXPECT_TRUE(record.truncated);
39 EXPECT_TRUE(record.message.empty()); 43 EXPECT_TRUE(record.message.empty());
40 } 44 }
41 45
46 // Ensure that timestamp is recorded correctly in traffic record
rlarocque 2013/01/31 19:13:10 nit: Please put periods after comments throughout
47 TEST(TrafficRecorderTest, TimestampTest) {
48 sync_pb::ClientToServerResponse response;
49
50 FakeTrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
51 recorder.SetTime(3);
52 recorder.RecordClientToServerResponse(response);
53
54 base::Time expect_time = ProtoTimeToTime(3);
55 TrafficRecorder::TrafficRecord record = recorder.records().front();
56 EXPECT_EQ(expect_time, record.timestamp);
57 }
58
59 // Ensure that timestamps are recorded correctly in traffic records
60 TEST(TrafficRecorderTest, MultipleTimestampTest) {
61 sync_pb::ClientToServerResponse response;
62 base::Time sample_time_1 = ProtoTimeToTime(1359484676659324);
63 base::Time sample_time_2 = ProtoTimeToTime(1359484676659324 * 2);
64
65 FakeTrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
66 recorder.SetTime(sample_time_1);
67 recorder.RecordClientToServerResponse(response);
68 recorder.SetTime(sample_time_2);
69 recorder.RecordClientToServerResponse(response);
70
71 TrafficRecorder::TrafficRecord record_1 = recorder.records().front();
72 TrafficRecorder::TrafficRecord record_2 = recorder.records().back();
73 EXPECT_EQ(sample_time_1, record_1.timestamp);
74 EXPECT_EQ(sample_time_2, record_2.timestamp);
75 }
76
77 // Ensure that timestamp is added to ListValue of DictionaryValues in ToValue()
78 TEST(TrafficRecorderTest, ToValueTimestampTest) {
79 sync_pb::ClientToServerResponse response;
80 base::Time sample_time = ProtoTimeToTime(1359484676659324);
81 std::string expect_time_str = GetTimeDebugString(sample_time);
82
83 FakeTrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
84 recorder.SetTime(sample_time);
85 recorder.RecordClientToServerResponse(response);
86
87 ListValue* value = recorder.ToValue();
88 DictionaryValue* record_value;
89 std::string time_str;
90
91 EXPECT_TRUE(value->GetDictionary(0, &record_value));
rlarocque 2013/01/31 19:13:10 Make this ASSERT_TRUE? ASSERTs will abort the tes
92 EXPECT_TRUE(record_value->GetString("timestamp", &time_str));
93 EXPECT_EQ(expect_time_str, time_str);
94 }
95
rlarocque 2013/01/31 19:13:10 nit: Please remove extra whitespace.
96
42 } // namespace syncer 97 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698