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

Side by Side Diff: components/offline_pages/offline_page_model_event_logger_unittest.cc

Issue 2489443002: Move all components/offline_pages/ files into component/offline_pages/core (Closed)
Patch Set: rebase Created 4 years 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 unified diff | Download patch
OLDNEW
(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/offline_page_model_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 kUrl[] = "http://www.wikipedia.org";
15 const char kOfflineId[] = "foobar";
16 const int kTimeLength = 21;
17 const char kPageSaved[] =
18 "http://www.wikipedia.org is saved at last_n with id foobar";
19 const char kPageDeleted[] = "Page with ID foobar has been deleted";
20 const char kPageExpired[] = "Page with ID foobar has been expired";
21 const char kRecordStoreClearError[] = "Offline store clear failed";
22 const char kRecordStoreCleared[] = "Offline store cleared";
23 const char kRecordStoreReloadError[] =
24 "There was an error reloading the offline store";
25
26 } // namespace
27
28 TEST(OfflinePageModelEventLoggerTest, RecordsWhenLoggingIsOn) {
29 OfflinePageModelEventLogger logger;
30 std::vector<std::string> log;
31
32 logger.SetIsLogging(true);
33 logger.RecordStoreCleared();
34 logger.RecordPageSaved(kNamespace, kUrl, kOfflineId);
35 logger.RecordPageDeleted(kOfflineId);
36 logger.RecordPageExpired(kOfflineId);
37 logger.RecordStoreClearError();
38 logger.RecordStoreReloadError();
39 logger.GetLogs(&log);
40
41 EXPECT_EQ(6u, log.size());
42 EXPECT_EQ(std::string(kRecordStoreCleared), log[5].substr(kTimeLength));
43 EXPECT_EQ(std::string(kPageSaved), log[4].substr(kTimeLength));
44 EXPECT_EQ(std::string(kPageDeleted), log[3].substr(kTimeLength));
45 EXPECT_EQ(std::string(kPageExpired), log[2].substr(kTimeLength));
46 EXPECT_EQ(std::string(kRecordStoreClearError), log[1].substr(kTimeLength));
47 EXPECT_EQ(std::string(kRecordStoreReloadError), log[0].substr(kTimeLength));
48 }
49
50 TEST(OfflinePageModelEventLoggerTest, DoesNotRecordWhenLoggingIsOff) {
51 OfflinePageModelEventLogger logger;
52 std::vector<std::string> log;
53
54 logger.SetIsLogging(false);
55 logger.RecordStoreCleared();
56 logger.RecordPageSaved(kNamespace, kUrl, kOfflineId);
57 logger.RecordPageDeleted(kOfflineId);
58 logger.RecordPageExpired(kOfflineId);
59 logger.RecordStoreClearError();
60 logger.RecordStoreReloadError();
61 logger.GetLogs(&log);
62
63 EXPECT_EQ(0u, log.size());
64 }
65
66 TEST(OfflinePageModelEventLoggerTest, DoesNotExceedMaxSize) {
67 OfflinePageModelEventLogger logger;
68 std::vector<std::string> log;
69
70 logger.SetIsLogging(true);
71 for (size_t i = 0; i < kMaxLogCount + 1; ++i) {
72 logger.RecordStoreCleared();
73 }
74 logger.GetLogs(&log);
75
76 EXPECT_EQ(kMaxLogCount, log.size());
77 }
78
79 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model_event_logger.cc ('k') | components/offline_pages/offline_page_model_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698