OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/offline_pages/background/request_coordinator_event_logger.h
" |
| 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 namespace offline_pages { |
| 10 |
| 11 namespace { |
| 12 |
| 13 const char kNamespace[] = "last_n"; |
| 14 const char kStatus[] = "pending"; |
| 15 const int64_t kId = 1234; |
| 16 const char kLogString[] = |
| 17 "Save page request for ID: 1234 and namespace: " |
| 18 "last_n has been updated with status pending"; |
| 19 const int kTimeLength = 21; |
| 20 |
| 21 } // namespace |
| 22 |
| 23 TEST(RequestCoordinatorEventLoggerTest, RecordsWhenLoggingIsOn) { |
| 24 RequestCoordinatorEventLogger logger; |
| 25 std::vector<std::string> log; |
| 26 |
| 27 logger.SetIsLogging(true); |
| 28 logger.RecordSavePageRequestUpdated(kNamespace, kStatus, kId); |
| 29 logger.GetLogs(&log); |
| 30 |
| 31 EXPECT_EQ(1u, log.size()); |
| 32 EXPECT_EQ(std::string(kLogString), log[0].substr(kTimeLength)); |
| 33 } |
| 34 |
| 35 TEST(RequestCoordinatorEventLoggerTest, RecordsWhenLoggingIsOff) { |
| 36 RequestCoordinatorEventLogger logger; |
| 37 std::vector<std::string> log; |
| 38 |
| 39 logger.SetIsLogging(false); |
| 40 logger.RecordSavePageRequestUpdated(kNamespace, kStatus, kId); |
| 41 logger.GetLogs(&log); |
| 42 |
| 43 EXPECT_EQ(0u, log.size()); |
| 44 } |
| 45 |
| 46 TEST(RequestCoordinatorEventLoggerTest, DoesNotExceedMaxSize) { |
| 47 RequestCoordinatorEventLogger logger; |
| 48 std::vector<std::string> log; |
| 49 |
| 50 logger.SetIsLogging(true); |
| 51 for (size_t i = 0; i < kMaxLogCount + 1; ++i) { |
| 52 logger.RecordSavePageRequestUpdated(kNamespace, kStatus, kId); |
| 53 } |
| 54 logger.GetLogs(&log); |
| 55 |
| 56 EXPECT_EQ(kMaxLogCount, log.size()); |
| 57 } |
| 58 |
| 59 } // namespace offline_pages |
OLD | NEW |