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

Unified Diff: components/offline_pages/offline_page_storage_manager_unittest.cc

Issue 2026843003: [Offline Pages] Removing client in storage manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/offline_page_storage_manager_unittest.cc
diff --git a/components/offline_pages/offline_page_storage_manager_unittest.cc b/components/offline_pages/offline_page_storage_manager_unittest.cc
index 9a389585bded462ff1e5b915febcc7d939c2e0bc..d8a15e09206cdcee7b6ce34a710fff115765ce5c 100644
--- a/components/offline_pages/offline_page_storage_manager_unittest.cc
+++ b/components/offline_pages/offline_page_storage_manager_unittest.cc
@@ -15,7 +15,7 @@
#include "components/offline_pages/archive_manager.h"
#include "components/offline_pages/client_policy_controller.h"
#include "components/offline_pages/offline_page_item.h"
-#include "components/offline_pages/offline_page_storage_manager.h"
+#include "components/offline_pages/offline_page_model_impl.h"
#include "components/offline_pages/offline_page_types.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -27,8 +27,6 @@ using StorageStats = offline_pages::ArchiveManager::StorageStats;
namespace offline_pages {
namespace {
-const char kBookmarkNamespace[] = "bookmark";
-const char kLastNNamespace[] = "last_n";
const GURL kTestUrl("http://example.com");
const base::FilePath::CharType kFilePath[] = FILE_PATH_LITERAL("/data");
const int64_t kTestFileSize = 500 * (1 << 10);
@@ -48,11 +46,11 @@ struct PageSettings {
};
} // namespace
-class StorageManagerTestClient : public OfflinePageStorageManager::Client {
+class OfflinePageTestModel : public OfflinePageModelImpl {
public:
- StorageManagerTestClient(std::vector<PageSettings> page_settings,
- base::SimpleTestClock* clock,
- TestOptions options = TestOptions::DEFAULT)
+ OfflinePageTestModel(std::vector<PageSettings> page_settings,
+ base::SimpleTestClock* clock,
+ TestOptions options = TestOptions::DEFAULT)
: policy_controller_(new ClientPolicyController()),
clock_(clock),
options_(options),
@@ -61,7 +59,7 @@ class StorageManagerTestClient : public OfflinePageStorageManager::Client {
AddPages(setting);
}
- ~StorageManagerTestClient() override;
+ ~OfflinePageTestModel() override;
void GetAllPages(const MultipleOfflinePageItemCallback& callback) override {
MultipleOfflinePageItemResult pages;
@@ -101,7 +99,7 @@ class StorageManagerTestClient : public OfflinePageStorageManager::Client {
int64_t next_offline_id_;
};
-void StorageManagerTestClient::ExpirePages(
+void OfflinePageTestModel::ExpirePages(
const std::vector<int64_t>& offline_ids,
const base::Time& expiration_time,
const base::Callback<void(bool)>& callback) {
@@ -114,7 +112,7 @@ void StorageManagerTestClient::ExpirePages(
callback.Run(true);
}
-void StorageManagerTestClient::DeletePagesByOfflineId(
+void OfflinePageTestModel::DeletePagesByOfflineId(
const std::vector<int64_t>& offline_ids,
const DeletePageCallback& callback) {
if (options_ & TestOptions::DELETE_FAILURE) {
@@ -128,7 +126,7 @@ void StorageManagerTestClient::DeletePagesByOfflineId(
callback.Run(DeletePageResult::SUCCESS);
}
-int64_t StorageManagerTestClient::GetTotalSize() const {
+int64_t OfflinePageTestModel::GetTotalSize() const {
int64_t res = 0;
for (const auto& id_page_pair : pages_) {
if (!id_page_pair.second.IsExpired())
@@ -137,9 +135,9 @@ int64_t StorageManagerTestClient::GetTotalSize() const {
return res;
}
-StorageManagerTestClient::~StorageManagerTestClient() {}
+OfflinePageTestModel::~OfflinePageTestModel() {}
-void StorageManagerTestClient::AddPages(const PageSettings& setting) {
+void OfflinePageTestModel::AddPages(const PageSettings& setting) {
std::string name_space = setting.name_space;
int fresh_pages_count = setting.fresh_pages_count;
int expired_pages_count = setting.expired_pages_count;
@@ -188,7 +186,7 @@ class OfflinePageStorageManagerTest : public testing::Test {
public:
OfflinePageStorageManagerTest();
OfflinePageStorageManager* manager() { return manager_.get(); }
- StorageManagerTestClient* client() { return client_.get(); }
+ OfflinePageTestModel* model() { return model_.get(); }
ClientPolicyController* policy_controller() {
return policy_controller_.get();
}
@@ -213,7 +211,7 @@ class OfflinePageStorageManagerTest : public testing::Test {
private:
std::unique_ptr<OfflinePageStorageManager> manager_;
- std::unique_ptr<StorageManagerTestClient> client_;
+ std::unique_ptr<OfflinePageTestModel> model_;
std::unique_ptr<ClientPolicyController> policy_controller_;
std::unique_ptr<TestArchiveManager> archive_manager_;
@@ -237,16 +235,16 @@ void OfflinePageStorageManagerTest::Initialize(
std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock());
clock_ = clock.get();
clock_->SetNow(base::Time::Now());
- client_.reset(new StorageManagerTestClient(page_settings, clock_, options));
+ model_.reset(new OfflinePageTestModel(page_settings, clock_, options));
if (stats.free_disk_space == 0)
stats.free_disk_space = kFreeSpaceNormal;
if (stats.total_archives_size == 0) {
- stats.total_archives_size = client_->GetTotalSize();
+ stats.total_archives_size = model_->GetTotalSize();
}
archive_manager_.reset(new TestArchiveManager(stats));
manager_.reset(new OfflinePageStorageManager(
- client_.get(), policy_controller(), archive_manager_.get()));
+ model_.get(), policy_controller(), archive_manager_.get()));
manager_->SetClockForTesting(std::move(clock));
}
@@ -257,7 +255,7 @@ void OfflinePageStorageManagerTest::TryClearPages() {
void OfflinePageStorageManagerTest::TearDown() {
manager_.reset();
- client_.reset();
+ model_.reset();
}
void OfflinePageStorageManagerTest::OnPagesCleared(size_t pages_cleared_count,
@@ -275,7 +273,7 @@ TEST_F(OfflinePageStorageManagerTest, TestClearPagesLessThanLimit) {
EXPECT_EQ(2, last_cleared_page_count());
EXPECT_EQ(1, total_cleared_times());
EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
- EXPECT_EQ(0, static_cast<int>(client()->GetRemovedPages().size()));
+ EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
}
TEST_F(OfflinePageStorageManagerTest, TestClearPagesMoreThanLimit) {
@@ -286,7 +284,7 @@ TEST_F(OfflinePageStorageManagerTest, TestClearPagesMoreThanLimit) {
EXPECT_EQ(45, last_cleared_page_count());
EXPECT_EQ(1, total_cleared_times());
EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
- EXPECT_EQ(0, static_cast<int>(client()->GetRemovedPages().size()));
+ EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
}
TEST_F(OfflinePageStorageManagerTest, TestClearPagesMoreFreshPages) {
@@ -301,7 +299,7 @@ TEST_F(OfflinePageStorageManagerTest, TestClearPagesMoreFreshPages) {
EXPECT_EQ(1 + (100 - last_n_page_limit), last_cleared_page_count());
EXPECT_EQ(1, total_cleared_times());
EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
- EXPECT_EQ(0, static_cast<int>(client()->GetRemovedPages().size()));
+ EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
}
TEST_F(OfflinePageStorageManagerTest, TestDeletionFailed) {
@@ -312,7 +310,7 @@ TEST_F(OfflinePageStorageManagerTest, TestDeletionFailed) {
EXPECT_EQ(20, last_cleared_page_count());
EXPECT_EQ(1, total_cleared_times());
EXPECT_EQ(ClearStorageResult::DELETE_FAILURE, last_clear_storage_result());
- EXPECT_EQ(0, static_cast<int>(client()->GetRemovedPages().size()));
+ EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
}
TEST_F(OfflinePageStorageManagerTest, TestRemoveFromStoreFailure) {
@@ -323,7 +321,7 @@ TEST_F(OfflinePageStorageManagerTest, TestRemoveFromStoreFailure) {
EXPECT_EQ(10, last_cleared_page_count());
EXPECT_EQ(1, total_cleared_times());
EXPECT_EQ(ClearStorageResult::EXPIRE_FAILURE, last_clear_storage_result());
- EXPECT_EQ(0, static_cast<int>(client()->GetRemovedPages().size()));
+ EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
}
TEST_F(OfflinePageStorageManagerTest, TestBothFailure) {
@@ -343,7 +341,7 @@ TEST_F(OfflinePageStorageManagerTest, TestStorageTimeInterval) {
EXPECT_EQ(20, last_cleared_page_count());
EXPECT_EQ(1, total_cleared_times());
EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
- EXPECT_EQ(0, static_cast<int>(client()->GetRemovedPages().size()));
+ EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
// Advance clock so we go over the gap, but no expired pages.
clock()->Advance(kClearStorageInterval + base::TimeDelta::FromMinutes(1));
@@ -351,7 +349,7 @@ TEST_F(OfflinePageStorageManagerTest, TestStorageTimeInterval) {
EXPECT_EQ(0, last_cleared_page_count());
EXPECT_EQ(2, total_cleared_times());
EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
- EXPECT_EQ(0, static_cast<int>(client()->GetRemovedPages().size()));
+ EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
// Advance clock so we are still in the gap, should be unnecessary.
clock()->Advance(kClearStorageInterval - base::TimeDelta::FromMinutes(1));
@@ -359,7 +357,7 @@ TEST_F(OfflinePageStorageManagerTest, TestStorageTimeInterval) {
EXPECT_EQ(0, last_cleared_page_count());
EXPECT_EQ(3, total_cleared_times());
EXPECT_EQ(ClearStorageResult::UNNECESSARY, last_clear_storage_result());
- EXPECT_EQ(0, static_cast<int>(client()->GetRemovedPages().size()));
+ EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
}
TEST_F(OfflinePageStorageManagerTest, TestTwoStepExpiration) {
@@ -369,14 +367,14 @@ TEST_F(OfflinePageStorageManagerTest, TestTwoStepExpiration) {
EXPECT_EQ(10, last_cleared_page_count());
EXPECT_EQ(1, total_cleared_times());
EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
- EXPECT_EQ(0, static_cast<int>(client()->GetRemovedPages().size()));
+ EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
clock()->Advance(kRemovePageItemInterval + base::TimeDelta::FromDays(1));
TryClearPages();
EXPECT_EQ(10, last_cleared_page_count());
EXPECT_EQ(2, total_cleared_times());
EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
- EXPECT_EQ(10, static_cast<int>(client()->GetRemovedPages().size()));
+ EXPECT_EQ(10, static_cast<int>(model()->GetRemovedPages().size()));
}
TEST_F(OfflinePageStorageManagerTest, TestClearMultipleTimes) {
@@ -392,7 +390,7 @@ TEST_F(OfflinePageStorageManagerTest, TestClearMultipleTimes) {
EXPECT_EQ(1 + (100 - last_n_page_limit), last_cleared_page_count());
EXPECT_EQ(1, total_cleared_times());
EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
- EXPECT_EQ(0, static_cast<int>(client()->GetRemovedPages().size()));
+ EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
// Advance the clock by expiration period of last_n namespace, should be
// expiring all pages left in the namespace.
@@ -401,7 +399,7 @@ TEST_F(OfflinePageStorageManagerTest, TestClearMultipleTimes) {
EXPECT_EQ(last_n_page_limit, last_cleared_page_count());
EXPECT_EQ(2, total_cleared_times());
EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
- EXPECT_EQ(0, static_cast<int>(client()->GetRemovedPages().size()));
+ EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
// Only 1 ms passes and no changes in pages, so no need to clear page.
clock()->Advance(base::TimeDelta::FromMilliseconds(1));
@@ -409,34 +407,34 @@ TEST_F(OfflinePageStorageManagerTest, TestClearMultipleTimes) {
EXPECT_EQ(0, last_cleared_page_count());
EXPECT_EQ(3, total_cleared_times());
EXPECT_EQ(ClearStorageResult::UNNECESSARY, last_clear_storage_result());
- EXPECT_EQ(0, static_cast<int>(client()->GetRemovedPages().size()));
+ EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
// Adding more fresh pages to make it go over limit.
clock()->Advance(base::TimeDelta::FromMinutes(5));
- client()->AddPages({kBookmarkNamespace, 400, 0});
- int64_t total_size_before = client()->GetTotalSize();
+ model()->AddPages({kBookmarkNamespace, 400, 0});
+ int64_t total_size_before = model()->GetTotalSize();
int64_t available_space = 300 * (1 << 20); // 300 MB
test_archive_manager()->SetValues({available_space, total_size_before});
EXPECT_GE(total_size_before,
kOfflinePageStorageLimit * (available_space + total_size_before));
TryClearPages();
EXPECT_LE(total_size_before * kOfflinePageStorageClearThreshold,
- client()->GetTotalSize());
+ model()->GetTotalSize());
EXPECT_EQ(4, total_cleared_times());
EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
- EXPECT_EQ(0, static_cast<int>(client()->GetRemovedPages().size()));
+ EXPECT_EQ(0, static_cast<int>(model()->GetRemovedPages().size()));
int expired_page_count = last_cleared_page_count();
// After more days, all pages should be expired and .
clock()->Advance(kRemovePageItemInterval + base::TimeDelta::FromDays(1));
TryClearPages();
- EXPECT_EQ(0, client()->GetTotalSize());
+ EXPECT_EQ(0, model()->GetTotalSize());
EXPECT_EQ(5, total_cleared_times());
EXPECT_EQ(ClearStorageResult::SUCCESS, last_clear_storage_result());
// Number of removed pages should be the ones expired above and all the pages
// initially created for last_n namespace.
EXPECT_EQ(expired_page_count + 101,
- static_cast<int>(client()->GetRemovedPages().size()));
+ static_cast<int>(model()->GetRemovedPages().size()));
}
} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698