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

Side by Side Diff: components/history/core/browser/expire_history_backend_unittest.cc

Issue 2903573002: [Thumbnails DB] Add functionality to clear unused on-demand favicons. (Closed)
Patch Set: Peter's comments #3 Created 3 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/history/core/browser/expire_history_backend.h" 5 #include "components/history/core/browser/expire_history_backend.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
17 #include "base/files/scoped_temp_dir.h" 17 #include "base/files/scoped_temp_dir.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/run_loop.h" 19 #include "base/run_loop.h"
20 #include "base/scoped_observer.h" 20 #include "base/scoped_observer.h"
21 #include "base/strings/string16.h" 21 #include "base/strings/string16.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "base/test/scoped_feature_list.h"
23 #include "base/test/scoped_task_environment.h" 24 #include "base/test/scoped_task_environment.h"
24 #include "components/history/core/browser/history_backend_client.h" 25 #include "components/history/core/browser/history_backend_client.h"
25 #include "components/history/core/browser/history_backend_notifier.h" 26 #include "components/history/core/browser/history_backend_notifier.h"
26 #include "components/history/core/browser/history_constants.h" 27 #include "components/history/core/browser/history_constants.h"
27 #include "components/history/core/browser/history_database.h" 28 #include "components/history/core/browser/history_database.h"
28 #include "components/history/core/browser/thumbnail_database.h" 29 #include "components/history/core/browser/thumbnail_database.h"
29 #include "components/history/core/browser/top_sites.h" 30 #include "components/history/core/browser/top_sites.h"
30 #include "components/history/core/browser/top_sites_impl.h" 31 #include "components/history/core/browser/top_sites_impl.h"
31 #include "components/history/core/browser/top_sites_observer.h" 32 #include "components/history/core/browser/top_sites_observer.h"
32 #include "components/history/core/common/thumbnail_score.h" 33 #include "components/history/core/common/thumbnail_score.h"
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 EXPECT_EQ(0U, visits.size()); 884 EXPECT_EQ(0U, visits.size());
884 885
885 // Verify that the early expiration threshold was updated, since there are no 886 // Verify that the early expiration threshold was updated, since there are no
886 // AUTO_SUBFRAME visits in the given time range. 887 // AUTO_SUBFRAME visits in the given time range.
887 EXPECT_TRUE(now <= main_db_->GetEarlyExpirationThreshold()); 888 EXPECT_TRUE(now <= main_db_->GetEarlyExpirationThreshold());
888 889
889 // Now, read all visits and verify that there's at least one. 890 // Now, read all visits and verify that there's at least one.
890 EXPECT_TRUE(all->Read(now, main_db_.get(), &visits, 1)); 891 EXPECT_TRUE(all->Read(now, main_db_.get(), &visits, 1));
891 EXPECT_EQ(1U, visits.size()); 892 EXPECT_EQ(1U, visits.size());
892 } 893 }
893 894
pkotwicz 2017/07/07 00:42:38 Can you please add comments for these test cases
jkrcal 2017/07/07 08:45:16 Done.
895 TEST_F(ExpireHistoryTest, ClearOldOnDemandFaviconsDoesDeleteUnstarred) {
896 base::test::ScopedFeatureList feature_list;
897 feature_list.InitAndEnableFeature(internal::kClearOldOnDemandFavicons);
898
899 const unsigned char kBlob1[] =
900 "12346102356120394751634516591348710478123649165419234519234512349134";
901 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1));
902 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data));
903
904 // Icon: old and not bookmarked case.
905 GURL url("http://google.com");
906 favicon_base::FaviconID icon =
907 thumb_db_->AddFavicon(url, favicon_base::FAVICON);
908 ASSERT_NE(0, icon);
909 FaviconBitmapID bitmap = thumb_db_->AddFaviconBitmap(
910 icon, favicon, FaviconBitmapType::ON_DEMAND,
911 base::Time::Now() - base::TimeDelta::FromDays(100), gfx::Size());
pkotwicz 2017/07/07 00:42:38 Can you please use the 6 argument version of Thumb
jkrcal 2017/07/07 08:45:16 Ah, good point. I also expanded the second test a
912 ASSERT_NE(0, bitmap);
913 ASSERT_NE(0, thumb_db_->AddIconMapping(url, icon));
914
915 expirer_.ClearOldOnDemandFavicons(base::Time::Now() -
916 base::TimeDelta::FromDays(90));
917
918 // The icon gets deleted.
919 EXPECT_FALSE(thumb_db_->GetIconMappingsForPageURL(url, nullptr));
920 EXPECT_FALSE(thumb_db_->GetFaviconHeader(icon, nullptr, nullptr));
921 EXPECT_FALSE(thumb_db_->GetFaviconBitmaps(icon, nullptr));
922 }
923
924 TEST_F(ExpireHistoryTest, ClearOldOnDemandFaviconsDoesNotDeleteStarred) {
925 base::test::ScopedFeatureList feature_list;
926 feature_list.InitAndEnableFeature(internal::kClearOldOnDemandFavicons);
927
928 const unsigned char kBlob1[] =
929 "12346102356120394751634516591348710478123649165419234519234512349134";
930 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1));
931 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data));
932
933 // Icon: old but bookmarked case.
934 GURL url("http://google.com");
935 StarURL(url);
936 favicon_base::FaviconID icon =
937 thumb_db_->AddFavicon(url, favicon_base::FAVICON);
938 ASSERT_NE(0, icon);
939 FaviconBitmapID bitmap = thumb_db_->AddFaviconBitmap(
940 icon, favicon, FaviconBitmapType::ON_DEMAND,
941 base::Time::Now() - base::TimeDelta::FromDays(100), gfx::Size());
942 ASSERT_NE(0, bitmap);
943 ASSERT_NE(0, thumb_db_->AddIconMapping(url, icon));
944
945 expirer_.ClearOldOnDemandFavicons(base::Time::Now() -
946 base::TimeDelta::FromDays(90));
947
948 // Nothing gets deleted.
949 EXPECT_TRUE(thumb_db_->GetFaviconHeader(icon, nullptr, nullptr));
950 std::vector<FaviconBitmap> favicon_bitmaps;
951 EXPECT_TRUE(thumb_db_->GetFaviconBitmaps(icon, &favicon_bitmaps));
952 EXPECT_EQ(1u, favicon_bitmaps.size());
953 std::vector<IconMapping> icon_mapping;
954 EXPECT_TRUE(thumb_db_->GetIconMappingsForPageURL(url, &icon_mapping));
955 EXPECT_EQ(1u, icon_mapping.size());
956 EXPECT_EQ(icon, icon_mapping[0].icon_id);
957 }
958
894 // TODO(brettw) add some visits with no URL to make sure everything is updated 959 // TODO(brettw) add some visits with no URL to make sure everything is updated
895 // properly. Have the visits also refer to nonexistent FTS rows. 960 // properly. Have the visits also refer to nonexistent FTS rows.
896 // 961 //
897 // Maybe also refer to invalid favicons. 962 // Maybe also refer to invalid favicons.
898 963
899 } // namespace history 964 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698