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

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: 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..6e82039280af62d8b972a3188565e85605c183c1
--- /dev/null
+++ b/components/offline_pages/background/request_coordinator_event_logger_unittest.cc
@@ -0,0 +1,56 @@
+// 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_internals {
fgorski 2016/06/23 16:34:06 I only noticed that now, but why did we go with a
chili 2016/06/24 02:45:50 Oops. brainfart. Fixed.
+
+namespace {
fgorski 2016/06/23 16:34:06 I don't think we need an anonymous namespace here.
chili 2016/06/24 02:45:50 Removed. A couple tests I was looking at had this.
+
+class RequestCoordinatorEventLoggerTest : public ::testing::Test {
fgorski 2016/06/23 16:34:06 Since the fixture is empty you can use TEST() macr
chili 2016/06/24 02:45:51 Done.
+ public:
+ RequestCoordinatorEventLoggerTest() {}
+ ~RequestCoordinatorEventLoggerTest() {}
+};
+
+TEST_F(RequestCoordinatorEventLoggerTest, RecordsWhenLoggingIsOn) {
+ OfflinePageModelEventLogger logger;
Pete Williamson 2016/06/24 00:38:32 Did you mean RequestCoordinatorEventLogger instead
chili 2016/06/24 02:45:51 haha good catch oops
+ std::vector<std::string> log;
+
+ logger.SetIsLogging(true);
+ logger.RecordSavePageRequestUpdated("last_n", "pending", "foo");
Pete Williamson 2016/06/24 00:38:32 It might be nice to make last_n, pending, and foo
chili 2016/06/24 02:45:51 Done.
+ logger.GetLogs(log);
+
+ EXPECT_EQ(1, log.size());
Pete Williamson 2016/06/24 00:38:32 Can we also test that the content of the logs are
chili 2016/06/24 02:45:51 As explained in the other comment, I ultimately di
Pete Williamson 2016/06/24 16:52:58 OK, I understand that the test will break if we ch
chili 2016/06/24 20:30:10 Added the test.
+}
+
+TEST_F(RequestCoordinatorEventLoggerTest, RecordsWhenLoggingIsOff) {
+ OfflinePageModelEventLogger logger;
+ std::vector<std::string> log;
+
+ logger.SetIsLogging(false);
+ logger.RecordSavePageRequestUpdated("last_n", "pending", "foo");
+ logger.GetLogs(log);
+
+ EXPECT_EQ(1, log.size());
+}
+
+TEST_F(RequestCoordinatorEventLoggerTest, DoesNotExceedMaxSize) {
+ OfflinePageModelEventLogger logger;
+ std::vector<std::string> log;
+
+ logger.SetIsLogging(true);
+ for (int i = 0; i < 21; i++) {
fgorski 2016/06/23 16:34:06 I am guessing your buffer size is 20. Could you pl
Pete Williamson 2016/06/24 00:38:31 Maybe you could expose MAX_LOGGED_ACTIVITY_COUNT i
chili 2016/06/24 02:45:51 Done.
+ logger.RecordSavePageRequestUpdated("last_n", "pending", "foo");
+ }
+ logger.GetLogs(log);
+
+ EXPECT_EQ(20, log.size());
fgorski 2016/06/23 16:34:06 ditto
chili 2016/06/24 02:45:51 Done.
+}
+
+} // namespace
+
+} // namespace offline_internals

Powered by Google App Engine
This is Rietveld 408576698