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

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 submitting. 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
« no previous file with comments | « sync/engine/traffic_recorder.cc ('k') | sync/sessions/sync_session_context.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..7099eb082ec18c363ffac8c3c0b3be0b86f50112
--- /dev/null
+++ b/sync/engine/traffic_recorder_unittest.cc
@@ -0,0 +1,42 @@
+// 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;
+
+ sync_pb::ClientToServerResponse::Error* error = response.mutable_error();
+ std::string error_description(kMaxMessageSize * 2, 'a');
+ error->set_error_description(error_description);
+
+ 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
« no previous file with comments | « sync/engine/traffic_recorder.cc ('k') | sync/sessions/sync_session_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698