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

Unified Diff: sync/engine/traffic_recorder_unittest.cc

Issue 9732008: [Sync] Store the past 10 traffic records in memory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review. Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: sync/engine/traffic_recorder_unittest.cc
diff --git a/sync/engine/traffic_recorder_unittest.cc b/sync/engine/traffic_recorder_unittest.cc
new file mode 100755
index 0000000000000000000000000000000000000000..9f230b3f532ef93fcdf8d2a38e23e3f5a93187fe
--- /dev/null
+++ b/sync/engine/traffic_recorder_unittest.cc
@@ -0,0 +1,44 @@
+// Copyright (c) 2012 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 "sync/engine/traffic_recorder.h"
+
+#include "sync/protocol/sync.pb.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace browser_sync {
+
+const unsigned int kMaxMessages = 10;
+const unsigned int kMaxMessageSize = 5 * 1024;
+
+// Ensure the number of records don't exceed |kMaxMessages|.
+TEST(TrafficRecorderTest, MaxRecordsTest) {
+ TrafficRecorder recorder(kMaxMessages,kMaxMessageSize);
+ sync_pb::ClientToServerResponse response;
+
+ for (unsigned int i = 0; i<2*kMaxMessages; ++i)
+ recorder.RecordClientToServerResponse(response);
+
+ EXPECT_EQ(recorder.records().size(), kMaxMessages);
+}
+
+// Ensure records with size greater than |kMaxMessageSize| are truncated.
+TEST(TrafficRecorderTest, MaxMessageSizeTest) {
+ sync_pb::ClientToServerResponse response;
+
+ int id = 0;
+ while ((unsigned int)response.ByteSize() < kMaxMessageSize) {
+ response.add_migrated_data_type_id(id);
+ ++id;
+ }
+
+ TrafficRecorder recorder(kMaxMessages,kMaxMessageSize);
+ recorder.RecordClientToServerResponse(response);
+
+ TrafficRecorder::TrafficRecord record = recorder.records().front();
+ EXPECT_TRUE(record.truncated);
+ EXPECT_TRUE(record.message.empty());
+}
+
+} //namespace browser_sync

Powered by Google App Engine
This is Rietveld 408576698