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

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

Issue 1977853004: [Offline pages] Adding ArchiveManager to abstract offline archives management (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding a missing destructor for OfflinePageStorageManager::Client Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « components/offline_pages/offline_page_storage_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/offline_pages/offline_page_storage_manager.h" 5 #include "components/offline_pages/offline_page_storage_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 base::SimpleTestClock* clock, 43 base::SimpleTestClock* clock,
44 TestOptions options = TestOptions::DEFAULT) 44 TestOptions options = TestOptions::DEFAULT)
45 : policy_controller_(new ClientPolicyController()), 45 : policy_controller_(new ClientPolicyController()),
46 clock_(clock), 46 clock_(clock),
47 options_(options), 47 options_(options),
48 next_offline_id_(0) { 48 next_offline_id_(0) {
49 for (const auto& setting : page_settings) 49 for (const auto& setting : page_settings)
50 AddPages(setting); 50 AddPages(setting);
51 } 51 }
52 52
53 ~StorageManagerTestClient() override;
54
53 void GetAllPages(const MultipleOfflinePageItemCallback& callback) override { 55 void GetAllPages(const MultipleOfflinePageItemCallback& callback) override {
54 callback.Run(pages_); 56 callback.Run(pages_);
55 } 57 }
56 58
57 void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, 59 void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids,
58 const DeletePageCallback& callback) override { 60 const DeletePageCallback& callback) override {
59 if (options_ & TestOptions::DELETE_FAILED) { 61 if (options_ & TestOptions::DELETE_FAILED) {
60 callback.Run(DeletePageResult::STORE_FAILURE); 62 callback.Run(DeletePageResult::STORE_FAILURE);
61 } else { 63 } else {
62 callback.Run(DeletePageResult::SUCCESS); 64 callback.Run(DeletePageResult::SUCCESS);
63 } 65 }
64 } 66 }
65 67
66 base::SimpleTestClock* clock() { return clock_; } 68 base::SimpleTestClock* clock() { return clock_; }
67 69
68 private: 70 private:
69 void AddPages(const PageSettings& setting); 71 void AddPages(const PageSettings& setting);
70 72
71 std::vector<OfflinePageItem> pages_; 73 std::vector<OfflinePageItem> pages_;
72 74
73 std::unique_ptr<ClientPolicyController> policy_controller_; 75 std::unique_ptr<ClientPolicyController> policy_controller_;
74 76
75 base::SimpleTestClock* clock_; 77 base::SimpleTestClock* clock_;
76 78
77 TestOptions options_; 79 TestOptions options_;
78 80
79 int64_t next_offline_id_; 81 int64_t next_offline_id_;
80 }; 82 };
81 83
84 StorageManagerTestClient::~StorageManagerTestClient() {}
85
82 void StorageManagerTestClient::AddPages(const PageSettings& setting) { 86 void StorageManagerTestClient::AddPages(const PageSettings& setting) {
83 std::string name_space = setting.name_space; 87 std::string name_space = setting.name_space;
84 int fresh_pages_count = setting.fresh_pages_count; 88 int fresh_pages_count = setting.fresh_pages_count;
85 int expired_pages_count = setting.expired_pages_count; 89 int expired_pages_count = setting.expired_pages_count;
86 base::Time now = clock()->Now(); 90 base::Time now = clock()->Now();
87 // Fresh pages. 91 // Fresh pages.
88 for (int i = 0; i < fresh_pages_count; i++) { 92 for (int i = 0; i < fresh_pages_count; i++) {
89 OfflinePageItem page = 93 OfflinePageItem page =
90 OfflinePageItem(kTestUrl, next_offline_id_, 94 OfflinePageItem(kTestUrl, next_offline_id_,
91 ClientId(name_space, std::to_string(next_offline_id_)), 95 ClientId(name_space, std::to_string(next_offline_id_)),
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 clock()->Advance(base::TimeDelta::FromMinutes(30)); 197 clock()->Advance(base::TimeDelta::FromMinutes(30));
194 manager()->ClearPagesIfNeeded(base::Bind( 198 manager()->ClearPagesIfNeeded(base::Bind(
195 &OfflinePageStorageManagerTest::OnPagesCleared, base::Unretained(this))); 199 &OfflinePageStorageManagerTest::OnPagesCleared, base::Unretained(this)));
196 int last_n_page_limit = policy_controller() 200 int last_n_page_limit = policy_controller()
197 ->GetPolicy(kLastNNamespace) 201 ->GetPolicy(kLastNNamespace)
198 .lifetime_policy.page_limit; 202 .lifetime_policy.page_limit;
199 EXPECT_EQ(1 + (100 - last_n_page_limit), last_cleared_page_count()); 203 EXPECT_EQ(1 + (100 - last_n_page_limit), last_cleared_page_count());
200 EXPECT_EQ(DeletePageResult::SUCCESS, last_delete_page_result()); 204 EXPECT_EQ(DeletePageResult::SUCCESS, last_delete_page_result());
201 } 205 }
202 } // namespace offline_pages 206 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_storage_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698