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

Unified Diff: components/offline_pages/offline_page_model_unittest.cc

Issue 1947323002: [Offline Pages] Implement OfflinePageStorageManager. (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_model_unittest.cc
diff --git a/components/offline_pages/offline_page_model_unittest.cc b/components/offline_pages/offline_page_model_unittest.cc
index ef5ad7f9f89fd491f1dfa1df1504fc79c5dc03d3..88758c247687486e7cb96f64dd9cb17b38f9f068 100644
--- a/components/offline_pages/offline_page_model_unittest.cc
+++ b/components/offline_pages/offline_page_model_unittest.cc
@@ -23,6 +23,7 @@
#include "base/time/time.h"
#include "components/offline_pages/offline_page_feature.h"
#include "components/offline_pages/offline_page_item.h"
+#include "components/offline_pages/offline_page_storage_manager.h"
#include "components/offline_pages/offline_page_test_archiver.h"
#include "components/offline_pages/offline_page_test_store.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -94,6 +95,7 @@ class OfflinePageModelTest
void OnGetMultipleOfflinePageItemsResult(
MultipleOfflinePageItemResult* storage,
const MultipleOfflinePageItemResult& result);
+ void OnClearPageByStorageManager(int pages_cleared);
// OfflinePageMetadataStore callbacks.
void OnStoreUpdateDone(bool /* success */);
@@ -162,6 +164,8 @@ class OfflinePageModelTest
const base::FilePath& last_archiver_path() { return last_archiver_path_; }
+ int last_cleared_pages_count() const { return last_cleared_pages_count_; }
+
private:
scoped_refptr<base::TestMockTimeTaskRunner> task_runner_;
base::ThreadTaskRunnerHandle task_runner_handle_;
@@ -176,6 +180,7 @@ class OfflinePageModelTest
ClientId last_deleted_client_id_;
bool last_has_pages_result_;
CheckPagesExistOfflineResult last_pages_exist_result_;
+ int last_cleared_pages_count_;
};
OfflinePageModelTest::OfflinePageModelTest()
@@ -381,6 +386,10 @@ void OfflinePageModelTest::OnGetMultipleOfflinePageItemsResult(
*storage = result;
}
+void OfflinePageModelTest::OnClearPageByStorageManager(int pages_cleared) {
+ last_cleared_pages_count_ = pages_cleared;
+}
+
base::Optional<OfflinePageItem> OfflinePageModelTest::GetPagesByOnlineURL(
const GURL& online_url) {
MultipleOfflinePageItemResult result;
@@ -929,6 +938,39 @@ TEST_F(OfflinePageModelTest, SaveRetrieveMultipleClientIds) {
EXPECT_TRUE(id_set.find(offline2) != id_set.end());
}
+TEST_F(OfflinePageModelTest, ClearPagesFromOneSource) {
+ base::Time now = base::Time::Now();
+ base::TimeDelta expiration_period = model()
+ ->GetPolicyController()
fgorski 2016/05/05 04:53:08 run "git cl format"
romax 2016/05/05 21:00:02 this is what I have after running that... and i kn
+ ->GetPolicy(kTestClientNamespace)
+ .lifetime_policy.expiration_period;
+
+ SavePage(kTestUrl, kTestClientId1);
+ GetStore()->UpdateLastAccessTime(
+ last_save_offline_id(),
+ now - base::TimeDelta::FromDays(10) - expiration_period);
+ SavePage(kTestUrl2, kTestClientId2);
+ GetStore()->UpdateLastAccessTime(
+ last_save_offline_id(),
+ now - base::TimeDelta::FromDays(1) - expiration_period);
+ SavePage(kTestUrl3, kTestClientId3);
+ GetStore()->UpdateLastAccessTime(last_save_offline_id(), now);
+
+ ResetModel();
+
+ // Only first two pages are expired.
+ model()->GetStorageManager()->ClearPagesIfNeeded(base::Bind(
+ &OfflinePageModelTest::OnClearPageByStorageManager, AsWeakPtr()));
+
+ PumpLoop();
+
+ const std::vector<OfflinePageItem>& offline_pages = GetAllPages();
fgorski 2016/05/05 04:53:08 don't use & here. returned value might not live lo
romax 2016/05/05 21:00:02 i didnt think i would do this... must be magic...
+
+ EXPECT_EQ(1UL, offline_pages.size());
+ EXPECT_EQ(1UL, GetStore()->GetAllPages().size());
+ EXPECT_EQ(2, last_cleared_pages_count());
+}
+
TEST(CommandLineFlagsTest, OfflineBookmarks) {
// Disabled by default.
EXPECT_FALSE(offline_pages::IsOfflineBookmarksEnabled());

Powered by Google App Engine
This is Rietveld 408576698