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

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: Fix comment 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
« no previous file with comments | « sync/engine/traffic_recorder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "sync/engine/traffic_recorder.h" 5 #include "sync/engine/traffic_recorder.h"
6 6
7 #include "base/time.h"
8 #include "base/values.h"
7 #include "sync/protocol/sync.pb.h" 9 #include "sync/protocol/sync.pb.h"
10 #include "sync/util/time.h"
8 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
9 12
10 namespace syncer { 13 namespace syncer {
11 14
12 const unsigned int kMaxMessages = 10; 15 const unsigned int kMaxMessages = 10;
13 const unsigned int kMaxMessageSize = 5 * 1024; 16 const unsigned int kMaxMessageSize = 5 * 1024;
14 17
15 // Ensure the number of records don't exceed |kMaxMessages|. 18 // Ensure the number of records don't exceed |kMaxMessages|.
16 TEST(TrafficRecorderTest, MaxRecordsTest) { 19 TEST(TrafficRecorderTest, MaxRecordsTest) {
17 TrafficRecorder recorder(kMaxMessages, kMaxMessageSize); 20 TrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
(...skipping 14 matching lines...) Expand all
32 error->set_error_description(error_description); 35 error->set_error_description(error_description);
33 36
34 TrafficRecorder recorder(kMaxMessages, kMaxMessageSize); 37 TrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
35 recorder.RecordClientToServerResponse(response); 38 recorder.RecordClientToServerResponse(response);
36 39
37 TrafficRecorder::TrafficRecord record = recorder.records().front(); 40 TrafficRecorder::TrafficRecord record = recorder.records().front();
38 EXPECT_TRUE(record.truncated); 41 EXPECT_TRUE(record.truncated);
39 EXPECT_TRUE(record.message.empty()); 42 EXPECT_TRUE(record.message.empty());
40 } 43 }
41 44
45 // Test implementation of TrafficRecorder.
46 class TestTrafficRecorder : public TrafficRecorder {
47 public:
48 TestTrafficRecorder(unsigned int max_messages, unsigned int max_message_size)
49 : TrafficRecorder(max_messages, max_message_size) {
50 set_time(0);
51 }
52 virtual ~TestTrafficRecorder() {}
53
54 virtual base::Time GetTime() OVERRIDE {
55 return time_;
56 }
57
58 void set_time(int64 time) {
59 time_ = ProtoTimeToTime(time);
60 }
61
62 void set_time(base::Time time) {
63 time_ = time;
64 }
65
66 private:
67 base::Time time_;
68 };
69
70 // Ensure that timestamp is recorded correctly in traffic record.
71 TEST(TrafficRecorderTest, TimestampTest) {
72 sync_pb::ClientToServerResponse response;
73
74 TestTrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
75 recorder.set_time(3);
76 recorder.RecordClientToServerResponse(response);
77
78 base::Time expect_time = ProtoTimeToTime(3);
79 TrafficRecorder::TrafficRecord record = recorder.records().front();
80 EXPECT_EQ(expect_time, record.timestamp);
81 }
82
83 // Ensure that timestamps are recorded correctly in traffic records.
84 TEST(TrafficRecorderTest, MultipleTimestampTest) {
85 sync_pb::ClientToServerResponse response;
86 base::Time sample_time_1 = ProtoTimeToTime(1359484676659324);
Lei Zhang 2013/02/01 05:19:11 These big numbers need GG_INT64_C.
87 base::Time sample_time_2 = ProtoTimeToTime(1359484676659324 * 2);
88
89 TestTrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
90 recorder.set_time(sample_time_1);
91 recorder.RecordClientToServerResponse(response);
92 recorder.set_time(sample_time_2);
93 recorder.RecordClientToServerResponse(response);
94
95 TrafficRecorder::TrafficRecord record_1 = recorder.records().front();
96 TrafficRecorder::TrafficRecord record_2 = recorder.records().back();
97 EXPECT_EQ(sample_time_1, record_1.timestamp);
98 EXPECT_EQ(sample_time_2, record_2.timestamp);
99 }
100
101 // Ensure that timestamp is added to ListValue of DictionaryValues in ToValue().
102 TEST(TrafficRecorderTest, ToValueTimestampTest) {
103 sync_pb::ClientToServerResponse response;
104 base::Time sample_time = ProtoTimeToTime(1359484676659324);
105 std::string expect_time_str = GetTimeDebugString(sample_time);
106
107 TestTrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
108 recorder.set_time(sample_time);
109 recorder.RecordClientToServerResponse(response);
110
111 ListValue* value = recorder.ToValue();
112 DictionaryValue* record_value;
113 std::string time_str;
114
115 ASSERT_TRUE(value->GetDictionary(0, &record_value));
116 EXPECT_TRUE(record_value->GetString("timestamp", &time_str));
117 EXPECT_EQ(expect_time_str, time_str);
118 }
119
42 } // namespace syncer 120 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/traffic_recorder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698