| 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 Offliner::RequestStatus kOfflinerStatus = Offliner::SAVED; |  | 
| 15 const RequestNotifier::BackgroundSavePageResult kDroppedResult = |  | 
| 16     RequestNotifier::BackgroundSavePageResult::START_COUNT_EXCEEDED; |  | 
| 17 const int64_t kId = 1234; |  | 
| 18 const UpdateRequestResult kQueueUpdateResult = |  | 
| 19     UpdateRequestResult::STORE_FAILURE; |  | 
| 20 |  | 
| 21 const char kOfflinerStatusLogString[] = |  | 
| 22     "Background save attempt for last_n:1234 - SAVED"; |  | 
| 23 const char kDroppedResultLogString[] = |  | 
| 24     "Background save request removed last_n:1234 - START_COUNT_EXCEEDED"; |  | 
| 25 const char kQueueUpdateResultLogString[] = |  | 
| 26     "Updating queued request for last_n failed - STORE_FAILURE"; |  | 
| 27 const int kTimeLength = 21; |  | 
| 28 |  | 
| 29 }  // namespace |  | 
| 30 |  | 
| 31 TEST(RequestCoordinatorEventLoggerTest, RecordsWhenLoggingIsOn) { |  | 
| 32   RequestCoordinatorEventLogger logger; |  | 
| 33   std::vector<std::string> log; |  | 
| 34 |  | 
| 35   logger.SetIsLogging(true); |  | 
| 36   logger.RecordOfflinerResult(kNamespace, kOfflinerStatus, kId); |  | 
| 37   logger.RecordDroppedSavePageRequest(kNamespace, kDroppedResult, kId); |  | 
| 38   logger.RecordUpdateRequestFailed(kNamespace, kQueueUpdateResult); |  | 
| 39   logger.GetLogs(&log); |  | 
| 40 |  | 
| 41   EXPECT_EQ(3u, log.size()); |  | 
| 42   EXPECT_EQ(std::string(kQueueUpdateResultLogString), |  | 
| 43             log[0].substr(kTimeLength)); |  | 
| 44   EXPECT_EQ(std::string(kDroppedResultLogString), log[1].substr(kTimeLength)); |  | 
| 45   EXPECT_EQ(std::string(kOfflinerStatusLogString), log[2].substr(kTimeLength)); |  | 
| 46 } |  | 
| 47 |  | 
| 48 TEST(RequestCoordinatorEventLoggerTest, RecordsWhenLoggingIsOff) { |  | 
| 49   RequestCoordinatorEventLogger logger; |  | 
| 50   std::vector<std::string> log; |  | 
| 51 |  | 
| 52   logger.SetIsLogging(false); |  | 
| 53   logger.RecordOfflinerResult(kNamespace, kOfflinerStatus, kId); |  | 
| 54   logger.GetLogs(&log); |  | 
| 55 |  | 
| 56   EXPECT_EQ(0u, log.size()); |  | 
| 57 } |  | 
| 58 |  | 
| 59 TEST(RequestCoordinatorEventLoggerTest, DoesNotExceedMaxSize) { |  | 
| 60   RequestCoordinatorEventLogger logger; |  | 
| 61   std::vector<std::string> log; |  | 
| 62 |  | 
| 63   logger.SetIsLogging(true); |  | 
| 64   for (size_t i = 0; i < kMaxLogCount + 1; ++i) { |  | 
| 65     logger.RecordOfflinerResult(kNamespace, kOfflinerStatus, kId); |  | 
| 66   } |  | 
| 67   logger.GetLogs(&log); |  | 
| 68 |  | 
| 69   EXPECT_EQ(kMaxLogCount, log.size()); |  | 
| 70 } |  | 
| 71 |  | 
| 72 }  // namespace offline_pages |  | 
| OLD | NEW | 
|---|