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

Unified Diff: components/offline_pages/background/request_coordinator_event_logger_unittest.cc

Issue 2089413002: [Offline Pages] Create a event/activity logger (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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: components/offline_pages/background/request_coordinator_event_logger_unittest.cc
diff --git a/components/offline_pages/background/request_coordinator_event_logger_unittest.cc b/components/offline_pages/background/request_coordinator_event_logger_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a8189a95c71e29ade4cdd305dbeb0fd46ab626f3
--- /dev/null
+++ b/components/offline_pages/background/request_coordinator_event_logger_unittest.cc
@@ -0,0 +1,59 @@
+// Copyright 2016 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 "components/offline_pages/background/request_coordinator_event_logger.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace offline_pages {
+
+namespace {
+
+const char kNamespace[] = "last_n";
+const char kStatus[] = "pending";
+const int64_t kId = 1234;
+const char kLogString[] =
+ "Save page request for ID: 1234 and namespace: "
+ "last_n has been updated with status pending";
+const int kTimeLength = 21;
+
+} // namespace
+
+TEST(RequestCoordinatorEventLoggerTest, RecordsWhenLoggingIsOn) {
+ RequestCoordinatorEventLogger logger;
+ std::vector<std::string> log;
+
+ logger.SetIsLogging(true);
+ logger.RecordSavePageRequestUpdated(kNamespace, kStatus, kId);
+ logger.GetLogs(&log);
+
+ EXPECT_EQ(1u, log.size());
+ EXPECT_EQ(std::string(kLogString), log[0].substr(kTimeLength));
+}
+
+TEST(RequestCoordinatorEventLoggerTest, RecordsWhenLoggingIsOff) {
+ RequestCoordinatorEventLogger logger;
+ std::vector<std::string> log;
+
+ logger.SetIsLogging(false);
+ logger.RecordSavePageRequestUpdated(kNamespace, kStatus, kId);
+ logger.GetLogs(&log);
+
+ EXPECT_EQ(0u, log.size());
+}
+
+TEST(RequestCoordinatorEventLoggerTest, DoesNotExceedMaxSize) {
+ RequestCoordinatorEventLogger logger;
+ std::vector<std::string> log;
+
+ logger.SetIsLogging(true);
+ for (size_t i = 0; i < kMaxLogCount + 1; ++i) {
+ logger.RecordSavePageRequestUpdated(kNamespace, kStatus, kId);
+ }
+ logger.GetLogs(&log);
+
+ EXPECT_EQ(kMaxLogCount, log.size());
+}
+
+} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698