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

Unified Diff: components/offline_pages/offline_page_model_impl_unittest.cc

Issue 2275833002: [Offline Pages] Don't remove user-requested pages when deleting cache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments. Created 4 years, 4 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_impl_unittest.cc
diff --git a/components/offline_pages/offline_page_model_impl_unittest.cc b/components/offline_pages/offline_page_model_impl_unittest.cc
index 55ea0b162ec5a7f34a69d0b4b68946d9d4074c4d..39dda8e40b89f08591f23fb9dcbdef64a16b061a 100644
--- a/components/offline_pages/offline_page_model_impl_unittest.cc
+++ b/components/offline_pages/offline_page_model_impl_unittest.cc
@@ -38,6 +38,7 @@ namespace offline_pages {
namespace {
const char kTestClientNamespace[] = "CLIENT_NAMESPACE";
+const char kUserRequestedNamespace[] = "download";
const GURL kTestUrl("http://example.com");
const GURL kTestUrl2("http://other.page.com");
const GURL kTestUrl3("http://test.xyz");
@@ -46,6 +47,7 @@ const GURL kFileUrl("file:///foo");
const ClientId kTestClientId1(kTestClientNamespace, "1234");
const ClientId kTestClientId2(kTestClientNamespace, "5678");
const ClientId kTestClientId3(kTestClientNamespace, "42");
+const ClientId kTestUserRequestedClientId(kUserRequestedNamespace, "714");
const int64_t kTestFileSize = 876543LL;
const base::string16 kTestTitle = base::UTF8ToUTF16("a title");
@@ -648,7 +650,41 @@ TEST_F(OfflinePageModelImplTest, DeletePageSuccessful) {
EXPECT_EQ(0u, store->GetAllPages().size());
}
-TEST_F(OfflinePageModelImplTest, DeletePageByPredicate) {
+TEST_F(OfflinePageModelImplTest, DeleteCachedPageByPredicateUserRequested) {
+ OfflinePageTestStore* store = GetStore();
+
+ // Save one page.
+ SavePage(kTestUrl, kTestClientId1);
+ int64_t offline1 = last_save_offline_id();
+ EXPECT_EQ(SavePageResult::SUCCESS, last_save_result());
+ EXPECT_EQ(1u, store->GetAllPages().size());
+
+ ResetResults();
+
+ // Save an user-requested page in same domain.
+ SavePage(kTestUrl, kTestUserRequestedClientId);
+ int64_t offline2 = last_save_offline_id();
+ EXPECT_EQ(SavePageResult::SUCCESS, last_save_result());
+ EXPECT_EQ(2u, store->GetAllPages().size());
+
+ ResetResults();
+
+ // Delete the second page.
+ model()->DeleteCachedPagesByURLPredicate(
+ base::Bind(&URLSpecContains, "example.com"),
+ base::Bind(&OfflinePageModelImplTest::OnDeletePageDone, AsWeakPtr()));
+
+ PumpLoop();
+
+ EXPECT_EQ(last_deleted_offline_id(), offline1);
+ EXPECT_EQ(last_deleted_client_id(), kTestClientId1);
+ EXPECT_EQ(DeletePageResult::SUCCESS, last_delete_result());
+ ASSERT_EQ(1u, store->GetAllPages().size());
+ EXPECT_EQ(kTestUrl, store->GetAllPages()[0].url);
+ EXPECT_EQ(offline2, store->GetAllPages()[0].offline_id);
+}
+
+TEST_F(OfflinePageModelImplTest, DeleteCachedPageByPredicate) {
OfflinePageTestStore* store = GetStore();
// Save one page.
@@ -668,7 +704,7 @@ TEST_F(OfflinePageModelImplTest, DeletePageByPredicate) {
ResetResults();
// Delete the second page.
- model()->DeletePagesByURLPredicate(
+ model()->DeleteCachedPagesByURLPredicate(
base::Bind(&URLSpecContains, "page.com"),
base::Bind(&OfflinePageModelImplTest::OnDeletePageDone, AsWeakPtr()));
@@ -683,7 +719,7 @@ TEST_F(OfflinePageModelImplTest, DeletePageByPredicate) {
ResetResults();
// Delete the first page.
- model()->DeletePagesByURLPredicate(
+ model()->DeleteCachedPagesByURLPredicate(
base::Bind(&URLSpecContains, "example.com"),
base::Bind(&OfflinePageModelImplTest::OnDeletePageDone, AsWeakPtr()));
@@ -704,7 +740,7 @@ TEST_F(OfflinePageModelImplTest, DeletePageNotFound) {
ResetResults();
- model()->DeletePagesByURLPredicate(
+ model()->DeleteCachedPagesByURLPredicate(
base::Bind(&URLSpecContains, "page.com"),
base::Bind(&OfflinePageModelImplTest::OnDeletePageDone, AsWeakPtr()));
PumpLoop();
« no previous file with comments | « components/offline_pages/offline_page_model_impl.cc ('k') | components/offline_pages/stub_offline_page_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698