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

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..cee7816d3472f775014cf891c339f4f1b6c90013
--- /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 {
+
+extern const unsigned int kMaxMessages;
akalin 2012/03/27 23:53:44 eh, this is pretty gross. :/ Make TrafficRecorder'
lipalani1 2012/03/29 00:23:13 Done.
+extern const unsigned int kMaxMessageSize;
+
+// Ensure the number of records don't exceed |kMaxMessages|.
+TEST(TrafficRecorderTest, MaxRecordsTest) {
+ TrafficRecorder recorder;
+ TrafficRecorder::TrafficRecord record;
+
+ for (unsigned int i = 0; i<2*kMaxMessages; ++i)
akalin 2012/03/27 23:53:44 prefer calling the public interface
lipalani1 2012/03/29 00:23:13 Done.
+ recorder.AddTrafficToQueue(record);
+
+ 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) {
akalin 2012/03/27 23:53:44 you can just assign to error_message some large st
lipalani1 2012/03/29 00:23:13 hmm... I dont want to type in a large error messag
akalin 2012/03/29 08:13:14 You don't have to literally type in the large erro
+ response.add_migrated_data_type_id(id);
+ ++id;
+ }
+
+ TrafficRecorder recorder;
+ 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